EJERCICIO 1. INTRODUCCION.

CARACTERISTICAS DE LA SERIE.

  1. PERIODICIDAD: Anual.
  2. UNIDAD DE MEDIDA: Millones de pies cubicos.
  3. FUENTE: INEGI.
library(forecast)
library(ggplot2)
library(readxl)
base<-read_xls("C:/Users/rodar/OneDrive/Escritorio/SERIES/PRODUCCION DE GAS.xls")
PGN <-ts(base$PG, frequency = 12, start=c(2006,1))
autoplot(PGN)

VEMOS QUE EL GRÁFICO RESULTANTE NO ES EL MÁS APROPIADO PARA DESCRIBIR UNA SERIE TEMPORAL.

fit<-decompose(PGN)
plot(fit)

PODEMOS OBSERVAR QUE LA GRAFICA MUESTRA ALEATORIEDAD.

ggseasonplot(PGN)

EN ESTE CASO LA SERIE SI PRESENTA ESTACIONALIDAD, DEBIDO A QUE LA PRODUCCION DE GAS DEPENDE DE ALGUNOS FACTORES ESTACIONALES.

EJERCICIO 2. DESCOMPOSICION DE SERIES DE TIEMPO.

  1. USANDO LA SERIE ELEGIDA PREVIAMENTE, PRESENTAR EN UN MISMO PANEL MA(3), MA(5), MA(7) Y MA(9) (USAR LA FUNCIÓN MA() DEL PAQUETE FORECAST).
autoplot(PGN,series= "Data")+autolayer(ma(PGN,3),series="3-MA")+xlab("Year")+ggtitle("PRODUCCION GAS")
## Warning: Removed 2 rows containing missing values (geom_path).

autoplot(PGN,series= "Data")+autolayer(ma(PGN,5),series="5-MA")+xlab("Year")+ggtitle("PRODUCCION GAS")
## Warning: Removed 4 rows containing missing values (geom_path).

autoplot(PGN,series= "Data")+autolayer(ma(PGN,7),series="7-MA")+xlab("Year")+ggtitle("PRODUCCION GAS")
## Warning: Removed 6 rows containing missing values (geom_path).

autoplot(PGN,series= "Data")+autolayer(ma(PGN,9),series="9-MA")+xlab("Year")+ggtitle("PRODUCCION GAS")
## Warning: Removed 8 rows containing missing values (geom_path).

  1. REALIZAR UNA DESCOMPOSICIÓN CLÁSICA (ADITIVA O MULTIPLICATIVA). INTERPRETAR.
fit<-decompose(PGN,type = 'additive')
autoplot(fit)

fit<-decompose(PGN,type = 'multiplicative')
autoplot(fit)

  1. EN UN MISMO GRAFICO PRESENTAR:
  1. Si existe evidencia de estacionalidad generar grafico de serie original y serie desestacionalizada, ó
  2. Si no existe evidencia de estacionalidad generar grafico de serie original y componente tendencia-ciclo.
autoplot(PGN,series="Data")+autolayer(seasadj(fit),series="Seasonally adj. data")+xlab("Year")+ylab("New orders index")+ggtitle("Produccion Gas")

EJERCICIO 4. TENDENCIAS.

  1. DE ACUERDO CON LAS CARACTERÍSTICAS DE LA SERIE ELEGIDA EN LOS EJERCICIOS 1 Y 2, SE PIDE PRESENTAR UNA PROPUESTA DE MODELO DE TENDENCIA CON EL MEJOR AJUSTE. ESPECÍFICAMENTE SE SOLICITA:
  1. Presentar la estimación del modelo de regresión en función del tiempo, el tiempo al cuadrado y/o medias estacionales.
library(forecast)
library(TSA)
## 
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
## 
##     acf, arima
## The following object is masked from 'package:utils':
## 
##     tar
data(PGN)
## Warning in data(PGN): data set 'PGN' not found
autoplot(PGN)+ggtitle("PRODUCCION DE GAS")

plot(PGN,type = 'l')
points(y=PGN, x=time(PGN),pch=as.vector(season(PGN)))

ggseasonplot(PGN)

  1. Interpretar los coeficientes estimados, significancia estadística y R cuadrada.
mes. <- season(PGN)
modelo1 <- lm(PGN ~ mes. + time(PGN) + I(time(PGN)^2))
summary(modelo1)
## 
## Call:
## lm(formula = PGN ~ mes. + time(PGN) + I(time(PGN)^2))
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -24461  -7989   1500   7214  23430 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    -5.913e+09  3.120e+08 -18.954  < 2e-16 ***
## mes.February   -1.714e+04  4.041e+03  -4.241 4.18e-05 ***
## mes.March       6.488e+01  4.040e+03   0.016   0.9872    
## mes.April      -6.786e+03  4.040e+03  -1.680   0.0954 .  
## mes.May        -9.157e+02  4.040e+03  -0.227   0.8211    
## mes.June       -5.544e+03  4.040e+03  -1.372   0.1723    
## mes.July        6.000e+02  4.040e+03   0.149   0.8822    
## mes.August      9.246e+02  4.040e+03   0.229   0.8193    
## mes.September  -8.038e+03  4.040e+03  -1.990   0.0487 *  
## mes.October     8.843e+01  4.040e+03   0.022   0.9826    
## mes.November   -5.945e+03  4.040e+03  -1.471   0.1436    
## mes.December    1.186e+03  4.041e+03   0.294   0.7696    
## time(PGN)       5.880e+06  3.101e+05  18.960  < 2e-16 ***
## I(time(PGN)^2) -1.462e+03  7.707e+01 -18.965  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 10080 on 131 degrees of freedom
## Multiple R-squared:   0.77,  Adjusted R-squared:  0.7472 
## F-statistic: 33.74 on 13 and 131 DF,  p-value: < 2.2e-16

Con una R-Squared= 0.77 Nos indica que mayor es el ajuste del modelo con respecto a la variable PGN.

Con una variable p-value: < 2.2e-16. Rechazamos la Ho.

  1. Presentar y analizar grafico de los residuos: grafica en el tiempo, grafico cuantil-cuantil, histograma y función de autocorrelación (correlograma).
plot(y=rstandard(modelo1), x=time(PGN), type='o')

qqnorm(rstandard(modelo1)); qqline(rstandard(modelo1)) 

shapiro.test(rstandard(modelo1))
## 
##  Shapiro-Wilk normality test
## 
## data:  rstandard(modelo1)
## W = 0.9845, p-value = 0.1023
ggAcf(rstandard(modelo1))

  1. Escribir la ecuación del modelo de regresión final y las conclusiones del análisis.

\[ PGN = \beta_0 + \beta_1 tiempo + \beta_2 tiempo^2 + meses + u \]