Diff: Differencing Transformation

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/diff.r

Description

The Diff() function returns a simple or seasonal differencing transformation of the provided time series. Diff.rev() reverses the transformation. Wrapper functions for diff and diffinv of the stats package, respectively.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Diff(
  x,
  lag = ifelse(type == "simple", 1, stats::frequency(x)),
  differences = NULL,
  type = c("simple", "seasonal"),
  ...
)

Diff.rev(
  x,
  lag = ifelse(type == "simple", 1, stats::frequency(x)),
  differences = 1,
  xi,
  type = c("simple", "seasonal"),
  addinit = TRUE
)

Arguments

x

A numeric vector or univariate time series containing the values to be differenced.

lag

Integer indicating the lag parameter. Default set to 1 if type = "simple", or frequency(x) if type = "seasonal".

differences

Integer representing the order of the difference. If NULL, the order of the difference is automatically selected using ndiffs (if type = "simple") or nsdiffs (if type = "seasonal") from the forecast package.

type

Character string. Indicates if the function should perform simple or seasonal differencing.

...

Additional arguments passed to ndiffs (if type = "simple") or nsdiffs (if type = "seasonal") from the forecast package.

xi

Numeric vector or time series containing the initial values for the integrals. If missing, zeros are used.

addinit

If FALSE, the reverse transformed time series does not contain xi. Default set to TRUE.

Value

x if differences is automatically selected, and is not set as greater than 0. Same as diff otherwise.

Author(s)

Rebecca Pontes Salles

References

R.J. Hyndman and G. Athanasopoulos, 2013, Forecasting: principles and practice. OTexts.

R.H. Shumway and D.S. Stoffer, 2010, Time Series Analysis and Its Applications: With R Examples. 3rd ed. 2011 edition ed. New York, Springer.

See Also

Other transformation methods: LogT(), WaveletT(), emd(), mas(), mlm_io(), outliers_bp(), pct(), train_test_subset()

Examples

1
2
3
4
data(CATS)
d <- Diff(CATS[,1], differences = 1)
x <- Diff.rev(as.vector(d), differences = attributes(d)$differences, xi = attributes(d)$xi)
all(round(x,4)==round(CATS[,1],4))

RebeccaSalles/TSPred documentation built on April 6, 2021, 2:44 a.m.