`R/generics.R`

, `R/varCompTest.lme.R`

, `R/varCompTest.merMod.R`

, and 1 more
`varCompTest.Rd`

Perform a likelihood ratio test to test whether a subset of the variances of the random effects
are equal to zero. The test is defined by two hypotheses, H0 and H1, and the model under H0 is
assumed to be nested within the model under H1. These functions can be used on objects of class
`lme`

-, `nlme`

-, `mer`

-, `lmerMod`

, `glmerMod`

, `nlmerMord`

or `SaemixObject`

.

It is possible to tests if any subset of the variances are equal to zero. However, the function does not currently support nested random effects, and assumes that the random effects are Gaussian.

```
varCompTest(
m1,
m0,
control = list(M = 5000, parallel = T, nb_cores = 1, B = 1000),
pval.comp = "bounds",
fim = "extract",
output = TRUE
)
# S3 method for lme
varCompTest(
m1,
m0,
control = list(M = 5000, parallel = FALSE, nb_cores = 1, B = 1000),
pval.comp = "bounds",
fim = "extract",
output = TRUE
)
# S3 method for merMod
varCompTest(
m1,
m0,
control = list(M = 5000, parallel = FALSE, nb_cores = 1, B = 1000),
pval.comp = "bounds",
fim = "extract",
output = TRUE
)
# S3 method for SaemixObject
varCompTest(
m1,
m0,
control = list(M = 5000, parallel = FALSE, nb_cores = 1, B = 1000),
pval.comp = "bounds",
fim = "extract",
output = TRUE
)
```

- m1
a fit of the model under H1, obtained from

`nlme`

,`lme4`

or`saemix`

- m0
a fit of the model under H0, obtained from the same package as

`m0`

- control
(optional) a list of control options for the computation of the chi-bar-weights (see Details section)

- pval.comp
(optional) the method to be used to compute the p-value, one of:

`"bounds"`

(the default),`"approx"`

or`"both"`

(see Details section)- fim
(optional) the method to compute the Fisher Information Matrix. Options are:

`fim="extract"`

to extract the FIM computed by the package which was used to fit the models,`fim="compute"`

to evaluate the FIM using parametric bootstrap, and`fim=I`

with`I`

a positive semidefinite matrix, for a FIM provided by the user.- output
a boolean specifying if any output should be printed in the console (default to TRUE)

An object of class `htest`

with the following components:

`statistic`

the likelihood ratio test statistics`null.value`

`alternative`

`parameters`

the parameters of the limiting chi-bar-square distribution: the degrees of freedom and the weights of the chi-bar-square components and the Fisher Information Matrix`method`

a character string indicating the name of the test`pvalue`

a named vector containing the different p-values computed by the function: using the (estimated) weights, using the random sample from the chi-bar-square distribution, and the two bounds on the p-value.

The asymptotic distribution of the likelihood ratio test is a chi-bar-square, with weights that need to be
approximated by Monte Carlo methods, apart from some specific cases where they are available explicitly.
Therefore, the p-value of the test is not exact but approximated. This computation can be time-consuming, so
the default behaviour of the function is to provide bounds on the exact p-value, which can be enough in practice
to decide whether to reject or not the null hypothesis. This is triggered by the option `pval.comp="bounds"`

.
To compute an approximation of the exact p-value, one should use the option `pval.comp="approx"`

or `pval.comp="both"`

.

When `pval.comp="approx"`

or `pval.comp="both"`

, the weights of the chi-bar-square distribution are computed using Monte Carlo,
which might involve a larger computing time.

The `control`

argument controls the options for chi-bar-square weights computation. It is a list with the
following elements: `M`

the size of the Monte Carlo simulation, i.e. the number of samples generated, `parallel`

a
boolean to specify if parallel computing should be used, and `nbcores`

the number of cores to be used in case of
parallel computing. Default is `M=5000`

, `parallel=FALSE`

and `nb_cores=1`

.
If `parallel=TRUE`

but the value of `nb_cores`

is not given, then it is set to the number of detected
cores minus 1

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
Statistics and Data Analysis* 135:107-122.

Silvapulle MJ, Sen PK, 2011. Constrained statistical inference: order, inequality and shape constraints.

```
# load lme4 package and example dataset
library(lme4)
#> Loading required package: Matrix
data(Orthodont, package = "nlme")
# fit the two models under H1 and H0
m1 <- lmer(distance ~ 1 + Sex + age + age*Sex +
(0 + age | Subject), data = Orthodont, REML = FALSE)
m0 <- lm(distance ~ 1 + Sex + age + age*Sex, data = Orthodont)
# compare them (order is important: m1 comes first)
varCompTest(m1,m0,pval.comp="bounds")
#> 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 = 46.58827
#>
#> p-value from exact weights: 4.379151e-12
#>
# using nlme
library(nlme)
#>
#> Attaching package: ‘nlme’
#> The following object is masked from ‘package:lme4’:
#>
#> lmList
m1 <- lme(distance ~ 1 + Sex + age + age*Sex,
random = pdSymm(Subject ~ 1 + age), data = Orthodont, method = "ML")
m0 <- lme(distance ~ 1 + Sex, random = ~ 1 | Subject, data = Orthodont, method = "ML")
varCompTest(m1,m0)
#> Variance components testing in mixed effects models
#> Testing that the means of the random effects associated to age and SexFemale:age are equal to 0 and that
#> the variance of the random effect associated to age is equal to 0
#> Likelihood ratio test statistic:
#> LRT = 79.15214
#>
#> p-value from exact weights: 1.550226e-16
#>
```