Laboratorio 8 Modelos SVAR

#install.packages("mFilter")
#install.packages("TSstudio")


#Loading the Dataset
series<-uschange
?uschange
autoplot(uschange[,1:3])

#Time Series Plots
ts.plot(series[,1:3], xlab="Tiempo",col=c(1,2))

#Buidling the Model

sv <- cbind(uschange[,1:3])
colnames(sv) <- cbind( "Consumption", "Income", "Production")
lagselect <- VARselect(diff(uschange[,1:3]), lag.max=8,type="const")
lagselect
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      8      2      2      8 
## 
## $criteria
##                 1          2          3           4           5          6
## AIC(n) -0.4299564 -0.7367583 -0.7485857 -0.79311593 -0.81848020 -0.8173440
## HQ(n)  -0.3429700 -0.5845321 -0.5311196 -0.51041005 -0.47053451 -0.4041585
## SC(n)  -0.2154542 -0.3613794 -0.2123300 -0.09598357  0.03952884  0.2015417
## FPE(n)  0.6505522  0.4787214  0.4732032  0.45278662  0.44174584  0.4426859
##                 7          8
## AIC(n) -0.8844529 -0.9479792
## HQ(n)  -0.4060276 -0.4043140
## SC(n)   0.2953095  0.3926600
## FPE(n)  0.4145168  0.3897025
lagselect$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      8      2      2      8
lagselect$criteria
##                 1          2          3           4           5          6
## AIC(n) -0.4299564 -0.7367583 -0.7485857 -0.79311593 -0.81848020 -0.8173440
## HQ(n)  -0.3429700 -0.5845321 -0.5311196 -0.51041005 -0.47053451 -0.4041585
## SC(n)  -0.2154542 -0.3613794 -0.2123300 -0.09598357  0.03952884  0.2015417
## FPE(n)  0.6505522  0.4787214  0.4732032  0.45278662  0.44174584  0.4426859
##                 7          8
## AIC(n) -0.8844529 -0.9479792
## HQ(n)  -0.4060276 -0.4043140
## SC(n)   0.2953095  0.3926600
## FPE(n)  0.4145168  0.3897025
Model1 <- VAR(sv, p = 2, season = NULL, exog = NULL, type = "const")

#Escogemos un modelo p=1, debido a que lagselect$selection en HQ(n) y  SC(n) nos da 2.
   
#Validación del modelo
#>PortManteu Test > 0.05 Autocorrelación
serial.test( Model1, lags.pt=15, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object Model1
## Chi-squared = 125.78, df = 117, p-value = 0.2731
#Raíz unitaria < 1
roots(Model1)
## [1] 0.6511648 0.4384550 0.4291059 0.4291059 0.3379285 0.3379285
#normalidad Jarque Bera < 0.05
normality.test(Model1, multivariate.only=FALSE)
## $Consumption
## 
##  JB-Test (univariate)
## 
## data:  Residual of Consumption equation
## Chi-squared = 40.868, df = 2, p-value = 1.336e-09
## 
## 
## $Income
## 
##  JB-Test (univariate)
## 
## data:  Residual of Income equation
## Chi-squared = 99.077, df = 2, p-value < 2.2e-16
## 
## 
## $Production
## 
##  JB-Test (univariate)
## 
## data:  Residual of Production equation
## Chi-squared = 64.871, df = 2, p-value = 8.216e-15
## 
## 
## $JB
## 
##  JB-Test (multivariate)
## 
## data:  Residuals of VAR object Model1
## Chi-squared = 193.05, df = 6, p-value < 2.2e-16
## 
## 
## $Skewness
## 
##  Skewness only (multivariate)
## 
## data:  Residuals of VAR object Model1
## Chi-squared = 18.645, df = 3, p-value = 0.0003237
## 
## 
## $Kurtosis
## 
##  Kurtosis only (multivariate)
## 
## data:  Residuals of VAR object Model1
## Chi-squared = 174.4, df = 3, p-value < 2.2e-16
#heteroscedasticity >0.05 NO HAY
arch<-arch.test(Model1, lags.multi = 15, multivariate.only = FALSE)
arch
## $Consumption
## 
##  ARCH test (univariate)
## 
## data:  Residual of Consumption equation
## Chi-squared = 17.311, df = 16, p-value = 0.3658
## 
## 
## $Income
## 
##  ARCH test (univariate)
## 
## data:  Residual of Income equation
## Chi-squared = 12.661, df = 16, p-value = 0.6973
## 
## 
## $Production
## 
##  ARCH test (univariate)
## 
## data:  Residual of Production equation
## Chi-squared = 40.337, df = 16, p-value = 0.0006951
## 
## 
## 
##  ARCH (multivariate)
## 
## data:  Residuals of VAR object Model1
## Chi-squared = 621.43, df = 540, p-value = 0.008583
#Structural breaks
stab<-stability(Model1, type = "OLS-CUSUM")
par(mar=c(1,1,1,1))
plot(stab)

#El modelo pasa todas las pruebas correspondientes por lo que procedemos al siguiente paso

#causalidad de granger 
#granger < 0.05 para que exista causalidad/ la variable impacta a la otra / si es causal 
 
GrangerConsumption <-causality(Model1, cause = 'Consumption')
GrangerConsumption
## $Granger
## 
##  Granger causality H0: Consumption do not Granger-cause Income
##  Production
## 
## data:  VAR object Model1
## F-Test = 10.451, df1 = 4, df2 = 534, p-value = 3.71e-08
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Consumption and Income
##  Production
## 
## data:  VAR object Model1
## Chi-squared = 47.294, df = 2, p-value = 5.374e-11
#en la variable Consumption existe causalidad con las diferentes variables dentro del conjunto de datos
GrangerIncome <-causality(Model1, cause = 'Income')
GrangerIncome
## $Granger
## 
##  Granger causality H0: Income do not Granger-cause Consumption
##  Production
## 
## data:  VAR object Model1
## F-Test = 1.7814, df1 = 4, df2 = 534, p-value = 0.1311
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Income and Consumption
##  Production
## 
## data:  VAR object Model1
## Chi-squared = 23.67, df = 2, p-value = 7.247e-06
#en la variable Income, si existe causalidad,si es causal con una de las otras variables del conjunto de datos 
#sin embargo parece que para una de ellas  no existe causalidad de income sobre ella debido a que es mayor.
GrangerProduction <-causality(Model1, cause = 'Production')
GrangerProduction
## $Granger
## 
##  Granger causality H0: Production do not Granger-cause Consumption
##  Income
## 
## data:  VAR object Model1
## F-Test = 2.6651, df1 = 4, df2 = 534, p-value = 0.03178
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Production and Consumption
##  Income
## 
## data:  VAR object Model1
## Chi-squared = 41.005, df = 2, p-value = 1.247e-09
#en la variable Production si es causal con una de las otras variables del conjunto de datos 
#sin embargo parece que para una no existe causalidad de income sobre ella debido a que es mayor.

#Al ver la causalidad establecere otro orden en el modelo de las variables 

sv <- cbind(uschange[,1:3])
colnames(sv) <- cbind (  "Production", "Income","Consumption")
lagselect <- VARselect(diff(uschange[,1:3]), lag.max=10,type="const")
lagselect
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      8      2      2      8 
## 
## $criteria
##                 1          2          3           4           5          6
## AIC(n) -0.4374355 -0.7509387 -0.7597492 -0.79540696 -0.82224978 -0.8218034
## HQ(n)  -0.3497583 -0.5975036 -0.5405562 -0.51045598 -0.47154089 -0.4053366
## SC(n)  -0.2212662 -0.3726423 -0.2193258 -0.09285653  0.04242767  0.2050011
## FPE(n)  0.6457053  0.4719828  0.4679557  0.45176266  0.44010601  0.4407536
##                 7          8          9         10
## AIC(n) -0.8841281 -0.9485725 -0.9461577 -0.9333716
## HQ(n)  -0.4019033 -0.4005899 -0.3324171 -0.2538732
## SC(n)   0.3048034  0.4024860  0.5670279  0.7419409
## FPE(n)  0.4147063  0.3895473  0.3914177  0.3976295
lagselect$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      8      2      2      8
lagselect$criteria
##                 1          2          3           4           5          6
## AIC(n) -0.4374355 -0.7509387 -0.7597492 -0.79540696 -0.82224978 -0.8218034
## HQ(n)  -0.3497583 -0.5975036 -0.5405562 -0.51045598 -0.47154089 -0.4053366
## SC(n)  -0.2212662 -0.3726423 -0.2193258 -0.09285653  0.04242767  0.2050011
## FPE(n)  0.6457053  0.4719828  0.4679557  0.45176266  0.44010601  0.4407536
##                 7          8          9         10
## AIC(n) -0.8841281 -0.9485725 -0.9461577 -0.9333716
## HQ(n)  -0.4019033 -0.4005899 -0.3324171 -0.2538732
## SC(n)   0.3048034  0.4024860  0.5670279  0.7419409
## FPE(n)  0.4147063  0.3895473  0.3914177  0.3976295
Model2 <- VAR(sv, p = 2, season = NULL, exog = NULL, type = "const")

#Se creo un nuevo modelo 

#Validación del modelo
#>PortManteu Test > 0.05 Autocorrelación
serial.test( Model2, lags.pt=15, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object Model2
## Chi-squared = 125.78, df = 117, p-value = 0.2731
#Raíz unitaria < 1
roots(Model2)
## [1] 0.6511648 0.4384550 0.4291059 0.4291059 0.3379285 0.3379285
#normalidad Jarque Bera < 0.05
normality.test(Model2, multivariate.only=FALSE)
## $Production
## 
##  JB-Test (univariate)
## 
## data:  Residual of Production equation
## Chi-squared = 40.868, df = 2, p-value = 1.336e-09
## 
## 
## $Income
## 
##  JB-Test (univariate)
## 
## data:  Residual of Income equation
## Chi-squared = 99.077, df = 2, p-value < 2.2e-16
## 
## 
## $Consumption
## 
##  JB-Test (univariate)
## 
## data:  Residual of Consumption equation
## Chi-squared = 64.871, df = 2, p-value = 8.216e-15
## 
## 
## $JB
## 
##  JB-Test (multivariate)
## 
## data:  Residuals of VAR object Model2
## Chi-squared = 193.05, df = 6, p-value < 2.2e-16
## 
## 
## $Skewness
## 
##  Skewness only (multivariate)
## 
## data:  Residuals of VAR object Model2
## Chi-squared = 18.645, df = 3, p-value = 0.0003237
## 
## 
## $Kurtosis
## 
##  Kurtosis only (multivariate)
## 
## data:  Residuals of VAR object Model2
## Chi-squared = 174.4, df = 3, p-value < 2.2e-16
#Structural breaks
stab<-stability(Model2, type = "OLS-CUSUM")
par(mar=c(1,1,1,1))
plot(stab)

#El modelo pasa todas las pruebas correspondientes por lo que procedemos al siguiente paso

#causalidad de granger 

GrangerProduction <-causality(Model2, cause = 'Production')
GrangerProduction
## $Granger
## 
##  Granger causality H0: Production do not Granger-cause Income
##  Consumption
## 
## data:  VAR object Model2
## F-Test = 10.451, df1 = 4, df2 = 534, p-value = 3.71e-08
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Production and Income
##  Consumption
## 
## data:  VAR object Model2
## Chi-squared = 47.294, df = 2, p-value = 5.374e-11
GrangerIncome <-causality(Model2, cause = 'Income')
GrangerIncome
## $Granger
## 
##  Granger causality H0: Income do not Granger-cause Production
##  Consumption
## 
## data:  VAR object Model2
## F-Test = 1.7814, df1 = 4, df2 = 534, p-value = 0.1311
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Income and Production
##  Consumption
## 
## data:  VAR object Model2
## Chi-squared = 23.67, df = 2, p-value = 7.247e-06
GrangerConsumption <-causality(Model2, cause = 'Consumption')
GrangerConsumption
## $Granger
## 
##  Granger causality H0: Consumption do not Granger-cause Production
##  Income
## 
## data:  VAR object Model2
## F-Test = 2.6651, df1 = 4, df2 = 534, p-value = 0.03178
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Consumption and Production
##  Income
## 
## data:  VAR object Model2
## Chi-squared = 41.005, df = 2, p-value = 1.247e-09
#Consumption -> Income -> Production
#Production -> Income->Consumption 
#Setting the Restrictions
amat <- diag(3)
amat[2,1] <- NA
amat[3,1] <- NA
amat[3,2] <- NA
amat
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]   NA    1    0
## [3,]   NA   NA    1
SVARMod1 <- SVAR(Model1, Amat = amat, Bmat = NULL, hessian = TRUE, estmethod =
                   c("scoring", "direct"))
SVARMod1
## 
## SVAR Estimation Results:
## ======================== 
## 
## 
## Estimated A matrix:
##             Consumption  Income Production
## Consumption      1.0000  0.0000          0
## Income          -0.5430  1.0000          0
## Production      -0.9828 -0.0886          1
SVARMod2 <- SVAR(Model2, Amat = amat, Bmat = NULL, hessian = TRUE, estmethod =
                   c("scoring", "direct"))
SVARMod2
## 
## SVAR Estimation Results:
## ======================== 
## 
## 
## Estimated A matrix:
##             Production  Income Consumption
## Production      1.0000  0.0000           0
## Income         -0.5430  1.0000           0
## Consumption    -0.9828 -0.0886           1
#Estimated A matrix:el modelo escogido y su matriz dice que, por cada unidad de consumo que se mueve la produccion disminuye en 0.9828.

#Impulse Response Functions

SVARogi <- irf(SVARMod2, impulse = "Income", response = "Consumption", n.ahead = 50)
SVARogi
## 
## Impulse response coefficients
## $Income
##         Consumption
##  [1,]  8.860414e-02
##  [2,] -6.405696e-02
##  [3,] -9.349434e-02
##  [4,]  4.294795e-03
##  [5,]  2.308502e-02
##  [6,]  1.867333e-02
##  [7,]  1.390486e-02
##  [8,]  7.945238e-03
##  [9,]  4.429710e-03
## [10,]  2.640265e-03
## [11,]  1.660412e-03
## [12,]  1.091210e-03
## [13,]  7.331953e-04
## [14,]  4.869520e-04
## [15,]  3.203031e-04
## [16,]  2.086750e-04
## [17,]  1.354085e-04
## [18,]  8.781385e-05
## [19,]  5.705643e-05
## [20,]  3.712486e-05
## [21,]  2.418439e-05
## [22,]  1.575770e-05
## [23,]  1.026614e-05
## [24,]  6.686276e-06
## [25,]  4.353927e-06
## [26,]  2.834842e-06
## [27,]  1.845787e-06
## [28,]  1.201844e-06
## [29,]  7.825894e-07
## [30,]  5.095988e-07
## [31,]  3.318383e-07
## [32,]  2.160837e-07
## [33,]  1.407068e-07
## [34,]  9.162329e-08
## [35,]  5.966173e-08
## [36,]  3.884953e-08
## [37,]  2.529741e-08
## [38,]  1.647278e-08
## [39,]  1.072650e-08
## [40,]  6.984719e-09
## [41,]  4.548204e-09
## [42,]  2.961630e-09
## [43,]  1.928509e-09
## [44,]  1.255777e-09
## [45,]  8.177178e-10
## [46,]  5.324690e-10
## [47,]  3.467251e-10
## [48,]  2.257751e-10
## [49,]  1.470168e-10
## [50,]  9.573217e-11
## [51,]  6.233741e-11
## 
## 
## Lower Band, CI= 0.95 
## $Income
##         Consumption
##  [1,] -5.074797e-02
##  [2,] -2.387415e-01
##  [3,] -2.962064e-01
##  [4,] -1.536982e-01
##  [5,] -5.812470e-02
##  [6,] -2.978848e-02
##  [7,] -1.218250e-02
##  [8,] -6.876874e-03
##  [9,] -4.835820e-03
## [10,] -4.262439e-03
## [11,] -2.370045e-03
## [12,] -1.250967e-03
## [13,] -8.629678e-04
## [14,] -6.084856e-04
## [15,] -4.003842e-04
## [16,] -2.649192e-04
## [17,] -1.750555e-04
## [18,] -1.160492e-04
## [19,] -7.682528e-05
## [20,] -5.084368e-05
## [21,] -3.368479e-05
## [22,] -2.231217e-05
## [23,] -1.477889e-05
## [24,] -9.792090e-06
## [25,] -6.488031e-06
## [26,] -4.299014e-06
## [27,] -2.848921e-06
## [28,] -1.888081e-06
## [29,] -1.251387e-06
## [30,] -8.294763e-07
## [31,] -5.498591e-07
## [32,] -3.645307e-07
## [33,] -2.416878e-07
## [34,] -1.602551e-07
## [35,] -1.062687e-07
## [36,] -7.047516e-08
## [37,] -4.674161e-08
## [38,] -3.100331e-08
## [39,] -2.056599e-08
## [40,] -1.364807e-08
## [41,] -9.063346e-09
## [42,] -6.019256e-09
## [43,] -3.997920e-09
## [44,] -2.655597e-09
## [45,] -1.764116e-09
## [46,] -1.172004e-09
## [47,] -7.786952e-10
## [48,] -5.174193e-10
## [49,] -3.438384e-10
## [50,] -2.285086e-10
## [51,] -1.518753e-10
## 
## 
## Upper Band, CI= 0.95 
## $Income
##        Consumption
##  [1,] 2.604924e-01
##  [2,] 1.930163e-01
##  [3,] 1.352770e-01
##  [4,] 1.069360e-01
##  [5,] 9.680964e-02
##  [6,] 7.209099e-02
##  [7,] 4.460374e-02
##  [8,] 2.845444e-02
##  [9,] 1.828780e-02
## [10,] 1.249706e-02
## [11,] 9.192963e-03
## [12,] 6.703185e-03
## [13,] 4.842453e-03
## [14,] 4.019038e-03
## [15,] 2.902003e-03
## [16,] 1.927689e-03
## [17,] 1.441586e-03
## [18,] 1.073485e-03
## [19,] 8.002573e-04
## [20,] 5.883142e-04
## [21,] 4.269351e-04
## [22,] 3.098419e-04
## [23,] 2.250095e-04
## [24,] 1.634056e-04
## [25,] 1.186476e-04
## [26,] 8.614135e-05
## [27,] 6.253353e-05
## [28,] 4.539949e-05
## [29,] 3.296058e-05
## [30,] 2.393104e-05
## [31,] 1.737489e-05
## [32,] 1.261475e-05
## [33,] 9.158631e-06
## [34,] 6.649389e-06
## [35,] 4.827652e-06
## [36,] 3.505029e-06
## [37,] 2.544774e-06
## [38,] 1.847593e-06
## [39,] 1.341417e-06
## [40,] 9.739153e-07
## [41,] 7.070974e-07
## [42,] 5.133788e-07
## [43,] 3.727325e-07
## [44,] 2.706183e-07
## [45,] 1.964796e-07
## [46,] 1.426522e-07
## [47,] 1.035714e-07
## [48,] 7.519718e-08
## [49,] 5.459639e-08
## [50,] 3.963937e-08
## [51,] 2.877996e-08
plot(SVARogi)

#la variable Consumption responde bien ya que  a lo largo del tiempo se estabiliza
#con el  "shock" o el impulso que le dio Income, si hubo cierta alteracion 
#pero se estabilizo.

SVARog <- irf(SVARMod2, impulse = "Production", response = "Income", n.ahead = 50)
SVARog
## 
## Impulse response coefficients
## $Production
##             Income
##  [1,] 5.430098e-01
##  [2,] 3.583625e-01
##  [3,] 6.317018e-02
##  [4,] 2.131747e-01
##  [5,] 7.324492e-02
##  [6,] 6.785597e-02
##  [7,] 3.651413e-02
##  [8,] 2.594086e-02
##  [9,] 1.528539e-02
## [10,] 1.072537e-02
## [11,] 6.668290e-03
## [12,] 4.504661e-03
## [13,] 2.881774e-03
## [14,] 1.902041e-03
## [15,] 1.226772e-03
## [16,] 8.032807e-04
## [17,] 5.205508e-04
## [18,] 3.398822e-04
## [19,] 2.209032e-04
## [20,] 1.440446e-04
## [21,] 9.372552e-05
## [22,] 6.106950e-05
## [23,] 3.975092e-05
## [24,] 2.589091e-05
## [25,] 1.685594e-05
## [26,] 1.097718e-05
## [27,] 7.147349e-06
## [28,] 4.654360e-06
## [29,] 3.030652e-06
## [30,] 1.973507e-06
## [31,] 1.285059e-06
## [32,] 8.367943e-07
## [33,] 5.448866e-07
## [34,] 3.548126e-07
## [35,] 2.310406e-07
## [36,] 1.504458e-07
## [37,] 9.796488e-08
## [38,] 6.379135e-08
## [39,] 4.153865e-08
## [40,] 2.704852e-08
## [41,] 1.761304e-08
## [42,] 1.146899e-08
## [43,] 7.468202e-09
## [44,] 4.863030e-09
## [45,] 3.166634e-09
## [46,] 2.062000e-09
## [47,] 1.342702e-09
## [48,] 8.743201e-10
## [49,] 5.693264e-10
## [50,] 3.707253e-10
## [51,] 2.414033e-10
## 
## 
## Lower Band, CI= 0.95 
## $Production
##              Income
##  [1,]  3.720084e-01
##  [2,]  1.006808e-01
##  [3,] -1.549203e-01
##  [4,]  9.533688e-02
##  [5,] -8.958196e-03
##  [6,]  9.516165e-03
##  [7,] -9.150062e-03
##  [8,]  5.054486e-04
##  [9,] -3.967839e-03
## [10,] -2.048072e-04
## [11,] -1.687843e-03
## [12,] -4.172551e-04
## [13,] -6.717644e-04
## [14,] -2.342077e-04
## [15,] -2.282362e-04
## [16,] -5.710194e-05
## [17,] -5.820704e-05
## [18,] -6.866194e-06
## [19,] -1.630421e-05
## [20,] -3.217298e-06
## [21,] -9.961314e-06
## [22,] -1.941394e-06
## [23,] -2.410767e-06
## [24,] -2.276040e-07
## [25,] -5.770542e-07
## [26,] -1.223413e-08
## [27,] -2.111537e-07
## [28,] -1.565765e-08
## [29,] -9.829208e-08
## [30,] -2.396019e-08
## [31,] -4.283546e-08
## [32,] -1.535421e-08
## [33,] -1.663405e-08
## [34,] -4.583484e-09
## [35,] -5.332867e-09
## [36,] -2.992355e-10
## [37,] -1.403019e-09
## [38,] -1.080327e-10
## [39,] -5.742427e-10
## [40,] -3.197897e-11
## [41,] -1.063395e-10
## [42,] -8.119453e-12
## [43,] -4.808150e-11
## [44,] -1.204099e-12
## [45,] -1.342107e-11
## [46,] -1.030077e-12
## [47,] -1.930820e-12
## [48,] -2.066950e-14
## [49,] -1.218631e-12
## [50,] -6.771051e-15
## [51,] -7.656344e-13
## 
## 
## Upper Band, CI= 0.95 
## $Production
##             Income
##  [1,] 7.237246e-01
##  [2,] 6.198639e-01
##  [3,] 2.634643e-01
##  [4,] 3.370610e-01
##  [5,] 1.665301e-01
##  [6,] 1.377130e-01
##  [7,] 8.381701e-02
##  [8,] 6.397445e-02
##  [9,] 4.623079e-02
## [10,] 3.489349e-02
## [11,] 2.590696e-02
## [12,] 1.943466e-02
## [13,] 1.447395e-02
## [14,] 1.082486e-02
## [15,] 8.037831e-03
## [16,] 6.111773e-03
## [17,] 4.574731e-03
## [18,] 3.477692e-03
## [19,] 2.608673e-03
## [20,] 1.974888e-03
## [21,] 1.482767e-03
## [22,] 1.119761e-03
## [23,] 8.414086e-04
## [24,] 6.346324e-04
## [25,] 4.772654e-04
## [26,] 3.597953e-04
## [27,] 2.707682e-04
## [28,] 2.040861e-04
## [29,] 1.536644e-04
## [30,] 1.158115e-04
## [31,] 8.722621e-05
## [32,] 6.573528e-05
## [33,] 4.951911e-05
## [34,] 3.731681e-05
## [35,] 2.811430e-05
## [36,] 2.118657e-05
## [37,] 1.597114e-05
## [38,] 1.204155e-05
## [39,] 9.077978e-06
## [40,] 6.844548e-06
## [41,] 5.160370e-06
## [42,] 3.890917e-06
## [43,] 2.933701e-06
## [44,] 2.212105e-06
## [45,] 1.667998e-06
## [46,] 1.257783e-06
## [47,] 9.484625e-07
## [48,] 7.152390e-07
## [49,] 5.393727e-07
## [50,] 4.067627e-07
## [51,] 3.067620e-07
plot(SVARog)

#la variable income responde bien ya que  a lo largo del tiempo se estabiliza
#con el  "shock" o el impulso que le dio production, si hubo cierta alteracion 
#pero se estabilizo.

SVARinf <- irf(SVARMod2, impulse = "Consumption", response =  "Production", n.ahead = 20)
SVARinf
## 
## Impulse response coefficients
## $Consumption
##          Production
##  [1,]  0.000000e+00
##  [2,] -8.423679e-02
##  [3,] -5.136470e-02
##  [4,] -2.629824e-02
##  [5,] -1.681976e-02
##  [6,] -9.015640e-03
##  [7,] -5.570241e-03
##  [8,] -3.710308e-03
##  [9,] -2.488058e-03
## [10,] -1.658355e-03
## [11,] -1.100716e-03
## [12,] -7.160481e-04
## [13,] -4.650416e-04
## [14,] -3.012246e-04
## [15,] -1.955897e-04
## [16,] -1.271815e-04
## [17,] -8.286333e-05
## [18,] -5.398839e-05
## [19,] -3.518190e-05
## [20,] -2.291475e-05
## [21,] -1.492248e-05
## 
## 
## Lower Band, CI= 0.95 
## $Consumption
##          Production
##  [1,]  0.0000000000
##  [2,] -0.1792486392
##  [3,] -0.1289074009
##  [4,] -0.0881160779
##  [5,] -0.0579981969
##  [6,] -0.0366052985
##  [7,] -0.0237174222
##  [8,] -0.0159463242
##  [9,] -0.0106266082
## [10,] -0.0075203060
## [11,] -0.0051949605
## [12,] -0.0035319861
## [13,] -0.0024255068
## [14,] -0.0016980868
## [15,] -0.0011936895
## [16,] -0.0008367640
## [17,] -0.0005880619
## [18,] -0.0004125421
## [19,] -0.0002898583
## [20,] -0.0002034346
## [21,] -0.0001429169
## 
## 
## Upper Band, CI= 0.95 
## $Consumption
##          Production
##  [1,]  0.0000000000
##  [2,] -0.0053602284
##  [3,]  0.0241184246
##  [4,]  0.0394737067
##  [5,]  0.0220339342
##  [6,]  0.0175444155
##  [7,]  0.0120689878
##  [8,]  0.0092024409
##  [9,]  0.0066583002
## [10,]  0.0044751546
## [11,]  0.0032229929
## [12,]  0.0023208134
## [13,]  0.0016815154
## [14,]  0.0012123306
## [15,]  0.0008754063
## [16,]  0.0006318708
## [17,]  0.0004557511
## [18,]  0.0003289365
## [19,]  0.0002373640
## [20,]  0.0001724593
## [21,]  0.0001255812
plot(SVARinf)

#la variable production responde bien ya que  a lo largo del tiempo se estabiliza
#con el  "shock" o el impulso que le dio Consumption, si hubo cierta alteracion 
#pero se estabilizo.

SVARrrp <- irf(SVARMod2, impulse = "Income", response = "Production", n.ahead = 20)
SVARrrp
## 
## Impulse response coefficients
## $Income
##          Production
##  [1,]  0.000000e+00
##  [2,]  6.919926e-02
##  [3,] -5.606690e-03
##  [4,]  3.181925e-02
##  [5,]  5.706925e-03
##  [6,]  8.159820e-03
##  [7,]  3.241685e-03
##  [8,]  2.824463e-03
##  [9,]  1.454388e-03
## [10,]  1.150342e-03
## [11,]  6.749486e-04
## [12,]  4.780171e-04
## [13,]  2.969751e-04
## [14,]  1.994109e-04
## [15,]  1.267185e-04
## [16,]  8.365239e-05
## [17,]  5.387704e-05
## [18,]  3.533142e-05
## [19,]  2.290820e-05
## [20,]  1.496815e-05
## [21,]  9.727921e-06
## 
## 
## Lower Band, CI= 0.95 
## $Income
##          Production
##  [1,] -1.251888e-17
##  [2,] -1.264273e-02
##  [3,] -1.006739e-01
##  [4,] -4.700813e-03
##  [5,] -2.642315e-02
##  [6,] -4.943795e-03
##  [7,] -8.766092e-03
##  [8,] -2.785605e-03
##  [9,] -3.158331e-03
## [10,] -1.640498e-03
## [11,] -1.454992e-03
## [12,] -8.115079e-04
## [13,] -5.950458e-04
## [14,] -3.983071e-04
## [15,] -2.837851e-04
## [16,] -1.904276e-04
## [17,] -1.383588e-04
## [18,] -9.415673e-05
## [19,] -6.855307e-05
## [20,] -4.732067e-05
## [21,] -3.388105e-05
## 
## 
## Upper Band, CI= 0.95 
## $Income
##         Production
##  [1,] 1.234489e-17
##  [2,] 1.727747e-01
##  [3,] 7.988889e-02
##  [4,] 7.903038e-02
##  [5,] 3.477547e-02
##  [6,] 3.127458e-02
##  [7,] 1.544000e-02
##  [8,] 1.399762e-02
##  [9,] 6.773049e-03
## [10,] 6.610886e-03
## [11,] 3.265562e-03
## [12,] 3.173641e-03
## [13,] 1.692247e-03
## [14,] 1.598266e-03
## [15,] 8.965009e-04
## [16,] 8.471079e-04
## [17,] 4.822422e-04
## [18,] 4.494266e-04
## [19,] 2.680326e-04
## [20,] 2.385495e-04
## [21,] 1.500150e-04
plot(SVARrrp)

#la variable Production responde bien ya que  a lo largo del tiempo se estabiliza
#con el  "shock" o el impulso que le dio Income, si hubo cierta alteracion 
#pero se estabilizo.


#Forecast Error Variance Decomposition

#el grafico muestra que en la variable Income, mas o menos el 30 % de varianza hay
#de production y un minimo de consumption , por lo que si se ve relacionada  en cierto grado por ambas.
#En Consumption hay varianza de Production en gran porcentaje.

SVARfevd <- fevd(SVARMod2, n.ahead = 20)
SVARfevd
## $Production
##       Production      Income Consumption
##  [1,]  1.0000000 0.000000000 0.000000000
##  [2,]  0.9890549 0.004410072 0.006535012
##  [3,]  0.9875870 0.004110863 0.008302089
##  [4,]  0.9863511 0.004896381 0.008752522
##  [5,]  0.9862347 0.004871204 0.008894130
##  [6,]  0.9861554 0.004911052 0.008933529
##  [7,]  0.9861454 0.004911129 0.008943516
##  [8,]  0.9861362 0.004914588 0.008949186
##  [9,]  0.9861335 0.004914852 0.008951598
## [10,]  0.9861318 0.004915359 0.008952801
## [11,]  0.9861312 0.004915475 0.008953328
## [12,]  0.9861309 0.004915557 0.008953557
## [13,]  0.9861308 0.004915584 0.008953652
## [14,]  0.9861307 0.004915598 0.008953692
## [15,]  0.9861307 0.004915603 0.008953708
## [16,]  0.9861307 0.004915605 0.008953715
## [17,]  0.9861307 0.004915606 0.008953718
## [18,]  0.9861307 0.004915606 0.008953719
## [19,]  0.9861307 0.004915606 0.008953720
## [20,]  0.9861307 0.004915606 0.008953720
## 
## $Income
##       Production    Income Consumption
##  [1,]  0.2277155 0.7722845  0.00000000
##  [2,]  0.2774727 0.7023961  0.02013119
##  [3,]  0.2780612 0.7004397  0.02149918
##  [4,]  0.2987711 0.6803238  0.02090511
##  [5,]  0.3011172 0.6779718  0.02091100
##  [6,]  0.3031299 0.6759958  0.02087428
##  [7,]  0.3037003 0.6754196  0.02088008
##  [8,]  0.3039901 0.6751269  0.02088308
##  [9,]  0.3040902 0.6750261  0.02088368
## [10,]  0.3041398 0.6749766  0.02088360
## [11,]  0.3041589 0.6749575  0.02088355
## [12,]  0.3041677 0.6749488  0.02088351
## [13,]  0.3041712 0.6749453  0.02088349
## [14,]  0.3041728 0.6749437  0.02088348
## [15,]  0.3041735 0.6749431  0.02088348
## [16,]  0.3041737 0.6749428  0.02088348
## [17,]  0.3041738 0.6749427  0.02088348
## [18,]  0.3041739 0.6749426  0.02088348
## [19,]  0.3041739 0.6749426  0.02088348
## [20,]  0.3041739 0.6749426  0.02088348
## 
## $Consumption
##       Production      Income Consumption
##  [1,]  0.5132621 0.003791464   0.4829464
##  [2,]  0.6810354 0.003190510   0.3157740
##  [3,]  0.7199512 0.004800969   0.2752478
##  [4,]  0.7328862 0.004575840   0.2625380
##  [5,]  0.7365771 0.004611959   0.2588109
##  [6,]  0.7377538 0.004658594   0.2575877
##  [7,]  0.7382487 0.004688847   0.2570625
##  [8,]  0.7384788 0.004697581   0.2568236
##  [9,]  0.7385832 0.004699711   0.2567170
## [10,]  0.7386298 0.004700294   0.2566699
## [11,]  0.7386498 0.004700493   0.2566497
## [12,]  0.7386583 0.004700581   0.2566411
## [13,]  0.7386618 0.004700626   0.2566376
## [14,]  0.7386633 0.004700647   0.2566360
## [15,]  0.7386639 0.004700656   0.2566354
## [16,]  0.7386642 0.004700660   0.2566351
## [17,]  0.7386643 0.004700662   0.2566350
## [18,]  0.7386644 0.004700662   0.2566350
## [19,]  0.7386644 0.004700663   0.2566350
## [20,]  0.7386644 0.004700663   0.2566349
plot(SVARfevd)

autoplot(forecast(Model1))