3
$\begingroup$

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.

$\endgroup$
5
  • 2
    $\begingroup$ 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) $\endgroup$ Sep 27, 2022 at 0:52
  • $\begingroup$ 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. $\endgroup$
    – JimB
    Sep 27, 2022 at 15:55
  • $\begingroup$ @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. $\endgroup$
    – Rupesh
    Sep 27, 2022 at 17:10
  • $\begingroup$ 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. $\endgroup$
    – JimB
    Sep 27, 2022 at 21:54
  • $\begingroup$ @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. $\endgroup$
    – Rupesh
    Sep 28, 2022 at 4:55

1 Answer 1

1
$\begingroup$

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];

dff = REvaluate["{ds<-data.frame(idx=Index, dose=vec1); head(ds);
model <- aov(dose~ idx, data = ds);
summary(model);
vals<-pairwise.t.test(ds$dose, ds$idx, p.adjust.method=\"bonferroni\");
 }"][[1, 3]]
DeleteMissing /@ (fromRObject[dff] // Quiet)
(*{{0.308928}, {0.0478164, 1.}}*)
$\endgroup$

Your Answer

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

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