LABORATORIO 6
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.1 ✔ fma 2.5
## ✔ forecast 8.21 ✔ expsmooth 2.3
##
library(TSA)
## Registered S3 methods overwritten by 'TSA':
## method from
## fitted.Arima forecast
## plot.Arima forecast
##
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
##
## acf, arima
## The following object is masked from 'package:utils':
##
## tar
series <- autoplot(uschange)
autoplot(uschange[,c(2:4)])

a <- VARselect(uschange[,c(2,4)], lag.max=15,type="trend")
a$selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 3 3 1 3
Los valores que se recomiendan para P son 1 y 3.
Se evaluaran 2 modelos
modelo1<-VAR(uschange[,c(2:4)],p=1,type=c("trend"))
modelo3<-VAR(uschange[,c(2:4)],p=3,type=c("trend"))
aic1<-summary(modelo1)$logLik
aic2<-summary(modelo3)$logLik
serial.test(modelo1, lags.pt=10, type="PT.asymptotic")
##
## Portmanteau Test (asymptotic)
##
## data: Residuals of VAR object modelo1
## Chi-squared = 137.67, df = 81, p-value = 8.763e-05
serial.test(modelo3, lags.pt=10, type="PT.asymptotic")
##
## Portmanteau Test (asymptotic)
##
## data: Residuals of VAR object modelo3
## Chi-squared = 75.303, df = 63, p-value = 0.1378
roots(modelo1)
## [1] 0.4816638 0.4816638 0.3158780
roots(modelo3)
## [1] 0.8688517 0.5809402 0.5809402 0.5679856 0.5679856 0.5427566 0.4075580
## [8] 0.4075580 0.1279951
Todas los valores de las raíces unitarias estan por encima de
0.05
stab<-stability(modelo1, type = "OLS-CUSUM")
plot(stab)

La mejor opción es el modelo 1 que contiene una P = 1