detrend function

Remove Polynomial Trend

Remove Polynomial Trend

detrend removes the polynomial trend of order p from the data x.

detrend(x, p = 1)

Arguments

  • x: Input vector or matrix. If x is a matrix, the trend is removed from the columns.

  • p: Order of the polynomial. Default: 1. The order of the polynomial can also be given as a string, in which case p must be either "constant" (corresponds to p = 0) or "linear"

    (corresponds to p = 1).

Returns

The detrended data, of same type and dimensions as x

Examples

t <- 0:20 x <- 3 * sin(t) + t y <- detrend(x) plot(t, x, type = "l", ylim = c(-5, 25), xlab = "", ylab = "") lines(t, y, col = "red") lines(t, x - y, lty = 2) legend('topleft', legend = c('Input Data', 'Detrended Data', 'Trend'), col = c(1, 2 ,1), lty = c(1, 1, 2))

Author(s)

Kurt Hornik, Kurt.Hornik@wu-wien.ac.at .

Conversion to R by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com .

  • Maintainer: Geert van Boxtel
  • License: GPL-3
  • Last published: 2024-09-11