Learn R Programming

TED (version 1.1.1)

detrendc: Conditionally detrend a time series

Description

This function detrends a time series when its linear trend is more significant than a threshold.

Usage

detrendc(x, thres = 0.85)

Arguments

x
a vector or time series.
thres
a scalar specifying the threshold. When the adjusted R square coefficient of the linear fitting is larger than this threshold, the linear trend is substracted from the original time series. Default is 0.85.

Value

detrended x.

Examples

Run this code
t=seq(0.001,1,0.001)
set.seed(123)
x=10*t+rnorm(1000)
dtrx=detrendc(x)
# plot the simulated x
plot(t,x,ty='l',xlab='t',ylab='x')
# plot the detrended x
lines(t,dtrx,col=2)
legend(0,12,legend=c('x','detrended x'),col=c(1,2),lty=1)

Run the code above in your browser using DataLab