set.seed(12345) u1<-rnorm(500) u2<-arima.sim(list(ar=0.6),n=500) #生成模拟的一阶自回归模型 u3<-arima.sim(list(ar=.4),n=500) y1<-cumsum(u1) #生成随机游走序列 y1 y2<-0.4*y1+u2 y3<-0.8*y1+u3 #调用urca包中的ca.jo()对时间序列y1 y2 y3进行Jonhansen协整检验 #2.Jonhansen协整检验 library(urca) data<-data.frame(y1=y1,y2=y2,y3=y3) #将变量组织为数据框
## ca.jo(x, type = c("eigen", "trace"), ecdet = c("none", "const", "trend"), K = 2,spec=c("longrun", "transitory"), season = NULL, dumvar = NULL) 注意这里只是用默认设置。 model.vecm<-ca.jo(data) head(model.vecm@x) #ca.jo使用S4方法,故用@提取变量 y1 y2 y3 [1,] 0.5855288 -0.31135095 -1.0377854 [2,] 1.2949948 0.59430322 -0.5116634 [3,] 1.1856915 1.28751444 -0.1316301 [4,] 0.7321943 1.64792194 0.7132483 [5,] 1.3380818 0.09367809 1.3288343 [6,] -0.4798742 -0.61468043 0.1199645 #使用slotNames()显示模型包含的全部对象类型 slotNames(model.vecm) [1] "x" "Z0" "Z1" "ZK" "type" "model" "ecdet" [8] "lag" "P" "season" "dumvar" "cval" "teststat" "lambda" [15] "Vorg" "V" "W" "PI" "DELTA" "GAMMA" "R0" [22] "RK" "bp" "spec" "call" "test.name" summary(model.vecm) ###################### # Johansen-Procedure # ###################### Test type: maximal eigenvalue statistic (lambda max) , with linear trend Eigenvalues (lambda): [1] 0.222707791 0.167079305 0.007684667 Values of teststatistic and critical values of test: test 10pct 5pct 1pct r <= 2 | 3.84 6.50 8.18 11.65 r <= 1 | 91.04 12.91 14.90 19.19 r = 0 | 125.47 18.90 21.07 25.75 Eigenvectors, normalised to first column: (These are the cointegration relations) y1.l2 y2.l2 y3.l2 y1.l2 1.0000000 1.000000 1.0000000 y2.l2 -0.2355148 -5.064504 -0.1799248 y3.l2 -1.1315152 1.143660 -0.1993207 Weights W: (This is the loading matrix) y1.l2 y2.l2 y3.l2 y1.d 0.05151358 0.002693258 -0.008416933 y2.d 0.11164178 0.075923301 -0.002918384 y3.d 0.51768302 -0.015197036 -0.006078055 从统计检验值可以看出,在r为2时接收原假设,即认为协整向量的秩为2