autoplot(aus_production, Gas) +labs(title ="Serie Original de Producción de Gas", y ="Producción")
library(urca) # Para pruebas de raíz unitaria# Convertimos la serie en un objeto tsgas_ts <-ts(aus_production$Gas, start =c(1956,1), frequency =4)# Aplicamos la prueba ADFadf_test <-ur.df(gas_ts, type ="drift", selectlags ="AIC")summary(adf_test)
###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################
Test regression drift
Call:
lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
Residuals:
Min 1Q Median 3Q Max
-44.678 -8.479 -2.883 12.636 54.097
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.084027 2.234202 1.828 0.0690 .
z.lag.1 -0.030465 0.018068 -1.686 0.0932 .
z.diff.lag -0.003119 0.069049 -0.045 0.9640
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 19.82 on 213 degrees of freedom
Multiple R-squared: 0.01352, Adjusted R-squared: 0.004255
F-statistic: 1.459 on 2 and 213 DF, p-value: 0.2347
Value of test-statistic is: -1.6861 1.7429
Critical values for test statistics:
1pct 5pct 10pct
tau2 -3.46 -2.88 -2.57
phi1 6.52 4.63 3.81
# Primera diferenciacióndiff_gas <-diff(gas_ts, differences =1)# Convertir diff_gas a un tsibblediff_gas_tsibble <-as_tsibble(diff_gas)# Graficar utilizando autoplotautoplot(diff_gas_tsibble) +labs(title ="Serie Diferenciada (1ra diferencia)", y ="Diferenciada")
Plot variable not specified, automatically selected `.vars = value`
library(forecast)
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
ggAcf(diff_gas) +labs(title ="ACF de la Serie Diferenciada")
ggPacf(diff_gas) +labs(title ="PACF de la Serie Diferenciada")
fit <-arima(gas_ts, order =c(2, 1, 2), method="ML")
Warning in arima(gas_ts, order = c(2, 1, 2), method = "ML"): possible
convergence problem: optim gave code = 1
summary(fit)
Call:
arima(x = gas_ts, order = c(2, 1, 2), method = "ML")
Coefficients:
ar1 ar2 ma1 ma2
-0.0164 -1 -0.1521 -0.0295
s.e. 0.0242 0 0.0463 0.0749
sigma^2 estimated as 42.46: log likelihood = -715.64, aic = 1441.27
Training set error measures:
ME RMSE MAE MPE MAPE MASE ACF1
Training set 2.459104 6.500893 4.556671 3.654972 5.855452 0.313208 -0.2681604