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.

The package works on models that were fitted using nlme, lme4, or saemix packages.


Baey C, Cournède P-H, Kuhn E, 2019. Asymptotic distribution of likelihood ratio test statistics for variance components in nonlinear mixed effects models. 135:107–122 (2019),


Install from CRAN:


Or install the development version from Github:



An example using the nlme package.

Since version 1.0.0, the name of the main function has been changed from varTest to varCompTest due to a conflict with an existing function from package EnvStats.


# 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.