0
$\begingroup$

I am working with time series, which is not stationary. I apply the differencing and log transformation to make my data stationary. I forecast one year ahead forecast and check the accuracy of the model by retransforming it into its original form, but fail to obtain the required result. I can explain my question with the help of a simple example:

    data <- c(10.45,45.6,33.67,32.12,76.34,12.3,23.5,13.76,35.78,98.45,77.88)
    ac <- diff(log(data))
    ad <- 10.45 + diffinv(exp(ac))

so ad= c(10.45000 ,14.81364, 15.55201, 16.50598, 18.88269, 19.04381, 20.95438, 21.53991, 24.14020,26.89174, 27.68280)
$\endgroup$
0

1 Answer 1

5
$\begingroup$

You need to undo the log and the diff in the correct order. Also diffing is done on the log scale so adding 10.45 must be done on the log scale:

data <- c(10.45,45.6,33.67,32.12,76.34,12.3,23.5,13.76,35.78,98.45,77.88)
ac <- diff(log(data))
ad <- exp(diffinv(ac, xi=log(10.45)))
print(ad)

This yields ad == data.

Alternatively

data <- c(10.45,45.6,33.67,32.12,76.34,12.3,23.5,13.76,35.78,98.45,77.88)
ac <- diff(log(data))
ad <- exp(log(10.45) + diffinv(ac))
print(ad)
$\endgroup$
2
  • $\begingroup$ thanks a lot Bernhard its really works $\endgroup$
    – faheem jan
    Commented Oct 10, 2020 at 11:29
  • $\begingroup$ In that case you may consider accepting the answer as in stackoverflow.com/help/someone-answers $\endgroup$
    – Bernhard
    Commented Oct 10, 2020 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.