使用regr()命令:选择未定义的列时出错
尝试运行 ()命令来自yhat
package :
Error in `[.data.frame`(new.data, , c(DV, IVx)) :
undefined columns selected
这是我正在使用的代码:
DEregr_model <- lm(TotalBiomass ~ propnC + propnV + propnR + I(propnC^2) + I(propnV^2) + propnC:propnV + propnV:propnR + propnV:I(propnC^2), DE_model)
DEregrout <- regr(DEregr_model)
为什么此函数返回错误?
I get the following error when trying to run the regr()
command from the yhat
package:
Error in `[.data.frame`(new.data, , c(DV, IVx)) :
undefined columns selected
Here is the code I'm using:
DEregr_model <- lm(TotalBiomass ~ propnC + propnV + propnR + I(propnC^2) + I(propnV^2) + propnC:propnV + propnV:propnR + propnV:I(propnC^2), DE_model)
DEregrout <- regr(DEregr_model)
Why is this function returning an error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我可以在此MCVE的评论中表达我的怀疑:
我怀疑i(。)术语并未以
lm
的结果保存,以的方式来调用。 regr
功能能够处理。围绕的工作将是在增强数据集中使用单独的名称计算平方变量的值。
I think I can demonstrate my suspicion expressed in the comments with this MCVE:
I suspect that the I(.) terms are not being saved in the result of the
lm
call in a manner that theregr
function is able to handle.The work around would be to calculate the values of the squared variables with separate names in an augmented dataset.
根据评论,我发现了问题。交互项(即i(propnv^2))的函数未正确读取。因此,我在数据框架中添加了其他列的平方值,以便该模型将这些术语读取为单个值,而不是试图将它们分开。校正的代码如下:
Regr()函数现在没有错误运行,感谢您的输入!
Based on the comments, I figured out the issue. The interaction terms (i.e., I(propnV^2)) weren't being read correctly by the function. So I added additional columns in my data frame with the squared values, so that the model was reading these terms as individual values, not trying to separate them. Corrected code is below:
The regr() function now runs without error, thanks everyone for your input!