detrend {oce}R Documentation

Detrend a set of observations

Description

Detrend a set of observations, which can be useful in operations that are thrown off by endpoints, e.g. digital filtering.

Usage

detrend(x, y)

Arguments

x

a vector of numerical values. If y is not given, then x is taken for y.

y

an optional vector

Details

Detrends y by subtracting a linear trend in x, to create Y that has Y[1]=0 and Y[length(Y)]=0. If y is not given, then y is taken from x, and x is set to the series of integers from 1 to length{x}.

Value

A list containing Y, the detrended version of y, and the intercept a and slope b of the linear function of x that is subtracted from y to yield Y.

Author(s)

Dan Kelley

Examples

x <- seq(0, 0.9 * pi, length.out=50)
y <- sin(x)
plot(x, y)
d <- detrend(x, y)
points(x, d$Y, pch=20)
abline(h=0, lty='dotted')
abline(d$a, d$b, col='red')
points(x, d$Y + d$a + d$b * x, col='blue', pch='+')

[Package oce version 0.9-18 Index]