2
$\begingroup$

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?

$\endgroup$
4
  • 2
    $\begingroup$ Have you looked at the tutorial for Mathematica's ANOVA package? Maybe you could start from there and narrow down your questions. $\endgroup$
    – MarcoB
    Commented Jun 29, 2015 at 0:32
  • $\begingroup$ @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. $\endgroup$
    – Cristopher
    Commented Jun 29, 2015 at 1:28
  • $\begingroup$ @MarcoB You don't have data, you have summary statistics. $\endgroup$ Commented Jun 29, 2015 at 9:26
  • $\begingroup$ @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 $\endgroup$
    – Bob Brooks
    Commented Jun 29, 2015 at 14:15

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
5
  • 2
    $\begingroup$ "…if you're in the medical field, I hope you're not just using a $p$-value to make decisions…" - speaking of which… $\endgroup$ Commented Jul 15, 2015 at 19:28
  • $\begingroup$ @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.) $\endgroup$
    – JimB
    Commented Jul 15, 2015 at 19:34
  • $\begingroup$ I know it's a great tool, but it has the unfortunate effect of making otherwise reasonable people sloppy. :( $\endgroup$ Commented Jul 15, 2015 at 19:38
  • $\begingroup$ 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! :) $\endgroup$
    – Cristopher
    Commented Jul 15, 2015 at 22:59
  • $\begingroup$ The steps could easily be made into a single function. $\endgroup$
    – JimB
    Commented Jul 16, 2015 at 0:32

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.