\Header{mad}{Median Absolute Deviation}
\keyword{univar}{mad}
\keyword{robust}{mad}
\begin{Usage}
\begin{verbatim}
mad(x, center, constant=1.4826, na.rm=FALSE)
\end{verbatim}
\end{Usage}
\begin{Description}
\texttt{mad} provides a scale estimate based on the
median absolute deviation.
The actual value calculated is
\texttt{constant * (median(abs(x - center)))}
with the default value of
\texttt{center} being \texttt{median(x)}.

The default \texttt{constant = 1.4826} (approximately
\eqn{1/\Phi^{-1}(\frac 3 4)}{1/ Phi^(-1)(3/4)} = \texttt{1/qnorm(3/4)})
ensures consistency, i.e.,
\deqn{E[mad(X_1,\dots,X_n)] = \sigma}{}
for \eqn{X_i}{} distributed as \eqn{N(\mu,\sigma^2)}{} and large \eqn{n}{}.

If \texttt{na.rm} is \texttt{TRUE} then \texttt{NA}
values are stripped from \texttt{x} before computation takes place.
If this is not done then an \texttt{NA} value in
\texttt{x} will cause \texttt{mad} to return \texttt{NA}.\end{Description}
\begin{SeeAlso}
\texttt{\Link{IQR}} which is simpler but less robust,
\texttt{\Link{median}}, \texttt{\Link{var}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
mad(c(1:9))
print(mad(c(1:9),     constant=1)) ==
      mad(c(1:8,100), constant=1)	# = 2 ; TRUE
\end{ExampleCode}
\end{Examples}

