MeanAD | R Documentation |
Calculates the mean absolute deviation from a center point, typically the sample mean or the median. %% ~~ A concise (1-5 lines) description of what the function does. ~~
MeanAD(x, weights = NULL, center = Mean, na.rm = FALSE)
x |
a vector containing the observations. %% ~~Describe |
weights |
a numerical vector of weights the same length as |
center |
a single numerical value or the name of a function applied to |
na.rm |
a logical value indicating whether or not missing values should
be removed. Defaults to |
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.
Andri Signorell andri@signorell.net following an idea of Danielle
Navarro (aad
in the lsr package)
mad
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, center=mean)
MeanAD(x, center=median)
# define a fixed center
MeanAD(x, center=4)
# use of weights
MeanAD(x=0:6, weights=c(21,46,54,40,24,10,5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.