library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(forecast)
library(ggplot2)
library(readxl)
url="https://raw.githubusercontent.com/vmoprojs/DataLectures/master/pib_ec_const.csv"
datos1=read.delim(url,sep = ";")
GCFH=datos1$GCFH
plot(GCFH)
GCFH_s=ts(GCFH,start = c(2000,1),frequency = 4)
HoltWinters(GCFH_s)
## Holt-Winters exponential smoothing with trend and additive seasonal component.
##
## Call:
## HoltWinters(x = GCFH_s)
##
## Smoothing parameters:
## alpha: 1
## beta : 0.0456811
## gamma: 0.4931984
##
## Coefficients:
## [,1]
## a 10390297.250
## b 8133.386
## s1 31203.250
## s2 -6893.000
## s3 -19194.000
## s4 -5116.250
plot(GCFH_s)
GCFH_s=diff(GCFH_s,4)
adf.test(GCFH_s)
##
## Augmented Dickey-Fuller Test
##
## data: GCFH_s
## Dickey-Fuller = -2.6077, Lag order = 4, p-value = 0.327
## alternative hypothesis: stationary
mod=auto.arima(GCFH_s,trace = T)
##
## ARIMA(2,1,2)(1,0,1)[4] with drift : Inf
## ARIMA(0,1,0) with drift : 2167.968
## ARIMA(1,1,0)(1,0,0)[4] with drift : 2160.704
## ARIMA(0,1,1)(0,0,1)[4] with drift : 2153.329
## ARIMA(0,1,0) : 2166.297
## ARIMA(0,1,1) with drift : 2170.122
## ARIMA(0,1,1)(1,0,1)[4] with drift : 2155.278
## ARIMA(0,1,1)(0,0,2)[4] with drift : 2155.086
## ARIMA(0,1,1)(1,0,0)[4] with drift : 2160.727
## ARIMA(0,1,1)(1,0,2)[4] with drift : Inf
## ARIMA(0,1,0)(0,0,1)[4] with drift : 2151.343
## ARIMA(0,1,0)(1,0,1)[4] with drift : 2153.25
## ARIMA(0,1,0)(0,0,2)[4] with drift : 2153.05
## ARIMA(0,1,0)(1,0,0)[4] with drift : 2158.7
## ARIMA(0,1,0)(1,0,2)[4] with drift : Inf
## ARIMA(1,1,0)(0,0,1)[4] with drift : 2153.337
## ARIMA(1,1,1)(0,0,1)[4] with drift : Inf
## ARIMA(0,1,0)(0,0,1)[4] : 2150.961
## ARIMA(0,1,0)(1,0,1)[4] : 2152.741
## ARIMA(0,1,0)(0,0,2)[4] : 2152.445
## ARIMA(0,1,0)(1,0,0)[4] : 2157.332
## ARIMA(0,1,0)(1,0,2)[4] : 2152.473
## ARIMA(1,1,0)(0,0,1)[4] : 2153.058
## ARIMA(0,1,1)(0,0,1)[4] : 2153.061
## ARIMA(1,1,1)(0,0,1)[4] : 2155.086
##
## Best model: ARIMA(0,1,0)(0,0,1)[4]
mod
## Series: GCFH_s
## ARIMA(0,1,0)(0,0,1)[4]
##
## Coefficients:
## sma1
## -0.7047
## s.e. 0.1243
##
## sigma^2 = 3.629e+10: log likelihood = -1073.4
## AIC=2150.8 AICc=2150.96 BIC=2155.54
\((y_t-y{t-0})-(y_{t-4}-y_{t-5})=--0.7047 E_{t-1}0 E_{t-0}\)
GCFH_sw = HoltWinters(GCFH_s, gamma = F)
GCFH_sp = predict(GCFH_sw, 3)
plot(GCFH_sw, GCFH_sp, main = "Gasto de Consumo final Hogares: 2000:2025")