【问题标题】:I computed ARMA equation from R manually but never got the same result with predict() or forecast() provided by R我从 R 手动计算了 ARMA 方程,但从未得到与 R 提供的 predict() 或 predict() 相同的结果
【发布时间】: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


【解决方案1】:

问题在于,被称为“截距”的系数会更准确地识别为“均值”。

as.numeric(fit$coef)[3]+as.numeric(fit$coef)[1]*(lh[45]-as.numeric(fit$coef)[3])+as.numeric(fit$coef)[2]*fit$residuals[45]

[1] 2.151328

【讨论】:

    【解决方案2】:

    根据documentation

    默认情况下,Arima() 函数在 d > 0 时设置 c=μ=0,并在 d = 0 时提供 μ 的估计值。

    因为这个模型有d = 0,所以常数是yt的平均值。因此,正确的方程是:

    2.3467 + (2.1 - 2.3467) * 0.4507 + 0.2533 * -0.3323993

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      • 2020-02-23
      • 2020-02-20
      • 2015-11-26
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多