roll icon indicating copy to clipboard operation
roll copied to clipboard

roll_mad() - Mean | Median Absolute Deviation

Open Eluvias opened this issue 5 years ago • 3 comments

Would that fit to the existing framework / family functions?

Eluvias avatar Sep 12 '19 17:09 Eluvias

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.

jasonjfoster avatar Sep 17 '19 10:09 jasonjfoster

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.

Eluvias avatar Sep 18 '19 20:09 Eluvias

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

dimfalk avatar Nov 09 '23 19:11 dimfalk