On Sat, Jul 31, 2010 at 1:44 AM, pdb <ph...@philbrierley.com> wrote: > > Thanks for the response. > > I can figure out the 'lag' parameter to the function, but I dont understand > the 'differences' parameter. > > differences - an integer indicating the order of the difference > > What does the 'order of the difference' mean in English? > > How are these numbers calculated? > >> x <- iris >> x$Species = NULL >> x$Petal.Width = NULL >> x$Sepal.Width = NULL >> x$Sepal.Length = NULL >> >> x <- zoo(x) >> >> x <- > + merge(orig = x > + ,l1d1 = diff(x, lag = 1, differences = 1, arithmetic = TRUE, na.pad = > TRUE) > + ,l1d2 = diff(x, lag = 1, differences = 2, arithmetic = TRUE, na.pad = > TRUE) > + ,l2d1 = diff(x, lag = 2, differences = 1, arithmetic = TRUE, na.pad = > TRUE) > + ,l2d2 = diff(x, lag = 2, differences = 2, arithmetic = TRUE, na.pad = > TRUE) > + ) >> >> x > Petal.Length.orig Petal.Length.l1d1 Petal.Length.l1d2 Petal.Length.l2d1 > Petal.Length.l2d2 > 1 1.4 NA NA NA > NA > 2 1.4 0.0 NA NA > NA > 3 1.3 -0.1 -1.000000e-01 -0.1 > NA > 4 1.5 0.2 3.000000e-01 0.1 > NA > 5 1.4 -0.1 -3.000000e-01 0.1 > 2.000000e-01 > 6 1.7 0.3 4.000000e-01 0.2 > 1.000000e-01 > 7 1.4 -0.3 -6.000000e-01 0.0 > -1.000000e-01 > 8 1.5 0.1 4.000000e-01 -0.2 > -4.000000e-01 > 9 1.4 -0.1 -2.000000e-01 0.0 > 0.000000e+00 > 10 1.5 0.1 2.000000e-01 0.0 > 2.000000e-01 > 11 1.5 0.0 -1.000000e-01 0.1 > 1.000000e-01 > 12 1.6 0.1 1.000000e-01 0.1 > 1.000000e-01 > -- > View this message in context: > http://r.789695.n4.nabble.com/Lags-and-Differences-of-zoo-Objects-tp2308666p2308681.html > Sent from the R help mailing list archive at Nabble.com. >
A kth order difference is analogous to a kth derivative and will annihilate and (k-1)-degree polynomial. It is just repeatedly applies diff. z2 <- zoo((1:5)^2) diff(z2) # linear diff(z2, diff = 2) # constant diff(z2, diff = 3) # all zeros # compare diff(z2, diff = 2) diff(diff(z2)) ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.