7.1.Ejemplo 1

uu <- "https://raw.githubusercontent.com/vmoprojs/DataLectures/master/CAEMP.DAT"
datos=read.csv(url(uu),sep=",",header=T)
d2s= ts(datos,st=1962,fr=4)
plot(d2s)

Interpretar El grafico muestra una tendencia positiva hasta 1975, se muestran fluctuaciones y caídas en 1982 y 1992. No se muestra estacionalidad regular, sí hay ciclos, no es estacionaria.

7.1.1. Estacionariedad

acf(d2s)

library(tseries)
## Warning: package 'tseries' was built under R version 4.5.1
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
adf.test(d2s)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  d2s
## Dickey-Fuller = -2.6391, Lag order = 5, p-value = 0.3106
## alternative hypothesis: stationary

Basado en la prueba de dickey fuller la serie no esytarasionario ademas la funcion de autocorrelacion muestra un decenso suave en los 12 primeros rezagos

d2sd=diff(d2s)
acf(d2sd)

adf.test(d2sd)
## Warning in adf.test(d2sd): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  d2sd
## Dickey-Fuller = -4.0972, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary

el p valor de la prueba de dickey fuller indica que la serie es estacionaria porque es menor que alfa = 5% ### **7.1.3.Modelo ARIMA

acf(d2sd)

pacf(d2sd)

m1=arima(d2s,order = c(0,1,2))
m1$aic
## [1] 488.5535
m2=arima(d2s,order = c(1,1,0))
m2$aic
## [1] 485.4119
m3=arima(d2s,order = c(1,1,2))
m3$aic
## [1] 489.1799

de los 3 valores presentes se escoje al quye represente al valor mas bajo de valor AIC en este caso el modelo2 (aic=485.41)

7.1.4.Pronostico

d2sp=predict(m2,3)
d2sp
## $pred
##          Qtr1     Qtr2     Qtr3
## 1996 92.17202 92.24426 92.27748
## 
## $se
##          Qtr1     Qtr2     Qtr3
## 1996 1.437907 2.544385 3.499883

7.1.5.Exportacion de datos

str(d2s)
##  Time-Series [1:136, 1] from 1962 to 1996: 83.1 82.8 84.6 85.4 86.2 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "caemp"
inicio=1962.
final=1996.5
fecha=seq(inicio,final,by=0.25)
length(fecha)
## [1] 139
desempleo=c(d2s,d2sp)
length(desempleo)
## [1] 138
data=c(rep("real",136),rep("pronostico",3))
length(data)
## [1] 139
#datosd=data.frame(fecha,desempleo,data)