EJERCICIO 1. INTRODUCCION

CARACTERISTICAS SERIE:

  1. PERIODICIDAD: Trimestral
  2. Unidad de medida: Indice base 2008=100
  3. FUENTE: INEGI. Encuesta mensual de la industria manufacturera
library(forecast)
library(ggplot2)
library(readxl)
base<-read_xls("C:/Users/rodar/OneDrive/Documents/MANUFACTURA.xls")
PM <-ts(base$PM, frequency = 3, start=c(2005,1))
autoplot(PM)

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

fit<-decompose(PM)
plot(fit)

PODEMOS OBSERVAR QUE LA GRAFICA MUESTRA ALEATORIEDAD.

ggseasonplot(PM)

EN ESTE CASO NOS DAMOS CUENTA QUE LA SERIE NO PRESENTA ESTACIONALIDAD, DEBIDO A QUE LA INDUSTRIA MANUFACTURERA NO DEPENDE DE CIERTOS FACTORES ESTACIONALES.

EJERCICIO 2. DESCOMPOSICION DE SERIES.

  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(PM,series= "Data")+autolayer(ma(PM,3),series="3-MA")+xlab("Year")+ggtitle("PRODUCCION MANUFACTURERA")
## Warning: Removed 2 rows containing missing values (geom_path).

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

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

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

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

fit<-decompose(PM,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(PM,series="Data")+autolayer(seasadj(fit),series="Seasonally adj. data")+xlab("Year")+ylab("New orders index")+ggtitle("Produccion manufacturera")

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.
  2. Interpretar los coeficientes estimados, significancia estadística y R cuadrada.
  3. Presentar y analizar grafico de los residuos: grafica en el tiempo, grafico cuantil-cuantil, histograma y función de autocorrelación (correlograma).
  4. Evaluar la normalidad de los residuos ocupando la prueba Shapiro-Wilk.
  5. Escribir la ecuación del modelo de regresión final y las conclusiones del análisis.
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(PM)
## Warning in data(PM): data set 'PM' not found
autoplot(PM)+ggtitle("PRODUCCION MANUFACTURERA")

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

ggseasonplot(PM)

mes. <- season(PM)
modelo1 <- lm(PM ~ mes. + time(PM) + I(time(PM)^2))
summary(modelo1)
## 
## Call:
## lm(formula = PM ~ mes. + time(PM) + I(time(PM)^2))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -10.9588  -0.9377   0.4520   1.3045   4.0477 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)   
## (Intercept)   -2.169e+05  6.374e+04  -3.403  0.00133 **
## mes.Season-2  -3.832e-02  9.292e-01  -0.041  0.96727   
## mes.Season-3  -4.370e-01  9.301e-01  -0.470  0.64053   
## time(PM)       2.148e+02  6.330e+01   3.394  0.00137 **
## I(time(PM)^2) -5.316e-02  1.572e-02  -3.382  0.00142 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.787 on 49 degrees of freedom
## Multiple R-squared:  0.6857, Adjusted R-squared:   0.66 
## F-statistic: 26.72 on 4 and 49 DF,  p-value: 8.627e-12

b). Con una R-Squared= 0.6857. Nos indica que mayor es el ajuste del modelo con respecto a la variable PM.

Con una variable p-value: 8.627e-12. Rechazamos la Ho.

plot(y=rstandard(modelo1), x=time(PM), type='o')

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

shapiro.test(rstandard(modelo1))
## 
##  Shapiro-Wilk normality test
## 
## data:  rstandard(modelo1)
## W = 0.88199, p-value = 7.186e-05
ggAcf(rstandard(modelo1))

\[ PRODUCCION MANUFACTURERA= PM= \beta_0 + \beta_1 tiempo + \beta_2 tiempo^2 + meses + u \]