I can use R summary function to get min, max and percentiles(25, 75).
How can i use summary to get arbitrary quantiles like 90th percentile and 99th percentile in summary stats?
You find a percentile in R by using the quantiles function. It produces the percentage with the value that is the percentile. This is the default version of this function, and it produces the 0th percentile, 25th percentile, 50th percentile, 75th percentile, and 100th percentile.
For this purpose, we can use quantile function in R. To find the 2.5th percentile, we would need to use the probability = 0.025 and for the 97.5th percentile we can use probability = 0.0975.
The nth percentile of an observation variable is the value that cuts off the first n percent of the data values when it is sorted in ascending order.
We obtain percentile values in R using the function qnorm. This function returns the value of the standard normal (by default) distribution corresponding to a given percentile. For example, qnorm(. 5) returns 0, the median of the standard normal distribution.
Use quantile
function
quantile(x, c(.90, .99))
Example:
> set.seed(1) > x <- rnorm(100) > summary(x) Min. 1st Qu. Median Mean 3rd Qu. Max. -2.2150 -0.4942 0.1139 0.1089 0.6915 2.4020 > quantile(x, c(.25, .50, .75, .90, .99)) 25% 50% 75% 90% 99% -0.4942425 0.1139092 0.6915454 1.1810651 2.1749017
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With