Accelerating the pace of engineering and science

# Documentation Center

• Trials
• Product Updates

# mad

Mean or median absolute deviation

y = mad(X)
Y = mad(X,1)
Y = mad(X,0)

## Description

y = mad(X) returns the mean absolute deviation of the values in X. For vector input, y is mean(abs(X-mean(X))). For a matrix input, y is a row vector containing the mean absolute deviation of each column of X. For N-dimensional arrays, mad operates along the first nonsingleton dimension of X.

Y = mad(X,1) returns the median absolute deviation of the values in X. For vector input, y is median(abs(X-median(X))). For a matrix input, y is a row vector containing the median absolute deviation of each column of X. For N-dimensional arrays, mad operates along the first nonsingleton dimension of X.

Y = mad(X,0) is the same as mad(X), and returns the mean absolute deviation of the values in X.

mad(X,flag,dim) computes absolute deviations along the dimension dim of X. flag is 0 or 1 to indicate mean or median absolute deviation, respectively.

mad treats NaNs as missing values and removes them.

For normally distributed data, multiply mad by one of the following factors to obtain an estimate of the normal scale parameter σ:

• sigma = 1.253*mad(X,0) — For mean absolute deviation

• sigma = 1.4826*mad(X,1) — For median absolute deviation

## Examples

The following compares the robustness of different scale estimates for normally distributed data in the presence of outliers:

```x = normrnd(0,1,1,50);
xo = [x 10]; % Add outlier

r1 = std(xo)/std(x)
r1 =
1.7385

r2 = mad(xo,0)/mad(x,0)
r2 =
1.2306

r3 = mad(xo,1)/mad(x,1)
r3 =
1.0602```

## References

[1] Mosteller, F., and J. Tukey. Data Analysis and Regression. Upper Saddle River, NJ: Addison-Wesley, 1977.

[2] Sachs, L. Applied Statistics: A Handbook of Techniques. New York: Springer-Verlag, 1984, p. 253.

## See Also

Was this topic helpful?