lme4 (version 1.1-5)

refit: Refit a model with a new response, by maximum likelihood criterion

Description

Refit a model with a different response vector

Usage

refit(object, newresp, ...)

## S3 method for class 'merMod': refit(object, newresp = NULL, rename.response=FALSE, ...)

Arguments

object
a fitted model, usually of class lmerMod, to be refit with a new response
newresp
an (optional) numeric vector providing the new response. Must be of the same length as the original response.
rename.response
when refitting the model, should the name of the response variable in the formula and model frame be replaced with the name of newresp?
...
optional additional parameters. None are used at present.

Value

  • an object like x, but fit by maximum likelihood

Details

Refit a model, possibly after modifying the response vector. This could be done using an update method but this approach should be faster because it bypasses the creation of the model representation and goes directly to the optimization step.

Setting rename.response to TRUE may be necessary if one wants to do further operations (such as update) on the fitted model. However, the refitted model will still be slightly different from the equivalent model fitted via update; in particular, the terms component is not updated to reflect the new response variable, if it has a different name from the original.

Examples

Run this code
## using refit() to fit each column in a matrix of responses
set.seed(101)
Y <- matrix(rnorm(1000),ncol=10)
res <- list()
d <- data.frame(y=Y[,1],x=rnorm(100),f=rep(1:10,10))
## need to disregard convergence checks because we
## are doing a fake example
fit1 <- lmer(y~x+(1|f),data=d,
             control=lmerControl(check.conv.grad="ignore",
             check.conv.hess="ignore"))
res <- c(fit1,lapply(as.data.frame(Y[,-1]),
        refit,object=fit1))

Run the code above in your browser using DataCamp Workspace