My last reply does not appear to have communicated with you, sorry.
The interquartile range is calculated using the 1st & 3rd sample quartiles,
but there are various ways to calculate those quartiles.
Five of Hyndman and Fan's sample quantile definitions have a particularly
simple common form given by the following VBA code. You select among the
methods according to which definition of m you uncomment.
Function quantile(data, p)
' p=fraction of population, e.g. p=0.25 for 1st quartile
n = WorksheetFunction.Count(data)
' m = 0 ' H&F 4: SAS (PCTLDEF=1), R (type=4), Maple (method=3)
' m = 0.5 ' H&F 5: R (type=5), Maple (method=4)
' m = p ' H&F 6: Minitab, SPSS, BMDP, JMP, SAS (PCTLDEF=4), R
(type=6), Maple (method=5)
' m = 1 - p ' H&F 7: Excel, S-Plus, R (type=7[default]), Maxima, Maple
(method=6)
' m = (p+1)/3 ' H&F 8: R (type=8), Maple (method=7[default])
' m=(p+1.5)/4 ' H&F 9: R (type=9), Maple (method=8)
npm = n * p + m
j = Fix(npm): If j = 0 Then j = 1
If j > n Then j = n
g = npm - j
quantile = WorksheetFunction.Small(data, j)
If g >= 0 And j < n Then
quantile = (1 - g) * quantile + g * WorksheetFunction.Small(data, j
+ 1)
End If
End Function
Excel, S-Plus, etc use H&F definition 7, which returns SMALL(data,i) as
quantile(data,(i-1)/(n-1)) and interpolates in between. For a continuous
distribution, this will tend to give too narrow an interquartile range, since
there will tend to be a small fraction of the population beyond the extreme
sample observations. In particular, for odd n (=2*k+1), Excel calculates the
1st (3rd) quartile as the median of the lower (upper) "half" of the sample
including the sample median (k+1 observations).
Minitab, etc use H&F definition 6, which calculates the 1st (3rd) quartile
as the median of the lower (upper) "half" of the sample. This "half" sample
excludes the sample median (k observations) for odd n (=2*k+1). This will
tend to be a better estimate for the population quartiles, but will tend to
give quartile estimates that are a bit too far from the center of the whole
sample (too wide an interquartile range).
Hyndman and Fan recommend their definition 8 (Maple's default definition),
which gives quartiles between those reported by Minitab and Excel. This
approach is approximately median unbiased for continuous distributions.
Jerry