【发布时间】:2020-08-19 00:00:56
【问题描述】:
样本数据 ->
> tail(India_df)
date confirmed deaths recovered
98 2020-04-28 31324 1008 7747
99 2020-04-29 33062 1079 8437
100 2020-04-30 34863 1154 9068
101 2020-05-01 37257 1223 10007
102 2020-05-02 39699 1323 10819
103 2020-05-03 42505 1391 11775
我想预测未来某个日期会有多少确诊病例,例如 ->“2020-05-05”
我正在使用多项式回归来拟合模型 ->
fit2 = lm(confirmed~poly(date,6))
我试过用这个 ->
new <- data.frame(pred_dates <- as.Date(c("2020-05-05","2020-05-06")))
predict.lm(fit2,new,interval = "confidence")
但它显示此错误 ->
'newdata' had 2 rows but variables found have 103 rows
【问题讨论】:
-
是
lm(...)ignoringIndia_df,还是您向我们展示的代码与您使用的代码不同? -
我使用了
attach(India_df),所以我直接使用列名,这就是为什么.. -
(在我看来,任何建议使用
attach的教程/课程/课程都应该停止。我想不出一种情况,除了拐杖不好,还有风险/使用它的后果超过了它可能带来的任何便利。)很高兴你得到了你需要的帮助:-)
标签: r date machine-learning prediction