Skip to contents

update() re-fits an mm_lmm or mm_glmm with a modified model specification, mirroring stats::update() and lme4's update() for the common cases: changing the formula (. ~ . - x), toggling REML, swapping weights/offset/family/control, or supplying new data.

Usage

# S3 method for class 'mm_lmm'
update(object, formula., ..., evaluate = TRUE)

# S3 method for class 'mm_glmm'
update(object, formula., ..., evaluate = TRUE)

Arguments

object

A fitted mm_lmm or mm_glmm.

formula.

A formula-change applied with stats::update.formula(); omit to keep the current formula. Random-effect terms ((x | g), (x || g)) are preserved across . ~ . edits.

...

Arguments to override on the re-fit. For mm_lmm: data, REML, weights, offset, na.action, control. For mm_glmm: additionally family, method, nAGQ, inference. The fit's missing-value handling carries over: a refit of the stored model frame keeps the original na.action record (so na.exclude padding persists), and new data is filtered with the original na.action (na.omit or na.exclude) unless na.action is supplied.

evaluate

If TRUE (default) re-fit and return the new model; if FALSE return the unevaluated call.

Value

A new fitted model of the same class as object, or an unevaluated call when evaluate = FALSE.

Details

The re-fit reuses the fitted model frame (model.frame()) as the default data source, so formula edits that remove terms or change estimation options work without re-supplying data. A formula edit that introduces a new variable absent from the original model frame requires an explicit data = argument.

Examples

set.seed(1)
df <- data.frame(
  y = rnorm(80), x = rnorm(80), z = rnorm(80),
  g = factor(rep(seq_len(10), each = 8))
)
fit <- lmm(y ~ x + z + (1 | g), df, control = mm_control(verbose = -1))
# drop a fixed term
fit2 <- update(fit, . ~ . - z)
# refit by ML for a likelihood-ratio comparison
fit_ml <- update(fit, REML = FALSE)
fixef(fit2)
#> (Intercept)           x 
#>  0.07858531 -0.28479350