Search code examples
rmeanarimaforecast

R Arima forecast mean back-transformation


I'm estimating a log-linear Arima model and I'd like to back-transform the fitted values using the exact method from https://www.r-bloggers.com/forecasting-from-log-linear-regressions/. I calculate the residual standard error four ways and I get four different answers. Could someone please explain which of these is the correct one I should be using?

library(forecast)

model <- Arima(log(AirPassengers), order = c(0, 1, 3), include.constant = TRUE, lambda = NULL)

resids <- residuals(model)

sqrt(mean(resids^2))

sqrt(var(resids))

sum(resids^2) / (length(resids) - 4)

model$sigma2

Solution

  • What you want to calculate is the residual standard error (RSE) i think. So, you have to calculate the sum of squared residuals (RSS) and divde it by "n-m", where "n" is the numbers of the residuals and "m" is the number of estimated parameters. model$sigma2 gives you the right answer. You just mistakenly used a "4" instead of a "5" when you calculated the RSE on your own in sum(resids^2) / (length(resids) - 4). If you divide the RSS by (length(resids)-5) you get the same result as in model$sigma2. You estimated 3 MA parameters, 1 constant and 1 parameter for the drift, which is 5 all over.

    This is the solution sum(resids^2) / (length(resids) - 5).

    With sqrt(mean(resids^2)) you just calculate the square root of the mean of the squared residuals which is obviously close to the RSE, but used the wrong standardisation cause it is the same as sqrt(sum(resids^2) / (length(resids))).

    With sqrt(var(resids)) you calculate the standard deviation (sd(resids)) of the residuals as sqrt(sum((resids-mean(resids))^2)/(length(resids)-1)). This it the standard deviation of the residuals but not the residual standard error from the model. Note here that R uses the empirical variance by dividing through "...-1" and not the theoritical one with out "...-1".

    If you need further explanations have a look into "An introduction to statistical learning" around page 66 in the file which is 75 in the pdf.