DETREND

Purpose:

Removes a linear trend line or mean value from a series.

Syntax:

DETREND(series, "opt", bp)

series

-

An input series.

"opt"

-

Optional. A string, the trend type.

 

 

"linear"

:

remove a linear trend (default)

"constant"

:

remove the mean

bp

-

Optional. A series, a list of breakpoint indices that determine the locations of a piecewise continuous linear trend. Defaults to a single regression line computed over the entire series.

Returns:

A series, the detrended output.

Example:

W1: gnorm(10, 1)

W2: W1 + 100

W3: detrend(w2, "constant")

W4: demean(w2)

 

W2 contains a 10 point random series with a mean of 10. Both W3 and W4 remove the mean value to recover the original series in W1.

Example:

W1: gcos(1000, 1/1000, 10)

W2: 10 * gtri(length(w1), deltax(w1), 1)

W3: W1 + W2

W4: detrend(w3, maxidx(w2))

 

W3 contains a 1000 point cosine with a triangular linear  trend.  W4 removes the trend and recovers W1 by setting a  breakpoint at the index of the apex of the triangle wave.  

Remarks:

If breakpoints are specified, each point represents the index shared by adjacent line segments. A piecewise continuous regression line is computed for each segment.

 

If no breakpoints are specified, a trend line computed over the entire input series is removed. This is equivalent to:

 

series - linreg(series)

 

See TREND to fit a linear trend to a series.

See Also:

DEMEAN

FFT

LINFIT

LINREG

POLYFIT

TREND