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)
A matrix, possibly in sparseMatrix
format.
An object of class HLfit
, as returned by the fitting functions in spaMM
.
Boolean; whether to return a matrix for all model coefficients (augmented matrix for fixed-effects coefficients and random-effect predictions) or a matrix only for fixed effects. Not operative for all which
values (currently only for which="left_ginv"
).
Which element to extract. For "model.matrix"
, the design matrix for fixed effects (similarly to stats::model.matrix
); for "ZAL"
, the design matrix for random effects (same as get_ZALMatrix()
), while "ZA"
and "L"
may return these two factors (detailed in random-effects
); for "AugX"
, the (unweighted) augmented design matrix of the least-square problem; for "hat_matrix"
, the projection matrix that gives model predictions from the (augmented) response vector; for "left_ginv"
, the pseudo-inverse that gives the model coefficients from the (augmented) response vector. See Details for further definitions and options for functions of the augmented design matrix.
Boolean; with the non-default value FALSE
, the function may return an object of class ZAXlist
, which is poorly documented and for development purposes only.
Other arguments that may be needed in some future versions of spaMM
.
(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"
: \(\sqrt{}\)(W)X;
"left_ginv"
: (X'WX)\(^{-1}\)X'W (the name stems from the fact that it is generalized inverse, denoted X\(^-\), since XX\(^-\)X=X, and it is a left one, since X\(^-\)X is an identity matrix when X has full rank);
"hat_matrix"
: XX\(^-\)=X (X'WX)\(^{-1}\)X'W;
"fixef_left_ginv"
: same as "left_ginv"
but for the fixed-effect design matrix only (not to be confused with the corresponding block of "left_ginv"
);
"beta_v_cov"
: joint covariance matrix of estimates/predictions of fixed-effect coefficients and random effects (the v in random-effects
).
"v_condcov"
: covariance matrix of predictions of random effects (the v in random-effects
) given fixed-effect coefficients.
vcov
for the variance-covariance matrix of the fixed-effects coefficients, and Corr
for correlation matrices of random effects.