Statistics
MovingStatistic
compute moving statistics for a data set
Calling Sequence
Parameters
Description
Examples
MovingStatistic(X, m, f, options)
X
-
data set
m
bandwidth
f
statistic
options
additional parameters to be passed to the procedure f.
The MovingStatistic function computes moving statistics for a set of observations.
The first parameter X is a single data sample - given as e.g. a Vector. Each value represents an individual observation.
The second parameter m is the size of the moving window.
The third argument f is the statistic; can be any of the DescriptiveStatistics routines or a maple procedure which accepts a Vector and returns a floating point number.
Note that after f has been called on one subsample, the same Vector is reused for the next subsample, for efficiency reasons. All the builtin DescriptiveStatistics routines can handle this, but if you specify a custom maple procedure for f, you may need to copy its input Vector if you will need access to it after returning. See the example below for an explanation.
with⁡Statistics:
A≔seq⁡sin⁡i,i=1..20:
U≔MovingStatistic⁡A,5,Mean
V≔MovingStatistic⁡A,5,t↦FivePointSummary⁡t,output=maximum
f := proc(A, q) Statistics[Quantile](A, q); end proc:
W≔MovingStatistic⁡A,5,f,0.3
LineChart⁡A,U,V,W,color=red..blue,thickness=3,legend=original,mean,maximum,quantile
The following command will fail to apply the unassigned name g to the two correct sub-Vectors, because the same Vector is reused internally, as described above:
MovingStatistic⁡1,2,3,2,g
g⁡23g⁡23
This command, however, will make a copy for every sub-Vector and thus get the correct answer.
MovingStatistic⁡1,2,3,2,v↦g⁡copy⁡v
g⁡12g⁡23
See Also
Statistics[DataSmoothing]
Statistics[ExponentialSmoothing]
Statistics[MovingAverage]
Download Help Document