2

I'm using step() to find a model to adjust a score based on other variables. My full model is thus :

mod<-lm(Adjusted.score ~ original.score + X1 + X2 + X3 + ... + X10)

It's logical that I need to keep the variable original.score in the final model but step() always omits it. Is there a way to force step() to keep the variable original.score and find the best combinations of the other variables to accompany it?

1 Answer 1

5

Are you perhaps looking for this (from ?step):

The set of models searched is determined by the ‘scope’ argument.
The right-hand-side of its ‘lower’ component is always included in
the model, and right-hand-side of the model is included in the
‘upper’ component.  If ‘scope’ is a single formula, it specifies
the ‘upper’ component, and the ‘lower’ model is empty.  If ‘scope’
is missing, the initial model is used as the ‘upper’ model.

Models specified by ‘scope’ can be templates to update ‘object’ as
used by ‘update.formula’.  So using ‘.’ in a ‘scope’ formula means
‘what is already there’, with ‘.^2’ indicating all interactions of
existing terms.

Responding to your comment: I haven't done this sort of thing before but a small example included below seems to do what you are asking for:

x = setNames(lapply(1:5, function (x) runif(100)), letters[1:5])
step(lmObj, scope=list(lower=as.formula(a ~ b), upper=as.formula(a ~ .)))
2
  • Thanks, I did step(mod, list(Adjusted.score ~ original.score, mod)) but this does not keep original.score in the best model. I am confused as to the 'scope' syntax. Mar 22, 2014 at 16:47
  • 2
    OK, so I found the solution, this modified code works ands forces it to keep the variable original.score: step(mod, scope=list(lower=Adjusted.score ~ original.score, upper=mod)) Mar 22, 2014 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.