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.

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

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`

.

```
data("Orthodont")
# using nlme, with correlated slope and intercept
m1.nlme <- lme(distance ~ 1 + Sex + age + age*Sex, random = pdDiag(Subject ~ 1 + age), data = Orthodont, method = "ML")
m0.nlme <- lme(distance ~ 1 + Sex + age + age*Sex, random = ~ 1 | Subject, data = Orthodont, method = "ML")
# using lme4, with correlated slope and intercept
m1.lme4 <- lmer(distance ~ 1 + Sex + age + age*Sex + (1 + age | Subject), data = Orthodont, REML = FALSE)
```

```
#> Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
#> Model failed to converge with max|grad| = 0.0464695 (tol = 0.002, component 1)
```

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

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.

```
m0noRE <- lm(distance ~ 1 + Sex + age + age*Sex, data = Orthodont)
vt <- varTest(m1diag.nlme,m0noRE,pval.comp = "both")
summary(vt)
```

```
#> Length Class Mode
#> 1 varTestObject S4
```

```
#> Length Class Mode
#> 1 varTestObject S4
```

By default, the FIM is extracted from the packages, but it is also possible to compute it via parametric bootstrap. In this case, simply use the option `fim="compute"`

. The default bootstrap sampling size is `B=1000`

but it can be changed. To get the exact p-value one can use

```
#> Length Class Mode
#> 1 varTestObject S4
```

```
#> Length Class Mode
#> 1 varTestObject S4
```

```
# with nlme
fm1Theo.nlme <- nlme(conc ~ SSfol(Dose, Time, lKe, lKa, lCl),
Theoph,
fixed = lKe + lKa + lCl ~ 1,
start=c( -2.4, 0.45, -3.2),
random = pdSymm(lKa + lCl ~ 1))
fm2Theo.nlme <- nlme(conc ~ SSfol(Dose, Time, lKe, lKa, lCl),
Theoph,
fixed = lKe + lKa + lCl ~ 1,
start=c( -2.4, 0.45, -3.2),
random = pdDiag(lCl ~ 1))
varTest(fm1Theo.nlme,fm2Theo.nlme, pval.comp = "both")
# with lme4
Th.start <- c(lKe = -2.4, lKa = 0.45, lCl = -3.2)
nm1 <- nlmer(conc ~ SSfol(Dose , Time ,lKe , lKa , lCl) ~
0+lKe+lKa+lCl +(lKe+lKa+lCl|Subject),
nAGQ=0,
Theoph,
start = Th.start)
nm0 <- nlmer(conc ~ SSfol(Dose , Time ,lKe , lKa , lCl) ~
0+lKe+lKa+lCl +(lKa+lCl|Subject),
nAGQ=0,
Theoph,
start = Th.start)
varTest(nm1,nm0)
```

Testing for the presence of randomness in the model.