knitr::opts_chunk$set(echo = TRUE)
lmer
fitting linear mixed modelslmerTestR overloads lmer
from lme4 in order to facilitate the computation of summary tables, anova tabels and tests of costum contrasts with $t$ and $F$ tests using the Satterthwaite method for computation of denominator degrees of freedom.
lmerTestR::lmer
produces an object of class lmerModLmerTest
extending class lmerMod
(as produced by lme4::lmer
)lmerTestR::lmer
adds slots containing the covariance matrix of the variance-covariance parameters in the model and the gradient of the covariance matrix of the fixed effect parameters, $\beta$ (and a few other things) which are required for the computation of Satterthwaite degrees of freedom.hessian
and jacobian
functions from the numDeriv package utilizing the accurate Richardson extrapolation method.Satterthwaite's method is implemented for one-df contrasts as well as for multi-df contrasts in two functions respectively:
contest1D
takes a contrast-vector (or 1D row-matrix) and produces a data.frame
with $t$-tests in the form similar to a summary coefficient table. This function is used by the summary
method for lmer
fits to compute the $p$-values for $t$-tests of the model coefficients.contestMD
takes a contrast-matrix (or a vector) and produces a data.frame
with sums of squares, mean squares, $F$-values, numerator and denominator degrees of freedom and $p$-values in a form similar to that of an ANOVA table. This function is used by the anova
method for lmer
fits.The computations involved in the Satterthwaite's method are described in a separate document/vignette.
summary
tables) may be respectively larger and smaller.pbkrtest::vcovAdj
and the KR df with pbkrtest::Lb_ddf
. Computing the KR $t$-tests for a whole set of one-df contrasts (as in a summary table) therefore only involves calculating the adjusted covariance matrix once.pbkrtest::KRmodcomp
. When computing $F$-tests for a series of terms (as is done in ANOVA tables) pbkrtest::KRmodcomp
is called multiple times in each case evaluating the same adjusted covariance matrix of $\beta$ (the computationally time consuming part). We have not found a way to decompose the computations in pbkrtest::KRmodcomp
so that pbkrtest::vcovAdj
could be called just once instead. The culprit is the calculation of the scaling of the $F$-value for which pbkrtest does not appear to export a low-level (direct) method.anova
methodsingle_anova
handles this.anova
. This is not implemented in lmerTestR; callNextMethod
is applied.single_anova
computes the appropriate contrast matrices (corresponding to type I, II, or III ANOVA tables) and then uses contestMD
to compute the relevant SSQ, MS, $F$-values etc.get_contrasts_type1
which forms the contrasts using the Doolittle decomposition of $X^\top X$ where $X$ is the standard full-rank (column rank) design matrix.get_contrasts_type3
which uses a SAS-type algorithm based on the 'full' rank-deficient design matrix (produced by get_rdX
) and a 'general' contrast matrix 'L' (produced by general_L
). contr.treatment
or contr.SAS
is used for coding of factors in the design matrix. Using other "contrasts", for example contr.sum
or contr.poly
, which is used by default for ordered factors produces an error.summary
method for lmer
model fitsThe summary method does two things to a lme4::lmer
summary table before it is returned. The lme4::print.summary.merMod
print method takes care of printing.
contest1D
.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.