是否存在用 R 识别线性模型中二次分量的方法?
假设我们有一个 y=x1+x2+... 形式的加法模型,其中包含很多变量。 R 中是否有一个例程来识别应被视为表现出二次效应的变量?我知道 Box-Cox 变换可以识别 y 的链接,但是 x 呢?如果只有几个变量,测试它们很容易,但是持有一大堆变量又如何呢?
来自德国的问候
Suppose we have an additive model of the form y=x1+x2+... with a lot of variables. Is there a routine in R to identify variables that should be considered as exhibiting a quadratic effect? I know that Box-Cox transformation allows to identify links for y, but what about x. If there are just a few variables, it's easy to test them, but what about holding a whole bunch?
Regards from Germany
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能不关心是否需要二次项,而是关心是否有任何影响是非线性的。虽然二次项可以吸收其中一些影响,但也有一些明显的非线性非二次效应。有很多方法可以做到这一点,但我喜欢使用在 Hmisc 和 Design 包中实现的受限三次样条。
例如:
ols
本质上相当于lm
。请注意输出中的方差分析表:它对效应的非线性进行了测试,包括全局测试。You probably don't care to know whether you need quadratic terms, but rather whether any of the effects are non-linear. While a quadratic term can pick up some of those, there are some decidedly non-quadratic effects that are not linear. There are many ways of doing that, but I like using restricted cubic splines as implemented in the
Hmisc
andDesign
packages.For example:
ols
is essentially the equivalent oflm
. Note the ANOVA table in the output: it has test for non-linearity of the effects including a global test.如果您想创建所有双向交互,您可以执行以下操作:
请参阅:
If you want to create all the two-way interactions you can do this:
See: