Get started


The varTesnlme package is very easy to use. Below are small examples on how to run it for linear, generalized linear and nonlinear mixed-effect models.

Mixed-effect models can be run using nlme or lme4, but also using saemix. varTestnlme can be used to compare two nested models using likelihood ratio tests, where the variance of at least one random effect is tested equal to 0. Fixed effects can also be tested simultaneously, as well as covariances.

# Load the packages

Linear models

Here we focus on models run using lme4 and nlme, but saemix can also be used.

Testing the variance of one random effect

We illustrate the results on the Orthodont dataset, which is part of the nlme package. We are interested in modelling the distance between the pituitary annd the pterygomaxillary fissure (in mm) as a function of age, in 27 children. We will fit a random slope and random intercept model, and test whether the slope is random or not.

We first need to fit the two nested models: the full model corresponding to \(H_1\) and the null model corresponding to \(H_0\), where there is no random effect associated to age.

Now we can run the likelihood ratio test using the varTestnlme package.

For correlated slope and intercept using nlme

Testing the variances of all random effects

In the previous section, the weights of the chi-bar-square distribution where available explicitly. However, it is not always the case. By default, since the computation of these weights can be time consuming, the function is computing bounds on the p-value. In many cases this can be enough to decide whether to reject or not the null hypothesis. If more precision is wanted or needed, it is possible to specify it via the option pval.comp, which then needs to be set to either pval.comp="approx" or to pval.comp="both". In both cases, the control argument can be used to control the computation process. It is a list which contains three slots: M (default to 5000), the size of the Monte Carlo computation, parallel (default to FALSE) to specify whether computation should be parallelized, and nbcores (default to 1) to set the number of cores to be used in case of parallel computing.

To get the exact p-value one can use