1

我想ar()R. 使用Arima()方法时,我使用fitted(model.object)函数获取它们,但我找不到ar().

4

2 回答 2

4

从 AR(p) 模型中获取拟合的最简单方法是使用auto.arima()forecast,它确实有一个fitted()方法。如果你真的想要一个纯 AR 模型,你可以通过参数约束差分,通过d参数约束 MA 顺序max.q

> library(forecast)
> fitted(auto.arima(WWWusage,d=0,max.q=0))
Time Series:
Start = 1 
End = 100 
Frequency = 1 
  [1]  91.68778  86.20842  82.13922  87.60576  ...
于 2014-05-29T18:43:58.317 回答
4

它不存储拟合向量,但确实具有残差。使用ar-object 的残差从原始数据重建预测的示例:

 data(WWWusage)
 arf <- ar(WWWusage)
str(arf)
#====================
List of 14
 $ order       : int 3
 $ ar          : num [1:3] 1.175 -0.0788 -0.1544
 $ var.pred    : num 117
 $ x.mean      : num 137
 $ aic         : Named num [1:21] 258.822 5.787 0.413 0 0.545 ...
  ..- attr(*, "names")= chr [1:21] "0" "1" "2" "3" ...
 $ n.used      : int 100
 $ order.max   : num 20
 $ partialacf  : num [1:20, 1, 1] 0.9602 -0.2666 -0.1544 -0.1202 -0.0715 ...
 $ resid       : Time-Series [1:100] from 1 to 100: NA NA NA -2.65 -4.19 ...
 $ method      : chr "Yule-Walker"
 $ series      : chr "WWWusage"
 $ frequency   : num 1
 $ call        : language ar(x = WWWusage)
 $ asy.var.coef: num [1:3, 1:3] 0.01017 -0.01237 0.00271 -0.01237 0.02449 ...
 - attr(*, "class")= chr "ar"
#===================
 str(WWWusage)
# Time-Series [1:100] from 1 to 100: 88 84 85 85 84 85 83 85 88 89 ...
png(); plot(WWWusage)
lines(seq(WWWusage),WWWusage - arf$resid, col="red"); dev.off()

在此处输入图像描述

于 2014-05-29T20:33:56.763 回答