Extract components from a fitted mixeff LMM
Source:R/methods-extract.R, R/revive.R
mm_lmm-methods.RdThese methods provide the common lme4-style extractor surface for
lmm() fits. The required values are stored directly on the R object or
rebuilt lazily from the serialized artifact, so these methods do not require
a live Rust handle after saveRDS() / readRDS().
ngrps() returns a named integer vector giving the number of levels of each
random-effect grouping factor, mirroring lme4::ngrps().
Produces the long form returned by as.data.frame(lme4::VarCorr(.)):
one row per variance (var2 = NA) and one row per covariance
(var1, var2 both set), with a final Residual row for LMMs. vcov
holds the (co)variance and sdcor the standard deviation (diagonal) or
correlation (off-diagonal). This is the shape broom.mixed::tidy() expects.
Produces the long form returned by as.data.frame(lme4::ranef(.)): columns
grpvar, term, grp, condval, and condsd. condsd is the
conditional standard deviation, taken from the postVar attribute when the
modes were extracted with condVar = TRUE, and NA otherwise.
Usage
fixef(object, ...)
# S3 method for class 'mm_lmm'
fixef(object, ...)
# S3 method for class 'mm_glmm'
fixef(object, ...)
ranef(object, ...)
# S3 method for class 'mm_lmm'
ranef(object, condVar = FALSE, ...)
# S3 method for class 'mm_glmm'
ranef(object, condVar = FALSE, ...)
# S3 method for class 'mm_lmm'
coef(object, ...)
# S3 method for class 'mm_glmm'
coef(object, ...)
VarCorr(x, ...)
# S3 method for class 'mm_lmm'
VarCorr(x, ...)
# S3 method for class 'mm_glmm'
VarCorr(x, ...)
# S3 method for class 'mm_lmm'
sigma(object, ...)
# S3 method for class 'mm_glmm'
sigma(object, ...)
# S3 method for class 'mm_lmm'
logLik(object, REML = NULL, ...)
# S3 method for class 'mm_glmm'
logLik(object, REML = NULL, ...)
# S3 method for class 'mm_lmm'
deviance(object, REML = NULL, ...)
# S3 method for class 'mm_glmm'
deviance(object, REML = NULL, ...)
# S3 method for class 'mm_lmm'
AIC(object, ..., k = 2)
# S3 method for class 'mm_glmm'
AIC(object, ..., k = 2)
# S3 method for class 'mm_lmm'
BIC(object, ...)
# S3 method for class 'mm_glmm'
BIC(object, ...)
# S3 method for class 'mm_lmm'
nobs(object, ...)
# S3 method for class 'mm_glmm'
nobs(object, ...)
# S3 method for class 'mm_lmm'
df.residual(object, ...)
# S3 method for class 'mm_glmm'
df.residual(object, ...)
# S3 method for class 'mm_lmm'
formula(x, ...)
# S3 method for class 'mm_glmm'
formula(x, ...)
# S3 method for class 'mm_lmm'
model.frame(formula, ...)
# S3 method for class 'mm_glmm'
model.frame(formula, ...)
ngrps(object, ...)
# Default S3 method
ngrps(object, ...)
# S3 method for class 'mm_lmm'
ngrps(object, ...)
# S3 method for class 'mm_glmm'
ngrps(object, ...)
# S3 method for class 'mm_lmm'
weights(object, ...)
# S3 method for class 'mm_glmm'
weights(object, ...)
# S3 method for class 'mm_lmm'
extractAIC(fit, scale, k = 2, ...)
# S3 method for class 'mm_glmm'
extractAIC(fit, scale, k = 2, ...)
# S3 method for class 'mm_lmm'
terms(x, ...)
# S3 method for class 'mm_glmm'
terms(x, ...)
# S3 method for class 'mm_varcorr'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
# S3 method for class 'mm_ranef'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
# S3 method for class 'mm_lmm'
model.matrix(object, type = c("fixed", "random"), ...)
# S3 method for class 'mm_glmm'
model.matrix(object, type = c("fixed", "random"), ...)
# S3 method for class 'mm_lmm'
vcov(object, type = c("fixed", "theta"), correlation = FALSE, ...)
# S3 method for class 'mm_glmm'
vcov(object, type = c("fixed", "theta"), correlation = FALSE, ...)Arguments
- object, x, formula, fit
A fitted
mm_lmmormm_glmmobject.- ...
Reserved for generic compatibility.
- condVar
Logical; when
TRUE, Phase 2 returns the random-effects tables with anNApostVararray and anmm_unavailable_reasonattribute rather than fabricating conditional variances.- REML
Ignored; included for S3 compatibility with likelihood and deviance generics.
- k
Penalty per parameter for
AIC().- scale
Ignored; included for S3 compatibility with
extractAIC().- row.names, optional
Ignored; present for S3 consistency.
- type
For
model.matrix(),"fixed"returns the fixed-effect design matrix and"random"returns the sparse random-effect design matrix. Forvcov(),"fixed"returns the fixed-effect covariance surface and"theta"returns an unavailable theta-covariance matrix with a reason attribute.- correlation
Logical; accepted for S3 compatibility with
vcov().
Examples
set.seed(1)
df <- data.frame(
y = rnorm(60), x = rnorm(60),
g = factor(rep(seq_len(10), each = 6))
)
fit <- lmm(y ~ x + (1 | g), df, control = mm_control(verbose = -1))
fixef(fit)
#> (Intercept) x
#> 0.1122739 -0.0416571
VarCorr(fit)
#> Variance components:
#> group name variance std_dev correlation note
#> g (Intercept) 0 0 [boundary]
#> [boundary]: variance component is at the boundary of the parameter space.
#> Residual std. dev.: 0.861654
head(ranef(fit)$g)
#> (Intercept)
#> 1 0
#> 2 0
#> 3 0
#> 4 0
#> 5 0
#> 6 0
sigma(fit)
#> [1] 0.8616536
logLik(fit)
#> 'log Lik.' -77.65847 (df=4)
nobs(fit)
#> [1] 60