refit.RdRe-estimates a model using the same formula and design but with a new response vector.
The refit generic allows simulation-based workflows (e.g.,
parametric bootstrap) where new synthetic responses are drawn from
a fitted model and the model is re-fitted with the same design
structure.
A new fitted model object of the same class as the original.
refit.lmRefits a linear model with the same formula but a new response vector.
refit.lmeRefits a linear mixed-effects model (from nlme) with new response data.
refit.glsRefits a generalized least squares model (from nlme) with new response data.
if (require(nlme) && require(lme4)) {
data(Orthodont, package = "nlme")
# Fit models
fit_lm <- lm(distance ~ age, data = Orthodont)
fit_gls <- gls(distance ~ age, data = Orthodont)
fit_lme <- lme(distance ~ age, random = ~ 1 | Subject, data = Orthodont)
# Simulate new response vectors
set.seed(123)
new_y <- rnorm(nrow(Orthodont), mean = mean(Orthodont$distance), sd = sd(Orthodont$distance))
# Refit models with new response
refit(fit_lm, newresp = new_y)
refit(fit_gls, newresp = new_y)
refit(fit_lme, newresp = new_y)
}
#> Error in UseMethod("refit"): no applicable method for 'refit' applied to an object of class "lm"