Learn R Programming

pbkrtest (version 0.5.3)

kr_modcomp: F-test and degrees of freedom based on Kenward-Roger approximation

Description

An approximate F-test based on the Kenward-Roger approach.

Usage

KRmodcomp(largeModel, smallModel, betaH = 0, details = 0)

# S3 method for lmerMod KRmodcomp(largeModel, smallModel, betaH = 0, details = 0)

Arguments

largeModel

An lmer model

smallModel

An lmer model or a restriction matrix

betaH

A number or a vector of the beta of the hypothesis, e.g. L beta=L betaH. If smallModel is a model object then betaH=0.

details

If larger than 0 some timing details are printed.

Author

Ulrich Halekoh uhalekoh@health.sdu.dk, Søren Højsgaard sorenh@math.aau.dk

Details

An F test is calculated according to the approach of Kenward and Roger (1997). The function works for linear mixed models fitted with the lmer() function of the lme4 package. Only models where the covariance structure is a linear combination (a weighted sum) of known matrices can be compared.

The smallModel is the model to be tested against the largeModel.

The largeModel is a model fitted with lmer(). A technical detail: The model must be fitted with REML=TRUE. If the model is fitted with REML=FALSE then the model is refitted with REML=TRUE before the p-values are calculated. Put differently, the user needs not worry about this issue.

The smallModel can be one of several things:

  1. a model fitted with lmer(). It must have the same covariance structure as largeModel. Furthermore, its linear space of expectation must be a subspace of the space for largeModel.

  2. a restriction matrix L specifying the hypothesis $$L \beta = L \beta_H$$ where L is a k x p matrix (there are k restrictions and p is the number of fixed effect parameters (the length of fixef(largeModel)) and beta_H is a p column vector.

  3. A formula or a text string specifying what is to be removed from the larger model to form the smaller model.

Notice: if you want to test a hypothesis

$$L \beta = c$$

with a \(k\) vector \(c\), a suitable \(\beta_H\) is obtained via \(\beta_H=L c\) where \(L_n\) is a g-inverse of \(L\).

Notice: It cannot be guaranteed that the results agree with other implementations of the Kenward-Roger approach!

References

Ulrich Halekoh, Søren Højsgaard (2014)., A Kenward-Roger Approximation and Parametric Bootstrap Methods for Tests in Linear Mixed Models - The R Package pbkrtest., Journal of Statistical Software, 58(10), 1-30., https://www.jstatsoft.org/v59/i09/

Kenward, M. G. and Roger, J. H. (1997), Small Sample Inference for Fixed Effects from Restricted Maximum Likelihood, Biometrics 53: 983-997.

See Also

getKR, lmer, vcovAdj, PBmodcomp, SATmodcomp

Examples

Run this code

(fm0 <- lmer(Reaction ~ (Days|Subject), sleepstudy))
(fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy))
(fm2 <- lmer(Reaction ~ Days + I(Days^2) + (Days|Subject), sleepstudy))

## Test for no effect of Days in fm1, i.e. test fm0 under fm1
KRmodcomp(fm1, "Days")
KRmodcomp(fm1, ~.-Days)
L1 <- cbind(0, 1) 
KRmodcomp(fm1, L1)
KRmodcomp(fm1, fm0)
anova(fm1, fm0)

## Test for no effect of Days and Days-squared in fm2, i.e. test fm0 under fm2
KRmodcomp(fm2, "(Days+I(Days^2))")
KRmodcomp(fm2, ~. - Days - I(Days^2))
L2 <- rbind(c(0, 1, 0), c(0, 0, 1))
KRmodcomp(fm2, L2)
KRmodcomp(fm2, fm0)
anova(fm2, fm0)

## Test for no effect of Days-squared in fm2, i.e. test fm1 under fm2
KRmodcomp(fm2, "I(Days^2)")
KRmodcomp(fm2, ~. - I(Days^2))
L3 <- rbind(c(0, 0, 1))
KRmodcomp(fm2, L3)
KRmodcomp(fm2, fm1)
anova(fm2, fm1)

Run the code above in your browser using DataLab