# kr-modcomp: Ftest and degrees of freedom based on Kenward-Roger... In hojsgaard/pbkrtest: Parametric Bootstrap and Kenward Roger Based Methods for Mixed Model Comparison

## Description

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

## Usage

 ```1 2 3 4 5 6 7``` ```KRmodcomp(largeModel, smallModel, betaH = 0, details = 0) ## S3 method for class 'lmerMod' KRmodcomp(largeModel, smallModel, betaH = 0, details = 0) ## S3 method for class 'mer' 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. betaH=0 if modelSmall is a model not a restriction matrix. `details` If larger than 0 some timing details are printed. `...` Additional arguments to print function

## Details

The model `object` must be fitted with restricted maximum likelihood (i.e. with `REML=TRUE`). If the object is fitted with maximum likelihood (i.e. 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.

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 sum of known matrices can be compared.

The `largeModel` may be a model fitted with `lmer` either using `REML=TRUE` or `REML=FALSE`. The `smallModel` can be 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`. The model `smallModel` can also be a restriction matrix `L` specifying the hypothesis L β = L β_H, where L is a k X p matrix and β is a p column vector the same length as `fixef(largeModel)`.

The β_H is a p column vector.

Notice: if you want to test a hypothesis L β = c with a k vector c, a suitable β_H is obtained via β_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!

## Note

This functionality is not thoroughly tested and should be used with care. Please do report bugs etc.

## Author(s)

Ulrich Halekoh [email protected], S<c3><b8>ren H<c3><b8>jsgaard [email protected]

## References

Ulrich Halekoh, S<c3><b8>ren H<c3><b8>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., http://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.

`getKR`, `lmer`, `vcovAdj`, `PBmodcomp`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15``` ```(fmLarge <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)) ## removing Days (fmSmall <- lmer(Reaction ~ 1 + (Days|Subject), sleepstudy)) anova(fmLarge,fmSmall) KRmodcomp(fmLarge,fmSmall) ## The same test using a restriction matrix L <- cbind(0,1) KRmodcomp(fmLarge, L) ## Same example, but with independent intercept and slope effects: m.large <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject), data = sleepstudy) m.small <- lmer(Reaction ~ 1 + (1|Subject) + (0+Days|Subject), data = sleepstudy) anova(m.large, m.small) KRmodcomp(m.large, m.small) ```