R/detrend.R

Defines functions detrend

Documented in detrend

detrend <-
function(series, order=1, lowess=FALSE, lowspan=2/3){
  if (NCOL(series) > 1) stop("univariate time series only")
    if (lowess) { 
      u = stats::lowess(series, f=lowspan)
      return(series-u$y)  
    } else {
      y = as.vector(time(series))
      u = stats::lm(series~ poly(y, order), na.action=NULL)
      return(resid(u))
    }
 }

Try the astsa package in your browser

Any scripts or data that you put into this service are public.

astsa documentation built on Jan. 10, 2023, 1:11 a.m.