mmad
Syntax
mmad(X, window, [useMedian=false], [minPeriods])
Please see Moving Functions (m-functions) for the parameters and windowing logic.
Arguments
useMedian is a Boolean value. The default value is false and it returns the mean absolute deviation, otherwise returns the median absolute deviation.
mean absolute deviation: mean(abs(X - mean(X)))
median absolute deviation: med(abs(X - med(X)))
Details
Calculate the the average absolute deviation of X in a sliding window.
Examples
$ x = 7 4 6 0 -5 32;
$ mmad(x, window=3);
[,,1.111111111111111,2.222222222222222,3.777777777777777,15.333333333333333]
$ mmad(x, window=3, useMedian=true)
[,,1,2,3.666666666666666,12.333333333333333]
$ y = NULL NULL 2 5 1 7 -3 0
$ mmad(y, window=3, minPeriods=2);
[,,,1.5,1.555555555555555,2.222222222222222,3.555555555555556,3.777777777777778]
$ m=matrix(85 90 95, 185 190 195);
$ m;
#0 |
#1 |
---|---|
85 |
185 |
90 |
190 |
95 |
195 |
$ mmad(x, 2)
#0 |
#1 |
---|---|
2.5 |
2.5 |
2.5 |
2.5 |
Related function: mad