rm(list = ls())
graphics.off()
setwd("F:\\THNN2")
library(vars)
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
library(urca)
library(readxl)
library(DT)
data <- read_xlsx("F:/THNN2/DLTH.xlsx")
# Chuyển thành chuỗi thời gian
cpi <- ts(data$CPI, start = c(2012, 1), frequency = 4)
m2 <- ts(data$M2, start = c(2012, 1), frequency = 4)
oea <- ts(data$OEA, start = c(2012, 1), frequency = 4)
cir <- ts(data$CIR, start = c(2012, 1), frequency = 4)
roe <- ts(data$ROE, start = c(2012, 1), frequency = 4)
ydata <- cbind(cir, cpi, m2, oea, roe)
colnames(ydata) <- c("cir", "cpi", "m2", "oea", "roe")
library(moments) # skewness, kurtosis
library(tseries) # jarque.bera.test
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(psych)
thong_ke_mo_ta <- function(x) {
n <- length(x)
mean_x <- mean(x)
median_x <- median(x)
max_x <- max(x)
min_x <- min(x)
sd_x <- sd(x)
skew <- skewness(x)
kurt <- kurtosis(x) - 3 # điều chỉnh về Excess Kurtosis như EViews
jb <- jarque.bera.test(x)
sum_x <- sum(x)
sum_sq_dev <- sum((x - mean_x)^2)
return(c(
Mean = round(mean_x, 2),
Median = round(median_x, 2),
Maximum = round(max_x, 2),
Minimum = round(min_x, 2),
`Std. Dev.` = round(sd_x, 2),
Skewness = round(skew, 2),
Kurtosis = round(kurt, 2),
`Jarque-Bera` = round(jb$statistic, 2),
Probability = round(jb$p.value, 4),
Sum = round(sum_x, 2),
`Sum Sq. Dev.` = round(sum_sq_dev, 2),
Observations = n
))
}
results <- apply(ydata, 2, thong_ke_mo_ta)
t(results)
## Mean Median Maximum Minimum Std. Dev. Skewness Kurtosis
## cir 36.90 37.61 52.10 23.92 6.84 0.15 -0.51
## cpi 97.20 97.08 116.86 77.75 10.90 0.08 -1.03
## m2 0.25 0.20 1.18 0.01 0.21 2.56 7.66
## oea 0.32 0.31 0.50 0.22 0.07 0.62 -0.39
## roe 3.81 3.95 5.67 1.25 1.19 -0.38 -0.77
## Jarque-Bera.X-squared Probability Sum Sum Sq. Dev. Observations
## cir 0.76 0.6850 1918.60 2387.20 52
## cpi 2.37 0.3059 5054.66 6059.83 52
## m2 184.13 0.0000 12.84 2.32 52
## oea 3.61 0.1644 16.57 0.26 52
## roe 2.52 0.2837 198.01 71.96 52
# Cài đặt lại để biểu đồ hiển thị 1 biến mỗi lần
par(mfrow = c(1, 1))
# Lặp qua từng cột trong ydata và vẽ biểu đồ đường
for (var_name in colnames(ydata)) {
plot(ydata[, var_name],
type = "l", # "l" = line
main = paste("Biến động của", toupper(var_name)),
xlab = "Thời gian",
ylab = var_name,
col = "blue",
lwd = 2)
grid()
}
cor_matrix <- cor(ydata)
print(cor_matrix)
## cir cpi m2 oea roe
## cir 1.00000000 -0.3487076 0.16001818 0.8486813 -0.09929364
## cpi -0.34870759 1.0000000 -0.52915370 -0.3216304 0.13267789
## m2 0.16001818 -0.5291537 1.00000000 0.2473261 -0.01223928
## oea 0.84868131 -0.3216304 0.24732609 1.0000000 -0.06906850
## roe -0.09929364 0.1326779 -0.01223928 -0.0690685 1.00000000
adf_test_auto <- function(series, max_lag = 10, trend_type = "trend", ic = "AIC") {
best_ic <- Inf
best_result <- NULL
for (i in 0:max_lag) {
test <- ur.df(series, type = trend_type, lags = i)
# Trích log-likelihood thủ công
SSR <- sum(test@res^2) # residual sum of squares
T <- length(series)
k <- i + 1 + ifelse(trend_type == "trend", 2, ifelse(trend_type == "drift", 1, 0)) # số tham số
sigma2 <- SSR / (T - k)
# log likelihood: theo AIC/SIC
loglik <- -T/2 * (log(2 * pi) + log(sigma2) + 1)
if (ic == "AIC") {
ic_value <- -2 * loglik + 2 * k
} else {
ic_value <- -2 * loglik + log(T) * k
}
if (ic_value < best_ic) {
best_ic <- ic_value
best_result <- test
}
}
return(best_result)
}
summary(adf_test_auto(cpi, max_lag = 10, trend_type = "trend", ic = "AIC"))
##
## ###############################################
## # 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
## -1.88761 -0.31599 0.03809 0.33381 1.65310
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 35.01358 16.89019 2.073 0.0463 *
## z.lag.1 -0.45144 0.22273 -2.027 0.0511 .
## tt 0.33344 0.15534 2.146 0.0395 *
## z.diff.lag1 0.10124 0.21442 0.472 0.6400
## z.diff.lag2 0.09077 0.19419 0.467 0.6434
## z.diff.lag3 0.07592 0.19797 0.383 0.7039
## z.diff.lag4 0.14249 0.18633 0.765 0.4500
## z.diff.lag5 0.10922 0.17665 0.618 0.5408
## z.diff.lag6 0.36080 0.16351 2.207 0.0346 *
## z.diff.lag7 0.07843 0.17250 0.455 0.6524
## z.diff.lag8 -0.04609 0.16762 -0.275 0.7851
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6639 on 32 degrees of freedom
## Multiple R-squared: 0.3533, Adjusted R-squared: 0.1512
## F-statistic: 1.748 on 10 and 32 DF, p-value: 0.1123
##
##
## Value of test-statistic is: -2.0269 6.9484 4.3828
##
## 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
Biến CPI không dừng -> lấy sai phân bậc 1
dcpi <- diff(cpi)
summary(adf_test_auto(dcpi, max_lag = 10, trend_type = "drift", ic = "AIC"))
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.42839 -0.37215 0.06158 0.35591 1.54880
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.87815 0.26188 3.353 0.001700 **
## z.lag.1 -1.20906 0.31312 -3.861 0.000383 ***
## z.diff.lag1 0.13224 0.25894 0.511 0.612222
## z.diff.lag2 0.01980 0.20219 0.098 0.922447
## z.diff.lag3 -0.04325 0.14300 -0.302 0.763810
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7308 on 42 degrees of freedom
## Multiple R-squared: 0.5622, Adjusted R-squared: 0.5205
## F-statistic: 13.48 on 4 and 42 DF, p-value: 3.75e-07
##
##
## Value of test-statistic is: -3.8614 7.5454
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1 6.70 4.71 3.86
Từ kết quả có thể kết luận biến CPI dừng tại sai phân bậc 1
summary(adf_test_auto(m2, max_lag = 10, trend_type = "trend", ic = "AIC"))
##
## ###############################################
## # 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
## -0.066609 -0.022010 -0.001518 0.022901 0.115709
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.303134 0.104038 2.914 0.00669 **
## z.lag.1 -0.811297 0.278868 -2.909 0.00676 **
## tt -0.004409 0.001490 -2.959 0.00597 **
## z.diff.lag1 0.394666 0.250138 1.578 0.12510
## z.diff.lag2 -0.229265 0.244403 -0.938 0.35571
## z.diff.lag3 -0.083120 0.215232 -0.386 0.70208
## z.diff.lag4 0.383615 0.184641 2.078 0.04640 *
## z.diff.lag5 -0.126405 0.157885 -0.801 0.42965
## z.diff.lag6 0.257354 0.118775 2.167 0.03832 *
## z.diff.lag7 0.023918 0.072538 0.330 0.74389
## z.diff.lag8 0.157726 0.068536 2.301 0.02850 *
## z.diff.lag9 0.062466 0.062303 1.003 0.32406
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.04021 on 30 degrees of freedom
## Multiple R-squared: 0.9167, Adjusted R-squared: 0.8862
## F-statistic: 30.01 on 11 and 30 DF, p-value: 3.537e-13
##
##
## Value of test-statistic is: -2.9093 3.3198 4.483
##
## 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
Biến M2 không dừng -> lấy sai phân bậc 1
dm2 <- diff(m2)
summary(adf_test_auto(dm2, max_lag = 10, trend_type = "trend", ic = "AIC"))
##
## ###############################################
## # 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
## -0.065490 -0.028699 -0.006216 0.023481 0.125153
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.0055548 0.0213968 0.260 0.796881
## z.lag.1 -2.4708064 0.6279297 -3.935 0.000438 ***
## tt -0.0004038 0.0006346 -0.636 0.529279
## z.diff.lag1 1.2899594 0.5594942 2.306 0.027989 *
## z.diff.lag2 0.5174858 0.4510601 1.147 0.260049
## z.diff.lag3 0.0434806 0.3344247 0.130 0.897394
## z.diff.lag4 0.1894094 0.2404556 0.788 0.436848
## z.diff.lag5 -0.1358887 0.1975455 -0.688 0.496640
## z.diff.lag6 -0.0327292 0.1177068 -0.278 0.782815
## z.diff.lag7 -0.0805785 0.0966190 -0.834 0.410672
## z.diff.lag8 0.0190271 0.0619890 0.307 0.760939
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.04479 on 31 degrees of freedom
## Multiple R-squared: 0.948, Adjusted R-squared: 0.9312
## F-statistic: 56.49 on 10 and 31 DF, p-value: < 2.2e-16
##
##
## Value of test-statistic is: -3.9348 5.5493 8.0401
##
## 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ừ kết quả có thể kết luận biến M2 dừng tại sai phân bậc 1
summary(adf_test_auto(oea, max_lag = 10, trend_type = "trend", ic = "AIC"))
##
## ###############################################
## # 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
## -0.076475 -0.022129 0.002557 0.020780 0.064746
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.571512 0.270632 2.112 0.0431 *
## z.lag.1 -1.471333 0.672254 -2.189 0.0365 *
## tt -0.003584 0.001818 -1.971 0.0580 .
## z.diff.lag1 0.158234 0.599036 0.264 0.7935
## z.diff.lag2 0.021686 0.508787 0.043 0.9663
## z.diff.lag3 -0.171576 0.402162 -0.427 0.6727
## z.diff.lag4 0.140340 0.313216 0.448 0.6573
## z.diff.lag5 0.206172 0.261962 0.787 0.4374
## z.diff.lag6 0.054975 0.245259 0.224 0.8242
## z.diff.lag7 -0.016559 0.207688 -0.080 0.9370
## z.diff.lag8 0.193225 0.175096 1.104 0.2786
## z.diff.lag9 0.081977 0.116430 0.704 0.4868
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.03818 on 30 degrees of freedom
## Multiple R-squared: 0.8931, Adjusted R-squared: 0.8539
## F-statistic: 22.79 on 11 and 30 DF, p-value: 1.334e-11
##
##
## Value of test-statistic is: -2.1887 3.1336 2.4949
##
## 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
Biến OEA không dừng -> lấy sai phân bậc 1
doea <- diff(oea)
summary(adf_test_auto(doea, max_lag = 10, trend_type = "trend", ic = "AIC"))
##
## ###############################################
## # 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
## -0.069308 -0.014469 -0.003119 0.017698 0.055431
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0274015 0.0177842 -1.541 0.135011
## z.lag.1 -8.6634566 1.6324185 -5.307 1.34e-05 ***
## tt 0.0002305 0.0005310 0.434 0.667655
## z.diff.lag1 6.3536208 1.5409117 4.123 0.000319 ***
## z.diff.lag2 4.9969929 1.3640435 3.663 0.001071 **
## z.diff.lag3 3.6020739 1.1569591 3.113 0.004343 **
## z.diff.lag4 2.6705234 0.9482241 2.816 0.008967 **
## z.diff.lag5 2.0045852 0.7859700 2.550 0.016743 *
## z.diff.lag6 1.5165003 0.6601659 2.297 0.029592 *
## z.diff.lag7 1.1291930 0.5297823 2.131 0.042307 *
## z.diff.lag8 0.8780783 0.3807371 2.306 0.029006 *
## z.diff.lag9 0.6702768 0.2437601 2.750 0.010510 *
## z.diff.lag10 0.3336725 0.1040150 3.208 0.003431 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0351 on 27 degrees of freedom
## Multiple R-squared: 0.9728, Adjusted R-squared: 0.9607
## F-statistic: 80.51 on 12 and 27 DF, p-value: < 2.2e-16
##
##
## Value of test-statistic is: -5.3071 9.7295 14.4426
##
## 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ừ kết quả có thể kết luận biến OEA dừng tại sai phân bậc 1
summary(adf_test_auto(cir, max_lag = 10, trend_type = "trend", ic = "AIC"))
##
## ###############################################
## # 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
## -13.4237 -3.2691 -0.5134 3.1814 11.7763
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 31.17016 10.99992 2.834 0.00718 **
## z.lag.1 -0.70300 0.25640 -2.742 0.00909 **
## tt -0.18280 0.07721 -2.368 0.02283 *
## z.diff.lag1 -0.26846 0.24933 -1.077 0.28806
## z.diff.lag2 -0.16479 0.21824 -0.755 0.45462
## z.diff.lag3 -0.35704 0.18663 -1.913 0.06292 .
## z.diff.lag4 0.02237 0.13503 0.166 0.86923
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.538 on 40 degrees of freedom
## Multiple R-squared: 0.68, Adjusted R-squared: 0.632
## F-statistic: 14.17 on 6 and 40 DF, p-value: 1.414e-08
##
##
## Value of test-statistic is: -2.7418 2.7311 4.092
##
## 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
Biến CIR không dừng -> lấy sai phân bậc 1
dcir <- diff(cir)
summary(adf_test_auto(dcir, max_lag = 10, trend_type = "drift", ic = "AIC"))
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -13.3084 -1.6245 -0.1747 2.7661 9.4414
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.7300 0.8802 -0.829 0.41394
## z.lag.1 -4.2720 1.4261 -2.996 0.00568 **
## z.diff.lag1 2.3259 1.3696 1.698 0.10055
## z.diff.lag2 1.6949 1.2772 1.327 0.19523
## z.diff.lag3 1.0967 1.1717 0.936 0.35730
## z.diff.lag4 0.9448 1.0564 0.894 0.37873
## z.diff.lag5 0.9661 0.9397 1.028 0.31271
## z.diff.lag6 0.9975 0.8066 1.237 0.22647
## z.diff.lag7 0.9494 0.6473 1.467 0.15360
## z.diff.lag8 0.9724 0.4747 2.048 0.05000 .
## z.diff.lag9 0.8028 0.3072 2.613 0.01427 *
## z.diff.lag10 0.3557 0.1373 2.590 0.01507 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.44 on 28 degrees of freedom
## Multiple R-squared: 0.9273, Adjusted R-squared: 0.8988
## F-statistic: 32.48 on 11 and 28 DF, p-value: 5.085e-13
##
##
## Value of test-statistic is: -2.9955 4.5441
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1 6.70 4.71 3.86
Từ kết quả có thể kết luận biến CIR dừng tại sai phân bậc 1
summary(adf_test_auto(roe, max_lag = 10, trend_type = "trend", ic = "AIC"))
##
## ###############################################
## # 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
## -1.6223 -0.7044 0.0128 0.5755 1.8696
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.720523 1.825331 0.395 0.6960
## z.lag.1 -0.327513 0.466990 -0.701 0.4889
## tt 0.018513 0.014796 1.251 0.2212
## z.diff.lag1 -0.408627 0.420250 -0.972 0.3392
## z.diff.lag2 -0.336407 0.394142 -0.854 0.4006
## z.diff.lag3 -0.256522 0.388503 -0.660 0.5145
## z.diff.lag4 0.062320 0.378025 0.165 0.8702
## z.diff.lag5 0.034224 0.370941 0.092 0.9271
## z.diff.lag6 0.100787 0.375429 0.268 0.7903
## z.diff.lag7 -0.138526 0.379650 -0.365 0.7179
## z.diff.lag8 -0.003203 0.327531 -0.010 0.9923
## z.diff.lag9 -0.198044 0.271040 -0.731 0.4710
## z.diff.lag10 -0.327467 0.173440 -1.888 0.0694 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.012 on 28 degrees of freedom
## Multiple R-squared: 0.6501, Adjusted R-squared: 0.5002
## F-statistic: 4.336 on 12 and 28 DF, p-value: 0.0006706
##
##
## Value of test-statistic is: -0.7013 0.8755 1.17
##
## 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
Biến ROE không dừng -> lấy sai phân bậc 1
droe <- diff(roe)
summary(adf_test_auto(droe, max_lag = 10, trend_type = "drift", ic = "AIC"))
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.42586 -0.66065 0.01646 0.65739 1.82290
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.08652 0.16254 0.532 0.59845
## z.lag.1 -3.75672 1.27562 -2.945 0.00619 **
## z.diff.lag1 2.07164 1.22351 1.693 0.10078
## z.diff.lag2 1.51391 1.14686 1.320 0.19680
## z.diff.lag3 1.07544 1.04198 1.032 0.31027
## z.diff.lag4 0.99923 0.92331 1.082 0.28777
## z.diff.lag5 0.90949 0.79463 1.145 0.26145
## z.diff.lag6 0.90245 0.64468 1.400 0.17182
## z.diff.lag7 0.67264 0.46728 1.439 0.16036
## z.diff.lag8 0.59342 0.29168 2.035 0.05082 .
## z.diff.lag9 0.34819 0.13349 2.608 0.01405 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.017 on 30 degrees of freedom
## Multiple R-squared: 0.8783, Adjusted R-squared: 0.8378
## F-statistic: 21.66 on 10 and 30 DF, p-value: 4.523e-11
##
##
## Value of test-statistic is: -2.945 4.3395
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1 6.70 4.71 3.86
dydata <- cbind(dcpi, dm2, doea, dcir, droe)
colnames(dydata) <- c("D_cpi", "D_m2", "D_oea","D_cir", "D_roe")
VARselect(dydata, lag.max = 4, type = "both")$selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 3 3 2 3
Chọn độ trễ tối ưu là 3
var.model <- VAR(dydata, p = 3, type = "const")
summary(var.model)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: D_cpi, D_m2, D_oea, D_cir, D_roe
## Deterministic variables: const
## Sample size: 48
## Log Likelihood: -52.73
## Roots of the characteristic polynomial:
## 0.9036 0.9036 0.8984 0.8706 0.8706 0.8195 0.8195 0.6965 0.6965 0.6503 0.6503 0.5708 0.5655 0.5655 0.523
## Call:
## VAR(y = dydata, p = 3, type = "const")
##
##
## Estimation results for equation D_cpi:
## ======================================
## D_cpi = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3 + const
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 7.651e-02 1.795e-01 0.426 0.67273
## D_m2.l1 -2.821e-01 1.393e+00 -0.202 0.84083
## D_oea.l1 3.397e+00 3.576e+00 0.950 0.34919
## D_cir.l1 -1.306e-02 3.268e-02 -0.400 0.69194
## D_roe.l1 1.331e-01 1.152e-01 1.156 0.25638
## D_cpi.l2 -1.445e-01 1.761e-01 -0.820 0.41805
## D_m2.l2 1.018e-01 1.290e+00 0.079 0.93762
## D_oea.l2 1.859e+00 4.826e+00 0.385 0.70263
## D_cir.l2 -2.937e-02 4.138e-02 -0.710 0.48297
## D_roe.l2 -9.741e-02 1.321e-01 -0.737 0.46632
## D_cpi.l3 4.404e-02 1.694e-01 0.260 0.79659
## D_m2.l3 -4.604e-01 8.310e-01 -0.554 0.58343
## D_oea.l3 4.228e+00 3.614e+00 1.170 0.25069
## D_cir.l3 -4.235e-02 3.305e-02 -1.281 0.20929
## D_roe.l3 2.653e-06 1.023e-01 0.000 0.99998
## const 7.565e-01 2.517e-01 3.006 0.00512 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.7309 on 32 degrees of freedom
## Multiple R-Squared: 0.3054, Adjusted R-squared: -0.02016
## F-statistic: 0.9381 on 15 and 32 DF, p-value: 0.5353
##
##
## Estimation results for equation D_m2:
## =====================================
## D_m2 = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3 + const
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 -0.0009298 0.0173104 -0.054 0.95750
## D_m2.l1 0.0606752 0.1343882 0.451 0.65468
## D_oea.l1 -1.7599792 0.3449016 -5.103 1.47e-05 ***
## D_cir.l1 0.0081837 0.0031516 2.597 0.01410 *
## D_roe.l1 -0.0144219 0.0111081 -1.298 0.20346
## D_cpi.l2 -0.0187926 0.0169898 -1.106 0.27693
## D_m2.l2 -0.2831060 0.1244570 -2.275 0.02976 *
## D_oea.l2 -1.8714549 0.4654508 -4.021 0.00033 ***
## D_cir.l2 0.0092009 0.0039915 2.305 0.02780 *
## D_roe.l2 -0.0039243 0.0127432 -0.308 0.76011
## D_cpi.l3 -0.0221240 0.0163410 -1.354 0.18525
## D_m2.l3 -0.4199739 0.0801492 -5.240 9.89e-06 ***
## D_oea.l3 -0.3118160 0.3485419 -0.895 0.37766
## D_cir.l3 0.0020847 0.0031880 0.654 0.51783
## D_roe.l3 0.0118724 0.0098632 1.204 0.23753
## const 0.0104018 0.0242760 0.428 0.67117
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.0705 on 32 degrees of freedom
## Multiple R-Squared: 0.8754, Adjusted R-squared: 0.8169
## F-statistic: 14.98 on 15 and 32 DF, p-value: 2.065e-10
##
##
## Estimation results for equation D_oea:
## ======================================
## D_oea = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3 + const
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 0.0122415 0.0119559 1.024 0.313565
## D_m2.l1 -0.1056086 0.0928185 -1.138 0.263653
## D_oea.l1 -0.9987378 0.2382149 -4.193 0.000203 ***
## D_cir.l1 0.0003632 0.0021767 0.167 0.868529
## D_roe.l1 -0.0043864 0.0076721 -0.572 0.571499
## D_cpi.l2 0.0063504 0.0117344 0.541 0.592135
## D_m2.l2 -0.0527220 0.0859593 -0.613 0.543989
## D_oea.l2 -0.8421564 0.3214752 -2.620 0.013346 *
## D_cir.l2 0.0014444 0.0027569 0.524 0.603937
## D_roe.l2 -0.0059063 0.0088014 -0.671 0.506996
## D_cpi.l3 -0.0034136 0.0112863 -0.302 0.764260
## D_m2.l3 -0.1782341 0.0553570 -3.220 0.002940 **
## D_oea.l3 -0.6777331 0.2407291 -2.815 0.008272 **
## D_cir.l3 0.0007156 0.0022019 0.325 0.747315
## D_roe.l3 -0.0049776 0.0068122 -0.731 0.470288
## const -0.0171927 0.0167668 -1.025 0.312864
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.04869 on 32 degrees of freedom
## Multiple R-Squared: 0.8636, Adjusted R-squared: 0.7997
## F-statistic: 13.51 on 15 and 32 DF, p-value: 8.027e-10
##
##
## Estimation results for equation D_cir:
## ======================================
## D_cir = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3 + const
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 1.63819 1.46862 1.115 0.2730
## D_m2.l1 -12.67489 11.40155 -1.112 0.2746
## D_oea.l1 -29.03583 29.26161 -0.992 0.3285
## D_cir.l1 -0.61588 0.26738 -2.303 0.0279 *
## D_roe.l1 -0.30010 0.94242 -0.318 0.7522
## D_cpi.l2 1.26345 1.44142 0.877 0.3873
## D_m2.l2 9.13707 10.55899 0.865 0.3933
## D_oea.l2 -83.45469 39.48906 -2.113 0.0425 *
## D_cir.l2 0.04107 0.33864 0.121 0.9042
## D_roe.l2 0.60235 1.08114 0.557 0.5813
## D_cpi.l3 -0.46351 1.38637 -0.334 0.7403
## D_m2.l3 -17.16049 6.79989 -2.524 0.0168 *
## D_oea.l3 -46.87005 29.57045 -1.585 0.1228
## D_cir.l3 -0.14091 0.27047 -0.521 0.6060
## D_roe.l3 1.02645 0.83680 1.227 0.2289
## const -2.16665 2.05959 -1.052 0.3007
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 5.981 on 32 degrees of freedom
## Multiple R-Squared: 0.7152, Adjusted R-squared: 0.5816
## F-statistic: 5.356 on 15 and 32 DF, p-value: 3.411e-05
##
##
## Estimation results for equation D_roe:
## ======================================
## D_roe = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3 + const
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 0.093699 0.267733 0.350 0.7287
## D_m2.l1 1.898129 2.078525 0.913 0.3680
## D_oea.l1 5.441418 5.334447 1.020 0.3154
## D_cir.l1 -0.082466 0.048744 -1.692 0.1004
## D_roe.l1 -0.799219 0.171804 -4.652 5.45e-05 ***
## D_cpi.l2 -0.158378 0.262774 -0.603 0.5509
## D_m2.l2 -2.101669 1.924924 -1.092 0.2831
## D_oea.l2 1.541766 7.198931 0.214 0.8318
## D_cir.l2 -0.001859 0.061736 -0.030 0.9762
## D_roe.l2 -0.539703 0.197094 -2.738 0.0100 *
## D_cpi.l3 -0.333059 0.252739 -1.318 0.1969
## D_m2.l3 0.097640 1.239633 0.079 0.9377
## D_oea.l3 4.147926 5.390750 0.769 0.4473
## D_cir.l3 -0.012981 0.049307 -0.263 0.7940
## D_roe.l3 -0.285162 0.152549 -1.869 0.0708 .
## const 0.358753 0.375467 0.955 0.3465
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 1.09 on 32 degrees of freedom
## Multiple R-Squared: 0.6617, Adjusted R-squared: 0.5031
## F-statistic: 4.173 on 15 and 32 DF, p-value: 0.0003383
##
##
##
## Covariance matrix of residuals:
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 0.53423 0.0030996 0.0135031 0.67903 0.0265760
## D_m2 0.00310 0.0049699 0.0007163 0.06072 0.0009674
## D_oea 0.01350 0.0007163 0.0023708 0.25045 -0.0084459
## D_cir 0.67903 0.0607172 0.2504495 35.77312 -1.2822854
## D_roe 0.02658 0.0009674 -0.0084459 -1.28229 1.1888834
##
## Correlation matrix of residuals:
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 1.00000 0.06015 0.3794 0.1553 0.03335
## D_m2 0.06015 1.00000 0.2087 0.1440 0.01259
## D_oea 0.37942 0.20868 1.0000 0.8600 -0.15908
## D_cir 0.15533 0.14400 0.8600 1.0000 -0.19662
## D_roe 0.03335 0.01259 -0.1591 -0.1966 1.00000
library(vars)
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
vars <- colnames(dydata)
p <- 3
for (dependent in vars) {
cat("\nDependent variable:", dependent, "\n")
cat("Excluded\tChi-sq\t\tdf\tProb\n")
for (excluded in vars) {
if (excluded != dependent) {
# Tạo chuỗi giả thuyết riêng cho từng biến
restrictions <- paste0(excluded, ".l", 1:p, " = 0")
model_eq <- var.model$varresult[[dependent]]
test <- linearHypothesis(model_eq, restrictions, test = "Chisq")
chisq <- round(test$Chisq[2], 4)
df <- test$Df[2]
pval <- round(test$`Pr(>Chisq)`[2], 4)
cat(sprintf("%-10s\t%-8.4f\t%d\t%.4f\n", excluded, chisq, df, pval))
}
}
# Dòng "All" – gom toàn bộ biến trễ khác lại
excluded_all <- setdiff(vars, dependent)
restrictions_all <- unlist(lapply(excluded_all, function(var) paste0(var, ".l", 1:p, " = 0")))
model_eq <- var.model$varresult[[dependent]]
test_all <- linearHypothesis(model_eq, restrictions_all, test = "Chisq")
chisq <- round(test_all$Chisq[2], 4)
df <- test_all$Df[2]
pval <- round(test_all$`Pr(>Chisq)`[2], 4)
cat(sprintf("%-10s\t%-8.4f\t%d\t%.4f\n", "All", chisq, df, pval))
}
##
## Dependent variable: D_cpi
## Excluded Chi-sq df Prob
## D_m2 0.3599 3 0.9484
## D_oea 3.5910 3 0.3091
## D_cir 1.7379 3 0.6285
## D_roe 5.0565 3 0.1677
## All 13.0354 12 0.3665
##
## Dependent variable: D_m2
## Excluded Chi-sq df Prob
## D_cpi 3.0196 3 0.3886
## D_oea 28.9967 3 0.0000
## D_cir 8.1275 3 0.0434
## D_roe 5.0184 3 0.1705
## All 60.0327 12 0.0000
##
## Dependent variable: D_oea
## Excluded Chi-sq df Prob
## D_cpi 1.5338 3 0.6745
## D_m2 17.0167 3 0.0007
## D_cir 0.2893 3 0.9620
## D_roe 0.6642 3 0.8816
## All 23.7644 12 0.0219
##
## Dependent variable: D_cir
## Excluded Chi-sq df Prob
## D_cpi 2.2699 3 0.5183
## D_m2 6.5955 3 0.0860
## D_oea 4.8033 3 0.1868
## D_roe 2.2972 3 0.5131
## All 16.1469 12 0.1846
##
## Dependent variable: D_roe
## Excluded Chi-sq df Prob
## D_cpi 2.2729 3 0.5177
## D_m2 2.1327 3 0.5453
## D_oea 2.8852 3 0.4097
## D_cir 4.3060 3 0.2303
## All 13.2992 12 0.3477
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
library(gridExtra)
vars <- colnames(var.model$y)
for (response_var in vars) {
irf_plots <- list()
for (impulse_var in vars) {
irf_result <- irf(var.model,
impulse = impulse_var,
response = response_var,
n.ahead = 8,
boot = TRUE,
ci = 0.95,
ortho = TRUE)
df <- data.frame(
period = 0:8,
irf = irf_result$irf[[impulse_var]][, response_var],
lower = irf_result$Lower[[impulse_var]][, response_var],
upper = irf_result$Upper[[impulse_var]][, response_var]
)
p <- ggplot(df, aes(x = period)) +
geom_line(aes(y = irf), color = "black", size = 0.8) +
geom_line(aes(y = lower), linetype = "dashed", color = "red", size = 0.6) +
geom_line(aes(y = upper), linetype = "dashed", color = "red", size = 0.6) +
geom_hline(yintercept = 0, linetype = "solid", color = "grey40") +
labs(
title = impulse_var,
x = "Horizon", y = "Response"
) +
theme_bw(base_size = 13) +
theme(plot.title = element_text(hjust = 0.5))
irf_plots[[impulse_var]] <- p
}
grid.arrange(grobs = irf_plots, ncol = 3,
top = paste("Impulse Response Functions of", response_var))
}
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
fevd.var <- fevd(var.model, n.ahead = 8)
print(fevd.var)
## $D_cpi
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 1.0000000 0.000000e+00 0.00000000 0.000000000 0.00000000
## [2,] 0.9552915 6.611757e-06 0.00532898 0.004200963 0.03517196
## [3,] 0.8582750 5.306887e-04 0.02672577 0.013383685 0.10108491
## [4,] 0.8443166 3.368636e-03 0.03565567 0.013396599 0.10326253
## [5,] 0.8426041 4.550872e-03 0.03558384 0.013658153 0.10360301
## [6,] 0.8358688 7.255491e-03 0.04066546 0.014730292 0.10147992
## [7,] 0.8246031 7.760289e-03 0.05059029 0.014753158 0.10229315
## [8,] 0.8218274 8.533376e-03 0.05138550 0.015378758 0.10287497
##
## $D_m2
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.003618553 0.9963814 0.0000000 0.00000000 0.00000000
## [2,] 0.090648645 0.6573843 0.1415503 0.07923368 0.03118310
## [3,] 0.155723522 0.5903059 0.1206624 0.08873611 0.04457205
## [4,] 0.134456448 0.5200802 0.1282539 0.10639826 0.11081123
## [5,] 0.174346698 0.4996593 0.1208819 0.10582391 0.09928824
## [6,] 0.165724493 0.4598043 0.1264781 0.10841903 0.13957407
## [7,] 0.189259155 0.4415678 0.1188302 0.11089379 0.13944907
## [8,] 0.180887442 0.4191484 0.1161957 0.11256724 0.17120123
##
## $D_oea
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.14395929 0.03466626 0.8213745 0.0000000000 0.000000000
## [2,] 0.09795429 0.07759752 0.8190934 0.0004550620 0.004899721
## [3,] 0.09427022 0.07892265 0.8157800 0.0004280259 0.010599067
## [4,] 0.09559370 0.09272234 0.7915703 0.0067828009 0.013330892
## [5,] 0.11487323 0.13042345 0.7326354 0.0052812475 0.016786678
## [6,] 0.11066130 0.13323226 0.7209192 0.0050685791 0.030118686
## [7,] 0.10594136 0.13180943 0.7225120 0.0090943514 0.030642890
## [8,] 0.10461828 0.14035281 0.7082463 0.0165426953 0.030239931
##
## $D_cir
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.02412618 0.01819780 0.7330150 0.2246610 0.000000000
## [2,] 0.01423065 0.05588854 0.7470819 0.1811137 0.001685244
## [3,] 0.01376472 0.08248380 0.6884159 0.1726851 0.042650519
## [4,] 0.01790386 0.09699919 0.6503979 0.1885665 0.046132489
## [5,] 0.02027816 0.11292638 0.6459418 0.1778046 0.043049119
## [6,] 0.02511546 0.13334237 0.6345607 0.1671477 0.039833836
## [7,] 0.02580247 0.14143537 0.6244132 0.1693359 0.039013029
## [8,] 0.02522241 0.14722386 0.6129496 0.1719462 0.042657904
##
## $D_roe
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.001112012 0.0001123379 0.03673764 0.006816167 0.9552218
## [2,] 0.003279372 0.0059317911 0.02243218 0.017522078 0.9508346
## [3,] 0.034522108 0.0207946605 0.04954722 0.073351013 0.8217850
## [4,] 0.034336736 0.0200469066 0.04774241 0.107286848 0.7905871
## [5,] 0.045230486 0.0228660907 0.05399128 0.112277693 0.7656345
## [6,] 0.046758871 0.0224990185 0.05311972 0.119678848 0.7579435
## [7,] 0.058533680 0.0217918678 0.05092503 0.133174536 0.7355749
## [8,] 0.057390524 0.0214780097 0.05430645 0.141626230 0.7251988
roots <- roots(var.model, modulus = TRUE)
print(roots)
## [1] 0.9035718 0.9035718 0.8984370 0.8705993 0.8705993 0.8194961 0.8194961
## [8] 0.6964571 0.6964571 0.6503347 0.6503347 0.5708488 0.5655156 0.5655156
## [15] 0.5230423
ydata1 <- as.data.frame(ydata)
# ✅ Giả sử:
# var.model là mô hình VAR đã được ước lượng trên dữ liệu sai phân
# ydata1 là dữ liệu gốc (level)
# forecast_diff là kết quả dự báo từ mô hình VAR (sai phân)
# Dự báo n quý
n_ahead <- 4
forecast_diff <- predict(var.model, n.ahead = n_ahead, ci = 0.95)
# Mở rộng forecast_levels thêm dòng NA để chứa dự báo
forecast_levels <- ydata1
for (i in 1:n_ahead) {
forecast_levels <- rbind(forecast_levels, NA)
}
# Gắn các cột *_F để lưu chuỗi dự báo dạng level
for (varname in colnames(ydata1)) {
dvarname <- paste0("D_", varname) # tên biến trong VAR (sai phân)
if (!dvarname %in% names(forecast_diff$fcst)) next
last_value <- tail(ydata1[[varname]], 1)
forecasts <- forecast_diff$fcst[[dvarname]][, "fcst"]
restored <- cumsum(c(last_value, forecasts))[-1]
restored_full <- c(rep(NA, nrow(ydata1)), restored) # NA cho dữ liệu gốc
forecast_levels[[paste0(varname, "_F")]] <- restored_full
}
# Xem kết quả hoàn chỉnh
tail(forecast_levels, 10)
| cir | cpi | m2 | oea | roe | cir_F | cpi_F | m2_F | oea_F | roe_F | |
|---|---|---|---|---|---|---|---|---|---|---|
| 47 | 33.79 | 112.1492 | 0.1103977 | 0.2833975 | 3.93 | NA | NA | NA | NA | NA |
| 48 | 38.01 | 113.6071 | 0.2077862 | 0.3403069 | 5.02 | NA | NA | NA | NA | NA |
| 49 | 31.40 | 114.8430 | 0.1186396 | 0.2315685 | 4.62 | NA | NA | NA | NA | NA |
| 50 | 33.17 | 115.2425 | 0.0104192 | 0.2660858 | 4.83 | NA | NA | NA | NA | NA |
| 51 | 36.55 | 116.0454 | 0.1017030 | 0.2448457 | 3.77 | NA | NA | NA | NA | NA |
| 52 | 35.53 | 116.8637 | 0.2250277 | 0.3398446 | 5.18 | NA | NA | NA | NA | NA |
| 53 | NA | NA | NA | NA | NA | 33.72918 | 118.1679 | 0.1123816 | 0.2422798 | 5.454404 |
| 54 | NA | NA | NA | NA | NA | 31.51892 | 118.5085 | -0.0302596 | 0.2605007 | 4.030213 |
| 55 | NA | NA | NA | NA | NA | 36.47269 | 119.3014 | 0.0289732 | 0.2450455 | 5.049530 |
| 56 | NA | NA | NA | NA | NA | 35.04081 | 120.0673 | 0.1287882 | 0.3227198 | 4.429498 |
a.mat <- diag(5)
diag(a.mat) <- NA # Đặt đường chéo chính là NA để hệ số tự tác động
# Thiết lập các ràng buộc: mỗi biến chỉ bị ảnh hưởng bởi các biến trước nó trong thứ tự
a.mat[2, 1] <- NA # m2 bị ảnh hưởng bởi cpi
a.mat[3, 1] <- NA; a.mat[3, 2] <- NA # oea bị ảnh hưởng bởi cpi, m2
a.mat[4, 1] <- NA; a.mat[4, 2] <- NA; a.mat[4, 3] <- NA # cir bị ảnh hưởng bởi cpi, m2, oea
a.mat[5, 1] <- NA; a.mat[5, 2] <- NA; a.mat[5, 3] <- NA; a.mat[5, 4] <- NA # roe bị ảnh hưởng bởi tất cả biến trước
print(a.mat)
## [,1] [,2] [,3] [,4] [,5]
## [1,] NA 0 0 0 0
## [2,] NA NA 0 0 0
## [3,] NA NA NA 0 0
## [4,] NA NA NA NA 0
## [5,] NA NA NA NA NA
b.mat <- diag(5)
diag(b.mat) <- NA # Cho phép tất cả các biến có sốc riêng
print(b.mat)
## [,1] [,2] [,3] [,4] [,5]
## [1,] NA 0 0 0 0
## [2,] 0 NA 0 0 0
## [3,] 0 0 NA 0 0
## [4,] 0 0 0 NA 0
## [5,] 0 0 0 0 NA
svar.short <- SVAR(var.model, Amat = a.mat, Bmat = b.mat, max.iter = 10000, hessian = TRUE)
## Warning in SVAR(var.model, Amat = a.mat, Bmat = b.mat, max.iter = 10000, : The
## AB-model is just identified. No test possible.
svar.short
##
## SVAR Estimation Results:
## ========================
##
##
## Estimated A matrix:
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 1.000000 0.0000 0.000 0.00000 0
## D_m2 -0.005802 1.0000 0.000 0.00000 0
## D_oea -0.024528 -0.1288 1.000 0.00000 0
## D_cir 1.641799 3.4839 -116.042 1.00000 0
## D_roe -0.112824 -0.6637 1.051 0.03175 1
##
## Estimated B matrix:
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 0.7309 0.00000 0.00000 0.000 0.000
## D_m2 0.0000 0.07037 0.00000 0.000 0.000
## D_oea 0.0000 0.00000 0.04413 0.000 0.000
## D_cir 0.0000 0.00000 0.00000 2.835 0.000
## D_roe 0.0000 0.00000 0.00000 0.000 1.066
svar.short$A # Ma trận A đã ước lượng
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 1.000000000 0.0000000 0.000000 0.00000000 0
## D_m2 -0.005802005 1.0000000 0.000000 0.00000000 0
## D_oea -0.024528284 -0.1288292 1.000000 0.00000000 0
## D_cir 1.641798757 3.4839240 -116.041997 1.00000000 0
## D_roe -0.112824086 -0.6637252 1.051144 0.03175393 1
svar.short$B # Ma trận B đã ước lượng
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 0.7309115 0.00000000 0.00000000 0.00000 0.000000
## D_m2 0.0000000 0.07037011 0.00000000 0.00000 0.000000
## D_oea 0.0000000 0.00000000 0.04412855 0.00000 0.000000
## D_cir 0.0000000 0.00000000 0.00000000 2.83493 0.000000
## D_roe 0.0000000 0.00000000 0.00000000 0.00000 1.065668
svar.short$Sigma.U # Ma trận hiệp phương sai phần dư
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 53.4231637 0.30996147 1.35031064 67.902778 2.65759747
## D_m2 0.3099615 0.49699365 0.07163012 6.071719 0.09674381
## D_oea 1.3503106 0.07163012 0.23708173 25.044946 -0.84459225
## D_cir 67.9027778 6.07171933 25.04494557 3577.312062 -128.22854077
## D_roe 2.6575975 0.09674381 -0.84459225 -128.228541 118.88833720
svar.short$logLik # Log likelihood
## NULL
library(svars)
## Registered S3 method overwritten by 'svars':
## method from
## stability.varest vars
library(ggplot2)
library(gridExtra)
library(grid)
# Tính IRF từ mô hình SVAR ngắn hạn
irf_svar <- irf(svar.short, n.ahead = 8, ci = 0.95, boot = TRUE)
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
vars <- colnames(var.model$y)
# Lặp qua từng biến phản ứng
for (response_var in vars) {
irf_plots <- list()
# Lặp qua từng biến gây sốc
for (impulse_var in vars) {
if (!is.null(irf_svar$irf[[impulse_var]]) &&
response_var %in% colnames(irf_svar$irf[[impulse_var]])) {
df <- data.frame(
period = 0:8,
irf = irf_svar$irf[[impulse_var]][, response_var],
lower = irf_svar$Lower[[impulse_var]][, response_var],
upper = irf_svar$Upper[[impulse_var]][, response_var]
)
p <- ggplot(df, aes(x = period)) +
geom_line(aes(y = irf), color = "black", size = 0.8) +
geom_line(aes(y = lower), linetype = "dashed", color = "red", size = 0.6) +
geom_line(aes(y = upper), linetype = "dashed", color = "red", size = 0.6) +
geom_hline(yintercept = 0, linetype = "solid", color = "gray40") +
labs(
title = impulse_var,
x = "Horizon", y = "Response"
) +
theme_bw(base_size = 13) +
theme(plot.title = element_text(hjust = 0.5))
irf_plots[[impulse_var]] <- p
}
}
# Hiển thị biểu đồ
grid.arrange(grobs = irf_plots, ncol = 3,
top = paste("Impulse Response Functions of", response_var, "(SVAR ngắn hạn)"))
}
one.inf <- irf(svar.short, response = "D_cpi", impulse = "D_oea",
n.ahead = 8, ortho = TRUE, boot = TRUE)
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
## Warning in SVAR(x = varboot, Amat = a.mat, Bmat = b.mat, max.iter = 10000, :
## The AB-model is just identified. No test possible.
par(mfrow = c(1, 1), mar = c(2.2, 2.2, 1, 1), cex = 0.6)
plot(one.inf)
fevd.short <- fevd(svar.short, n.ahead = 8)
fevd.short
## $D_cpi
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 1.0000000 6.781839e-34 2.730928e-31 0.000000000 0.00000000
## [2,] 0.9552915 6.611757e-06 5.328980e-03 0.004200963 0.03517196
## [3,] 0.8582750 5.306887e-04 2.672577e-02 0.013383685 0.10108491
## [4,] 0.8443166 3.368636e-03 3.565567e-02 0.013396599 0.10326253
## [5,] 0.8426041 4.550872e-03 3.558384e-02 0.013658153 0.10360301
## [6,] 0.8358688 7.255491e-03 4.066546e-02 0.014730292 0.10147992
## [7,] 0.8246031 7.760289e-03 5.059029e-02 0.014753158 0.10229315
## [8,] 0.8218274 8.533376e-03 5.138550e-02 0.015378758 0.10287497
##
## $D_m2
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.003618553 0.9963814 0.0000000 0.00000000 0.00000000
## [2,] 0.090648645 0.6573843 0.1415503 0.07923368 0.03118310
## [3,] 0.155723522 0.5903059 0.1206624 0.08873611 0.04457205
## [4,] 0.134456448 0.5200802 0.1282539 0.10639826 0.11081123
## [5,] 0.174346698 0.4996593 0.1208819 0.10582391 0.09928824
## [6,] 0.165724493 0.4598043 0.1264781 0.10841903 0.13957407
## [7,] 0.189259155 0.4415678 0.1188302 0.11089379 0.13944907
## [8,] 0.180887442 0.4191484 0.1161957 0.11256724 0.17120123
##
## $D_oea
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.14395929 0.03466626 0.8213745 0.0000000000 0.000000000
## [2,] 0.09795429 0.07759752 0.8190934 0.0004550620 0.004899721
## [3,] 0.09427022 0.07892265 0.8157800 0.0004280259 0.010599067
## [4,] 0.09559370 0.09272234 0.7915703 0.0067828009 0.013330892
## [5,] 0.11487323 0.13042345 0.7326354 0.0052812475 0.016786678
## [6,] 0.11066130 0.13323226 0.7209192 0.0050685791 0.030118686
## [7,] 0.10594136 0.13180943 0.7225120 0.0090943514 0.030642890
## [8,] 0.10461828 0.14035281 0.7082463 0.0165426953 0.030239931
##
## $D_cir
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.02412618 0.01819780 0.7330150 0.2246610 0.000000000
## [2,] 0.01423065 0.05588854 0.7470819 0.1811137 0.001685244
## [3,] 0.01376472 0.08248380 0.6884159 0.1726851 0.042650519
## [4,] 0.01790386 0.09699919 0.6503979 0.1885665 0.046132489
## [5,] 0.02027816 0.11292638 0.6459418 0.1778046 0.043049119
## [6,] 0.02511546 0.13334237 0.6345607 0.1671477 0.039833836
## [7,] 0.02580247 0.14143537 0.6244132 0.1693359 0.039013029
## [8,] 0.02522241 0.14722386 0.6129496 0.1719462 0.042657904
##
## $D_roe
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.001112012 0.0001123379 0.03673764 0.006816167 0.9552218
## [2,] 0.003279372 0.0059317911 0.02243218 0.017522078 0.9508346
## [3,] 0.034522108 0.0207946605 0.04954722 0.073351013 0.8217850
## [4,] 0.034336736 0.0200469066 0.04774241 0.107286848 0.7905871
## [5,] 0.045230486 0.0228660907 0.05399128 0.112277693 0.7656345
## [6,] 0.046758871 0.0224990185 0.05311972 0.119678848 0.7579435
## [7,] 0.058533680 0.0217918678 0.05092503 0.133174536 0.7355749
## [8,] 0.057390524 0.0214780097 0.05430645 0.141626230 0.7251988
serial.test(var.model, lags.pt = 5, type = "ES")
##
## Edgerton-Shukur F test
##
## data: Residuals of VAR object var.model
## F statistic = 1.8666, df1 = 125, df2 = 19, p-value = 0.0587
Mô hình không bị tự tương quan
arch.test(var.model, lags.multi = 3)
##
## ARCH (multivariate)
##
## data: Residuals of VAR object var.model
## Chi-squared = 675, df = 675, p-value = 0.4928
Mô hình không bị PSSSTD
var.bq <- VAR(dydata, p = 3, type = "none")
summary(var.bq)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: D_cpi, D_m2, D_oea, D_cir, D_roe
## Deterministic variables: none
## Sample size: 48
## Log Likelihood: -62.749
## Roots of the characteristic polynomial:
## 0.9152 0.9152 0.8967 0.8956 0.871 0.871 0.7802 0.7802 0.6541 0.6541 0.6286 0.6286 0.6249 0.6249 0.5839
## Call:
## VAR(y = dydata, p = 3, type = "none")
##
##
## Estimation results for equation D_cpi:
## ======================================
## D_cpi = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 0.37530 0.16663 2.252 0.0311 *
## D_m2.l1 0.21054 1.54292 0.136 0.8923
## D_oea.l1 1.93574 3.95047 0.490 0.6274
## D_cir.l1 -0.01311 0.03644 -0.360 0.7214
## D_roe.l1 0.12296 0.12837 0.958 0.3451
## D_cpi.l2 0.12130 0.16987 0.714 0.4802
## D_m2.l2 1.05859 1.39442 0.759 0.4531
## D_oea.l2 -1.28077 5.25365 -0.244 0.8089
## D_cir.l2 -0.02727 0.04614 -0.591 0.5585
## D_roe.l2 -0.12872 0.14687 -0.876 0.3871
## D_cpi.l3 0.31778 0.15930 1.995 0.0544 .
## D_m2.l3 -0.90932 0.91154 -0.998 0.3257
## D_oea.l3 3.36800 4.01697 0.838 0.4078
## D_cir.l3 -0.04044 0.03685 -1.097 0.2804
## D_roe.l3 0.01549 0.11389 0.136 0.8927
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.815 on 33 degrees of freedom
## Multiple R-Squared: 0.5716, Adjusted R-squared: 0.3769
## F-statistic: 2.936 on 15 and 33 DF, p-value: 0.004845
##
##
## Estimation results for equation D_m2:
## =====================================
## D_m2 = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 0.003178 0.014233 0.223 0.824672
## D_m2.l1 0.067449 0.131794 0.512 0.612216
## D_oea.l1 -1.780076 0.337444 -5.275 8.19e-06 ***
## D_cir.l1 0.008183 0.003112 2.629 0.012895 *
## D_roe.l1 -0.014561 0.010965 -1.328 0.193306
## D_cpi.l2 -0.015138 0.014510 -1.043 0.304427
## D_m2.l2 -0.269950 0.119109 -2.266 0.030108 *
## D_oea.l2 -1.914624 0.448760 -4.266 0.000157 ***
## D_cir.l2 0.009230 0.003941 2.342 0.025376 *
## D_roe.l2 -0.004355 0.012545 -0.347 0.730701
## D_cpi.l3 -0.018360 0.013608 -1.349 0.186441
## D_m2.l3 -0.426147 0.077862 -5.473 4.56e-06 ***
## D_oea.l3 -0.323634 0.343124 -0.943 0.352434
## D_cir.l3 0.002111 0.003148 0.671 0.507121
## D_roe.l3 0.012085 0.009728 1.242 0.222876
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.06962 on 33 degrees of freedom
## Multiple R-Squared: 0.8765, Adjusted R-squared: 0.8204
## F-statistic: 15.61 on 15 and 33 DF, p-value: 7.436e-11
##
##
## Estimation results for equation D_oea:
## ======================================
## D_oea = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 0.0054512 0.0099622 0.547 0.587930
## D_m2.l1 -0.1168047 0.0922459 -1.266 0.214296
## D_oea.l1 -0.9655201 0.2361858 -4.088 0.000262 ***
## D_cir.l1 0.0003642 0.0021784 0.167 0.868261
## D_roe.l1 -0.0041561 0.0076748 -0.542 0.591779
## D_cpi.l2 0.0003094 0.0101562 0.030 0.975882
## D_m2.l2 -0.0744664 0.0833675 -0.893 0.378202
## D_oea.l2 -0.7708035 0.3140982 -2.454 0.019573 *
## D_cir.l2 0.0013966 0.0027586 0.506 0.616036
## D_roe.l2 -0.0051947 0.0087808 -0.592 0.558155
## D_cpi.l3 -0.0096348 0.0095243 -1.012 0.319087
## D_m2.l3 -0.1680310 0.0544978 -3.083 0.004118 **
## D_oea.l3 -0.6581996 0.2401612 -2.741 0.009820 **
## D_cir.l3 0.0006721 0.0022032 0.305 0.762229
## D_roe.l3 -0.0053295 0.0068089 -0.783 0.439368
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.04873 on 33 degrees of freedom
## Multiple R-Squared: 0.8592, Adjusted R-squared: 0.7952
## F-statistic: 13.42 on 15 and 33 DF, p-value: 5.747e-10
##
##
## Estimation results for equation D_cir:
## ======================================
## D_cir = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 0.78247 1.22475 0.639 0.5273
## D_m2.l1 -14.08583 11.34068 -1.242 0.2230
## D_oea.l1 -24.84968 29.03659 -0.856 0.3983
## D_cir.l1 -0.61577 0.26781 -2.299 0.0280 *
## D_roe.l1 -0.27109 0.94353 -0.287 0.7757
## D_cpi.l2 0.50215 1.24861 0.402 0.6902
## D_m2.l2 6.39680 10.24917 0.624 0.5368
## D_oea.l2 -74.46268 38.61512 -1.928 0.0625 .
## D_cir.l2 0.03505 0.33914 0.103 0.9183
## D_roe.l2 0.69203 1.07951 0.641 0.5259
## D_cpi.l3 -1.24751 1.17091 -1.065 0.2944
## D_m2.l3 -15.87469 6.69994 -2.369 0.0238 *
## D_oea.l3 -44.40839 29.52532 -1.504 0.1421
## D_cir.l3 -0.14639 0.27086 -0.540 0.5925
## D_roe.l3 0.98211 0.83708 1.173 0.2491
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 5.991 on 33 degrees of freedom
## Multiple R-Squared: 0.7054, Adjusted R-squared: 0.5714
## F-statistic: 5.267 on 15 and 33 DF, p-value: 3.439e-05
##
##
## Estimation results for equation D_roe:
## ======================================
## D_roe = D_cpi.l1 + D_m2.l1 + D_oea.l1 + D_cir.l1 + D_roe.l1 + D_cpi.l2 + D_m2.l2 + D_oea.l2 + D_cir.l2 + D_roe.l2 + D_cpi.l3 + D_m2.l3 + D_oea.l3 + D_cir.l3 + D_roe.l3
##
## Estimate Std. Error t value Pr(>|t|)
## D_cpi.l1 0.2353892 0.2226196 1.057 0.29803
## D_m2.l1 2.1317512 2.0613693 1.034 0.30859
## D_oea.l1 4.7482786 5.2779163 0.900 0.37482
## D_cir.l1 -0.0824855 0.0486801 -1.694 0.09960 .
## D_roe.l1 -0.8040235 0.1715039 -4.688 4.61e-05 ***
## D_cpi.l2 -0.0323234 0.2269562 -0.142 0.88761
## D_m2.l2 -1.6479372 1.8629682 -0.885 0.38279
## D_oea.l2 0.0528764 7.0189841 0.008 0.99403
## D_cir.l2 -0.0008615 0.0616452 -0.014 0.98893
## D_roe.l2 -0.5545526 0.1962208 -2.826 0.00794 **
## D_cpi.l3 -0.2032442 0.2128340 -0.955 0.34655
## D_m2.l3 -0.1152623 1.2178335 -0.095 0.92517
## D_oea.l3 3.7403274 5.3667521 0.697 0.49072
## D_cir.l3 -0.0120745 0.0492332 -0.245 0.80778
## D_roe.l3 -0.2778185 0.1521547 -1.826 0.07693 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 1.089 on 33 degrees of freedom
## Multiple R-Squared: 0.6521, Adjusted R-squared: 0.4939
## F-statistic: 4.123 on 15 and 33 DF, p-value: 0.0003361
##
##
##
## Covariance matrix of residuals:
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 0.638605 0.0046634 0.0103540 0.31316 0.082943
## D_m2 0.004663 0.0048421 0.0006569 0.05413 0.001724
## D_oea 0.010354 0.0006569 0.0023612 0.25071 -0.009489
## D_cir 0.313164 0.0541297 0.2507071 35.67798 -1.407169
## D_roe 0.082943 0.0017242 -0.0094893 -1.40717 1.179969
##
## Correlation matrix of residuals:
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 1.00000 0.08386 0.2666 0.06561 0.09555
## D_m2 0.08386 1.00000 0.1943 0.13023 0.02281
## D_oea 0.26664 0.19428 1.0000 0.86377 -0.17977
## D_cir 0.06561 0.13023 0.8638 1.00000 -0.21688
## D_roe 0.09555 0.02281 -0.1798 -0.21688 1.00000
model1 <- BQ(var.bq)
summary(model1)
##
## SVAR Estimation Results:
## ========================
##
## Call:
## BQ(x = var.bq)
##
## Type: Blanchard-Quah
## Sample size: 48
## Log Likelihood: -107.712
##
## Estimated contemporaneous impact matrix:
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 0.803948 -0.0004258 0.08559 0.103107 -0.003554
## D_m2 0.006660 0.0593151 0.02600 -0.024533 0.002496
## D_oea 0.007467 -0.0112807 0.04647 -0.001898 0.005365
## D_cir -0.562845 -0.5732135 5.52782 2.103276 -0.512717
## D_roe 0.107020 0.2384225 -0.26668 0.343736 0.963418
##
## Estimated identified long run impact matrix:
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 4.137757 0.000000 0.0000 0.00000 0.0000
## D_m2 -0.084469 0.057818 0.0000 0.00000 0.0000
## D_oea 0.006551 -0.009934 0.0155 0.00000 0.0000
## D_cir 0.398982 -0.233350 1.8164 1.28591 0.0000
## D_roe 0.035290 0.074780 -0.1167 0.08384 0.3654
##
## Covariance matrix of reduced form residuals (*100):
## D_cpi D_m2 D_oea D_cir D_roe
## D_cpi 66.4302 0.50167 0.97700 23.957 9.5129
## D_m2 0.5017 0.48470 0.06489 5.312 0.1892
## D_oea 0.9770 0.06489 0.23745 25.238 -0.9766
## D_cir 23.9569 5.31178 25.23796 3588.875 -144.2068
## D_roe 9.5129 0.18918 -0.97662 -144.207 118.5747
library(ggplot2)
library(gridExtra)
library(grid)
vars <- colnames(var.bq$y)
for (response_var in vars) {
irf_plots <- list()
for (impulse_var in vars) {
irf_long <- irf(model1,
impulse = impulse_var,
response = response_var,
n.ahead = 8,
boot = TRUE)
if (!is.null(irf_long$irf[[impulse_var]]) &&
response_var %in% colnames(irf_long$irf[[impulse_var]])) {
cum_irf <- cumsum(irf_long$irf[[impulse_var]][, response_var])
df <- data.frame(
period = 0:(length(cum_irf) - 1),
cum_irf = cum_irf
)
p <- ggplot(df, aes(x = period, y = cum_irf)) +
geom_line(color = "blue", size = 0.9) +
geom_hline(yintercept = 0, color = "grey40", linetype = "solid", size = 0.5) +
labs(
title = impulse_var,
x = "Horizon", y = "Cumulative IRF"
) +
theme_minimal(base_size = 11) +
theme(
plot.title = element_text(hjust = 0.5, size = 11),
plot.margin = margin(5, 5, 5, 5)
)
irf_plots[[impulse_var]] <- p
}
}
# Gộp biểu đồ và thêm tiêu đề tổng quát
grid.arrange(
grobs = irf_plots,
ncol = 3,
top = textGrob(paste("Cumulative Impulse Response to:", response_var),
gp = gpar(fontsize = 14, fontface = "bold"))
)
}
fevd.long <- fevd(model1, n.ahead = 8)
print(fevd.long)
## $D_cpi
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.9729492 2.729544e-07 0.011028205 0.01600333 0.0000190104
## [2,] 0.9508015 9.332569e-04 0.009779376 0.01577040 0.0227154992
## [3,] 0.8751536 6.988830e-03 0.033523366 0.03232962 0.0520045448
## [4,] 0.8765127 7.499155e-03 0.032999915 0.03228919 0.0506990550
## [5,] 0.8809830 8.074147e-03 0.031463826 0.03097166 0.0485073852
## [6,] 0.8841893 7.613452e-03 0.033669169 0.02903389 0.0454941415
## [7,] 0.8795606 7.510847e-03 0.038986601 0.02831961 0.0456223200
## [8,] 0.8802479 7.402802e-03 0.039640691 0.02800209 0.0447064759
##
## $D_m2
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.009152246 0.7258701 0.1395146 0.1241776 0.001285487
## [2,] 0.042951968 0.5142988 0.2281123 0.1097901 0.104846853
## [3,] 0.105157406 0.4530788 0.2073548 0.1395274 0.094881504
## [4,] 0.090422476 0.4144639 0.1821042 0.1187471 0.194262305
## [5,] 0.117581755 0.3795887 0.1949995 0.1238934 0.183936635
## [6,] 0.117092562 0.3437292 0.1905820 0.1121797 0.236416514
## [7,] 0.161639911 0.3194518 0.1774167 0.1059926 0.235498989
## [8,] 0.153594598 0.3043184 0.1702793 0.1008770 0.270930719
##
## $D_oea
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.02347874 0.05359127 0.9092933 0.001516602 0.01212005
## [2,] 0.01648889 0.03011485 0.9205206 0.005522831 0.02735287
## [3,] 0.01546191 0.02902354 0.9167714 0.005197803 0.03354533
## [4,] 0.01916324 0.02974293 0.9099293 0.007827294 0.03333723
## [5,] 0.03723718 0.02722289 0.8904329 0.006477537 0.03862949
## [6,] 0.03534890 0.02285873 0.8791535 0.005702129 0.05693671
## [7,] 0.03461536 0.02209378 0.8804097 0.007323532 0.05555759
## [8,] 0.03377598 0.02528275 0.8778909 0.007640301 0.05541004
##
## $D_cir
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.008827137 0.009155339 0.8514294 0.12326335 0.007324808
## [2,] 0.012667607 0.006648556 0.8886369 0.08745065 0.004596246
## [3,] 0.011729760 0.030969387 0.8396761 0.08915259 0.028472140
## [4,] 0.011172918 0.038447315 0.8220135 0.10126072 0.027105511
## [5,] 0.011526966 0.035572875 0.8379444 0.08697777 0.027978005
## [6,] 0.012445176 0.039903607 0.8408409 0.08041232 0.026397981
## [7,] 0.012247041 0.045853535 0.8360499 0.07939361 0.026455915
## [8,] 0.011952424 0.049740723 0.8285250 0.07752426 0.032257602
##
## $D_roe
## D_cpi D_m2 D_oea D_cir D_roe
## [1,] 0.009659139 0.04794049 0.05997902 0.09964531 0.7827760
## [2,] 0.026050817 0.03155703 0.03773448 0.18087243 0.7237852
## [3,] 0.059758284 0.03202810 0.04751752 0.22224125 0.6384548
## [4,] 0.057655748 0.03754901 0.04628559 0.24060805 0.6179016
## [5,] 0.061386493 0.05096024 0.04559599 0.24644501 0.5956123
## [6,] 0.061572573 0.05241291 0.04465084 0.25637217 0.5849915
## [7,] 0.072693146 0.05128218 0.04271872 0.25029018 0.5830158
## [8,] 0.071436631 0.05422170 0.04426968 0.24190228 0.5881697
serial.test(var.bq, lags.pt = 5, type = "ES")
##
## Edgerton-Shukur F test
##
## data: Residuals of VAR object var.bq
## F statistic = 2.2009, df1 = 125, df2 = 24, p-value = 0.01374
Mô hình bị tự tương quan
arch.test(var.bq, lags.multi = 3)
##
## ARCH (multivariate)
##
## data: Residuals of VAR object var.bq
## Chi-squared = 675, df = 675, p-value = 0.4928
Mô hình không bị PSSSTD