【发布时间】:2015-02-16 10:02:31
【问题描述】:
我还是 R 新手,面临一个我似乎无法解决的问题。
我想预测我的时间序列数据。 我有今年的每日数字:y 和去年的每日数字,我想用作预测器。 数字显示周周期。我试过这段代码。 (为了清楚起见,假数字)
x = rnorm(60,0,1)
y = rnorm(60,0 ,1) + 2*cos(2*pi*1:60/7) + 10*x
new_x = rnorm(10,0,1)
y <- ts(y,frequency = 7)
fit <- tslm(y ~ trend + season + x)
fcast = forecast.lm(fit, h = 10, newdata = new_x)
我收到错误消息:
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
variable lengths differ (found for 'x')
In addition: Warning message:
'newdata' had 10 rows but variables found have 60 rows
关于我做错了什么的任何提示?
【问题讨论】:
-
来自
?forecast.lm:newdata An optional data frame。new_x是一个向量。
标签: r time-series forecasting