Cargamos la base de datos USCHANGE con las variables Income y Unemployment

series<-uschange
autoplot(uschange[,c(2,5)])

Gráfica de serie de tiempo de las variables seleccionadas

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

Serie de tiempo de las variables del modelo

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

Selección de los parámetros

Se obtiene un estimado automático de los mejores parametros para la creación del modelo VAR. /8 y 1

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

Creación del modelo

modelo1<-VAR(uschange[,c(2,5)],p=5,type=c("const"))
summary(modelo1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Income, Unemployment 
## Deterministic variables: const 
## Sample size: 182 
## Log Likelihood: -262.292 
## Roots of the characteristic polynomial:
## 0.7776 0.7776 0.7661 0.7661 0.7488 0.7488 0.672 0.672 0.6364 0.5646
## Call:
## VAR(y = uschange[, c(2, 5)], p = 5, type = c("const"))
## 
## 
## Estimation results for equation Income: 
## ======================================= 
## Income = Income.l1 + Unemployment.l1 + Income.l2 + Unemployment.l2 + Income.l3 + Unemployment.l3 + Income.l4 + Unemployment.l4 + Income.l5 + Unemployment.l5 + const 
## 
##                 Estimate Std. Error t value Pr(>|t|)    
## Income.l1       -0.13069    0.07628  -1.713  0.08848 .  
## Unemployment.l1 -0.47812    0.22736  -2.103  0.03693 *  
## Income.l2        0.08289    0.07790   1.064  0.28883    
## Unemployment.l2  0.39251    0.23868   1.644  0.10191    
## Income.l3        0.03524    0.07602   0.464  0.64351    
## Unemployment.l3 -0.65814    0.24414  -2.696  0.00773 ** 
## Income.l4       -0.09359    0.07556  -1.239  0.21717    
## Unemployment.l4 -0.14117    0.24531  -0.575  0.56571    
## Income.l5       -0.12761    0.07471  -1.708  0.08944 .  
## Unemployment.l5  0.39764    0.22214   1.790  0.07522 .  
## const            0.87038    0.14889   5.846 2.49e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.8936 on 171 degrees of freedom
## Multiple R-Squared: 0.1347,  Adjusted R-squared: 0.08413 
## F-statistic: 2.663 on 10 and 171 DF,  p-value: 0.004781 
## 
## 
## Estimation results for equation Unemployment: 
## ============================================= 
## Unemployment = Income.l1 + Unemployment.l1 + Income.l2 + Unemployment.l2 + Income.l3 + Unemployment.l3 + Income.l4 + Unemployment.l4 + Income.l5 + Unemployment.l5 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)    
## Income.l1       -0.050174   0.025657  -1.956  0.05215 .  
## Unemployment.l1  0.436087   0.076472   5.703 5.08e-08 ***
## Income.l2       -0.004766   0.026202  -0.182  0.85589    
## Unemployment.l2  0.156143   0.080280   1.945  0.05342 .  
## Income.l3       -0.023081   0.025569  -0.903  0.36796    
## Unemployment.l3  0.067925   0.082118   0.827  0.40930    
## Income.l4       -0.012685   0.025414  -0.499  0.61833    
## Unemployment.l4 -0.183030   0.082510  -2.218  0.02785 *  
## Income.l5        0.068785   0.025128   2.737  0.00685 ** 
## Unemployment.l5  0.038701   0.074718   0.518  0.60516    
## const            0.012796   0.050080   0.256  0.79863    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.3006 on 171 degrees of freedom
## Multiple R-Squared: 0.3665,  Adjusted R-squared: 0.3295 
## F-statistic: 9.893 on 10 and 171 DF,  p-value: 5.479e-13 
## 
## 
## 
## Covariance matrix of residuals:
##               Income Unemployment
## Income        0.7985     -0.05280
## Unemployment -0.0528      0.09033
## 
## Correlation matrix of residuals:
##               Income Unemployment
## Income        1.0000      -0.1966
## Unemployment -0.1966       1.0000

Datos del modelo final por cada variable

Se obtienen los datos de modelo final para cada variable

Unemployment

summary(modelo1,equation="Unemployment")
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Income, Unemployment 
## Deterministic variables: const 
## Sample size: 182 
## Log Likelihood: -262.292 
## Roots of the characteristic polynomial:
## 0.7776 0.7776 0.7661 0.7661 0.7488 0.7488 0.672 0.672 0.6364 0.5646
## Call:
## VAR(y = uschange[, c(2, 5)], p = 5, type = c("const"))
## 
## 
## Estimation results for equation Unemployment: 
## ============================================= 
## Unemployment = Income.l1 + Unemployment.l1 + Income.l2 + Unemployment.l2 + Income.l3 + Unemployment.l3 + Income.l4 + Unemployment.l4 + Income.l5 + Unemployment.l5 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)    
## Income.l1       -0.050174   0.025657  -1.956  0.05215 .  
## Unemployment.l1  0.436087   0.076472   5.703 5.08e-08 ***
## Income.l2       -0.004766   0.026202  -0.182  0.85589    
## Unemployment.l2  0.156143   0.080280   1.945  0.05342 .  
## Income.l3       -0.023081   0.025569  -0.903  0.36796    
## Unemployment.l3  0.067925   0.082118   0.827  0.40930    
## Income.l4       -0.012685   0.025414  -0.499  0.61833    
## Unemployment.l4 -0.183030   0.082510  -2.218  0.02785 *  
## Income.l5        0.068785   0.025128   2.737  0.00685 ** 
## Unemployment.l5  0.038701   0.074718   0.518  0.60516    
## const            0.012796   0.050080   0.256  0.79863    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.3006 on 171 degrees of freedom
## Multiple R-Squared: 0.3665,  Adjusted R-squared: 0.3295 
## F-statistic: 9.893 on 10 and 171 DF,  p-value: 5.479e-13 
## 
## 
## 
## Covariance matrix of residuals:
##               Income Unemployment
## Income        0.7985     -0.05280
## Unemployment -0.0528      0.09033
## 
## Correlation matrix of residuals:
##               Income Unemployment
## Income        1.0000      -0.1966
## Unemployment -0.1966       1.0000

Income

summary(modelo1,equation="Income")
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Income, Unemployment 
## Deterministic variables: const 
## Sample size: 182 
## Log Likelihood: -262.292 
## Roots of the characteristic polynomial:
## 0.7776 0.7776 0.7661 0.7661 0.7488 0.7488 0.672 0.672 0.6364 0.5646
## Call:
## VAR(y = uschange[, c(2, 5)], p = 5, type = c("const"))
## 
## 
## Estimation results for equation Income: 
## ======================================= 
## Income = Income.l1 + Unemployment.l1 + Income.l2 + Unemployment.l2 + Income.l3 + Unemployment.l3 + Income.l4 + Unemployment.l4 + Income.l5 + Unemployment.l5 + const 
## 
##                 Estimate Std. Error t value Pr(>|t|)    
## Income.l1       -0.13069    0.07628  -1.713  0.08848 .  
## Unemployment.l1 -0.47812    0.22736  -2.103  0.03693 *  
## Income.l2        0.08289    0.07790   1.064  0.28883    
## Unemployment.l2  0.39251    0.23868   1.644  0.10191    
## Income.l3        0.03524    0.07602   0.464  0.64351    
## Unemployment.l3 -0.65814    0.24414  -2.696  0.00773 ** 
## Income.l4       -0.09359    0.07556  -1.239  0.21717    
## Unemployment.l4 -0.14117    0.24531  -0.575  0.56571    
## Income.l5       -0.12761    0.07471  -1.708  0.08944 .  
## Unemployment.l5  0.39764    0.22214   1.790  0.07522 .  
## const            0.87038    0.14889   5.846 2.49e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.8936 on 171 degrees of freedom
## Multiple R-Squared: 0.1347,  Adjusted R-squared: 0.08413 
## F-statistic: 2.663 on 10 and 171 DF,  p-value: 0.004781 
## 
## 
## 
## Covariance matrix of residuals:
##               Income Unemployment
## Income        0.7985     -0.05280
## Unemployment -0.0528      0.09033
## 
## Correlation matrix of residuals:
##               Income Unemployment
## Income        1.0000      -0.1966
## Unemployment -0.1966       1.0000

Validación del modelo

Prueba de Autocorrelación

Al realizar esta prueba se obtuvo un p-value de 0.05929 > 0.05, lo cual indica que existe autocorrelación.

serial.test(modelo1, lags.pt=11, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 35.653, df = 24, p-value = 0.05929

Prueba de estacionariedad

Al realizar esta prueba se puede ver que ya que los valores obtenidos no son mayores a 1, se confirma que el modelo creado es estacionario.

roots(modelo1)
##  [1] 0.7775660 0.7775660 0.7660914 0.7660914 0.7488061 0.7488061 0.6720236
##  [8] 0.6720236 0.6364359 0.5646411

Prueba de Jarque Bera (Normalidad)

Al realizar esta prueba se obtuvo un p-value de 2.2e-16 < 0.05, lo cual indica que existe normalidad en el comportamiento de los residuos del modelo.

normality.test(modelo1, multivariate.only=FALSE)
## $Income
## 
##  JB-Test (univariate)
## 
## data:  Residual of Income equation
## Chi-squared = 195.51, df = 2, p-value < 2.2e-16
## 
## 
## $Unemployment
## 
##  JB-Test (univariate)
## 
## data:  Residual of Unemployment equation
## Chi-squared = 33.197, df = 2, p-value = 6.184e-08
## 
## 
## $JB
## 
##  JB-Test (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 216.79, df = 4, p-value < 2.2e-16
## 
## 
## $Skewness
## 
##  Skewness only (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 7.8916, df = 2, p-value = 0.01934
## 
## 
## $Kurtosis
## 
##  Kurtosis only (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 208.9, df = 2, p-value < 2.2e-16

Prueba de Heteroscedasticidad

Con esta prueba se obtiene un p-value menor a 0.05, lo que significa que no hay heteroscedasticidad en el modelo. Además, este resultado confirma que la varianza de los residuos del modelo es constante.

arch<-arch.test(modelo1, lags.multi = 12, multivariate.only = FALSE)
arch
## $Income
## 
##  ARCH test (univariate)
## 
## data:  Residual of Income equation
## Chi-squared = 11.621, df = 16, p-value = 0.7697
## 
## 
## $Unemployment
## 
##  ARCH test (univariate)
## 
## data:  Residual of Unemployment equation
## Chi-squared = 21.391, df = 16, p-value = 0.164
## 
## 
## 
##  ARCH (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 121.69, df = 108, p-value = 0.1737

Prueba de choques estructurales

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

Pruba de Granger (Causalidad)

GrangerIncome <-causality(modelo1, cause = 'Income')
GrangerIncome
## $Granger
## 
##  Granger causality H0: Income do not Granger-cause Unemployment
## 
## data:  VAR object modelo1
## F-Test = 2.8057, df1 = 5, df2 = 342, p-value = 0.01687
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Income and Unemployment
## 
## data:  VAR object modelo1
## Chi-squared = 6.7734, df = 1, p-value = 0.009253
GrangerUnemployment <-causality(modelo1, cause = 'Unemployment')
GrangerUnemployment
## $Granger
## 
##  Granger causality H0: Unemployment do not Granger-cause Income
## 
## data:  VAR object modelo1
## F-Test = 3.7264, df1 = 5, df2 = 342, p-value = 0.002681
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Unemployment and Income
## 
## data:  VAR object modelo1
## Chi-squared = 6.7734, df = 1, p-value = 0.009253

Evaluación del modelo ante un impulso

En ambas gráficas es posible observar que al recibir un shock en los valores, en el largo plazo, las variables evaluadas vuelven a correlacionarse.

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

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

Prediccion del modelo en graficas

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

autoplot(forecast(modelo1))