Trying to figure out how to inverse-difference correctly if using 2 differences.
I can difference twice with the option differences = 2
and everything works:
diff(c(3,6,23,64,77)) = 3 17 41 13
diff(c(3, 17, 41, 13)) = 14 24 -28
diff(c(3,6,23,64,77), lag = 1, differences = 2) = 14 24 -28
When I use diffinv
twice, using 3
as the init conditions (since the first element of the first difference is 3
, the answer is the correct, it is the starting vector:
diffinv(
diffinv(
diff(c(3,6,23,64,77), lag = 1, differences = 2),
xi = 3),
xi=3) = 3 6 23 64 77
But if I try to do two inverse differences, I get the incorrect answer:
diffinv(
diff(c(3, 6, 23, 64, 77), lag = 1, differences = 2),
lag = 1, differences = 2, xi = c(3, 3)
) = 3 3 17 55 65
What am I doing wrong when trying to use difinv
with differences = 2
?