Quartiles, Deciles, and Percentiles
[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.
The measures of position such as quartiles, deciles, and percentiles are available in quantile function. This function has a usage,Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quantile(x, probs = seq(0, 1, 0.25), na.rm = FALSE, | |
names = TRUE, type = 7, ...) |
- x – the data points
- prob – the location to measure
- na.rm – if FALSE, NA (Not Available) data points are not ignored
- names – for attributes, FALSE means no attributes, hence speeds-up the computation
- type – type of the quantile algorithms
- … – further arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scores <- c(88, 84, 83, 80, 94, 90, 81, 79, 79, 81, 85, 87, 86, 89, 92) | |
quantile(scores) | |
0% 25% 50% 75% 100% | |
79.0 81.0 85.0 88.5 94.0 |
Example 2. The surveyed weights (in kilograms) of the students in Stat 131 were the following: 69, 70, 75, 66, 83, 88, 66, 63, 61, 68, 73, 57, 52, 58, and 77. Compute and interpret the deciles of these weights.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
weights <- c(69, 70, 75, 66, 83, 88, 66, 63, 61, 68, 73, 57, 52, 58, 77) | |
quantile(weights, prob = seq(0, 1, length = 11), type = 5) | |
0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% | |
52.0 57.0 59.5 63.0 66.0 68.0 69.5 73.0 76.0 83.0 88.0 |
Interpretation: The first decile is $D_1$=10%, implies that one-tenth of the weights fall below or equal to 57.0, and the remaining nine-tenth fall above 57.0. The $D_5$=50% is the median, thus half of the students’ weights weigh below or equal to 68.0, while the other half fall above this. And so on.
Example 3. Compute the $15^{th}$, $25^{th}$, and $35^{th}$ percentiles of weights in Example 2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quantile(datad, prob = c(0.15, 0.25, 0.35)) | |
15% 25% 35% | |
58.3 62.0 65.7 |
Reference:
Yau, Chi. R Tutorial: Percentile.
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.