DescTools (version 0.99.14)

MeanAD: 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, FUN = mean, na.rm = FALSE)

Arguments

x
a vector containing the observations.
FUN
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.

Value

  • Numeric value.

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)$$ It exists primarily to simplify the discussion of descriptive statistics during an introductory stats class.

See Also

mad

Examples

Run this code
x <- runif(100)
MeanAD(x)

speed <- c(58, 88, 40, 60, 72, 66, 80, 48, NA)
MeanAD(speed)
MeanAD(speed, na.rm=TRUE)


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

MeanAD(x, FUN=mean)
MeanAD(x, FUN=median)

# define a fix center
MeanAD(x, 4)

Run the code above in your browser using DataCamp Workspace