r - 在时间序列数据集上应用 GAM
问题描述
我正在尝试在时间序列数据上创建一个 gam 模型。在mydata
中,我只有两列:Var1
和date
(从 2013 年 1 月到 2018 年 12 月)。这是我正在使用的代码:
training.samples <- mydata$Var1 %>% createDataPartition(p = 0.8, list = FALSE)
train.data <- mydata[training.samples, ]
test.data <- mydata[-training.samples, ]
library(mgcv)
# Build the model
model <- gam(Var1 ~ s(date, bs="cr"), data = train.data, fit= TRUE)
Error in names(dat) <- object$term :
'names' attribute [1] must be the same length as the vector [0]
我的问题是:这段代码有问题还是在 gam 函数中使用日期变量有什么根本区别?任何帮助将不胜感激。
解决方案
推荐阅读
- common-lisp - 带有防御性副本的 SETQ 或 SETF
- angular - Ionic 3 存储无法在 forEach 内部读取
- c++11 - C++ - 'operator<' 不匹配
- node.js - 将 Adwords 帐户链接到 MCC 帐户、Adwords API、NodeJs
- outlook - Create a mailing distribution group by outlook office365 API REST
- python - hubspot3 客户端和“重试次数过多”错误
- sql - 过去 6 个月的 SQL Server 查询
- lua - 我将如何使这个“仅限团队项目”脚本工作?
- html - .css 中的样式不起作用。怎么了?
- security - 存储由 Bitbucket Server 管理的本地存储库的最佳实践是什么?