detrend: Remove Polynomial Trend

View source: R/detrend.R

detrendR Documentation

Remove Polynomial Trend

Description

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

Usage

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).

Value

The detrended data, of same type and dimensions as x

Author(s)

Kurt Hornik, Kurt.Hornik@wu-wien.ac.at.
Conversion to R by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

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))


gjmvanboxtel/gsignal documentation built on Nov. 22, 2023, 8:19 p.m.