问题描述
我想使用预测函数预测fjbjor
何时为5.5,并且我总是收到此警告消息,并且我已经尝试了很多方法,但总是会出现这种情况,所以有人可以看到我在这里做错了什么吗
I am suppose to use the predict function to predict when fjbjor
is 5.5 and I always get this warning message and I have tried many ways but it always comes so is there anyone who can see what I am doing wrong here
这是我的代码
fit.lm <- lm(fjbjor~amagn, data=bjor)
summary(fit.lm)
new.bjor<- data.frame(fjbjor=5.5)
predict(fit.lm,new.bjor)
这出来
1 2 3 4 5 6 7 8 9 10 11
5.981287 2.864521 9.988559 5.758661 4.645530 2.419269 4.645530 5.313409 6.871792 3.309773 4.200278
12 13 14 15 16
3.755026 5.981287 5.536035 1.974016 3.755026
如果任何人都能看到问题所在,我将非常感谢您的帮助.
If anyone can see what is wrong I would be really thankful for the help.
推荐答案
您的模型是fjbjor ~ amagn
,其中fjbjor
是响应,而amagn
是协变量.那么您的newdata
是data.frame(fjbjor=5.5)
.
Your model is fjbjor ~ amagn
, where fjbjor
is response and amagn
is covariate. Then your newdata
is data.frame(fjbjor=5.5)
.
newdata
应该用于提供协变量而不是响应. predict
将仅保留newdata
中的协变量列.对于您指定的newdata
,它将为NULL
.结果,predict
将使用内部模型框架进行预测,这将返回您拟合的值.
newdata
should be used to provide covariates rather than response. predict
will only retain columns of covariates in newdata
. For your specified newdata
, this will be NULL
. As a result, predict
will use the internal model frame for prediction, which returns you fitted values.
警告消息非常清楚. predict
根据nrow(newdata)
确定期望的预测数,即1.但是随后我发生了上述情况,因此返回了16个拟合值.这种不匹配会产生警告.
The warning message is fairly clear. predict
determines the expected number of predictions from nrow(newdata)
, which is 1. But then what I described above happened so 16 fitted values are returned. Such mismatch produces the warning.
您真正想要的模型是:amagn ~ fjbjor
.
Looks like the model you really want is: amagn ~ fjbjor
.
这篇关于警告消息"newdata"有1行,但在R中找到的变量有16行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!