spacepy_logo

Previous topic

spacepy.toolbox.intsolve

Next topic

spacepy.toolbox.mlt2rad

This Page

spacepy.toolbox.medAbsDev

spacepy.toolbox.medAbsDev(series)[source]

Calculate median absolute deviation of a given input series

Median absolute deviation (MAD) is a robust and resistant measure of the spread of a sample (same purpose as standard deviation). The MAD is preferred to the inter-quartile range as the inter-quartile range only shows 50% of the data whereas the MAD uses all data but remains robust and resistant. See e.g. Wilks, Statistical methods for the Atmospheric Sciences, 1995, Ch. 3.

Parameters:

series : array_like

the input data series

Returns:

out : float

the median absolute deviation

Examples

Find the median absolute deviation of a data set. Here we use the log- normal distribution fitted to the population of sawtooth intervals, see Morley and Henderson, Comment, Geophysical Research Letters, 2009.

>>> import numpy
>>> import spacepy.toolbox as tb
>>> numpy.random.seed(8675301)
>>> data = numpy.random.lognormal(mean=5.1458, sigma=0.302313, size=30)
>>> print data
array([ 181.28078923,  131.18152745, ... , 141.15455416, 160.88972791])
>>> tb.medabsdev(data)
28.346646721370192

note This implementation is robust to presence of NaNs