## Mean Absolute Deviation From a Center Point

### Description

Calculates the mean absolute deviation from a center point, typically the sample mean or the median.

### Usage

MeanAD(x, weights = NULL, center = Mean, na.rm = FALSE)


### Arguments

 x a vector containing the observations. weights a numerical vector of weights the same length as x giving the weights to use for elements of x. center a single numerical value or the name of a function to be used as center. Can as well be a self defined function. Default is Mean(). na.rm a logical value indicating whether or not missing values should be removed. Defaults to FALSE.

### Details

The MeanAD function calculates the mean absolute deviation from the mean value (or from another supplied center point) of x, after having removed NA values (if requested):

\frac{1}{n} \cdot \sum_{i=1}^{n}\left | x_{i}-c \right | \; \; \; \textup{where} \; c=mean(x) \; \textup{or} \; c=med(x)

The function supports the use of weights. The default function for the center value Mean() has a weights arguments, too. If a user defined function is used it must be assured that it has a weights argument.

Numeric value.

### Author(s)

Andri Signorell <andri@signorell.net> following an idea of Danielle Navarro (aad in the lsr package)

mad

### Examples

x <- runif(100)

speed <- c(58, 88, 40, 60, 72, 66, 80, 48, NA)

# using the median as centerpoint
x <- c(2,3,5,3,1,15,23)