In: Computer Science
Please assist with how I can solve this in R
For the usgdp series:
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
# a. if necessary, find a suitable Box-Cox transformation for the data;
autoplot(usgdp)
autoplot(BoxCox(usgdp, BoxCox.lambda(usgdp)))
# When I transformed the original data, I could get more linearly
increasing line. Therefore I'm going to do Box-Cox
transformation.
lambda_usgdp <- BoxCox.lambda(usgdp)
# b.fit a suitable ARIMA model to the transformed data
using auto.arima();
usgdp_autoarima <- auto.arima(usgdp,
lambda = lambda_usgdp)
autoplot(usgdp, series = "Data") +
autolayer(usgdp_autoarima$fitted, series = "Fitted")
# It looked like the model fits well to the data.
usgdp_autoarima
#ARIMA(2, 1, 0) with drift model after Box-Cox transformation.
# c. try some other plausible models by experimenting with
the orders chosen;
ndiffs(BoxCox(usgdp, lambda_usgdp))
# the data need 1 first differencing to be stationary.
ggtsdisplay(diff(BoxCox(usgdp, lambda_usgdp)))
# ACF plot shows sinusoidal decrease while PACF plot shows
significant spikes at lag 1 and 12. I think that I can ignore the
spike at lag 12 because the data are aggregated quarterly, not
monthly. Therefore, I'll experiment with ARIMA(1, 1, 0)
model.
usgdp_arima.1.1.0 <- Arima(
usgdp, lambda = lambda_usgdp, order = c(1, 1, 0)
)
usgdp_arima.1.1.0
autoplot(usgdp, series = "Data") +
autolayer(usgdp_arima.1.1.0$fitted, series = "Fitted")
# I'll also try ARIMA(1, 1, 0) with drift model.
usgdp_arima.1.1.0.drift <- Arima(
usgdp, lambda = lambda_usgdp, order = c(1, 1, 0),
include.drift = TRUE
)
usgdp_arima.1.1.0.drift
autoplot(usgdp, series = "Data") +
autolayer(usgdp_arima.1.1.0.drift$fitted, series = "Fitted")
# It looked like that these models also fit well to the data.
# d. choose what you think is the best model and check the
residual diagnostics;
accuracy(usgdp_autoarima)
accuracy(usgdp_arima.1.1.0)
accuracy(usgdp_arima.1.1.0.drift)
# Some errors show that ARIMA(2, 1, 0) with drift is the best model
while others show that ARIMA(1, 1, 0) with drift is the best. Check
the residuals of both cases.
checkresiduals(usgdp_autoarima)
checkresiduals(usgdp_arima.1.1.0.drift)
# In either case, the residuals are like white noise series and are
not normally distributed.
# I'll choose the best model as ARIMA(2, 1, 0) with drift model.
With the model, RMSE and MASE values were lower. And there wasn't
significant spike at lag 2 in ACF plot of ARIMA(2, 1, 0) with drift
model, even if it exists in ARIMA(1, 1, 0) with drift model.
# e. produce forecasts of your fitted model. Do the
forecasts look reasonable?
fc_usgdp_autoarima <- forecast(
usgdp_autoarima
)
autoplot(fc_usgdp_autoarima)
# It looked like the forecasts are reasonable.
# f. compare the results with what you would obtain using
ets() (with no transformation).
fc_usgdp_ets <- forecast(
ets(usgdp)
)
autoplot(fc_usgdp_ets)
# It looked like these forecasts are more likely than the ones with
ARIMA model. When trend is obvious, is ETS better than ARIMA model?
I wonder about it.
```
Kindly revert for any queries
Thanks.