|
一般用AIC,比如
adf1 <- ur.df(x, type = "trend", lags = 2),lag=2是根据AIC准则确定的。过程是我分别从ar(1)模型拟合到ar(4)模型,选择AIC值最小的模型ar(2),因此设定lags=2
但是这个有时候会把人搞疯掉,因为如果这样设置——
adf2 <- ur.df(x, type = "trend", lags = 4,selectlags="AIC")
他俩结果是不一样的。这是因为第一种默认情况下用的是Fixed,而不是AIC准则。
所以换个思路,
我的抄几个程序给你,我用数据试过了,可行的。
>library(TSA )
>data(spots)
> pvaluem=NULL
> for (d in 1:5)
+ {res=tlrt(sqrt(spots),p=5,d=d,a=0.25,b=0.75); pvaluem=
+ cbind(pvaluem,c(d,restest.statistic,resp.value))}
> rownames(pvaluem)=c('d','test statistic','p-value')
> round(pvaluem,3)
[,1] [,2] [,3] [,4] [,5]
d 1.000 2.000 3.000 4.000 5.00
test statistic 46.897 111.341 99.058 84.962 45.12
p-value 0.000 0.000 0.000 0.000 0.00
还有一种程序:
>ibrary(TSA )
> AICM=NULL
> for(d in 1:4)
+ {predator.tar=tar(y=sqrt(spots),p1=4,p2=4,d=d,a=.1,b=.9)
>AICM=rbind(AICM, c(d, predator.tarAIC,signif(ptrdator.tarthd,4),
+predator.tarp1,predator.tarp2))}
> colnames(AICM)=c('d','nominal AIC','r','p1','p2')
> rownames(AICM)=NULL
>AICM
d nominal AIC r p1 p2
[1,] 1 155.8 5.882 2 4
[2,] 2 113.7 6.058 3 4[4,] 4 132.5 8.044 3 4
[3,] 3 130.2 6.595 2 4
后面这个绝对好用~
|