2015-09-07 41 views
1

我使用rugarch包在R以適應GARCH模型與所述均值方程ARMA階(1,0)。儘管滯後,但殘差序列與原始序列長度相同。殘差rugarch長度相同原始系列儘管滯後

library(rugarch) 
set.seed(123) 
x <- rnorm(1000) 
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(1,0))) 
fit <- ugarchfit(spec, x) 
coef <- [email protected]$coef 

xhat <- [email protected]$fitted.values 
myxhat <- coef["mu"] + coef["ar1"]*c(NA, x[-length(x)]) 
resid <- [email protected]$residuals 
myresid <- x-myxhat 

length(resid)==length(x) 
[1] TRUE 

head(cbind(x, xhat, myxhat, resid, myresid)) 
       x  xhat  myxhat  resid  myresid 
[1,] -0.56047565 0.01615305   NA -0.57662870   NA 
[2,] -0.23017749 0.03207118 0.03162527 -0.26224867 -0.26180276 
[3,] 1.55870831 0.02295313 0.02250722 1.53575518 1.53620110 
[4,] 0.07050839 -0.02642998 -0.02687590 0.09693838 0.09738429 
[5,] 0.12928774 0.01465254 0.01420663 0.11463519 0.11508111 
[6,] 1.71506499 0.01302991 0.01258399 1.70203508 1.70248099 

tail(cbind(x, xhat, myxhat, resid, myresid)) 
       x   xhat  myxhat  resid myresid 
[995,] 0.3132288 0.022487416 0.022041503 0.29074136 0.2911873 
[996,] -0.0899752 0.007952121 0.007506207 -0.09792732 -0.0974814 
[997,] 1.0705160 0.019082774 0.018636861 1.05143326 1.0518792 
[998,] -1.3511004 -0.012953185 -0.013399098 -1.33814720 -1.3377013 
[999,] -0.5226167 0.053896785 0.053450872 -0.57651348 -0.5760676 
[1000,] -0.2491907 0.031026066 0.030580152 -0.28021674 -0.2797708 

有誰知道如何(或爲什麼?)rugarch計算第一次觀察的殘差?我看到有人試圖在here之前問這個問題而沒有答案。感謝任何幫助。

+1

比較你的''x'的'head'和'tail',你的'x'的擬合值和你的殘差是多少?您可以嘗試根據garch模型的參數估計值自己構造殘差,並將第一個或最後一個觀察結果作爲違規的觀察結果作爲開始。 – js86

+0

我自己的計算是相似的,但不完全相同(當結果出現時,可能會寫入一些四捨五入的係數)。然而,我注意到第一個擬合值等於平均等式中的截距。 – Jonathan

回答

0

rugarch使用截距作爲用於估計與滯後值的方程式時,其通常除去這些觀測的擬合值。

coef["mu"] 
mu 
0.01615305