我正在尝试根据TSA软件包中电力数据集中的以下数据预测未来24个月。我使用了基于线性回归的月份和时间来建立模型。
library(TSA)
library(forecast)
data(electricity)
logdata = log(electricity)
month = season(electricity)
time = time(electricity)
model = lm(logdata~month +time(electricity))
summary(model)
但是我很难预测未来的24个月。
newelec= ts(rep(0,24), start=end(electricity), freq=frequency(electricity))
month = season(newelec)
mat = as.matrix(model.matrix(~month+time(newelec)+0)[,-1])
pred = forecast(model,mat)
执行此操作时,出现以下错误:
Error in `[[<-.data.frame`(`*tmp*`, length(tmpdata) + 1, value = c(1973, : replacement has 396 rows, data has 24
向我指出正确方向的任何帮助都会很棒!