varTestnlme implements the likelihood ratio test (LRT) for testing the presence of random effects in linear, generalized linear and nonlinear mixed-effects model. The test can be used to answer questions of the type:
It is possible to compare two models with different random effects, provided that the random structures of the two models are nested.
Baey C, Kuhn E, 2023. varTestnlme: An R Package for Variance Components Testing in Linear and Nonlinear Mixed-Effects Models. Journal of Statistical Software. https://doi.org/10.18637/jss.v107.i06
Baey C, Cournède P-H, Kuhn E, 2019. Asymptotic distribution of likelihood ratio test statistics for variance components in nonlinear mixed effects models. Computational Statistic and Data Analysis. 135:107–122 (2019), https://doi.org/10.1016/j.csda.2019.01.014
Install from CRAN:
Or install the development version from Github:
An example using the
Since version 1.0.0, the name of the main function has been changed from
varCompTest due to a conflict with an existing function from package
library(nlme) data("Orthodont") # using nlme, with correlated slope and intercept m1 <- lme(distance ~ 1 + Sex + age + age*Sex, random = pdSymm(Subject ~ 1 + age), data = Orthodont, method = "ML") m0 <- lme(distance ~ 1 + Sex + age + age*Sex, random = ~ 1 | Subject, data = Orthodont, method = "ML") vt <- varCompTest(m1,m0) #> Variance components testing in mixed effects models #> Testing that the variance of the random effect associated to age is equal to 0 #> Likelihood ratio test statistic: #> LRT = 0.8331072 #> #> p-value from exact weights: 0.5103454 #>
It works similarly with lme4 package or saemix.