detrend {oce} | R Documentation |
Detrend a set of observations, which can be useful in operations that are thrown off by endpoints, e.g. digital filtering.
detrend(x, y)
x |
a vector of numerical values. If |
y |
an optional vector |
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}
.
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
.
Dan Kelley
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='+')