如何将变量的正方形作为i(x^2)与循环添加在线性模型中?
我生成了获取数据的东西,这些数据将所有列名添加到线性回归中,添加了它们的交互和该变量的第二度,并使用步骤函数来找到最佳的线性回归模型。我添加了所有列的名称和交互,但是在这里我有一个问题,添加了第二度变量。我使用上述代码,但
Error in (colnames(dpt)[i])^2 : non-numeric argument to binary operator" error
有人可以帮忙吗?我真的很感激。
for (i in colnames(dpt)) {
lmod <- lmod %>% update(paste('. ~ . + I((colnames(dpt)[i])^2)'),
data = dpt)
}
I generated something that takes data, which adds all column names to the linear regression, adds their interactions and their second degree of that variable, and uses step function to finds out the best linear regression model. I added both all column names and interactions but here I have a problem adding a second degree of the variables. I use the above-given code but it gives an
Error in (colnames(dpt)[i])^2 : non-numeric argument to binary operator" error
Could anyone help? I really appreciate it.
for (i in colnames(dpt)) {
lmod <- lmod %>% update(paste('. ~ . + I((colnames(dpt)[i])^2)'),
data = dpt)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
sprintf
。或者,如果您进入管道:
或者如果没有循环的
Using
sprintf
.Or, if you are into pipes:
Or if you cannot do without the
for
loop:Gives