update() a model inside a function with local covariate
问题 I need to update a regression model from inside a function. Ideally, the function should work with any kind of models ( lm , glm , multinom , clm ). More precisely, I need to add one or several covariates that are defined inside the function. Here is an exemple. MyUpdate <- function(model){ randData <- data.frame(var1=rnorm(length(model$residuals))) model2 <- update(model, ".~.+randData$var1") return(model2) } Here is an example use data(iris) model1 <- lm(Sepal.Length~Species, data=iris)