0

I am converting some MatLab code to Python, and cannot solve why the results I am getting are different.

In MatLab, the mad function on the input x = [1, 2, 4, 3, 7, 2, 1, 3, 2, 1] yields a result of 1.32. However, when using the equiv function in SciPy.Stats, that is, median_abs_deviation, I get a different result of 1.0.

My code, exactly is:

Matlab:

x = [1, 2, 4, 3, 7, 2, 1, 3, 2, 1];
mdat = mad(x)

Python:

from scipy import stats

x = np.array([1, 2, 4, 3, 7, 2, 1, 3, 2, 1])
print(stats.median_abs_deviation(x))

1 Answers1

1

The default in Matlab is to compute the mean absolute deviation. If you want the median absolute deviation, then the command is mad(x,1).

If you're interested in computing the mean absolute deviation in Python, see this post.

Ben Grossmann
  • 4,387
  • 1
  • 12
  • 16