Se debe realizar una diferenciación para que la serie de tiempo sea estacionaria.
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(seasonal)
library(tseries)
data <- read.table(file.choose(),head=TRUE,sep=";")
data <- data.frame(data)
datos_ts<-ts(data$CPIB, frequency = 1)
plot(datos_ts)
tseries::adf.test(datos_ts)
##
## Augmented Dickey-Fuller Test
##
## data: datos_ts
## Dickey-Fuller = -3.2283, Lag order = 3, p-value = 0.09141
## alternative hypothesis: stationary
Con el fin de aprobar la prueba de Dickey-Fuller debo realizar una diferenciación:
diff_ts<-diff(datos_ts)
tseries::adf.test(diff_ts)
## Warning in tseries::adf.test(diff_ts): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff_ts
## Dickey-Fuller = -5.4143, Lag order = 3, p-value = 0.01
## alternative hypothesis: stationary
plot(diff_ts)
Determino que hay 2 potenciales modelos de acuerdo a las siguientes gráficas (0,1,1) y (1,1,1).
par(mfrow = c(2,1))
acf(datos_ts)
pacf(datos_ts)
Elijo el modelo#1 debido al siguiente resultado:
modelo1 = Arima(datos_ts, order=c(0,1,1), include.drift = T)
modelo2 = Arima(datos_ts, order=c(1,1,1), include.drift = T)
modelo1$aic
## [1] 261.1881
modelo2$aic
## [1] 262.024
Gráfica de pronóstico para el modelo 1
par(mfrow = c(1,1))
modelo1 = Arima(datos_ts, order=c(0,1,1), include.drift = T)
a<-forecast::forecast(modelo1, h=20)
plot(a)
Verificando residuales
checkresiduals(modelo1$residuals)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.
Considero que esta gráfica puede demostrar una mejor predicción:
par(mfrow = c(2,1))
acf(modelo1$residuals)
pacf(modelo1$residuals)
par(mfrow = c(1,1))
modelo1 = Arima(datos_ts, order=c(0,1,1), seasonal= list(order=c(1,1,1),period=20), include.drift = T)
## Warning in Arima(datos_ts, order = c(0, 1, 1), seasonal = list(order = c(1, : No
## drift term fitted as the order of difference is 2 or more.
a<-forecast::forecast(modelo1, h=20)
plot(a)
checkresiduals(modelo1$residuals)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.