【问题标题】:How to predict next month given a fitted model?给定一个拟合模型,如何预测下个月?
【发布时间】:2021-06-27 03:00:07
【问题描述】:

假设我已经为数据拟合了 GAM 模型:

model <- gam(Cases~s(Time, k=5, bs="cs"), data=dengue, family = gaussian(link = indentity))

数据最长可达 32 周。我如何预测接下来的 4 周(第 33 至第 36 周)?

prediction <- predict(model, se.fit=T, n.ahead=4)

也许是这样的?提前致谢。

【问题讨论】:

    标签: r predict gam


    【解决方案1】:

    您必须向predict() 提供一个包含新数据的数据框才能进行预测。详情请见documentation

    在您的情况下,这意味着:

    testdata = data.frame(Time= c(33:36))
    prediction <- predict(model, newdata = testdata)
    

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 1970-01-01
      • 2010-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 2020-07-15
      • 2015-09-13
      相关资源
      最近更新 更多