Statistics
Detrend
remove any trend from a set of data
Calling Sequence
Parameters
Options
Description
Notes
Examples
Compatibility
Detrend( XY, options )
Detrend( Y, options )
Detrend( X, Y, options )
XY
-
data set, DataFrame; Matrix or DataFrame of values with 2 columns
X, Y
data set, DataSeries; numeric list of values
options
(optional) equation(s) of the form option=value where option can be mode
mode : one of the names mean or linear; specifies the method used to detrend the data. The mode mean removes the mean value of the data from the data. The mode linear removes the line of best-fit from the data. The default is linear.
The Detrend command is used to remove any trend from a set of data. The Detrend command returns a Vector containing the detrended values.
If the argument XY is a 2-column rtable or DataFrame, the first column is used as the independent variables and the Detrend command is applied to the dependent values in the second column. Note that values in the first column do not need to be equally spaced.
If the argument Y is a 1-column rtable or DataSeries and there is no specified value for X, the Detrend command uses the index positions for each value in Y as the independent values and the Detrend command is applied to the dependent values in Y.
If the argument X and argument Y are 1-column rtables or DataSeries, the values in X are treated as the independent variables and the Detrend command is applied to the dependent values in Y.
To print the model used by the Detrend command, set infolevel[Statistics] to 1.
with⁡Statistics:
Specify some data:
data≔Matrix⁡0,1.8,1,0.7,2.5,2.8,4,4.2,6.2,3
data≔
Fit a linear model to the data:
lm≔LinearFit⁡a+b⁢x,data,x
lm≔1.49598376946009+0.366429281218947⁢x
It can be observed that from the plot of the data and the linear model that there is some upward trend.
plots:-display⁡ScatterPlot⁡data,symbol=solidcircle,symbolsize=15,color=Black,legend=Original Data,plot⁡lm,color=Black,legend=Trend,linestyle=dash,view=min⁡data..,1−0.1..max⁡data..,1+0.1,min⁡data..,2−0.1..max⁡data..,2+0.1
The Detrend command removes any trend from the data.
detrend_data≔Detrend⁡data
detrend_data≔
This can be observed in the following plot:
plots:-display⁡ScatterPlot⁡data,color=Black,legend=Original Data,symbol=solidcircle,symbolsize=15,plot⁡lm,color=Black,legend=Trend,linestyle=dash,ScatterPlot⁡data..,1,detrend_data,color=Red,legend=Detrended Data,symbol=diamond,symbolsize=15,plot⁡Mean⁡detrend_data,color=Red,legend=Mean of Detrended Data,linestyle=dot,view=min⁡data..,1−0.1..max⁡data..,1+0.1,default
Generate a random signal with an added trend.
with⁡SignalProcessing:
signal_data≔GenerateGaussian⁡100,0.5,0.3+seq⁡i,i=0.01..1,0.01
signal_data≔
Plot the signal and the trend line.
plots:-display⁡SignalPlot⁡signal_data,legend=Data,plot⁡LinearFit⁡a+b⁢x,seq⁡1..100,signal_data,x,x=1..100,color=Black,legend=Trend,linestyle=dash
Plot the signal, the detrended signal, the trend line and the mean of the detrended data.
plots:-display⁡SignalPlot⁡signal_data,legend=Original Data,plot⁡LinearFit⁡a+b⁢x,seq⁡1..100,signal_data,x,x=1..100,color=Black,legend=Trend,linestyle=dash,SignalPlot⁡signal_data,detrend,color=Red,legend=Detrended Data,plot⁡Mean⁡Detrend⁡signal_data,x=1..100,color=Red,legend=Mean of Detrended Data,linestyle=dot
The Statistics[Detrend] command was introduced in Maple 2019.
For more information on Maple 2019 changes, see Updates in Maple 2019.
See Also
Statistics[Mean]
Statistics[Scale]
TimeSeriesAnalysis[Decomposition]
Download Help Document