kt与gt的协整分析
library(urca)
s<-ur.df(k_likelihood, type = c("trend"), lags = 1,
selectlags = c("AIC"))
summary(s)
###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################
Test regression trend
Call:
lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
Residuals:
Min 1Q Median 3Q Max
-3.6683 -0.8258 0.0533 0.9626 3.4472
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.01652 2.32422 0.868 0.389
z.lag.1 -0.08669 0.05406 -1.604 0.114
tt -0.10658 0.07113 -1.498 0.140
z.diff.lag -0.03778 0.13163 -0.287 0.775
Residual standard error: 1.574 on 57 degrees of freedom
Multiple R-squared: 0.05296, Adjusted R-squared: 0.003116
F-statistic: 1.063 on 3 and 57 DF, p-value: 0.3722
Value of test-statistic is: -1.6037 10.8166 1.4228
Critical values for test statistics:
1pct 5pct 10pct
tau3 -4.04 -3.45 -3.15
phi2 6.50 4.88 4.16
phi3 8.73 6.49 5.47
##一阶的t值为-1.604>-4.04,>-3.45,>-3.15
不在拒绝域里面,接受有单位跟的原假设。
hh<-ur.df(diff(k_likelihood), type = c("none"), lags = 1,
selectlags = c("AIC"))
summary(hh)
###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################
Test regression none
Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
Residuals:
Min 1Q Median 3Q Max
-3.5749 -1.8058 -0.7448 1.0218 3.2996
Coefficients:
Estimate Std. Error t value Pr(>|t|)
z.lag.1 -0.3637 0.1325 -2.746 0.008031 **
z.diff.lag -0.4226 0.1187 -3.561 0.000745 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.762 on 58 degrees of freedom
Multiple R-squared: 0.4374, Adjusted R-squared: 0.418
F-statistic: 22.55 on 2 and 58 DF, p-value: 5.701e-08
Value of test-statistic is: -2.7455
Critical values for test statistics:
1pct 5pct 10pct
tau1 -2.6 -1.95 -1.61
t值是-2.7455,<-2.6,<-1.95,<-1.61
在拒绝域里面,是平稳的。
> pp.test(g)
Phillips-Perron Unit Root Test
data: g
Dickey-Fuller Z(alpha) = -7.527, Truncation lag parameter = 3, p-value = 0.6673
alternative hypothesis: stationary
p大,接受原假设,不平稳
> pp.test(diff(g))
Phillips-Perron Unit Root Test
data: diff(g)
Dickey-Fuller Z(alpha) = -36.495, Truncation lag parameter = 3, p-value = 0.01
alternative hypothesis: stationary
Warning message:
In pp.test(diff(g)) : p-value smaller than printed p-value
p小,拒绝原假设,平稳
kt和gt都是不平稳的时间序列,但一阶差分平稳
求相关系数
ss<-data.frame(k_likelihood[11:63],1/g)
cor(ss)
k_likelihood.11.63. X1.g
k_likelihood.11.63. 1.0000000 0.9728327
X1.g 0.9728327 1.0000000
cor.test(k_likelihood[11:63],1/g,conf.level=0.99)
Pearson's product-moment correlation
data: k_likelihood[11:63] and 1/g
t = 30.009, df = 51, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
99 percent confidence interval:
0.9445150 0.9867961
sample estimates:
cor
0.9728327
有很强的相关性
协整分析
协整回归
> s<-lm(k_likelihood[11:63]~g)
> summary(s)
Call:
lm(formula = k_likelihood[11:63] ~ g)
Residuals:
Min 1Q Median 3Q Max
-10.241 -4.408 -0.130 4.019 8.631
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 633.95 21.80 29.09 <2e-16 ***
g -61.74 2.10 -29.41 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.799 on 51 degrees of freedom
Multiple R-squared: 0.9443, Adjusted R-squared: 0.9432
F-statistic: 864.7 on 1 and 51 DF, p-value: < 2.2e-16
有很强的拟合优度
DW检验
> library(lmtest)
> dwtest(s)
Durbin-Watson test
data: s
DW = 0.23248, p-value < 2.2e-16
alternative hypothesis: true autocorrelation is greater than 0
DW = 0.23248>0.05,残差序列不存在自相关
残差的单整性检验
> m<-ur.df(residuals(s), type = c("none"), lags = 1,
> + selectlags = c("AIC"))
> summary(m)
###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################
Test regression none
Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
Residuals:
Min 1Q Median 3Q Max
-5.7814 -1.3393 0.1946 1.4806 5.1945
Coefficients:
Estimate Std. Error t value Pr(>|t|)
z.lag.1 -0.13787 0.06857 -2.011 0.0499 *
z.diff.lag 0.22519 0.13969 1.612 0.1134
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.22 on 49 degrees of freedom
Multiple R-squared: 0.097, Adjusted R-squared: 0.06015
F-statistic: 2.632 on 2 and 49 DF, p-value: 0.08209
Value of test-statistic is: -2.0106
Critical values for test statistics:
1pct 5pct 10pct
tau1 -2.6 -1.95 -1.61
-2.0106<-1.95,<-1.61,在拒绝域里,不存在单位跟,残差序列平稳
故存在协整关系
代表了一种长期均衡关系
残差图没有明显的时间趋势
误差修正模型
> diffk<<-diff(k_likelihood[11:63])
> diffg<-diff(g)
> error<-residuals(s)
> error.lag<-error[-(52:52)]
> ecm.reg1<-lm(diffk~diffg+error.lag)
> summary(ecm.reg1)
Call:
lm(formula = diffk ~ diffg + error.lag)
Residuals:
Min 1Q Median 3Q Max
-2.8531 -0.8762 -0.0453 1.0218 3.6047
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.74864 0.29075 -6.014 2.22e-07 ***
diffg 21.68558 10.16602 2.133 0.0379 *
error.lag -0.06900 0.04451 -1.550 0.1275
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.497 on 49 degrees of freedom
Multiple R-squared: 0.1347, Adjusted R-squared: 0.09941
F-statistic: 3.815 on 2 and 49 DF, p-value: 0.02885
> dwtest(ecm.reg1)
Durbin-Watson test
data: ecm.reg1
DW = 2.2397, p-value = 0.7558
alternative hypothesis: true autocorrelation is greater than 0
残差序列也没有自相关
∆k_t=-1.74864+21.68558∆g_t-0.06900〖ecm〗_t
存在短期均衡