我想使用rugarch包估算R中的Ar(1)-Garch(1,1)模型。我现在正在运行测试,并且在模型中包含外部回归器时遇到问题。我可以在我的均值方程或方差方程中包括一个外部回归变量,但不能同时包括两者(这是我所需要的)。 Ugarchspec没有给我错误消息,但是当我要拟合模型时,会出现以下错误消息:
pars [idx [“ mxreg”,1]:idx [“ mxreg”,2],1]中的错误<-fit.mean [i]: 替换的长度为零
我在做什么错?我正在使用的数据(Reg1)是一个时间序列。(请忽略,它只是40次观察,只是一个测试运行)
我仅使用均值方程式就使用外部回归函数对其进行了尝试,并且效果很好,我也使用矩阵而不是时间序列数据进行了尝试。
Spec1<- ugarchspec(
variance.model = list(model = "sGARCH", garchOrder = c(1,1),
external.regressors =Reg1[1:40,1:2]),
mean.model = list(armaOrder = c(1,0), include.mean = F,
external.regressors =Reg1[1:40,2]), distribution.model = "std")
fit1 <-ugarchfit(spec=Spec1,data=Reg1[1:40,1])
Error in pars[idx["mxreg", 1]:idx["mxreg", 2], 1] <- fit.mean[i] :
replacement has length zero
> Reg1[1:40]
weekreturn weekreturn1
2010-11-03 0.0018533675 0.0066020518
2010-11-10 0.0054522440 0.0072355717
2010-11-17 -0.0080023499 -0.0175327649
2010-11-24 -0.0006116435 0.0083274354
2010-12-01 0.0045637580 0.0084704193
2010-12-08 0.0035956818 0.0034966325
2010-12-15 -0.0009122183 0.0007687969
2010-12-22 0.0022032432 0.0041542532
2010-12-29 0.0118825438 0.0017621218
2011-01-05 -0.0023936587 -0.0018079717
2011-01-12 0.0051343640 0.0034256437
2011-01-19 0.0091805311 -0.0027364546
2011-01-26 0.0013110765 -0.0079251628
2011-02-02 0.0004902113 0.0079251628
2011-02-09 0.0027050851 -0.0093501286
2011-02-16 -0.0080829036 -0.0040071230
2011-02-23 -0.0065242275 0.0358634410
2011-03-02 0.0093583210 0.0082475620
2011-03-09 -0.0056961698 0.0041625819
2011-03-16 -0.0193926662 -0.0126549420
2011-03-23 0.0158149375 0.0152628883
2011-03-30 0.0042398967 -0.0028188258
2011-04-06 0.0131899706 0.0085606686
2011-04-13 0.0050939083 -0.0031861376
2011-04-20 0.0031597325 0.0079439432
2011-04-27 -0.0032323717 0.0029214016
2011-05-04 -0.0028337146 -0.0063428739
2011-05-11 -0.0069015444 -0.0212878507
2011-05-18 0.0051629648 0.0038123286
2011-05-25 -0.0012130035 0.0024228278
2011-06-01 0.0083575515 -0.0025544590
2011-06-08 0.0042632089 0.0008953902
2011-06-15 -0.0104308821 -0.0121336103
2011-06-22 -0.0067400310 0.0012617012
2011-06-29 0.0092369278 -0.0013460983
2011-07-06 -0.0035327721 0.0049108255
2011-07-13 0.0006245218 0.0028762694
2011-07-20 -0.0001176851 0.0001834956
2011-07-27 0.0003880984 -0.0015137640
2011-08-03 0.0023767744 -0.0115597586
我们将非常感谢您的帮助,因为它是针对我的硕士论文的。谢谢!