Cargar Librerias

library(forecast)
## Warning: package 'forecast' was built under R version 4.5.1
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(tseries)
## Warning: package 'tseries' was built under R version 4.5.1
library(writexl)
## Warning: package 'writexl' was built under R version 4.5.1
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.1
library(readxl)
## Warning: package 'readxl' was built under R version 4.5.1
library(TTR)
## Warning: package 'TTR' was built under R version 4.5.1

Importacion de Datos

url="https://raw.githubusercontent.com/vmoprojs/DataLectures/master/pib_ec_const.csv"
IMPOR=read.delim(url,sep=";")
IMPOR=IMPOR$IMPOR/1000000
IMPOR_s=ts(IMPOR,start = c(2000,1),frequency = 4)
plot(IMPOR_s)

El comportamiento del grafico es de manera multiplicativa,se observa tendencia creciente con caidas en los años 2016 y 2020

IMPORl=log(IMPOR)
plot(IMPORl)

Serie Estacionaria

IMPORld=diff(IMPORl)
IMPORlds=diff(IMPORld,4)
adf.test(IMPORlds)
## Warning in adf.test(IMPORlds): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  IMPORlds
## Dickey-Fuller = -4.9516, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary
plot(IMPORlds)

Ajuste al mejor Modelo

acf(IMPORlds,lag.max = 24,main=" Funcion de autocorrelacion ")

Se observa en la función de autocorrelación un resago de forma significativa en la parte regular (MA(1)) y en la parte estacional es significativo (SMA(0)).

pacf(IMPORlds,lag.max = 24,main="función de autocorrelación parcial")

la función de autocorrelación parcial se observa igualmente un resago significativo en la parte reguar (AR(1)) y (SAR(0)).

mod1 = arima(IMPORl,order= c(0,1,1),
              seasonal   = list(order = c(0,1,1), period = 4))
mod1
## 
## Call:
## arima(x = IMPORl, order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 4))
## 
## Coefficients:
##          ma1     sma1
##       0.2006  -0.6760
## s.e.  0.1035   0.1058
## 
## sigma^2 estimated as 0.002765:  log likelihood = 119.35,  aic = -232.69

Descomposicion de la serie

IMPOR_sd=decompose(IMPOR_s)
plot(IMPOR_sd)

Modelo de Holtwinters

IMPOR_sw=HoltWinters(IMPOR_s,seasonal = "additive")
IMPOR_sp=predict(IMPOR_sw,9)
IMPOR_sp
##          Qtr1     Qtr2     Qtr3     Qtr4
## 2021 5.177510 5.046085 5.074954 5.167071
## 2022 5.266849 5.135423 5.164293 5.256409
## 2023 5.356187

Prediccion Sarima

mod=auto.arima(IMPORl,trace = T)
## 
##  ARIMA(2,1,2) with drift         : Inf
##  ARIMA(0,1,0) with drift         : -233.6767
##  ARIMA(1,1,0) with drift         : -231.7997
##  ARIMA(0,1,1) with drift         : -231.8522
##  ARIMA(0,1,0)                    : -231.4263
##  ARIMA(1,1,1) with drift         : -229.6876
## 
##  Best model: ARIMA(0,1,0) with drift