Measures of Absolute Variability

[This article was first published on Analysis with R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Measures of absolute variability deal with the dispersion of the data points. This include the following:
  • Range – range
  • Interquartile Range – IQR
  • Quartile Deviation
  • Average Deviation
  • Standard Deviation – sd
These measures of variability restrict to uniform units of measurement when comparing two distributions.

Example 1. The heights (in centimetres) of the 17 BS Stat students in section A23 of Statistical Inference under Dr. Supe were recorded. The data are the following: 151, 160, 162, 155, 154, 154, 153, 168, 169, 153, 158, 166, 152, 157, 150, 169, and 167. Compute the range, interquartile range, quartile deviation, average deviation, and standard deviation.

The range is computed using the function range, while the interquartile range is obtained by IQR. Thus,

heights <- c(151, 160, 162, 155, 154, 154, 153, 168, 169, 153, 158, 166, 152, 157, 150, 169, 167)
range(heights)
[1] 150 169
IQR(heights)
[1] 13
view raw MVariability.R hosted with ❤ by GitHub
The range returned the minimum and maximum values of the data which are 150 and 169, respectively. And for the interquartile range, the output returned the difference between the third and first quartiles. Going back to the range, one might want immediately the difference between the maximum and the minimum values. Well, simply insert this to a function for generality, i.e.

Range <- function(data){
max(data) - min(data)
}
view raw MVariability1.R hosted with ❤ by GitHub
Using this new function, the range would be

Range(heights)
[1] 19
view raw MVariability2.R hosted with ❤ by GitHub
For quartile deviation, the formula is given by$$QD=\frac{Q_3-Q_1}{2}$$where:
  • $QD$ – quartile deviation
  • $Q_3$ – third quartile
  • $Q_1$ – first quartile
This equation is just the interquartile range over 2. And thus, the function would be

QD <- function(data){
IQR(data)/2
}
view raw MVariability3.R hosted with ❤ by GitHub
The quartile deviation of the heights then, follows

QD(heights)
[1] 6.5
view raw MVariability4.R hosted with ❤ by GitHub
Lastly, the mean deviation$$AD=\displaystyle\frac{\displaystyle\sum_{i=1}^{n}\left|X_i-\bar{X}\right|}{n-1}$$where:
  • $AD$ – average deviation
  • $X_i$ – $i^{th}$ individual observations
  • $\bar{X}$ – sample mean
  • $n$ – total number of observations
has an equivalent R code,

AD <- function(data){
sum(abs(data-mean(data)))/(length(data)-1)
}
view raw MVariability5.R hosted with ❤ by GitHub
And therefore, the average deviation of the heights is,

AD(heights)
[1] 6.257353
view raw MVariability6.R hosted with ❤ by GitHub


Reference:

Asaad, Abubakar S. (2011). Simplified Biostatistics. Manila: Rex Book Store, Inc.

To leave a comment for the author, please follow the link and comment on their blog: Analysis with R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)