get_nested_model_info.RdConstructs or extracts a nested model (fit0) from a full model (fit1)
using flexible input: a model object, formula, character string, or matrix.
This function is useful for preparing models for comparison, e.g., via likelihood ratio test.
get_nested_model_info(fit1, fit0)A list with:
Formula for fit1.
Formula for resolved fit0.
The full model fit1.
The nested model fit0.
Restriction matrix defining the nested model.
if (requireNamespace("lme4", quietly = TRUE)) {
library(lme4)
data(sleepstudy)
fit1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
fit0 <- lmer(Reaction ~ (Days | Subject), sleepstudy)
get_nested_model_info(fit1, fit0) # as model object
get_nested_model_info(fit1, ~ . - Days) # as formula
get_nested_model_info(fit1, "Days") # as string
## get_nested_model_info(fit1, c(0, 1)) # numeric (converted to matrix)
}
#> $formula.large
#> Reaction ~ Days + (Days | Subject)
#>
#> $formula.small
#> Reaction ~ (Days | Subject)
#>
#> $largeModel
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: Reaction ~ Days + (Days | Subject)
#> Data: sleepstudy
#> REML criterion at convergence: 1743.628
#> Random effects:
#> Groups Name Std.Dev. Corr
#> Subject (Intercept) 24.741
#> Days 5.922 0.07
#> Residual 25.592
#> Number of obs: 180, groups: Subject, 18
#> Fixed Effects:
#> (Intercept) Days
#> 251.41 10.47
#>
#> $smallModel
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: Reaction ~ (Days | Subject)
#> Data: sleepstudy
#> REML criterion at convergence: 1769.845
#> Random effects:
#> Groups Name Std.Dev. Corr
#> Subject (Intercept) 25.53
#> Days 11.93 -0.18
#> Residual 25.59
#> Number of obs: 180, groups: Subject, 18
#> Fixed Effects:
#> (Intercept)
#> 257.8
#>
#> $L
#> [,1] [,2]
#> [1,] 0 1
#>