April – Frequentist inference in Mathematica

Mathematica provides a package called “Hypothesis Testing” for analyzing random data. The package includes handy objects like “Around”, representing a quantity and the uncertainty around it. The following example code returns an Around object representing the confidence interval of the estimated bias of a coin after a repeated trial. As shown in the code, the ListPlot plots Around objects as such.

(*Load the Hypothesis Testing Package.*)

coin[flips_, bias_] :=
 (*Make the experiment and collect the data*) 
 Module[{index, realizations, mean, conf, around},
  realizations = {};
  For[index = 1, index <= flips, index++,
   realizations =  
  mean = Mean[realizations[[All]]];
  (*Confidence interval*)
  conf = MeanCI[realizations[[All]]];
  (*Around object*)
  around = Around[mean, Abs[conf[[1]] - conf[[2]]]]
around = coin[1000, 0.5]