I was trying to automate a final step model building. I would like to combine predictors from two separate models into one final model. I played around with update.formula() but realized I can update an old lmfit$call to a new one, e.g update.formula(lmfit$call,lmfitnew$call). here i need to cherry pick variables from both models and run the final one
lmfit1 <- lm(y~ x1+x2+x3, data = modelready)
best.ngc_fit <- stepAIC(lmfit1, direction="backward")
best.ngc_fit$call
lm(formula = y~ x2+x3, data = modelready)
lmfit2 <- lm(y ~ a+b+c+d+f, data=fcstmodel)
best.fcst_fit <- stepAIC(lmfit2, direction ="backward")
best.fcst_fit$call
lm(formula = y~ a+c+d+f, data = fcstmodel)
This is what I would like to have in my final model
best.full_fit <- lm(y~x2+x3+a+c+d+f, data = fullmodel)
I can do it manually without a problem, but I would like to automate it in order to make the whole process less tedious.
Any help will be much appreciated
For more advanced manipulation of fomulas you can use Formula package.