# Is there any way to perform an ANOVA test given $n$, $\bar{x}$ and $S^2$?

Suppose I have the following data about the incomes of residents of three cities.

$$\begin{array}{|l|c|c|c|} \hline & n & \bar{x} & S^2 \\ \hline \text{City A} & 10 & 2.8 & 3.2 \\ \hline \text{City B} & 7 & 2.6 & 2.9 \\ \hline \text{City C} & 11 & 3.1 & 3.3 \\ \hline \end{array}$$

I want to test whether the mean income in the three cities are equal, with a significance level of $\alpha=0.10$. Is there an efficient way to perform an ANOVA test in Mathematica given the data I have?

• Have you looked at the tutorial for Mathematica's ANOVA package? Maybe you could start from there and narrow down your questions. Commented Jun 29, 2015 at 0:32
• @MarcoB Yes, I have. It doesn't really give me the answer I'm looking for. It says the data must be of a certain form, but it doesn't say anything about other forms of data. So I asked here. I was hoping there might be a way of doing it with the kind of data I have. Commented Jun 29, 2015 at 1:28
• @MarcoB You don't have data, you have summary statistics. Commented Jun 29, 2015 at 9:26
• @Cristopher I'm after the same info, and I'm keeping a eye on this one. Excel has the same test and I would like to see if the answer in excel is the same as MMA, thanks for bring this one up Commented Jun 29, 2015 at 14:15

## 1 Answer

If a model with a common variance is appropriate and you are able to (rather than just willing to) ignore any examination of goodness-of-fit, then the following can give you the basic ANOVA elements:

(* Give data *)
n = {10, 7, 11};
xbar = {2.8, 2.6, 3.1};
s2 = {3.2, 2.9, 3.3};

(* Calculate ANOVA terms *)
errorSS = N[Total[s2 (n - 1)]]
(* 79.2 *)
errorMS = errorSS/Total[n - 1]
(* 3.168 *)
errorDF = Total[n - 1]
(* 25 *)
totalSS = N[Total[s2 (n - 1) + n xbar^2] - Total[n xbar]^2/Total[n]]
(* 80.3411 *)
modelDF = Length[xbar] - 1
(* 2 *)
modelSS = totalSS - errorSS
(* 1.14107 *)
modelMS = modelSS/modelDF
(* 0.570536 *)
fRatio = modelMS/errorMS
(* 0.180093 *)
pValue = 1 - CDF[FRatioDistribution[modelDF, errorDF], fRatio]
(* 0.163734 *)


And if you're in the medical field, I hope you're not just using a P-value to make decisions - but that's a whole other topic.

• "…if you're in the medical field, I hope you're not just using a $p$-value to make decisions…" - speaking of which… Commented Jul 15, 2015 at 19:28
• @Guess who it is. Thanks! Excellent article. The use of P-values can be a good tool. But the widespread misuse is the problem. (And, of course, it doesn't just apply to the medical field.)
– JimB
Commented Jul 15, 2015 at 19:34
• I know it's a great tool, but it has the unfortunate effect of making otherwise reasonable people sloppy. :( Commented Jul 15, 2015 at 19:38
• I had lost hope that someone would ever answer this, but I'm glad you did. The solution you propose may not be completely automatic, but it's very good. Thank you! :) Commented Jul 15, 2015 at 22:59
• The steps could easily be made into a single function.
– JimB
Commented Jul 16, 2015 at 0:32