![]() |
VOOZH | about |
The Median Absolute Deviation is calculated in R Language using the mad() function. It is a statistical measurement of a dataset's dispersion or variability. Because it is resistant to outliers and extreme values, the MAD can serve as a robust alternative to standard deviation.
The Median Absolute Deviation (MAD) is calculated using the following formula:
MAD = median (|xi - x)|
where:
mad(x)
Parameters:
We can calculate the Median Absolute Deviation for vectors.
Example 1:
[1] 2.9652
Example 2:
[1] 1.4826
We can calculate MAD for a single column in a data set so we can take the iris dataset.
[1] 0.44478
To find the MAD for multiple columns, we can apply the apply() or sapply() function together with the mad() function. Here's how you can find the MAD for all the columns except the categorical ones in the iris dataset:
Output:
Sepal.Length Sepal.Width Petal.Length Petal.Width
1.03782 0.44478 1.85325 1.03782
The sapply() function uses the mad() function for every column in the dataset except for the categorical Species column. The MAD value for every numerical column is returned.
Related Articles: