具有p值和标准误差的vecm模型的代码

时间:2017-09-12 05:28:32

标签: model error-correction

我已经运行了VECM模型并且只获得了系数值。如何在相同的结果中获得p值和标准误差

1 个答案:

答案 0 :(得分:1)

据我所知,答案是:

library(urca)   

以下是deg。未经调整的自由:

coeftest(cajorls(ca.jo(finland, ecdet="none", type="eigen", K=2),r=1)$rlm) 
coef(summary(cajorls(ca.jo(finland, ecdet="none", type="eigen", K=2), r=1)$rlm))

以下是deg。自由调整:

V1.eigen <- ca.jo(finland, ecdet="none", type="eigen", K=2) # rank=1
vecm <- cajorls(V1.eigen, r=1)
beta <- V1.eigen@V[,1] 
alfa <- V1.eigen@W[,1] 
residuals <- resid(vecm$rlm)
N <- nrow(residuals)
sigma <- crossprod(residuals)/N     
beta.se <- sqrt(diag(kronecker(solve(crossprod(V1.eigen@RK[,-1])), solve(t(alfa)%*%solve(sigma) %*% alfa))))
beta.t <- c(NA, beta[-1]/beta.se) # deg.of freedom adjusted
names(beta.t) <- rownames(cajorls(ca.jo(finland, ecdet="none", type="eigen", K=2), r=1)$beta) 
beta.t
beta.pval <- dt(beta.t, df=vecm$rlm$df.residual)
beta.pval

来自here的启发,可能会建议(做一个简洁的演示):

library(texreg)
cajo_beta_create <- function(cajo_o, cajorls_o) {
alfa <- coef(cajorls_o$rlm)[1, ]
residuals <- resid(cajorls_o$rlm)
N <- nrow(residuals)
sigma <- crossprod(residuals) / N
beta <- cajorls_o$beta
# standard errors
beta.se <- sqrt(diag(kronecker(solve(crossprod(cajo_o@RK[, -1])), solve(t(alfa) %*% solve(sigma) %*% alfa))))
beta.se2 <- c(NA, beta.se)
beta.t <- c(NA, beta[-1] / beta.se)
beta.pvalue <- dt(beta.t, df=cajorls_o$rlm$df.residual)     # p values

tr <- createTexreg(coef.names = as.character(rownames(beta)), coef = as.numeric(beta), se = beta.se2, pvalues=beta.pvalue,
gof.names = c('Dummy'), gof=c(1), gof.decimal=c(FALSE))
return(tr)
 }
cajo_beta_create(V1.eigen, vecm)
screenreg(cajo_beta_create(V1.eigen, vecm))