Language Reference

MAD Function

MAD (x <, method> ) ;

This function is supported by the IML procedure and the iml action.

The MAD function computes the univariate (scaled) median absolute deviation of each column of the input matrix.

The arguments to the MAD function are as follows:

x

is an n times p input data matrix.

method

is an optional string argument with the following values:

"MAD"

for computing the median absolute deviation (MAD); this is the default.

"NMAD"

for computing the normalized version of MAD

"SN"

for computing upper S Subscript n

"QN"

for computing upper Q Subscript n

For simplicity, the following descriptions assume that the input argument x is a column vector. The notation x Subscript i means the ith element of the column vector x.

The MAD function can be used for computing one of the following three robust scale estimates:

  • median absolute deviation (MAD) or normalized form of MAD,

    MAD Subscript n Baseline equals b asterisk med Subscript i Superscript n Baseline StartAbsoluteValue x Subscript i Baseline minus med Subscript j Superscript n Baseline x Subscript j Baseline EndAbsoluteValue

    where b equals 1 is the unscaled default and b equals 1.4826 is used for the scaled version (consistency with the Gaussian distribution).

  • upper S Subscript n, which is a more efficient alternative to MAD,

    upper S Subscript n Baseline equals c Subscript n Baseline asterisk med Subscript i Baseline med Subscript j Baseline StartAbsoluteValue x Subscript i Baseline minus x Subscript j Baseline EndAbsoluteValue

    where the outer median is a low median (order statistic of rank left-bracket StartFraction n plus 1 Over 2 EndFraction right-bracket) and the inner median is a high median (order statistic of rank left-bracket StartFraction n Over 2 EndFraction plus 1 right-bracket), and where c Subscript n is a scalar that depends on sample size n.

  • upper Q Subscript n is another efficient alternative to MAD. It is based on the kth-order statistic of the StartBinomialOrMatrix n Choose 2 EndBinomialOrMatrix inter-point distances,

    upper Q Subscript n Baseline equals d Subscript n Baseline asterisk StartSet StartAbsoluteValue x Subscript i Baseline minus x Subscript j Baseline EndAbsoluteValue semicolon i less-than j EndSet Subscript left-parenthesis k right-parenthesis Baseline with k almost-equals StartBinomialOrMatrix n Choose 2 EndBinomialOrMatrix slash 4

    where d Subscript n is a scalar similar to but different from c Subscript n. See Rousseeuw and Croux (1993) for more details.

The scalars c Subscript n and d Subscript n are defined as follows:

c Subscript n Baseline equals 1.1926 asterisk StartLayout Enlarged left-brace 1st Row 1st Column 0.743 2nd Column for n equals 2 2nd Row 1st Column 1.851 2nd Column for n equals 3 3rd Row 1st Column 0.954 2nd Column for n equals 4 4th Row 1st Column 1.351 2nd Column for n equals 5 5th Row 1st Column 0.993 2nd Column for n equals 6 6th Row 1st Column 1.198 2nd Column for n equals 7 7th Row 1st Column 1.005 2nd Column for n equals 8 8th Row 1st Column 1.131 2nd Column for n equals 9 9th Row 1st Column n slash left-parenthesis n minus 0.9 right-parenthesis 2nd Column for other odd n 10th Row 1st Column 1.0 2nd Column otherwise EndLayout d Subscript n Baseline equals 2.2219 asterisk StartLayout Enlarged left-brace 1st Row 1st Column 0.399 2nd Column for n equals 2 2nd Row 1st Column 0.994 2nd Column for n equals 3 3rd Row 1st Column 0.512 2nd Column for n equals 4 4th Row 1st Column 0.844 2nd Column for n equals 5 5th Row 1st Column 0.611 2nd Column for n equals 6 6th Row 1st Column 0.857 2nd Column for n equals 7 7th Row 1st Column 0.669 2nd Column for n equals 8 8th Row 1st Column 0.872 2nd Column for n equals 9 9th Row 1st Column n slash left-parenthesis n plus 1.4 right-parenthesis 2nd Column for other odd n 10th Row 1st Column n slash left-parenthesis n plus 3.8 right-parenthesis 2nd Column otherwise EndLayout

Example

The following example uses the univariate data set of Barnett and Lewis (1978). The data set is used in Chapter 14 to illustrate the univariate LMS and LTS estimates.

 b = {3, 4, 7, 8, 10, 949, 951};

 rmad1 = mad(b);
 rmad2 = mad(b,"mad");
 rmad3 = mad(b,"nmad");
 rmad4 = mad(b,"sn");
 rmad5 = mad(b,"qn");
 print "Default MAD=" rmad1,
       "Common MAD =" rmad2,
       "MAD*1.4826 =" rmad3,
       "Robust S_n =" rmad4,
       "Robust Q_n =" rmad5;

Figure 240: Median Absolute Deviations

 rmad1
Default MAD=4

 rmad2
Common MAD =4

 rmad3
MAD*1.4826 =5.9304089

 rmad4
Robust S_n =7.143674

 rmad5
Robust Q_n =5.7125049


Last updated: May 07, 2026