我用step()来找一个模型来根据其他变量来调整分数。因此,我的完整模型是:
mod<-lm(Adjusted.score ~ original.score + X1 + X2 + X3 + ... + X10)我需要将变量original.score保留在最后的模型中,这是合乎逻辑的,但是step()总是忽略它。有没有办法强迫step()保留变量original.score,并找到其他变量的最佳组合来陪伴它?
发布于 2014-03-22 16:35:12
您是否正在寻找这个(来自?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.回应你的评论:我以前没有做过这类事情,但下面的一个小例子似乎能满足你的要求:
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 ~ .)))https://stackoverflow.com/questions/22580293
复制相似问题