[R] function to undo the DIFF command in ARIMA command

(Ted Harding) ted.harding at wlandres.net
Tue Jun 21 09:15:07 CEST 2011


On 21-Jun-11 04:21:08, Flávio Fagundes wrote:
> Hi users.
> I'm new user in R.
> I'm workiing with Time series and I would like to know how
> can I do to undo the command DIFF(X), for exemple:
> If I have the model: m=arima(X, order=c(0,1,1),
> seasonal=list(order=c(0,0,1)))
> (note that have d=1 one difference), to find,in the same scale,
> the original numbers (like one "unDiff"), after the forecast,
> I need to develop some function or in R there is some command
> ready or function?
> Thanks
> Flávio

Consider the sequence X = x1, x2, x3, x4
diff(X) = (x2-x1), (x3-x2), (x4-x3)

cumsum(diff(X)) = (x2-x1), (x3-x1), (x4-x1)

c(x1, x1 + cumsum(diff(X)) ) = x1, x2, x3, x4

So, provided you have a value for the first point x1, you can
"undiff" using cumsum() as shown.

If you do not have a value for x1, then you can only get as
far as cumsum(diff(X)) which is a sequence shorter by 1 and
indeterminate to within an additive constant. (Or you could
extend it be prepending "0" as in c(0,cumsum(diff(X))) but
you still have the undetermined additive constant).

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 21-Jun-11                                       Time: 08:15:03
------------------------------ XFMail ------------------------------



More information about the R-help mailing list