##Estacionariedad
##Laboratorio 3
#Miguel Antonio Garcia
#Notas: Buscar un p-value < 0.05 para que exista la estacionariedad y verificar que en grafico no exista ningun patron.
#identificar datos
rainfall <- c(799,1174.8,865.1,1334.6,635.4,918.5,685.5,998.6,784.2,985,882.8,1071)
x <- ts(rainfall,start = c(2012,1),frequency = 12)
plot(x)
tseries::adf.test(x)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo

##
## Augmented Dickey-Fuller Test
##
## data: x
## Dickey-Fuller = -1.5247, Lag order = 2, p-value = 0.7535
## alternative hypothesis: stationary
#En este caso no hay estacionariedad, ya que el p-value es mayor a 0.05 aun que en el grafico no notamos ninguna tendencia por lo que es necesario analisar en diferencia.
dx <- diff(x)
plot(dx)

tseries::adf.test(dx)
## Warning in tseries::adf.test(dx): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: dx
## Dickey-Fuller = -8.9033, Lag order = 2, p-value = 0.01
## alternative hypothesis: stationary
#En este caso si hay estacionalidad, ya que es p-value es meno a 0.05 y en el grafico no se distingue ninguna tendencia.
d2x <- diff(dx)
plot(d2x)

tseries::adf.test(d2x)
## Warning in tseries::adf.test(d2x): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: d2x
## Dickey-Fuller = -28.323, Lag order = 2, p-value = 0.01
## alternative hypothesis: stationary
#No necesario
d3x <- diff(d2x)
plot(d3x)

tseries::adf.test(d3x)
## Warning in tseries::adf.test(d3x): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: d3x
## Dickey-Fuller = -50.853, Lag order = 2, p-value = 0.01
## alternative hypothesis: stationary
#No necesario