 MovingStatistic - Maple Help

Statistics

 MovingStatistic
 compute moving statistics for a data set Calling Sequence MovingStatistic(X, m, f, options) Parameters

 X - m - bandwidth f - statistic options - additional parameters to be passed to the procedure f. Description

 • 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. Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $A≔⟨\mathrm{seq}\left(\mathrm{sin}\left(i\right),i=1..20\right)⟩:$
 > $U≔\mathrm{MovingStatistic}\left(A,5,\mathrm{Mean}\right)$
 ${U}{≔}\begin{array}{c}\left[\begin{array}{c}{0.0352323299444757}\\ {-0.188944966656889}\\ {-0.239407132278267}\\ {-0.0697594845655643}\\ {0.164024711544373}\\ {0.247005344299126}\\ {0.102890402628771}\\ {-0.135821500715074}\\ {-0.249659742674422}\\ {-0.133961968583799}\\ {⋮}\end{array}\right]\\ \hfill {\text{16 element Vector[column]}}\end{array}$ (1)
 > $V≔\mathrm{MovingStatistic}\left(A,5,t↦\mathrm{FivePointSummary}\left(t,\mathrm{output}=\mathrm{maximum}\right)\right)$
 ${V}{≔}\begin{array}{c}\left[\begin{array}{c}{0.909297426825682}\\ {0.909297426825682}\\ {0.656986598718789}\\ {0.989358246623382}\\ {0.989358246623382}\\ {0.989358246623382}\\ {0.989358246623382}\\ {0.989358246623382}\\ {0.420167036826641}\\ {0.990607355694870}\\ {⋮}\end{array}\right]\\ \hfill {\text{16 element Vector[column]}}\end{array}$ (2)
 > f := proc(A, q)   Statistics[Quantile](A, q); end proc:
 > $W≔\mathrm{MovingStatistic}\left(A,5,f,0.3\right)$
 ${W}{≔}\begin{array}{c}\left[\begin{array}{c}{-0.770277280598276}\\ {-0.770277280598276}\\ {-0.770277280598276}\\ {-0.770277280598276}\\ {-0.324716083296540}\\ {-0.297055872378289}\\ {-0.574419050600125}\\ {-0.574419050600125}\\ {-0.574419050600125}\\ {-0.574419050600125}\\ {⋮}\end{array}\right]\\ \hfill {\text{16 element Vector[column]}}\end{array}$ (3)
 > $\mathrm{LineChart}\left(\left[A,U,V,W\right],\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{thickness}=3,\mathrm{legend}=\left["original","mean","maximum","quantile"\right]\right)$ 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:

 > $\mathrm{MovingStatistic}\left(⟨1,2,3⟩,2,g\right)$
 $\left[\begin{array}{c}{\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{g}{}\left(\left[\begin{array}{r}2\\ 3\end{array}\right]\right)\right]\right)\\ {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{g}{}\left(\left[\begin{array}{r}2\\ 3\end{array}\right]\right)\right]\right)\end{array}\right]$ (4)

This command, however, will make a copy for every sub-Vector and thus get the correct answer.

 > $\mathrm{MovingStatistic}\left(⟨1,2,3⟩,2,v↦g\left(\mathrm{copy}\left(v\right)\right)\right)$
 $\left[\begin{array}{c}{\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{g}{}\left(\left[\begin{array}{r}1\\ 2\end{array}\right]\right)\right]\right)\\ {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{g}{}\left(\left[\begin{array}{r}2\\ 3\end{array}\right]\right)\right]\right)\end{array}\right]$ (5)