Lectura de Paquetes

library("foreign")
library("ggfortify")
## Loading required package: ggplot2
library("ggplot2")

Lectura de Datos

ventas<-read.dta("Datos/Ventas Semanales de Disco de Video Digital.dta")
head(ventas)
##   t    y
## 1 1 45.9
## 2 2 45.4
## 3 3 42.8
## 4 4 34.4
## 5 5 31.9
## 6 6 36.6

Definimos la serie como serie de tiempo

ventas_ts <- ts(ventas[,2])

Evaluación de la Estacionariedad

Gráfico de la Serie

plot.ts(ventas_ts, xlab="Tiempo",ylab="Ventas")

autoplot(ventas_ts)

autoplot(ventas_ts, ts.colour = 'red', 
         ts.linetype = 'dashed')

Función de autocorralación Simple

autoplot(acf(ventas_ts, plot = FALSE))

Función de autocorralación Parcial

autoplot(pacf(ventas_ts, plot = FALSE))

Prueba de Dickey - Fuller

library(CADFtest)
## Loading required package: dynlm
## Warning: package 'dynlm' was built under R version 3.5.2
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: tseries
## Loading required package: urca
CADFtest(ventas_ts, max.lag.y=0, type="none")
## 
##  ADF test
## 
## data:  ventas_ts
## ADF(0) = 0.77644, p-value = 0.8801
## alternative hypothesis: true delta is less than 0
## sample estimates:
##       delta 
## 0.002839715

Evaluación de la Primera Diferencia

Visualización Gráfica

autoplot(diff(ventas_ts))

autoplot(acf(diff(ventas_ts)))

autoplot(pacf(diff(ventas_ts)))

Estimación de Modelo

Modelo AR(2)

arima1<-arima(ventas_ts,c(2,1,0))
arima1
## 
## Call:
## arima(x = ventas_ts, order = c(2, 1, 0))
## 
## Coefficients:
##          ar1      ar2
##       0.5425  -0.2393
## s.e.  0.0766   0.0775
## 
## sigma^2 estimated as 6.058:  log likelihood = -371.3,  aic = 748.6
library("lmtest")
coeftest(arima1)
## 
## z test of coefficients:
## 
##      Estimate Std. Error z value  Pr(>|z|)    
## ar1  0.542516   0.076603  7.0822 1.419e-12 ***
## ar2 -0.239316   0.077529 -3.0868  0.002023 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

\[ Z_t = 0.5425Z_{t-1}-0.2393Z_{t-2}\]

Modelo MA(1)

arima2<-arima(ventas_ts,c(0,1,1))
arima2
## 
## Call:
## arima(x = ventas_ts, order = c(0, 1, 1))
## 
## Coefficients:
##          ma1
##       0.5811
## s.e.  0.0665
## 
## sigma^2 estimated as 5.915:  log likelihood = -369.43,  aic = 742.86
coeftest(arima2)
## 
## z test of coefficients:
## 
##     Estimate Std. Error z value  Pr(>|z|)    
## ma1 0.581116   0.066476  8.7417 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

\[ Z_t = 0.5811e_{t-1}\]

Modelo ARMA(2,1)

arima3<-arima(ventas_ts,c(2,1,1))
arima3
## 
## Call:
## arima(x = ventas_ts, order = c(2, 1, 1))
## 
## Coefficients:
##          ar1      ar2     ma1
##       0.0656  -0.0310  0.5213
## s.e.  0.2907   0.1779  0.2837
## 
## sigma^2 estimated as 5.913:  log likelihood = -369.41,  aic = 746.81
coeftest(arima3)
## 
## z test of coefficients:
## 
##      Estimate Std. Error z value Pr(>|z|)  
## ar1  0.065607   0.290684  0.2257  0.82144  
## ar2 -0.030968   0.177934 -0.1740  0.86183  
## ma1  0.521325   0.283692  1.8376  0.06611 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

\[ Z_t = 0.0656Z_{t-1}-0.0310_{t-2}+0.5213e_{t-1}\]

Validación del Modelo MA(1)

Gráfica de Residuales

ggtsdiag(arima2)

shapiro.test(arima2$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  arima2$residuals
## W = 0.99056, p-value = 0.3629