Predictions follow the lme4 generic shape. In-sample predictions reuse
the cached fitted/fixed values; new-data predictions are dispatched
through the Rust predict_new contract.
Usage
# S3 method for class 'mm_lmm'
predict(
object,
newdata = NULL,
re.form = NULL,
allow.new.levels = FALSE,
type = c("response", "link"),
se.fit = FALSE,
interval = c("none", "confidence", "prediction"),
level = 0.95,
na.action = stats::na.pass,
offset = NULL,
...
)
# S3 method for class 'mm_lmm'
fitted(object, ...)
# S3 method for class 'mm_lmm'
residuals(
object,
type = c("response", "pearson", "deviance", "working"),
scaled = FALSE,
...
)
# S3 method for class 'mm_glmm'
fitted(object, ...)
# S3 method for class 'mm_glmm'
residuals(
object,
type = c("deviance", "pearson", "working", "response"),
scaled = FALSE,
...
)Arguments
- object
A fitted
mm_lmmobject.- newdata
Optional new data. Must be a
data.framecontaining every variable the requested prediction needs (the fixed-effect variables, plus the grouping and slope variables of the random terms used); other columns are ignored. Grouping columns may be factor, character, or integer (coerced the way they were at fit time); fixed-effect factor and character columns are matched to the training levels, and a level not seen when fitting is refused. Stateful terms (poly(),scale(),ns(), ...) are evaluated with the training basis, as instats::lm().- re.form
Random-effects conditioning, following lme4.
NULLreturns conditional predictions;NA(or~0) returns population-level (fixed-effect) predictions; a one-sided formula naming some of the model's random terms (e.g.~ (1 | subject)) conditions on those terms' conditional modes only. Standard errors and intervals are not available for such partial conditioning.- allow.new.levels
When
FALSE(default), unseen grouping levels innewdataraisemm_inference_unavailablethrough the RustNewReLevels::Errorpolicy. WhenTRUE, unseen levels are replaced by the population mean (zero random effect), matchinglme4::predict(allow.new.levels = TRUE).- type
Prediction scale. Gaussian LMMs use the same values for
"response"and"link". Forresiduals(), the residual type, as in lme4: LMMs default to"response"(y - mu, also"working"), with"pearson"/"deviance"the weighted residualssqrt(w) * (y - mu); GLMMs default to"deviance"and also offer"pearson"((y - mu) * sqrt(w / V(mu))),"working"and"response".- se.fit
Logical; when
TRUE, returns a list withfitandse.fit. For population predictions (re.form = NA) the standard error is the Wald SE of the fixed-effect linear predictor,sqrt(diag(X V X')). For conditional predictions (re.form = NULL) the SE comes from the engine prediction-variance payload, which adds the random-effect contribution (BLUP variance and the fixed/random covariance). Rows the engine cannot certify — e.g. unseen grouping levels underallow.new.levels = TRUE— returnNAwith the engine's reason in themm_reasonattribute. (lme4::predict.merModoffers no conditional SE at all.)- interval
Interval type:
"confidence"for the fitted mean or"prediction"for a new observation (adds the residual variance). Population (re.form = NA) intervals arefit +/- z*secomputed R-side; conditional (re.form = NULL) bounds come from the engine prediction-variance payload. Returns a matrix withfit/lwr/upr.- level
Confidence level for
interval/se.fitintervals.- na.action
Missing-value handling for
newdata, as inlme4::predict.merMod(): the default stats::na.pass returnsNAfor rows with a missing value in a variable the prediction needs; stats::na.omit drops them and stats::na.exclude pads them back asNA. In-sample predictions of a fit made withna.action = na.excludeare padded to the original rows, likefitted()andresiduals().- offset
Offset for
newdatarows when the model was fitted with theoffset =argument: a numeric vector (one value pernewdatarow) or an expression evaluated innewdata. Offsets written in the formula (offset(log(t))) are evaluated fromnewdataautomatically. (lme4 silently drops anoffset =argument offset for new data; mixeff refuses instead of guessing.)- ...
Reserved for generic compatibility.
- scaled
Logical; when
TRUE, residuals are divided bysigma(object)(once), as in lme4.