En este laboratorio se estará realizando un modelo VAR para luego aplicar la Prueba de Granger.

Se instalan las librerías

#library(vars)
#library(fpp2)
#library(TSA)

Se cargan los datos

series<-uschange
autoplot(uschange[,3:5])

Gráfico de la serie de tiempo

ts.plot(series[,3:5], xlab="Tiempo",col=c(1,2))

Buscamos los parámetros

a <- VARselect(uschange[,3:5], lag.max=15,type="const")
a$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      2      2      1      2

Creamos nuestros modelos

modelo1<-VAR(uschange[,3:5],p=2,type=c("const"))
modelo_s<-summary(modelo1)

modelo_s$roots
## [1] 0.6558793 0.4112444 0.3989926 0.3989926 0.3189046 0.3189046
summary(modelo1,equation="Production")
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Production, Savings, Unemployment 
## Deterministic variables: const 
## Sample size: 185 
## Log Likelihood: -1000.283 
## Roots of the characteristic polynomial:
## 0.6559 0.4112 0.399 0.399 0.3189 0.3189
## Call:
## VAR(y = uschange[, 3:5], p = 2, type = c("const"))
## 
## 
## Estimation results for equation Production: 
## =========================================== 
## Production = Production.l1 + Savings.l1 + Unemployment.l1 + Production.l2 + Savings.l2 + Unemployment.l2 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)    
## Production.l1    0.443231   0.099938   4.435 1.61e-05 ***
## Savings.l1      -0.009834   0.006923  -1.420  0.15722    
## Unemployment.l1 -1.253058   0.393103  -3.188  0.00169 ** 
## Production.l2   -0.057492   0.097578  -0.589  0.55648    
## Savings.l2      -0.010007   0.006867  -1.457  0.14681    
## Unemployment.l2  0.530691   0.401838   1.321  0.18831    
## const            0.350422   0.110694   3.166  0.00182 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 1.2 on 178 degrees of freedom
## Multiple R-Squared: 0.409,   Adjusted R-squared: 0.389 
## F-statistic: 20.53 on 6 and 178 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##              Production  Savings Unemployment
## Production        1.441  -1.5606     -0.26799
## Savings          -1.561 169.1681      0.55216
## Unemployment     -0.268   0.5522      0.09667
## 
## Correlation matrix of residuals:
##              Production  Savings Unemployment
## Production      1.00000 -0.09996      -0.7181
## Savings        -0.09996  1.00000       0.1365
## Unemployment   -0.71807  0.13654       1.0000
summary(modelo1,equation="Unemployment")
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Production, Savings, Unemployment 
## Deterministic variables: const 
## Sample size: 185 
## Log Likelihood: -1000.283 
## Roots of the characteristic polynomial:
## 0.6559 0.4112 0.399 0.399 0.3189 0.3189
## Call:
## VAR(y = uschange[, 3:5], p = 2, type = c("const"))
## 
## 
## Estimation results for equation Unemployment: 
## ============================================= 
## Unemployment = Production.l1 + Savings.l1 + Unemployment.l1 + Production.l2 + Savings.l2 + Unemployment.l2 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)   
## Production.l1   -0.036885   0.025887  -1.425  0.15595   
## Savings.l1       0.002445   0.001793   1.363  0.17453   
## Unemployment.l1  0.337628   0.101825   3.316  0.00111 **
## Production.l2    0.025596   0.025275   1.013  0.31258   
## Savings.l2       0.001638   0.001779   0.921  0.35848   
## Unemployment.l2  0.197631   0.104087   1.899  0.05922 . 
## const           -0.001303   0.028673  -0.045  0.96381   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.3109 on 178 degrees of freedom
## Multiple R-Squared: 0.3155,  Adjusted R-squared: 0.2925 
## F-statistic: 13.68 on 6 and 178 DF,  p-value: 9.504e-13 
## 
## 
## 
## Covariance matrix of residuals:
##              Production  Savings Unemployment
## Production        1.441  -1.5606     -0.26799
## Savings          -1.561 169.1681      0.55216
## Unemployment     -0.268   0.5522      0.09667
## 
## Correlation matrix of residuals:
##              Production  Savings Unemployment
## Production      1.00000 -0.09996      -0.7181
## Savings        -0.09996  1.00000       0.1365
## Unemployment   -0.71807  0.13654       1.0000

Conclusión

El modelos es estacionario ,ya que los valores obtenidos no pasan de 1

Validación del modelo

Autocorrelación

serial.test(modelo1, lags.pt=10, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 104.64, df = 72, p-value = 0.007221

Conclusión

PortManteu Test > 0.05 Autocorrelación. El modelo 1 no presenta un p-value mayor a 0.05.

Raíz unitaria

roots(modelo1)
## [1] 0.6558793 0.4112444 0.3989926 0.3989926 0.3189046 0.3189046

Conclusión

Raíz unitaria > 0.05. El modelo 1 presenta una raíz mayor a 0.05.

Normalidad

normality.test(modelo1, multivariate.only=FALSE)
## $Production
## 
##  JB-Test (univariate)
## 
## data:  Residual of Production equation
## Chi-squared = 44.717, df = 2, p-value = 1.949e-10
## 
## 
## $Savings
## 
##  JB-Test (univariate)
## 
## data:  Residual of Savings equation
## Chi-squared = 149.08, df = 2, p-value < 2.2e-16
## 
## 
## $Unemployment
## 
##  JB-Test (univariate)
## 
## data:  Residual of Unemployment equation
## Chi-squared = 33.933, df = 2, p-value = 4.282e-08
## 
## 
## $JB
## 
##  JB-Test (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 187.43, df = 6, p-value < 2.2e-16
## 
## 
## $Skewness
## 
##  Skewness only (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 3.8415, df = 3, p-value = 0.2791
## 
## 
## $Kurtosis
## 
##  Kurtosis only (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 183.59, df = 3, p-value < 2.2e-16

Conclusión

Jarque Bera < 0.05. El modelo presenta un Jarque Bera menor a 0.05.

Heteroscedasticidad

arch<-arch.test(modelo1, lags.multi = 12, multivariate.only = FALSE)
arch
## $Production
## 
##  ARCH test (univariate)
## 
## data:  Residual of Production equation
## Chi-squared = 40.409, df = 16, p-value = 0.0006783
## 
## 
## $Savings
## 
##  ARCH test (univariate)
## 
## data:  Residual of Savings equation
## Chi-squared = 28.324, df = 16, p-value = 0.02891
## 
## 
## $Unemployment
## 
##  ARCH test (univariate)
## 
## data:  Residual of Unemployment equation
## Chi-squared = 27.944, df = 16, p-value = 0.03211
## 
## 
## 
##  ARCH (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 437.41, df = 432, p-value = 0.4184

Conclusión

Heteroscedasticity > 0.05 NO HAY. El modelo presenta un p-value mayor a 0.05.

Structural breaks

stab<-stability(modelo1, type = "OLS-CUSUM")
par(mar=c(1,1,1,1))
plot(stab)

Causalidad de granger

GrangerIncome <-causality(modelo1, cause = 'Production')
GrangerIncome
## $Granger
## 
##  Granger causality H0: Production do not Granger-cause Savings
##  Unemployment
## 
## data:  VAR object modelo1
## F-Test = 1.6836, df1 = 4, df2 = 534, p-value = 0.1523
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Production and Savings
##  Unemployment
## 
## data:  VAR object modelo1
## Chi-squared = 62.938, df = 2, p-value = 2.154e-14
GrangerConsumptions <-causality(modelo1, cause = 'Unemployment')
GrangerConsumptions
## $Granger
## 
##  Granger causality H0: Unemployment do not Granger-cause Production
##  Savings
## 
## data:  VAR object modelo1
## F-Test = 4.2428, df1 = 4, df2 = 534, p-value = 0.002173
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Unemployment and Production
##  Savings
## 
## data:  VAR object modelo1
## Chi-squared = 63.278, df = 2, p-value = 1.821e-14

Conclusión

Granger < 0.05 para que exista causalidad. El valor de la prueba es menor a 0.05 para ambas variables, por lo que si existe causalidad.

Respuesta de impulso

IncomeIRF <- irf(modelo1,  impulse = "Unemployment", response="Production", n.ahead = 20, boot = T )
plot(IncomeIRF, ylab = "Production", main = "Shock desde Unemployment")

ConsumptionIRF <- irf(modelo1,  impulse = "Production", response="Unemployment", n.ahead = 20, boot = T )
plot(ConsumptionIRF, ylab = "Unemployment", main = "Shock desde Production")

Conclusión

La produccón y el desempleo son variables que si una de estas se ve afectada, el mismo problema se puede ver reflejada en la otra.

Descomposición de la varianza

FEVD1 <- fevd(modelo1, n.ahead = 10)
plot(FEVD1)

Predicción

fore<-predict(modelo1, n.ahead = 10, ci=0.95)
fanchart(fore)

autoplot(forecast(modelo1))

Fórmula

modelo1$varresult$Production$coefficients
##   Production.l1      Savings.l1 Unemployment.l1   Production.l2      Savings.l2 
##     0.443231138    -0.009833695    -1.253057668    -0.057492433    -0.010006992 
## Unemployment.l2           const 
##     0.530690891     0.350422160
modelo1$varresult$Unemployment$coefficients
##   Production.l1      Savings.l1 Unemployment.l1   Production.l2      Savings.l2 
##    -0.036884554     0.002444545     0.337627743     0.025596317     0.001637642 
## Unemployment.l2           const 
##     0.197630824    -0.001302766
autoplot(forecast(modelo1))

Conclusión

El modelo en relación a la producción se ve fectada en un 0.44, mientras que en relación al desempleo seve afectadoen un 0.33.