根据您提供的代码和分析结果,我们可以采取以下步骤进行改进:
VARselect
函数,以确定最佳滞后阶数。library(vars)
VAR_model_candidate <- VARselect(data, lag.max = 12, type="const")
print(VAR_model_candidate$selection[,"AIC"])
# 选择AIC最小的滞后阶数,例如,如果第2个滞后阶数有最小AIC,则使用p=2
optimal_lag <- which.min(VAR_model_candidate$selection[,"AIC"])
data_transformed <- as.data.frame(log(data[-1])) # 排除年份这一非时间序列
colnames(data_transformed) <- c("log_coal", "log_oil", "log_el")
var_model_improved <- VAR(data_transformed, p=optimal_lag, type="const")
summary(var_model_improved)
ser_test_improved <- serial.test(var_model_improved, lags.pt = 12, type = "PT.asymptotic")
arch_test_improved <- arch.test(var_model_improved, lags.multi = 5)
norm_test_improved <- normality.test(var_model_improved)
stab_test_improved <- stability(var_model_improved)
print(ser_test_improved)
print(arch_test_improved)
print(norm_test_improved)
plot(stab_test_improved)
irf_response_improved <- irf(var_model_improved, impulse='log_coal', response='log_el', n.ahead = 10)
plot(irf_response_improved)
granger_coal_improved <- causality(var_model_improved, cause = "log_coal")
print(granger_coal_improved)
请注意,上述代码需要根据您的数据结构和需求进行适当的调整。例如,如果数据中存在缺失值或异常值,可能还需要进行预处理。此外,如果发现模型仍然存在问题,可能需要考虑使用其他时间序列模型或方法,如ARIMA、GARCH等。