R/modelCoercion.R
model-coerce.Rd
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.
model2restrictionMatrix(largeModel, smallModel) restrictionMatrix2model(largeModel, LL)
largeModel, smallModel | Model objects of the same "type". Possible types are linear mixed effects models and linear models (including generalized linear models) |
---|---|
LL | A restriction matrix. |
model2restrictionMatrix
: A restriction matrix.
restrictionMatrix2model
: A model object.
That these functions are visible is a recent addition; minor changes may occur.
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., http://www.jstatsoft.org/v59/i09/
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 <- model2restrictionMatrix(sug, sug.h); L.h#> 1 x 8 sparse Matrix of class "dgCMatrix" #> #> [1,] -2.220446e-16 1.01349e-16 . . . . . -1L.s <- model2restrictionMatrix(sug, sug.s); L.s#> 4 x 8 sparse Matrix of class "dgCMatrix" #> #> [1,] . . . -0.91766294 0.2294157 0.2294157 #> [2,] . . . 0.06362848 0.8907987 -0.3181424 #> [3,] . 1.665335e-16 . 0.10482848 0.1048285 0.8386279 #> [4,] -3.885781e-16 . -2.220446e-16 -0.37796447 -0.3779645 -0.3779645 #> #> [1,] 0.2294157 1.801957e-16 #> [2,] -0.3181424 -1.014701e-16 #> [3,] -0.5241424 . #> [4,] -0.7559289 .## Construct submodels from restriction matrices mod.h <- restrictionMatrix2model(sug, L.h); mod.h#> #> Call: #> lm(formula = sugpct ~ .X1 + .X2 + .X3 + .X4 + .X5 + .X6 + .X7 - #> 1, data = new.data) #> #> Coefficients: #> .X1 .X2 .X3 .X4 .X5 .X6 .X7 #> -0.0500 -0.0800 0.1167 0.1667 -0.1000 -0.3500 -16.8933 #>mod.s <- restrictionMatrix2model(sug, L.s); mod.s#> #> Call: #> lm(formula = sugpct ~ .X1 + .X2 + .X3 + .X4 - 1, data = new.data) #> #> Coefficients: #> .X1 .X2 .X3 .X4 #> -8.0892 -8.0910 -12.4612 -0.1133 #>#> 'log Lik.' 36.03257 (df=8)logLik(sug.h)#> 'log Lik.' 36.03257 (df=8)logLik(mod.s)#> 'log Lik.' 7.397588 (df=5)logLik(sug.s)#> 'log Lik.' 7.397588 (df=5)