mem.getcomp: Extract per-observation components for fixed and random...

View source: R/memtools.R

mem.getcompR Documentation

Extract per-observation components for fixed and random effects of a mixed-effects model

Description

Assuming a mixed-effects model of form y_fit = Xb + Zu + e, where X is the model matrix for fixed effects, Z is the model matrix for random effects, and b and u are the fixed and random effects respectively, this function returns these components per each fitted value y. These may be useful for model inference and/or diagnostic purposes.

Usage

mem.getcomp(fit)

Arguments

fit

A fitted mixed-effects model generated either through the lme4 or the nlme package.

Details

Notice that per-observation model error is e = Xb + Zu - y_observation. Similarly, the components Xb and Zu are extracted.

Value

The function returns per-observation model fit components for a mixed-effects model. The return fields are

Xb

Fixed effects component Xb

Zu

Random effects component Zu

XbZu

Full model fit by summing the above two Xb+Zu

e

Model error e

y

Original observations y

Author(s)

Teemu Daniel Laajala <teelaa@utu.fi>

See Also

mem.plotran mem.plotresid

Examples

data(vcaplong)

exdat <- vcaplong[vcaplong[,"Group"] %in% c("Vehicle", "ARN"),]

library(lme4)
f1 <- lmer(log2PSA ~ 1 + DrugWeek + DrugWeek:ARN + (1 + DrugWeek|ID), data = exdat)

mem.getcomp(f1)

Syksy/hamlet documentation built on Aug. 28, 2023, 6:52 a.m.