Extract matrices from a fit
get_matrix
is a first attempt at a unified extractor of various matrices from a fit. All augmented matrices follow (Henderson's) block order (upper blocks: X,Z; lower blocks: 0,I).
get_ZALMatrix
returns the design matrix for the random effects v.
get_matrix(object, which="model.matrix", augmented=TRUE, ...) get_ZALMatrix(object, force_bind=TRUE)
object |
An object of class |
augmented |
Boolean; whether to return an augmented matrix for all model coefficients (fixed-effects coefficients and random-effect predictions) or only for fixed effects. Not operative for all |
which |
Which element to extract. For |
force_bind |
Boolean; with the non-default value |
... |
Other arguments that may be needed in some future versions of |
(Given the pain that it is to write maths in R documentation files, readers are gently asked to be tolerant about any imperfections of the following).
Model coefficients estimates of a (weighted) linear model can be written as (X'WX)^{-1}X'Wy where X is the design matrix for fixed effects, W a diagonal weight matrix, and y the response vector. In a linear mixed model, the same expression holds in terms of Henderson's augmented design matrix, of an augmented (still diagonal) weight matrix, and of an augmented response vector. For GLMMs and hierarchical GLMs generally, the solution of each step of the iteratively reweighted least squares algorithm again has the same expression in terms of appropriately defined augmented matrices and vectors.
get_matrix
returns, for given values of the which
argument, the following matrices from the model fit: "AugX"
: X; "wei_AugX"
: WX; "wAugX"
: √(W)X; "left_ginv"
: X^-=(X'WX)^{-1}X'W (viewed as a pseudo-inverse since X^-X is an identity matrix); "hat_matrix"
: XX^-=X (X'WX)^{-1}X'W.
A matrix, possibly in sparse-matrix format.
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.