Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

model-coerce

Conversion between a model object and a restriction matrix


Description

Testing a small model under a large model corresponds imposing restrictions on the model matrix of the larger model and these restrictions come in the form of a restriction matrix. These functions converts a model to a restriction matrix and vice versa.

Usage

model2remat(largeModel, smallModel, sparse = FALSE)

remat2model(largeModel, L, REML = TRUE, ...)

make_modelmat(X, L)

make_remat(X, X2)

Arguments

largeModel, smallModel

Model objects of the same "type". Possible types are linear mixed effects models and linear models (including generalized linear models)

sparse

Should the restriction matrix be sparse or dense?

L

A restriction matrix; a full rank matrix with as many columns as 'X' has.

REML

Controls if new model object should be fitted with REML or ML.

...

Additional arguments; not used.

X, X2

Model matrices. Must have same numer of rows.

Details

'make_remat' Make a restriction matrix. If span(X2) is in span(X) then the corresponding restriction matrix 'L' is returned.

Value

model2remat: A restriction matrix. remat2model: A model object.

Note

That these functions are visible is a recent addition; minor changes may occur.

Author(s)

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

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/

See Also

Examples

library(pbkrtest)
data("beets", package = "pbkrtest")
sug <- lm(sugpct ~ block + sow + harvest, data=beets)
sug.h <- update(sug, .~. - harvest)
sug.s <- update(sug, .~. - sow)

## Construct restriction matrices from models
L.h <- model2remat(sug, sug.h); L.h
L.s <- model2remat(sug, sug.s); L.s

## Construct submodels from restriction matrices
mod.h <- remat2model(sug, L.h); mod.h
mod.s <- remat2model(sug, L.s); mod.s

## Sanity check: The models have the same fitted values and log likelihood
plot(fitted(mod.h), fitted(sug.h))
plot(fitted(mod.s), fitted(sug.s))
logLik(mod.h)
logLik(sug.h)
logLik(mod.s)
logLik(sug.s)

pbkrtest

Parametric Bootstrap, Kenward-Roger and Satterthwaite Based Methods for Test in Mixed Models

v0.5.1
GPL (>= 2)
Authors
Ulrich Halekoh [aut, cph], Søren Højsgaard [aut, cre, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.