Se analizaron diferentes pares de variables y se eligió la producción y consumo por la relación
Se trasladan los datos a una serie de tiempo como se visualiza en la siguiente gráfica:
Como siguiente paso se buscan los parámetros y se crea el modelo:
a <- VARselect(uschange[,c(1,3)], lag.max=15,type="const")
a$selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 3 2 1 3
modelo1<-VAR(uschange[,c(1,3)],p=1,type=c("const"))
modelo_s<-summary(modelo1)
A partir de esto se puede verificar si es estacionaria y se analizan los datos del modelo, como la correlación, significacia y explicación de los datos:
modelo_s$roots
## [1] 0.3776887 0.3776887
summary(modelo1,equation="Consumption")
##
## VAR Estimation Results:
## =========================
## Endogenous variables: Consumption, Production
## Deterministic variables: const
## Sample size: 186
## Log Likelihood: -436.992
## Roots of the characteristic polynomial:
## 0.3777 0.3777
## Call:
## VAR(y = uschange[, c(1, 3)], p = 1, type = c("const"))
##
##
## Estimation results for equation Consumption:
## ============================================
## Consumption = Consumption.l1 + Production.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## Consumption.l1 0.352745 0.082730 4.264 3.22e-05 ***
## Production.l1 -0.002188 0.035096 -0.062 0.95
## const 0.484938 0.070611 6.868 9.84e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.6188 on 183 degrees of freedom
## Multiple R-Squared: 0.1225, Adjusted R-squared: 0.1129
## F-statistic: 12.77 on 2 and 183 DF, p-value: 6.42e-06
##
##
##
## Covariance matrix of residuals:
## Consumption Production
## Consumption 0.3830 0.3627
## Production 0.3627 1.3590
##
## Correlation matrix of residuals:
## Consumption Production
## Consumption 1.0000 0.5027
## Production 0.5027 1.0000
summary(modelo1,equation="Production")
##
## VAR Estimation Results:
## =========================
## Endogenous variables: Consumption, Production
## Deterministic variables: const
## Sample size: 186
## Log Likelihood: -436.992
## Roots of the characteristic polynomial:
## 0.3777 0.3777
## Call:
## VAR(y = uschange[, c(1, 3)], p = 1, type = c("const"))
##
##
## Estimation results for equation Production:
## ===========================================
## Production = Consumption.l1 + Production.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## Consumption.l1 0.79308 0.15584 5.089 8.88e-07 ***
## Production.l1 0.39948 0.06611 6.042 8.31e-09 ***
## const -0.27113 0.13301 -2.038 0.0429 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 1.166 on 183 degrees of freedom
## Multiple R-Squared: 0.4284, Adjusted R-squared: 0.4221
## F-statistic: 68.58 on 2 and 183 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## Consumption Production
## Consumption 0.3830 0.3627
## Production 0.3627 1.3590
##
## Correlation matrix of residuals:
## Consumption Production
## Consumption 1.0000 0.5027
## Production 0.5027 1.0000
Ya con este modelo se puede empezar a hacer diferentes validaciones comenzando por el de autocorrelación. Debido a que el p-valor es menor de 0.05 no existe autocorrelación
serial.test(modelo1, lags.pt=10, type="PT.asymptotic")
##
## Portmanteau Test (asymptotic)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 66.725, df = 36, p-value = 0.001388
También se puede realizar uno de las raices unitarias para verificar que sean menores a uno
roots(modelo1)
## [1] 0.3776887 0.3776887
Para validar la normalidad del modelo se puede observar que el p-valor es menor de 0.05
normality.test(modelo1, multivariate.only=FALSE)
## $Consumption
##
## JB-Test (univariate)
##
## data: Residual of Consumption equation
## Chi-squared = 41.335, df = 2, p-value = 1.057e-09
##
##
## $Production
##
## JB-Test (univariate)
##
## data: Residual of Production equation
## Chi-squared = 54.373, df = 2, p-value = 1.56e-12
##
##
## $JB
##
## JB-Test (multivariate)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 88.328, df = 4, p-value < 2.2e-16
##
##
## $Skewness
##
## Skewness only (multivariate)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 8.8607, df = 2, p-value = 0.01191
##
##
## $Kurtosis
##
## Kurtosis only (multivariate)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 79.467, df = 2, p-value < 2.2e-16
Para verificar que no exista heteroscedasticidad se debe de validar que el número sea mayor a 0.05
arch<-arch.test(modelo1, lags.multi = 12, multivariate.only = FALSE)
arch
## $Consumption
##
## ARCH test (univariate)
##
## data: Residual of Consumption equation
## Chi-squared = 16.51, df = 16, p-value = 0.4179
##
##
## $Production
##
## ARCH test (univariate)
##
## data: Residual of Production equation
## Chi-squared = 35.302, df = 16, p-value = 0.003613
##
##
##
## ARCH (multivariate)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 183.74, df = 108, p-value = 7.561e-06
Luego se pueden verificar los cambios estructurales:
Para reconocer si existe causalidad se procede a realizar una prueba de Granger para ambas variables y debe de ser menor a 0.05
GrangerConsumption <-causality(modelo1, cause = 'Consumption')
GrangerConsumption
## $Granger
##
## Granger causality H0: Consumption do not Granger-cause Production
##
## data: VAR object modelo1
## F-Test = 25.898, df1 = 1, df2 = 366, p-value = 5.767e-07
##
##
## $Instant
##
## H0: No instantaneous causality between: Consumption and Production
##
## data: VAR object modelo1
## Chi-squared = 37.524, df = 1, p-value = 9.028e-10
GrangerProduction <-causality(modelo1, cause = 'Production')
GrangerProduction
## $Granger
##
## Granger causality H0: Production do not Granger-cause Consumption
##
## data: VAR object modelo1
## F-Test = 0.0038864, df1 = 1, df2 = 366, p-value = 0.9503
##
##
## $Instant
##
## H0: No instantaneous causality between: Production and Consumption
##
## data: VAR object modelo1
## Chi-squared = 37.524, df = 1, p-value = 9.028e-10
Ahora se aplica un shock a las variables para ver como se comporta la otra.
Para analizar la varianza:
Ya con estas validaciones se puede generar una predicción: