Tests of vector or matrix contrasts for lmer model fits.
# S3 method for class 'lmerModLmerTest'
contest(
model,
L,
rhs = 0,
joint = TRUE,
collect = TRUE,
confint = TRUE,
level = 0.95,
check_estimability = FALSE,
ddf = c("Satterthwaite", "Kenward-Roger", "lme4"),
...
)
# S3 method for class 'lmerMod'
contest(
model,
L,
rhs = 0,
joint = TRUE,
collect = TRUE,
confint = TRUE,
level = 0.95,
check_estimability = FALSE,
ddf = c("Satterthwaite", "Kenward-Roger", "lme4"),
...
)a model object fitted with lmer from package
lmerTest, i.e., an object of class lmerModLmerTest.
a contrast vector or matrix or a list of these.
The length/ncol of each contrasts should equal
length(fixef(model)).
right-hand-side of the statistical test, i.e. the hypothesized value (a numeric scalar).
make an F-test of potentially several contrast vectors? If
FALSE single DF t-tests are applied to each vector or each row of
contrasts matrices.
collect list of tests in a matrix?
include columns for lower and upper confidence limits? Applies
when joint is FALSE.
confidence level.
check estimability of contrasts? Only single DF
contrasts are checked for estimability thus requiring joint = FALSE to
take effect. See details section for necessary adjustments to L when
estimability is checked with rank deficient design matrices.
the method for computing the denominator degrees of freedom.
ddf="Kenward-Roger" uses Kenward-Roger's method.
passed to contestMD.
a data.frame or a list of data.frames.
If the design matrix is rank deficient, lmer drops columns for the
aliased coefficients from the design matrix and excludes the corresponding
aliased coefficients from fixef(model). When estimability is checked
the original rank-deficient design matrix is recontructed and therefore
L contrast vectors need to include elements for the aliased
coefficients. Similarly when L is a matrix, its number of columns
needs to match that of the reconstructed rank-deficient design matrix.
data("sleepstudy", package="lme4")
fm <- lmer(Reaction ~ Days + I(Days^2) + (1|Subject) + (0+Days|Subject),
sleepstudy)
# F-test of third coeffcients - I(Days^2):
contest(fm, c(0, 0, 1))
#> Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
#> 1 1079.503 1079.503 1 144.6311 1.659144 0.1997759
# Equivalent t-test:
contest(fm, L=c(0, 0, 1), joint=FALSE)
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> 1 0.3370223 0.2616475 144.6311 1.288078 -0.1801245 0.8541692 0.1997759
# Test of 'Days + I(Days^2)':
contest(fm, L=diag(3)[2:3, ])
#> Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
#> 1 30399.15 15199.57 2 54.40752 23.36102 4.744897e-08
# Other options:
contest(fm, L=diag(3)[2:3, ], joint=FALSE)
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> 1 7.4340850 2.8242827 114.9943 2.632203 1.8397217 13.0284483 0.00964808
#> 2 0.3370223 0.2616475 144.6311 1.288078 -0.1801245 0.8541692 0.19977590
contest(fm, L=diag(3)[2:3, ], joint=FALSE, collect=FALSE)
#> [[1]]
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> 1 7.4340850 2.8242827 114.9943 2.632203 1.8397217 13.0284483 0.00964808
#> 2 0.3370223 0.2616475 144.6311 1.288078 -0.1801245 0.8541692 0.19977590
#>
# Illustrate a list argument:
L <- list("First"=diag(3)[3, ], "Second"=diag(3)[-1, ])
contest(fm, L)
#> Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
#> First 1079.503 1079.503 1 144.63110 1.659144 1.997759e-01
#> Second 30399.146 15199.573 2 54.40752 23.361016 4.744897e-08
contest(fm, L, collect = FALSE)
#> $First
#> Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
#> 1 1079.503 1079.503 1 144.6311 1.659144 0.1997759
#>
#> $Second
#> Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
#> 1 30399.15 15199.57 2 54.40752 23.36102 4.744897e-08
#>
contest(fm, L, joint=FALSE, confint = FALSE)
#> Estimate Std. Error df t value Pr(>|t|)
#> First 0.3370223 0.2616475 144.6311 1.288078 0.19977590
#> Second.1 7.4340850 2.8242827 114.9943 2.632203 0.00964808
#> Second.2 0.3370223 0.2616475 144.6311 1.288078 0.19977590
contest(fm, L, joint=FALSE, collect = FALSE, level=0.99)
#> $First
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> 1 0.3370223 0.2616475 144.6311 1.288078 -0.3459429 1.019988 0.1997759
#>
#> $Second
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> 1 7.4340850 2.8242827 114.9943 2.632203 0.03655396 14.831616 0.00964808
#> 2 0.3370223 0.2616475 144.6311 1.288078 -0.34594295 1.019988 0.19977590
#>
# Illustrate testing of estimability:
# Consider the 'cake' dataset with a missing cell:
data("cake", package="lme4")
cake$temperature <- factor(cake$temperature, ordered=FALSE)
cake <- droplevels(subset(cake, temperature %in% levels(cake$temperature)[1:2] &
!(recipe == "C" & temperature == "185")))
with(cake, table(recipe, temperature))
#> temperature
#> recipe 175 185
#> A 15 15
#> B 15 15
#> C 15 0
fm <- lmer(angle ~ recipe * temperature + (1|recipe:replicate), cake)
#> fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
fixef(fm)
#> (Intercept) recipeB recipeC
#> 29.1333333 -2.2666667 -1.2000000
#> temperature185 recipeB:temperature185
#> 2.4000000 0.1333333
# The coefficient for recipeC:temperature185 is dropped:
attr(model.matrix(fm), "col.dropped")
#> recipeC:temperature185
#> 6
# so any contrast involving this coefficient is not estimable:
Lmat <- diag(6)
contest(fm, Lmat, joint=FALSE, check_estimability = TRUE)
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> 1 29.1333333 1.853278 52.51829 15.71989449 25.4153325 32.851334 1.661995e-21
#> 2 -2.2666667 2.620931 52.51829 -0.86483271 -7.5247139 2.991381 3.910638e-01
#> 3 -1.2000000 2.620931 52.51829 -0.45785261 -6.4580472 4.058047 6.489471e-01
#> 4 2.4000000 1.581345 26.57668 1.51769553 -0.8470716 5.647072 1.408979e-01
#> 5 0.1333333 2.236359 26.57668 0.05962071 -4.4587193 4.725386 9.529038e-01
#> 6 NA NA NA NA NA NA NA