# Bonferroni in ANOVA

Hi I am trying to use ANOVA to compare between the groups. I came across an article "bonferroni" which explains a method to do a Bonferroni test in R. However, I am unable to find a function such as pairwise in Mathematica. To reproduce the same example in the link I have tried this so far:

Needs["ANOVA"]
trialList= {76, 77, 77, 81, 82, 82, 83, 84, 85, 89, 81, 82, 83, 83, 83, 84, 87, 90, 92, 93, 77, 78, 79, 88, 89, 90, 91, 95, 95, 98}
indices=ConstantArray[{1, 2, 3}, 10] // Transpose // Flatten
(*{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}*)
ANOVA[{indices, trialList} // Transpose, PostTests -> Bonferroni,  CellMeans -> False]


This gives me the anova table, but I can't find a way to find the Bonferroni as explained in the 4th step of bonferreni. I would appreciate any help or workaround. Thank you.

• Jenny Baglivo's book Mathematica Laboratories for Mathematical Statistics: Emphasizing Simulation and Computer Intensive Methods [amzn.to/3Sk8bGo] has an implementation of Bonferroni; the code can be downloaded from her website [jennybaglivo.bc.edu/curriculum/mathematical-statistics/] (the Bonferroni stuff is in the Group4.m file) Sep 27, 2022 at 0:52
• I'm not sure what you think is missing. With the code you used you get as part of the output PostTests->{Model->Bonferroni {1,3}} which tells you that using the Bonferroni adjustment the means of index 1 and index 3 are significantly different at the 0.05 level (and neither of the other 2 pairwise comparisons are significantly different). That's all you're going to get from ANOVA. If you want more, you'll need to go the R route or use LinearModelFit. But in any event you need to spell out exactly what kind of output you need.
– JimB
Sep 27, 2022 at 15:55
• @JimB Thanks Jim, the thing that's missing is the relative p values based on which Bonferroni has pointed out {1,3}. I have used PairedTtest but the pvalues differ because they're not relative to the next pair. The type of output I need is provided in the link in the question. Sep 27, 2022 at 17:10
• Your data doesn't appear to be paired so I wouldn't use the PairedTtest. If the 10 sets of {1, 2, 3} values are blocks, then that would justify using the PairedTtest but it invalidates your current use of ANOVA that appears to ignore that blocking.
– JimB
Sep 27, 2022 at 21:54
• @JimB, sorry, my bad, this is just a sample from the example in the link. For my research, I study the lists as a pair like lists {1,2,3} are the individual plans, and we can always compare the plans forming a pair like {1,2} or {2,3}. Thank you for your help though. Sep 28, 2022 at 4:55

Also, there is a workaround way of getting the results. But, you need to use a dependency RLink Package. Essentially do it in R.

<< RLink
InstallR[]

RSet["vec1", trialList];
RSet["Index", indices];

vals<-pairwise.t.test(ds$$dose, ds$$idx, p.adjust.method=\"bonferroni\");