I am using tsCV function from Forecast package, I want to have log(y) as the dependent variable and then forecast y rather than forecasting log(y). I tried to obtain the forecast errors from tsCV and then exponentiate them as:
far2_xreg <- function(x, h, xreg, newxreg) { forecast(Arima(x, order=c(0,0,0), xreg=xreg), xreg=newxreg) }
# generating forecast errors
e1 <- mytsCV(log(data$y), far2_xreg, h=7, window = 1000, xreg_actual=xreg_actual, xreg_forecast=xreg_forecast)
data$e1 <- e1
data$e1<−shift(data$e1, n=1L, fill=NA, type=c("lag"), give.names=FALSE)
# exponentiating the forecast erros
data$e<− exp(data$e1)
mape <- mean(abs((data$e)/data$y), na.rm = TRUE)*100
But I know in this form, It is forecasting the log(y) and then it obtaines the errors, and I transform those errors to the original data. However, it seems it is not the correct approach. Can someone guide me about it please, is this possible within this function to use log(y) to forecast y? Thank you very much.
tsCV
. You can't do this in general becauseforecast::tsCV
requires you to return aforecast
object rather than ats
or bare vector. Luckily, withforecast::Arima
you can simply setlambda=0
. Otherwise you can do it the way you're suggesting but you have to actually backtransform correctly (i.e. use the transformed actuals and the errors to get back the forecasts in logs, exponentiate and compute the untransformed errors). $\endgroup$