當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R ar 將自回歸模型擬合到時間序列

R語言 ar 位於 stats 包(package)。

說明

將自回歸時間序列模型擬合到數據,默認情況下選擇 AIC 的複雜性。

用法

ar(x, aic = TRUE, order.max = NULL,
   method = c("yule-walker", "burg", "ols", "mle", "yw"),
   na.action, series, ...)

ar.burg(x, ...)
## Default S3 method:
ar.burg(x, aic = TRUE, order.max = NULL,
        na.action = na.fail, demean = TRUE, series,
        var.method = 1, ...)
## S3 method for class 'mts'
ar.burg(x, aic = TRUE, order.max = NULL,
        na.action = na.fail, demean = TRUE, series,
        var.method = 1, ...)

ar.yw(x, ...)
## Default S3 method:
ar.yw(x, aic = TRUE, order.max = NULL,
      na.action = na.fail, demean = TRUE, series, ...)
## S3 method for class 'mts'
ar.yw(x, aic = TRUE, order.max = NULL,
      na.action = na.fail, demean = TRUE, series,
      var.method = 1, ...)

ar.mle(x, aic = TRUE, order.max = NULL, na.action = na.fail,
       demean = TRUE, series, ...)

## S3 method for class 'ar'
predict(object, newdata, n.ahead = 1, se.fit = TRUE, ...)

參數

x

單變量或多變量時間序列。

aic

logical 。如果TRUE,則使用 Akaike 信息準則來選擇自回歸模型的階數。如果 FALSE ,則擬合階數 order.max 的模型。

order.max

要擬合的模型的最大階數(或階數)。默認為 中較小的一個,其中 是非缺失觀測值的數量,method = "mle" 除外,它是該數量和 12 中的最小值。

method

指定擬合模型方法的字符串。必須是默認參數中的字符串之一(前幾個字符就足夠了)。默認為 "yule-walker"

na.action

調用函數來處理缺失值。目前,通過na.action = na.pass,隻有Yule-Walker方法可以處理在一個時間點內必須一致的缺失值:或者所有變量都缺失,或者沒有。

demean

應該在擬合過程中估計平均值嗎?

series

該係列的名稱。默認為 deparse1(substitute(x))

var.method

估計創新方差的方法(參見“詳細信息”)。

...

特定方法的附加參數。

object

來自 ar() 的擬合。

newdata

應用預測的數據。

n.ahead

預測的提前步數。

se.fit

邏輯:返回預測誤差的估計標準誤差?

細節

為了明確起見,請注意 AR 係數的符號為

ar 隻是函數 ar.ywar.burgar.olsar.mle 的包裝。

如果 aic 為 true,則訂單選擇由 AIC 完成。這是有問題的,因為這裏的方法中隻有 ar.mle 執行真正的最大似然估計。 AIC 的計算方式就像方差估計是 MLE,從似然中省略了行列式項。請注意,這與在估計參數值下評估的高斯似然不同。在 ar.yw 中,創新的方差矩陣是根據 x 的擬合係數和自協方差計算的。

ar.burg 允許兩種方法來估計創新方差以及 AIC。方法 1 是使用 Levinson-Durbin 遞歸給出的更新(Brockwell 和 Davis,1991,第 242 頁的(8.2.6)),並遵循 S-PLUS。方法 2 是前向和後向預測誤差的平方和的平均值(如 Brockwell 和 Davis,1996 年,第 145 頁)。 Percival 和 Walden (1998) 討論了兩者。在多變量情況下,估計係數將(稍微)取決於方差估計方法。

請記住,ar 默認情況下在模型中包含一個常量,方法是在擬合 AR 模型之前刪除 x 的總體平均值,或者 ( ar.mle ) 估計要減去的常量。

對於 ar 及其方法,類 "ar" 的列表包含以下元素:

order

擬合模型的順序。這是通過在 aic = TRUE 時最小化 AIC 來選擇的,否則為 order.max

ar

擬合模型的估計自回歸係數。

var.pred

預測方差:對時間序列方差中自回歸模型無法解釋的部分的估計。

x.mean

用於擬合和預測的序列的估計平均值。

x.intercept

(僅限 ar.ols。)x - x.mean 模型中的截距。

aic

每個模型與 best-fitting 模型之間 AIC 的差異。請注意,後者的 AIC 可以為 -Inf

n.used

時間序列中的觀測值數量,包括缺失值。

n.obs

時間序列中非缺失觀測值的數量。

order.max

order.max 參數的值。

partialacf

偏自相關函數的估計滯後 order.max

resid

擬合模型的殘差,以第一個 order 觀測值為條件。第一個 order 殘差設置為 NA 。如果 x 是時間序列,那麽 resid 也是時間序列。

method

method 參數的值。

series

時間序列的名稱。

frequency

時間序列的頻率。

call

匹配的調用。

asy.var.coef

(單變量情況,order > 0。)係數估計的asymptotic-theory 方差矩陣。

對於 predict.ar ,預測的時間序列,或者如果 se.fit = TRUE ,則包含組件 pred 的列表(預測)和 se (估計的標準誤差)。兩個組成部分都是時間序列。

注意

僅實現ar.mle 的單變量情況。

通過 method="mle" 擬合長序列可能會非常慢。

如果 x 包含缺失值,請參閱 NA ,還可以考慮使用 arima() ,可能與 method = "ML" 一起使用。

例子

ar(lh)
ar(lh, method = "burg")
ar(lh, method = "ols")
ar(lh, FALSE, 4) # fit ar(4)

(sunspot.ar <- ar(sunspot.year))
predict(sunspot.ar, n.ahead = 25)
## try the other methods too

ar(ts.union(BJsales, BJsales.lead))
## Burg is quite different here, as is OLS (see ar.ols)
ar(ts.union(BJsales, BJsales.lead), method = "burg")

作者

Martyn Plummer. Univariate case of ar.yw, ar.mle and C code for univariate case of ar.burg by B. D. Ripley.

參考

Brockwell, P. J. and Davis, R. A. (1991). Time Series and Forecasting Methods, second edition. Springer, New York. Section 11.4.

Brockwell, P. J. and Davis, R. A. (1996). Introduction to Time Series and Forecasting. Springer, New York. Sections 5.1 and 7.6.

Percival, D. P. and Walden, A. T. (1998). Spectral Analysis for Physical Applications. Cambridge University Press.

Whittle, P. (1963). On the fitting of multivariate autoregressions and the approximate canonical factorization of a spectral density matrix. Biometrika, 40, 129-134. doi:10.2307/2333753.

也可以看看

ar.olsarima 用於 ARMA 模型; acf2AR ,用於 ACF 的 AR 構建。

arima.sim 用於模擬 AR 過程。

相關用法


注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Fit Autoregressive Models to Time Series。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。