在 R 中使用 forecast() 匹配 "next day"
Match "next day" using forecast() in R
我正在学习 "Forecasting Using R" DataCamp 课程。除了一个特定练习的最后一部分(link here,如果你有帐户),我已经完成了整个事情,在那里我完全迷路了。它给我的错误帮助也无济于事。我将把任务的各个部分与我用来解决它们的代码放在一起:
Produce time plots of only the daily demand and maximum temperatures with facetting.
autoplot(elec[, c("Demand", "Temperature")], facets = TRUE)
Index elec
accordingly to set up the matrix of regressors to include MaxTemp
for the maximum temperatures, MaxTempSq
which represents the squared value of the maximum temperature, and Workday
, in that order.
xreg <- cbind(MaxTemp = elec[, "Temperature"],
MaxTempSq = elec[, "Temperature"] ^2,
Workday = elec[,"Workday"])
Fit a dynamic regression model of the demand column with ARIMA errors and call this fit
.
fit <- auto.arima(elec[,"Demand"], xreg = xreg)
If the next day is a working day (indicator is 1) with maximum temperature forecast to be 20°C, what is the forecast demand? Fill out the appropriate values in cbind()
for the xreg
argument in forecast()
.
这就是我卡住的地方。他们提供的示例代码如下所示:
forecast(___, xreg = cbind(___, ___, ___))
我设法计算出第一个空白是 fit
,所以我正在尝试如下所示的代码:
forecast(fit, xreg = cbind(elec[,"Workday"]==1, elec[, "Temperature"]==20, elec[,"Demand"]))
但这给我错误提示 "Make sure to forecast the next day using the inputs given in the instructions." 这...没有告诉我任何有用的信息。知道我应该做什么吗?
当您提前进行预测时,您会使用 elec
中未包含的新数据(这是您用来拟合模型的数据集)。新数据已在问题中提供给您(温度 20C 和工作日 1)。因此,您的 forecast
调用中不需要 elec
。就用新数据提前预测吧:
forecast(fit, xreg = cbind(20, 20^2, 1))
我正在学习 "Forecasting Using R" DataCamp 课程。除了一个特定练习的最后一部分(link here,如果你有帐户),我已经完成了整个事情,在那里我完全迷路了。它给我的错误帮助也无济于事。我将把任务的各个部分与我用来解决它们的代码放在一起:
Produce time plots of only the daily demand and maximum temperatures with facetting.
autoplot(elec[, c("Demand", "Temperature")], facets = TRUE)
Indexelec
accordingly to set up the matrix of regressors to includeMaxTemp
for the maximum temperatures,MaxTempSq
which represents the squared value of the maximum temperature, andWorkday
, in that order.
xreg <- cbind(MaxTemp = elec[, "Temperature"],
MaxTempSq = elec[, "Temperature"] ^2,
Workday = elec[,"Workday"])
Fit a dynamic regression model of the demand column with ARIMA errors and call this fit
.
fit <- auto.arima(elec[,"Demand"], xreg = xreg)
If the next day is a working day (indicator is 1) with maximum temperature forecast to be 20°C, what is the forecast demand? Fill out the appropriate values incbind()
for thexreg
argument inforecast()
.
这就是我卡住的地方。他们提供的示例代码如下所示:
forecast(___, xreg = cbind(___, ___, ___))
我设法计算出第一个空白是 fit
,所以我正在尝试如下所示的代码:
forecast(fit, xreg = cbind(elec[,"Workday"]==1, elec[, "Temperature"]==20, elec[,"Demand"]))
但这给我错误提示 "Make sure to forecast the next day using the inputs given in the instructions." 这...没有告诉我任何有用的信息。知道我应该做什么吗?
当您提前进行预测时,您会使用 elec
中未包含的新数据(这是您用来拟合模型的数据集)。新数据已在问题中提供给您(温度 20C 和工作日 1)。因此,您的 forecast
调用中不需要 elec
。就用新数据提前预测吧:
forecast(fit, xreg = cbind(20, 20^2, 1))