Calculate quantiles of vector producing unexpected results

224 views Asked by At

I was asked to calculate BY HAND the IQR of this data

-1,400 -1,000 -0,600 0,400 1,000 1,700 2,300 2,600 3,300 3,700 4,400 4,600 7,000 7,500 7,700 13,500 18,500

The results are

MEDIAN 3.300
1 QUARTILE 1
3 QUARTILE 7
Q3-Q1=IQR = 7-1=6

My results were also confirmed by R.

x <- c(-1.400,-1.000,-0.600,0.400,1.000,1.700,2.300,2.600,3.300,3.700,4.400,4.600,7.000,7.500,7.700,13.500,18.500)
summary(x)
#   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
# -1.400   1.000   3.300   4.424   7.000  18.500 

The problem is that they expect instead this value instead.

1 QUARTILE 0.7
3 QUARTILE 7.25
IQR= 6.55

Could someone explain what is happening? Where is my miscalculation or misuse?

1

There are 1 answers

0
Allan Cameron On

There are 9 different ways of calculating quantiles that are implemented by the quantile function in R. You can read about these by doing ?quantile and test them all on your vector by doing:

 t(sapply(1:9, function(i) quantile(x, c(0.25, 0.75), type = i)))
#>          25%      75%
#>  [1,] 1.0000 7.000000
#>  [2,] 1.0000 7.000000
#>  [3,] 0.4000 7.000000
#>  [4,] 0.5500 6.400000
#>  [5,] 0.8500 7.125000
#>  [6,] 0.7000 7.250000
#>  [7,] 1.0000 7.000000
#>  [8,] 0.8000 7.166667
#>  [9,] 0.8125 7.156250

You can see that your method is 1, 2, or 7, (R's default is method 7), and the "expected" answer is method 6. If you were simply asked asked to work out the first and third quartiles, you should be given guidance on the expected method.