Skip to contents

Drops each fixed-effect term of the primary (mu) formula in turn, refits, and tabulates AIC (and likelihood-ratio tests with test = "Chisq"), following stats::drop1() and lme4's drop1.merMod. Random-effect, smooth, and mo()/mi() terms are not part of the deletion scope.

Usage

# S3 method for class 'frmtmb_fit'
drop1(object, scope, test = c("none", "Chisq"), k = 2, ...)

Arguments

object

A frmtmb_fit from an ML fit (REML = FALSE) of a univariate model.

scope

Terms to drop: a character vector or a right-hand-side formula. Defaults to all fixed-effect terms that marginality allows (stats::drop.scope()).

test

"Chisq" adds likelihood-ratio tests.

k

AIC penalty per parameter.

...

Refused: an argument the method does not have is an error naming it, rather than silently changing nothing.

Value

An anova table with one row per dropped term.

Details

A family without a mu gives the main formula to every location predictor that has no formula of its own: each category of categorical(), multinomial(), dirichlet() and logistic_normal(), and each component of a mixture(). A dropped term leaves all of them at once, as nnet::multinom()'s drop1() drops it from every logit.

Each refit reads the data the fit holds (see update.frmtmb_fit()), on the rows the fit used, so a term such as log(x), scale(x) or splines::ns(x, 3) is evaluated again from x, and the table does not depend on the data object in the workspace. The terms a refit keeps keep the fit's bases: scale(x) keeps the center and scale, and ns() and poly() the knots and coefficients, that the fit computed from every row of the data before na.action. So each submodel is nested in the fit, and on a linear or generalized linear model the statistics are those of stats::drop1(). A fit whose prior adds a log density to the objective is refused, as in anova.frmtmb_fit().

Examples

set.seed(1)
dd <- data.frame(x = rnorm(100), z = rnorm(100),
                 g = factor(rep(1:10, 10)))
dd$y <- rnorm(100, 1 + 0.5 * dd$x + rnorm(10, 0, 0.8)[dd$g], 1)
fit <- frm(bf(y ~ x * z + (1 | g)) + gaussian(), data = dd)

# marginality keeps the main effects out of scope while x:z is in it
drop1(fit)
#> Single term deletions
#> 
#> Model: y ~ x * z + (1 | g)
#> 
#>        Df    AIC
#> <none>    313.20
#> x:z     1 315.12
drop1(fit, test = "Chisq")
#> Single term deletions
#> 
#> Model: y ~ x * z + (1 | g)
#> 
#>        Df    AIC    LRT Pr(>Chi)  
#> <none>    313.20                  
#> x:z     1 315.12 3.9187  0.04775 *
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

# name the terms to override the default scope
drop1(fit, scope = ~ x + z, test = "Chisq")
#> Single term deletions
#> 
#> Model: y ~ x * z + (1 | g)
#> 
#>        Df    AIC     LRT  Pr(>Chi)    
#> <none>    313.20                      
#> x       1 328.23 17.0327 3.674e-05 ***
#> z       1 312.12  0.9277    0.3355    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1