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(fpp2)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.5 ──
## ✔ ggplot2 3.4.0 ✔ fma 2.5
## ✔ forecast 8.20 ✔ expsmooth 2.3
##
series<-uschange
autoplot(uschange[,1:2])
ts.plot(series[,1:2], xlab="Tiempo",col=c(1,2))
a <- VARselect(uschange[,1:2], lag.max=15,type="trend")
a$selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 3 3 1 3
modelo1<-VAR(uschange[,1:2],p=1,type=c("trend"))
modelo3<-VAR(uschange[,1:2],p=3,type=c("trend"))
aic1<-summary(modelo1)$logLik
aic2<-summary(modelo3)$logLik
aic1
aic2
summary(modelo1,equation="Consumption")
summary(modelo1,equation="Income")
###Prueba PortManteu > 0.05 Autocorrelación
serial.test(modelo1, lags.pt=10, type="PT.asymptotic")
##
## Portmanteau Test (asymptotic)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 59.238, df = 36, p-value = 0.008678
###Prueba Raíz unitaria > 0.05
roots(modelo1)
## [1] 0.5838062 0.3286818
###Prueba de normalidad Jarque Bera < 0.05
normality.test(modelo1, multivariate.only=FALSE)
## $Consumption
##
## JB-Test (univariate)
##
## data: Residual of Consumption equation
## Chi-squared = 17.514, df = 2, p-value = 0.0001573
##
##
## $Income
##
## JB-Test (univariate)
##
## data: Residual of Income equation
## Chi-squared = 166.38, df = 2, p-value < 2.2e-16
##
##
## $JB
##
## JB-Test (multivariate)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 156.99, df = 4, p-value < 2.2e-16
##
##
## $Skewness
##
## Skewness only (multivariate)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 3.6264, df = 2, p-value = 0.1631
##
##
## $Kurtosis
##
## Kurtosis only (multivariate)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 153.36, df = 2, p-value < 2.2e-16
###Prueba de heteroscedasticity >0.05 NO HAY
arch<-arch.test(modelo1, lags.multi = 12, multivariate.only = TRUE)
arch
##
## ARCH (multivariate)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 130.87, df = 108, p-value = 0.06642
###Prueba quiebres estructurales
stab<-stability(modelo1, type = "OLS-CUSUM")
plot(stab)
###Prueba PortManteu > 0.05 Autocorrelación
serial.test(modelo3, lags.pt=10, type="PT.asymptotic")
##
## Portmanteau Test (asymptotic)
##
## data: Residuals of VAR object modelo3
## Chi-squared = 30.575, df = 28, p-value = 0.3363
###Prueba Raíz unitaria > 0.05
roots(modelo3)
## [1] 0.8886006 0.5506206 0.5506206 0.4563212 0.2912480 0.2912480
###Prueba de normalidad Jarque Bera < 0.05
normality.test(modelo3, multivariate.only=FALSE)
## $Consumption
##
## JB-Test (univariate)
##
## data: Residual of Consumption equation
## Chi-squared = 35.893, df = 2, p-value = 1.607e-08
##
##
## $Income
##
## JB-Test (univariate)
##
## data: Residual of Income equation
## Chi-squared = 187.91, df = 2, p-value < 2.2e-16
##
##
## $JB
##
## JB-Test (multivariate)
##
## data: Residuals of VAR object modelo3
## Chi-squared = 183.35, df = 4, p-value < 2.2e-16
##
##
## $Skewness
##
## Skewness only (multivariate)
##
## data: Residuals of VAR object modelo3
## Chi-squared = 4.2546, df = 2, p-value = 0.1192
##
##
## $Kurtosis
##
## Kurtosis only (multivariate)
##
## data: Residuals of VAR object modelo3
## Chi-squared = 179.1, df = 2, p-value < 2.2e-16
###Prueba de heteroscedasticity >0.05 NO HAY
arch<-arch.test(modelo3, lags.multi = 12, multivariate.only = TRUE)
arch
##
## ARCH (multivariate)
##
## data: Residuals of VAR object modelo3
## Chi-squared = 120.4, df = 108, p-value = 0.1953
###Prueba quiebres estructurales
stab<-stability(modelo3, type = "OLS-CUSUM")
plot(stab)
A pesar de que R nos sugiere utilizar el modelo 3, luego de realizar las pruebas vemos que el modelo 1 pasa más pruebas que el modelo 3, por lo que elegimos el modelo 1.