【发布时间】:2018-08-01 12:06:17
【问题描述】:
这里有个小问题。我一直在使用 ARMA 对时间序列数据进行分析,结果发现当我手动执行时,我从 R 获得的参数不适合我的计算。
为了通用,我在这里使用“lh”数据集进行分析:
> #Given 'lh' dataset which provided me a ts dataset with 48 periods of time
> lh
Time Series:
Start = 1
End = 48
Frequency = 1
[1] 2.4 2.4 2.4 2.2 2.1 1.5 2.3 2.3 2.5 2.0 1.9 1.7 2.2 1.8 3.2 3.2 2.7 2.2 2.2 1.9
[21] 1.9 1.8 2.7 3.0 2.3 2.0 2.0 2.9 2.9 2.7 2.7 2.3 2.6 2.4 1.8 1.7 1.5 1.4 2.1 3.3
[41] 3.5 3.5 3.1 2.6 2.1 3.4 3.0 2.9
>
> #I divided the dataset into training and testing
> lh.train <- lh[1:45] #training data is from period 1 to 45
> lh.test <- lh[46:48] #testing data is from period 46 to 48
>
> #Then I applied ARMA(1,1) to training dataset
> fit <- arima(lh.train, order = c(1,0,1))
> fit #from this output, I'd get the equation Yt = 2.3467 + 0.4507Yt-1 + et - 0.2533et-1
Call:
arima(x = lh.train, order = c(1, 0, 1))
Coefficients:
ar1 ma1 intercept
0.4507 0.2533 2.3467
s.e. 0.1701 0.1557 0.1370
sigma^2 estimated as 0.1696: log likelihood = -24.18, aic = 56.37
>
> #I did forecast to 3 periods of time, which are period 46, 47, and 48 from the original dataset
> lh.forecast <- predict(fit, n.ahead=3)
>
> #Then, I want to compare the prediction using R and computed manually
> #let's say to period of 46
> lh.forecast$pred[1] #it will give me prediction of period 46
[1] 2.151328
如您所见,从我的 R 输出中,对周期 46 的预测为 2.151328。从fit 我得到像 Yt = 2.3467 + 0.4507Yt-1 + et - 0.2533et-1 这样的方程。但是当我手动计算它时,使用这里的 et-1 和 Yt-1:
> fit$residuals[45] #et-1
[1] -0.3323993
> lh.train[45] #Yt-1
[1] 2.1
我的计算不正确。我得到了 period-46 的预测:3.349711,不等于 R 代码预测。
为什么我的预测不正确?我做错什么了吗?是因为我的方程式吗?我误解了吗?因为这不是唯一一次发生这种事情。每次我用 ARIMA 做分析时,总是这样。而且由于我的同事想知道真正的方程式,我担心我所做的事情是错误的。请帮帮我:(
【问题讨论】:
标签: r time-series arima