@BeginModule
@Name      = Detrend
@Title     = Detrend time series
@Section   = Regression
@Class     = Regression
@Arguments = ifile ofile
@Operators = detrend
@EndModule


@BeginOperator_detrend
@Title     = Detrend

@BeginDescription
@IfMan
Every time series in @file{ifile} is linearly detrended. For every field element x 
only those time steps t belong to the sample S(x), which have i(t,x) NE miss.
@EndifMan
@IfDoc
Every time series in @file{ifile} is linearly detrended.
For every field element \begin{math}x\end{math} only those time steps \begin{math}t\end{math} belong to the sample
\begin{math}S(x)\end{math}, which have \begin{math}i(t,x) \neq \mbox{miss}\end{math}.
With
@BeginDisplayMath
a(x) = \frac{1}{\#S(x)} \sum\limits_{t \in S(x)}i(t,x) - b(x)\left(\frac{1}{\#S(x)} \sum\limits_{t \in S(x)}t\right)
@EndDisplayMath
and
@BeginDisplayMath
b(x) = \frac{\sum\limits_{t \in S(x)}\left(i(t,x) - \frac{1}{\#S(x)} \sum\limits_{t' \in S(x)}i(t',x)\right)
                                     \left(t - \frac{1}{\#S(x)} \sum\limits_{t' \in S(x)}t'\right)}
            {\sum\limits_{t \in S(x)}\left(t - \frac{1}{\#S(x)} \sum\limits_{t' \in S(x)}t'\right)^{2}}
@EndDisplayMath
it is
@BeginDisplayMath
o(t,x) = i(t,x) - (a(x) + b(x)t)
@EndDisplayMath
@EndifDoc
@EndDescription
@EndOperator


@BeginNote
This operator has to keep the fields of all time steps concurrently in the memory.
If not enough memory is available use the operators @mod{trend} and @mod{subtrend}.
@EndNote


@BeginExample
To detrend the data in @file{ifile} and to store the detrended data in @file{ofile} use:
@BeginVerbatim
  cdo detrend ifile ofile
@EndVerbatim
@EndExample
