要实现以下的几个步骤,数据集已经有了,请高手们可以介绍下相关的函数吗?
halfyear_vector=data.frame(hsi_ir_h_ts,cenlhkl_ir_h_ts,m2_h_ts,ue_h_ts,cpi_h_ts,exp_h_ts,gdp_h_ts)
halfyear_vector=ts(halfyear_vector,start=c(1995,1),frequency=2)
halfyear_vector
plot(halfyear_vector,plot.type="single",lty=1:7,col=1:7)
title("key indicators")
legend("topleft",c("hsi_ir_h_ts","cenlhkl_ir_h_ts","m2_h_ts","ue_h_ts","cpi_h_ts","exp_h_ts","gdp_h_ts"),lty=1:7,col=1:7)
#稳定性检验
for (i in 1:7)
{
print(kpss.test(halfyear_vector[,i],null="Level"))
print(kpss.test(halfyear_vector[,i],null="Trend"))
print(kpss.test(diff(halfyear_vector[,i]),null="Level"))
print(kpss.test(diff(halfyear_vector[,i]),null="Trend"))
}
#需求一:进行ADF检验
#格兰杰因果检验
granger.test(halfyear_vector,p=7)
#需求二:进行指标共线性判断
#需求三:进行VAR阶数判断
#VAR模型拟合
halfyear_VAR=VAR(halfyear_vector,p=3,type="both")
halfyear_VAR
#需求四:价模型的稳定性、自相关性,异方差检验
#需求五:导出VAR模型
#VAR模型预测
halfyear_VAR_Predict=predict(halfyear_VAR,n.head=1,ci=0.9999)
plot(halfyear_VAR_Predict)
#需求六:计算95%,99%,99.9%分位数的预测取值