There's an exercise in Khan Academy' Probability and Statistics course on creating box-and-whisker plot. Here's screenshot representing correct solution. But when I tried to check solution in R I got the following:
d <- c(11, 4, 1, 4, 2, 2, 6, 10, 5, 6, 0, 6, 3, 3)
summary(d)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.00 2.25 4.00 4.50 6.00 11.00
You can see 2.25 value for 1st Qu. But the correct value is 2. Any other values returned with summary() are correct. Any ideas why summary() returns wrong result?
I had this very same issue as well. I think this is to do with the
type
of the quantile calculation used.This article explains it better than I can: http://datapigtechnologies.com/blog/index.php/why-excel-has-multiple-quartile-functions-and-how-to-replicate-the-quartiles-from-r-and-other-statistical-packages/
To see examples:
In a nutshell, there are many reasonable ways to compute quantiles. This is evidenced by the nine (!) different methods supported by the
quantile
function.summary
is not wrong, it is just using a different method to the one you're expecting. It likely is using the default method 7 (called "type 7" in the help page). Like most other methods, it is performing linear interpolation between two adjacent values, 2 and 3.You could try experimenting with the other methods by calling
quantile
with the appropriatetype
argument: