[英]How should I get the forecasted values in R using Arima Model?
I am new to R so doesn't know how exactly the forecasting works in R using Arima Model.我是 R 的新手,所以不知道使用 Arima Model 在 R 中的预测究竟是如何工作的。 I have a dataset is like: 92 Aug-17 9533 93 Sep-17 8718 94 Oct-17 2035 95 Nov-17 2539 96 Dec-17 1333 97 Jan-18 2444 98 Feb-18 9371 99 Mar-18 9697 100 Apr-18 3989 101 May-18 4061 102 Jun-18 2797 103 Jul-18 2949
我有一个数据集如下: 92 Aug-17 9533 93 Sep-17 8718 94 Oct-17 2035 95 Nov-17 2539 96 Dec-17 1333 97 Jan-18 2444 98 Feb-18 9371 99 Mar-18 9697 100 Apr- 18 3989 101 May-18 4061 102 Jun-18 2797 103 Jul-18 2949
I want see the forecasted values for next 12 months by using arima model in R.我想通过在 R 中使用 arima model 查看未来 12 个月的预测值。 So how should I achieve this.
那么我应该如何实现这一点。
Thanks in Advance.提前致谢。 this is a dataset
这是一个数据集
You can use forecast
package in R
to forecast. 您可以使用
R
forecast
包进行预测。 However, your question is very broad, an example would be: 但是,您的问题非常广泛,例如:
library(forecast)
data("airmiles")
auto.arima(airmiles, stepwise = F,approximation = F)->arima_fit # fit an arima model with autoarima
forecast(arima_fit, h= 12 )->fc # forcast next 12 months
accuracy(fc) #check accuracy of your forecast
for more details check this book 有关更多详细信息, 请查看这本书
fit
fit
so you can use the following method for predicting values. 因此您可以使用以下方法预测值。 Here
n
is the number of values you want to predict. 这里
n
是您要预测的值的数量。 In your case, n
will be 12. 在您的情况下,
n
将为12。
pred = predict(fit,n.ahead = 1*n)
If you are taking log of values during ARIMA modeling so you use the following method for actual output. 如果您在ARIMA建模期间正在记录值,则可以使用以下方法进行实际输出。
values = 2.718^pred$pred
library(forecast)
forecast_horizon <- 12 # because you said 12 months
model <- auto.arima(data)
forecasts <- forecast(model, forecast_horizon)
y_pred <- forecasts$mean
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.