gpt4 book ai didi

r - 强制step()保留一定的值(value)

转载 作者:行者123 更新时间:2023-12-02 04:33:12 26 4
gpt4 key购买 nike

我正在使用 step() 寻找一个模型来根据其他变量调整分数。我的完整模型是:

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

按照逻辑,我需要将变量 original.score 保留在最终模型中,但 step() 总是忽略它。有没有办法强制 step() 保留变量 original.score 并找到伴随它的其他变量的最佳组合?

最佳答案

您是否正在寻找这个(来自?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 ~ .)))

关于r - 强制step()保留一定的值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22580293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com