Importacion del modelo
library(readxl)
library(tidyr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
IVAE_03_22<-read_excel("C:\\Users\\MOLINA\\OneDrive\\Escritorio\\ARCHIVOS DE R\\IVAE_03_22.xls.xlsx",col_names = FALSE,skip = 6,n_max = 10)
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
## • `` -> `...19`
## • `` -> `...20`
## • `` -> `...21`
## • `` -> `...22`
## • `` -> `...23`
## • `` -> `...24`
## • `` -> `...25`
## • `` -> `...26`
## • `` -> `...27`
## • `` -> `...28`
## • `` -> `...29`
## • `` -> `...30`
## • `` -> `...31`
## • `` -> `...32`
## • `` -> `...33`
## • `` -> `...34`
## • `` -> `...35`
## • `` -> `...36`
## • `` -> `...37`
## • `` -> `...38`
## • `` -> `...39`
## • `` -> `...40`
## • `` -> `...41`
## • `` -> `...42`
## • `` -> `...43`
## • `` -> `...44`
## • `` -> `...45`
## • `` -> `...46`
## • `` -> `...47`
## • `` -> `...48`
## • `` -> `...49`
## • `` -> `...50`
## • `` -> `...51`
## • `` -> `...52`
## • `` -> `...53`
## • `` -> `...54`
## • `` -> `...55`
## • `` -> `...56`
## • `` -> `...57`
## • `` -> `...58`
## • `` -> `...59`
## • `` -> `...60`
## • `` -> `...61`
## • `` -> `...62`
## • `` -> `...63`
## • `` -> `...64`
## • `` -> `...65`
## • `` -> `...66`
## • `` -> `...67`
## • `` -> `...68`
## • `` -> `...69`
## • `` -> `...70`
## • `` -> `...71`
## • `` -> `...72`
## • `` -> `...73`
## • `` -> `...74`
## • `` -> `...75`
## • `` -> `...76`
## • `` -> `...77`
## • `` -> `...78`
## • `` -> `...79`
## • `` -> `...80`
## • `` -> `...81`
## • `` -> `...82`
## • `` -> `...83`
## • `` -> `...84`
## • `` -> `...85`
## • `` -> `...86`
## • `` -> `...87`
## • `` -> `...88`
## • `` -> `...89`
## • `` -> `...90`
## • `` -> `...91`
## • `` -> `...92`
## • `` -> `...93`
## • `` -> `...94`
## • `` -> `...95`
## • `` -> `...96`
## • `` -> `...97`
## • `` -> `...98`
## • `` -> `...99`
## • `` -> `...100`
## • `` -> `...101`
## • `` -> `...102`
## • `` -> `...103`
## • `` -> `...104`
## • `` -> `...105`
## • `` -> `...106`
## • `` -> `...107`
## • `` -> `...108`
## • `` -> `...109`
## • `` -> `...110`
## • `` -> `...111`
## • `` -> `...112`
## • `` -> `...113`
## • `` -> `...114`
## • `` -> `...115`
## • `` -> `...116`
## • `` -> `...117`
## • `` -> `...118`
## • `` -> `...119`
## • `` -> `...120`
## • `` -> `...121`
## • `` -> `...122`
## • `` -> `...123`
## • `` -> `...124`
## • `` -> `...125`
## • `` -> `...126`
## • `` -> `...127`
## • `` -> `...128`
## • `` -> `...129`
## • `` -> `...130`
## • `` -> `...131`
## • `` -> `...132`
## • `` -> `...133`
## • `` -> `...134`
## • `` -> `...135`
## • `` -> `...136`
## • `` -> `...137`
## • `` -> `...138`
## • `` -> `...139`
## • `` -> `...140`
## • `` -> `...141`
## • `` -> `...142`
## • `` -> `...143`
## • `` -> `...144`
## • `` -> `...145`
## • `` -> `...146`
## • `` -> `...147`
## • `` -> `...148`
## • `` -> `...149`
## • `` -> `...150`
## • `` -> `...151`
## • `` -> `...152`
## • `` -> `...153`
## • `` -> `...154`
## • `` -> `...155`
## • `` -> `...156`
## • `` -> `...157`
## • `` -> `...158`
## • `` -> `...159`
## • `` -> `...160`
data.ivae<-pivot_longer(data = IVAE_03_22[1,],names_to = "vars",cols = 2:160,values_to = "indice") %>% select("indice")
serie.ivae.ts<-data.ivae %>% ts(start = c(2009,1),frequency = 12)
Yt <- serie.ivae.ts
serie.ivae.ts %>%
autoplot(main="IVAE ENERO 2009- MARZ0 2022",
xlab="Años/meses",
ylab="Indice")

PRONOSTICO DE SERIES TEMPORALES, ENFOQUE DETERMINISTICO
(CLASICO)
Pronostico modelo de Holt Winters
Usando Stats y Forecast
Multiplicativo
library(forecast)
#Estimar el modelo
modelohw<-HoltWinters(x = Yt,
seasonal= "multiplicative",
optim.start=c(0.9,0.9,0.9)) #OPCIONAL:BUSCA establecer los valores quinceales para la busqueda de parametros que busca HW
modelohw
## Holt-Winters exponential smoothing with trend and multiplicative seasonal component.
##
## Call:
## HoltWinters(x = Yt, seasonal = "multiplicative", optim.start = c(0.9, 0.9, 0.9))
##
## Smoothing parameters:
## alpha: 0.8472467
## beta : 0
## gamma: 1
##
## Coefficients:
## [,1]
## a 118.3719784
## b 0.1600947
## s1 0.9529095
## s2 1.0192349
## s3 1.0440936
## s4 0.9962326
## s5 1.0009929
## s6 0.9838373
## s7 0.9554392
## s8 1.0145286
## s9 1.0872315
## s10 0.9748891
## s11 0.9626701
## s12 1.0059813
#Generar el pronostico
pronosticoshw<-forecast(object = modelohw,h = 12,level = c(0.95))
pronosticoshw
## Point Forecast Lo 95 Hi 95
## Apr 2022 112.9503 107.46492 118.4358
## May 2022 120.9752 113.57246 128.3779
## Jun 2022 124.0929 115.22236 132.9634
## Jul 2022 118.5640 108.86876 128.2592
## Aug 2022 119.2908 108.50116 130.0804
## Sep 2022 117.4038 105.81297 128.9947
## Oct 2022 114.1680 101.97016 126.3657
## Nov 2022 121.3911 107.66977 135.1125
## Dec 2022 130.2643 114.88360 145.6450
## Jan 2023 116.9603 102.34981 131.5708
## Feb 2023 115.6485 100.48405 130.8129
## Mar 2023 121.0126 83.19827 158.8270
#Grafico de la serie original t del pronostico
pronosticoshw %>% autoplot(main="Pronostco HW multiplicativo", xlab="Años/meses")

Aditivo
library(forecast)
#Estimar el modelo
modelohw.ad<-HoltWinters(x = Yt,
seasonal= "additive",
optim.start=c(0.9,0.9,0.9)) #OPCIONAL:bUSCA establecer los valores quinceales para la busqueda de parametros que busca HW
modelohw.ad
## Holt-Winters exponential smoothing with trend and additive seasonal component.
##
## Call:
## HoltWinters(x = Yt, seasonal = "additive", optim.start = c(0.9, 0.9, 0.9))
##
## Smoothing parameters:
## alpha: 0.9142733
## beta : 0
## gamma: 1
##
## Coefficients:
## [,1]
## a 118.0938359
## b 0.1600947
## s1 -3.9032233
## s2 3.0467916
## s3 3.9273013
## s4 -1.6040517
## s5 -0.5787492
## s6 -1.8288955
## s7 -4.0808499
## s8 2.2490593
## s9 9.6275698
## s10 -2.7962367
## s11 -4.4557494
## s12 0.9861641
#Generar el pronostico
pronosticoshw.ad<-forecast(object = modelohw.ad,h = 12,level = c(0.95))
pronosticoshw.ad
## Point Forecast Lo 95 Hi 95
## Apr 2022 114.3507 109.10096 119.6005
## May 2022 121.4608 114.34766 128.5740
## Jun 2022 122.5014 113.92039 131.0825
## Jul 2022 117.1302 107.29801 126.9623
## Aug 2022 118.3156 107.37443 129.2567
## Sep 2022 117.2255 105.27790 129.1731
## Oct 2022 115.1336 102.25799 128.0093
## Nov 2022 121.6237 107.88248 135.3648
## Dec 2022 129.1623 114.60695 143.7176
## Jan 2023 116.8985 101.57229 132.2248
## Feb 2023 115.3991 99.33889 131.4594
## Mar 2023 121.0011 104.23903 137.7632
#Grafico de la serie original y del pronostico
pronosticoshw.ad %>% autoplot(main="Pronostco HW aditivo", xlab="Años/meses")

Usando forecast(aproximacion por espacios de los estados ETS)
Multiplicativo
library(forecast)
#generar el pronostico
pronosticoshw2_mul<-hw(y = Yt,
h = 12,
level = c(0.95),
seasonal = "multiplicative",
initial = "optimal")
pronosticoshw2_mul
## Point Forecast Lo 95 Hi 95
## Apr 2022 111.9184 105.09260 118.7442
## May 2022 119.3664 110.67455 128.0583
## Jun 2022 122.8422 112.63807 133.0464
## Jul 2022 118.4498 107.52066 129.3789
## Aug 2022 120.0189 107.93209 132.1056
## Sep 2022 118.4260 105.56932 131.2828
## Oct 2022 114.3087 101.05402 127.5633
## Nov 2022 120.2837 105.49291 135.0745
## Dec 2022 127.9776 111.38423 144.5709
## Jan 2023 114.4558 98.88074 130.0309
## Feb 2023 113.5923 97.43199 129.7527
## Mar 2023 119.3883 101.68918 137.0873
#grafico de la serie original y del pronostico
pronosticoshw2_mul %>% autoplot(main ="Pronostico aproximacion por espacios multiplicativo",xlab="Años/meses")

Aditivo
library(forecast)
#Estimar el modelo
modelohw.ad2<-HoltWinters(x = Yt,
seasonal= "additive",
optim.start=c(0.9,0.9,0.9))
modelohw.ad2
## Holt-Winters exponential smoothing with trend and additive seasonal component.
##
## Call:
## HoltWinters(x = Yt, seasonal = "additive", optim.start = c(0.9, 0.9, 0.9))
##
## Smoothing parameters:
## alpha: 0.9142733
## beta : 0
## gamma: 1
##
## Coefficients:
## [,1]
## a 118.0938359
## b 0.1600947
## s1 -3.9032233
## s2 3.0467916
## s3 3.9273013
## s4 -1.6040517
## s5 -0.5787492
## s6 -1.8288955
## s7 -4.0808499
## s8 2.2490593
## s9 9.6275698
## s10 -2.7962367
## s11 -4.4557494
## s12 0.9861641
#Generar el modelo
pronosticoshw.ad.2<-forecast(object = modelohw.ad,h = 12,level = c(0.95))
pronosticoshw.ad.2
## Point Forecast Lo 95 Hi 95
## Apr 2022 114.3507 109.10096 119.6005
## May 2022 121.4608 114.34766 128.5740
## Jun 2022 122.5014 113.92039 131.0825
## Jul 2022 117.1302 107.29801 126.9623
## Aug 2022 118.3156 107.37443 129.2567
## Sep 2022 117.2255 105.27790 129.1731
## Oct 2022 115.1336 102.25799 128.0093
## Nov 2022 121.6237 107.88248 135.3648
## Dec 2022 129.1623 114.60695 143.7176
## Jan 2023 116.8985 101.57229 132.2248
## Feb 2023 115.3991 99.33889 131.4594
## Mar 2023 121.0011 104.23903 137.7632
#Grafico de la serie original y del pronostico
pronosticoshw.ad.2 %>% autoplot(main="Pronostco HW aditivo", xlab="Años/meses")
