roll
roll copied to clipboard
roll_mad() - Mean | Median Absolute Deviation
Would that fit to the existing framework / family functions?
The current list of functions is mostly from my own survey of rolling statistics that focuses on common use cases and demand, so could you share links to other GH repos or SO questions that discuss something like roll_mad
? For more background, the function implementations in roll
need to offer an "online" algorithm, which is more difficult, so need to consider the cost-benefit of each function too. Luckily the roll
package does some of the heavy-lifting via roll_median
that can be used in another function to calculate roll_mad
(also as a one-off exercise too), if needed.
An R
package with a rolling mad
implementation is TTR with runMAD() function which has the option stats
to return either the rolling median or mean absolute deviation.
Another R
implementation is caTools::runmad().
MATLAB
has a family of core Moving Statistics which includes a rolling median absolute deviation
via movmad function.
MATHEMATICA
has MedianDeviation but offers a generic MovingMap to apply any function, so there is no need for a separate implementation.
Perhaps only for the case of the median absolute deviation, it looks natural for the roll
package to offer an additional but more robust measure of dispersion.
Thank you.
I'd also be very much interested in having this function!
{RcppRoll}
also has this feature request (https://github.com/kevinushey/RcppRoll/issues/38) but does not seem to be maintained very actively - this is how I found {roll}
in the end - but maybe this snippet in {m181}
could be of some help:
https://github.com/dleutnant/m181/blob/9b8160b9596225dbcc5671c6cf0d64e90711b710/src/m181_criteria_core.cpp#L119-L133