6
$\begingroup$

I am aware of one convention for the uncertainty in a median:
it is 1.58 * IQR / Sqrt[n], where IQR is the inter-quartile range and n is the number of data points. This was proposed by McGill, Tukey, and Larsen in 1978, and is used by R for their boxplots. It corresponds roughly to a 95% confidence interval.

It seems that the "Notched" function in Mathematica's BoxWhiskerChart function is using a different calculation, but I have failed to find any information on what that calculation is.

$\endgroup$
2
  • 1
    $\begingroup$ I believe the documentation says the fat part of the plot is bounded by the 1st and 3rd quartiles (Properties & Relations section). Am I missing something? $\endgroup$ Commented May 10, 2015 at 19:35
  • 1
    $\begingroup$ @SjoerdC.deVries Those are the boundaries of the box itself. I think the OP is referring to the limits of the notched part of the box, when you request the "Notched" option. $\endgroup$
    – MarcoB
    Commented May 10, 2015 at 20:44

1 Answer 1

7
$\begingroup$

Update: You can control the median confidence interval using the suboption "MedianConfidenceIntervalParameter" of the option Method:

data = Table[RandomReal[BetaDistribution[a, 1.5], 100], {a, 1, 5, 1}]; 

opts = {{"Notched", {"MedianMarker", Purple}, {"MedianNotch", Orange}}, 
       ImageSize -> 300,  ChartElementFunction -> "GlassBoxWhisker"};
bwc1 = BoxWhiskerChart[data[[1]], ## & @@ opts, PlotLabel -> Style["Default" , 16]];
bwcs = BoxWhiskerChart[data[[1]], Sequence @@ opts,
     PlotLabel -> Style["MedianConfidenceIntervalParameter ->" <> ToString@#, 16],
     Method -> {"MedianConfidenceIntervalParameter" -> #}] & /@ 
     {1.7, .5, 1., 2., 3};

Row[{bwc1, bwcs[[1]]}]

enter image description here

Row[Rest@bwcs]

enter image description here

Note: The function Charting`iBoxWhiskerChart is the first function called in the TracePrint of BoxWhiskerChart[...]. One of its options is "MedianConfidenceIntervalParameter" with default value 1.7:

Options[Charting`iBoxWhiskerChart, "MedianConfidenceIntervalParameter"]

{"MedianConfidenceIntervalParameter" -> 1.7`}


Original post:

The core function used rendering the box plots in BoxWhiskerChart is System`BarFunctionDump`boxplot. You can see the code using

?? System`BarFunctionDump`boxplot

The relevant line that determines the median interval is

System`BarFunctionDump`medianInterval = 
 (System`BarFunctionDump`medianConfIntPara 1.25` System`BarFunctionDump`iqr)/
 ( 1.35` Sqrt[Length[System`BarFunctionDump`data]])

where System`BarFunctionDump`iqr is the IQR and the default value for the parameter System`BarFunctionDump`medianConfIntPara is previously defined as

System`BarFunctionDump`medianConfIntPara = 1.7`

So, the default value of the median interval parameter is

(1.7 1.25/1.35) IQR / Sqrt[n] = 1.574074 IQR / Sqrt[n]

The value of System`BarFunctionDump`medianConfIntPara is controlled by the option "MedianConfIntPara" but I could not figure out how this option is to be used in BoxWhiskerChart.

$\endgroup$
3
  • 1
    $\begingroup$ This is brilliant (+1)! Would you mind sharing how you found out where to look for boxplot etc? I tried to dig around a bit, but came up empty. $\endgroup$
    – MarcoB
    Commented May 10, 2015 at 20:46
  • 1
    $\begingroup$ @MarcoB, thank you for the vote and kind words. I use the general spelunking method: use ?? *`*BoxWhisker* and click on some the results; found that System`BarFunctionDump`boxplot is called by few functions that inspected. I was lucky to bump into something that was relevant without going through a long chain of other function calls. $\endgroup$
    – kglr
    Commented May 10, 2015 at 21:48
  • $\begingroup$ Thank you! I will use this example as a study tool in spelunking, by trying to retrace your steps. I am curious to see how far I can get with this approach on my own, knowing a) that there is something to find; 2) what that something is already ;-) $\endgroup$
    – MarcoB
    Commented May 10, 2015 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.