The statistics book I am using defines quartiles the same as Method 1 explained in wikipedia.
Use the median to divide the ordered data set into two-halves. If there is an odd number of data points in the original ordered data set, do not include the median (the central value in the ordered list) in either half. If there is an even number of data points in the original ordered data set, split this data set exactly in half. The lower quartile value is the median of the lower half of the data. The upper quartile value is the median of the upper half of the data. This rule is employed by the TI-83 calculator boxplot and "1-Var Stats" functions.
For the following illustration, the numbers with yellow background represent the data while the curly braced three numbers represent their quartiles.
As Quartiles
defined in Mathematica uses different algorithm, I create my own implementing the Method 1 above as follows.
CorrectedQuartile[raw_List] := Module[{data, length, Q1, Q2, Q3},
data = Sort@raw;
length = Length@data;
Q2 = Median@data;
If[Mod[length, 2] == 0,
Q1 = Median@Take[data, length/2];
Q3 = Median@Take[data, -length/2],
Q1 = Median@Take[data, (length - 1)/2];
Q3 = Median@Take[data, (1 - length)/2]
];
{Q1, Q2, Q3}
];
Question
My rule of thumb is "Writing our own functions must be the last resort". Is it possible to use the existing or built-in Quartiles
to behaves the same as the Method 1 does?
Quantile
gives 8 different definitions one of which almost certainly matches the Texas Instruments approach. It also gives a general formula to be able to customize however you want. I would expect this question to be closed. $\endgroup$ – JimB Jun 29 '20 at 15:16{{a,b},{c,d}}
. $\endgroup$ – Money Sets You Free Jun 29 '20 at 15:51tiQuartiles[list_] := With[{med = Median[list]}, Riffle[Median /@ Lookup[GroupBy[list, Sign[# - med] &], {-1, 1}], med]];
$\endgroup$ – Michael E2 Jun 29 '20 at 16:07