R:auto.arima() 与 xreg 对比 lm()

R: auto.arima() with xreg vs. lm()

我想了解 auto.arima() 与线性回归与 lm() 的工作原理。

我的假设似乎不正确,当您使用 auto.arima() 并指定 xreg 时,线性模型适合整个系列,然后 ARMA 模型是用于进一步拟合残差。我从 arima() 的文档中的这句话中得到了这一点(我相信这是 auto.arima():

If am xreg term is included, a linear regression (with a constant
term if include.mean is true and there is no differencing) is fitted
with an ARMA model for the error term.

来自这里:http://stat.ethz.ch/R-manual/R-patched/library/stats/html/arima.html

这意味着当我使用 xreg 执行 auto.arima() 时,我认为我应该为模型的线性回归部分获得与使用 lm() 相同的系数。但事实并非如此。我在下面有一个玩具示例。如果有人能弄清楚模型的实际工作方式,以及为什么系数的结果不一样(以及为什么我不应该期望它们是一样的),我将不胜感激。

这是代码示例。请注意,Interceptxdomain 在模型之间并不相同。

> ### Setup
> suppressPackageStartupMessages(library(forecast))
> 
> 
> ### Simulate some data
> set.seed(11111)
> m <- 9
> b <- 100
> escale <- 7
> xdomain <- seq(0, 40, by=0.5)
> 
>   ## ARMA errors
> errors <- as.vector(escale * arima.sim(model=list(ar=0.5, ma=c(0.5, 0.1)), n=length(xdomain)))
> 
> yrange <- m * xdomain + b + errors
> # plot(xdomain, yrange, main="Series to model")
> 
> 
> ### linear model
> lmmod <- lm(yrange ~ xdomain)
> summary(lmmod)

Call:
lm(formula = yrange ~ xdomain)

Residuals:
    Min      1Q  Median      3Q     Max 
-20.498  -8.070  -1.626   6.936  41.034 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  91.7352     2.7424   33.45   <2e-16 ***
xdomain       9.1478     0.1184   77.28   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 12.46 on 79 degrees of freedom
Multiple R-squared:  0.9869,    Adjusted R-squared:  0.9868 
F-statistic:  5972 on 1 and 79 DF,  p-value: < 2.2e-16

> 
> 
> ### ARIMA fit
> arimamod <- auto.arima(yrange, xreg = data.frame(xdomain=xdomain))
> summary(arimamod)
Series: yrange 
ARIMA(1,0,0) with non-zero mean 

Coefficients:
         ar1  intercept  xdomain
      0.8141    92.4565   9.0600
s.e.  0.0634     7.4766   0.3151

sigma^2 estimated as 51.18:  log likelihood=-274.86
AIC=557.72   AICc=558.25   BIC=567.3

Training set error measures:
                     ME     RMSE      MAE       MPE     MAPE      MASE      ACF1
Training set 0.07110327 7.154324 5.480392 -0.169368 2.498902 0.7892721 0.1302347

auto.arima() 通过最大似然而非单独估计联合模型。如果增加样本量,则系数之间的差异将减小。

这里是?arima关于估计的参考:

Gardner, G、Harvey, A. C. 和 Phillips, G. D. A. (1980) 算法 AS154。一种通过卡尔曼滤波对自回归移动平均模型进行精确最大似然估计的算法。应用统计学 29, 311–322.