My goal is to drive $E(MSA)$ for this design(the 1-way ANOVA); $$y_{ij}=\mu +\alpha_i + \epsilon_{ij}$$for i=1,2,...,a (that is, there are a groups)and j=1,2,...,n. $\epsilon_{ij}$ and $\alpha_i$ are random as follows;$$E(\alpha_i)=0, E(\epsilon_{ij})=0$$ $$var(\alpha_i)=\sigma_{\alpha}^2, var(\epsilon_{ij})=\sigma_{\epsilon}^2 $$and all the covariances are zero.

The answer shoud be $E(MSA)=n\sigma_{\alpha}^2+\sigma_{\epsilon}^2$.Could I let mathematica derive the answer? I have tried inputting as below naively, but I couldn't get the answer.

    Subscript[y, i] = (*definition for average value yi for each group i*)
      Sum[Subscript[y, i, j], 
        {j, 1, n}]/n
     Subscript[y] =  (*definition for average of all yij*)
      Sum[Subscript[y, i, j], 
        {i, 1, a}, {j, 1, n}]/
Expectation[(n/(a - 1))*
   Sum[(Subscript[y, i] - 
    {i, 1, a}], 
     i], NormalDistribution[
     0, Subscript[\[Sigma], \[Alpha]]]], 
     Subscript[\[Sigma], \[Epsilon]]]]}]

  • 3
    $\begingroup$ Please include all other definitions in your code, e.g. $y_i$ etc. Also see: How to copy code from Mathematica so it looks good on this site. $\endgroup$
    – MarcoB
    Commented Jun 6, 2023 at 13:50
  • 1
    $\begingroup$ Either your definition of $MSA$ or $E(MSA)$ is wrong. As evidence for that consider $a=1$. Then Sum[(Subscript[y, i] - Subscript[y])^2, {i, 1, a}] is identically 0 and $n \sigma_\alpha^2+\sigma^2$ can't be zero. Also, you should use indexed variables rather than Subscript. See mathematica.stackexchange.com/questions/245319/…. $\endgroup$
    – JimB
    Commented Jun 6, 2023 at 17:13
  • 1
    $\begingroup$ I suspect you want to multiply Sum[(Subscript[y, i] - Subscript[y])^2, {i, 1, a}] by n/(a - 1). $\endgroup$
    – JimB
    Commented Jun 6, 2023 at 17:29

1 Answer 1


Here are three approaches that work for specified values of a and n:

For the first two approaches perform the following:

a = 6;
n = 7;
y = Table[μ + α[i] + ϵ[i, j], {j, 1, n}, {i, 1, a}];
overallMean = Total[Total[y]]/(n a);
groupMean = Total[y]/n;
msa = (n/(a - 1)) Sum[(groupMean[[i]] - overallMean)^2, {i, 1, a}] // Expand;

Approach 1: Using TransformedDistribution

dist = TransformedDistribution[msa, Flatten[{
  Table[α[i] \[Distributed] NormalDistribution[0, σα], {i, 1, a}], 
  Table[ϵ[i, j] \[Distributed] NormalDistribution[0, σ], {i, 1, a}, {j, 1, n}]}]];
Mean[dist] // Expand
(* σ^2 + 7 σα^2 *)

Approach 2: Using substitution.

Emsa = msa /. {α[i_]^2 -> σα^2, α[i1_] α[i2_] -> 0, ϵ[i_, j_]^2 -> σ^2, 
  α[i1_] ϵ[i2_, j_] -> 0, ϵ[i1_, j1_] ϵ[i2_, j2_] -> 0}
(* σ^2 + 7 σα^2 *)

Approach 3: Knowledge of distribution of sample group means

If it is recognized that the sample group means all have a mean of $\mu$ and variance $\sigma_\alpha^2+\sigma^2/n$, then one can use the following:

msa = (n/(a - 1)) Sum[(ybar[i] - Sum[ybar[j], {j, 1, a}]/a)^2, {i, 1,  a}]
Emsa = (msa // Expand) /. ybar[i_]^2 -> σα^2 + σ^2/n + μ^2 /. ybar[i_] -> μ // Expand
(* σ^2 + n σα^2 *)

With this 3rd approach we get the general result when giving a specific value of $a$.

Maybe someone else knows how to do this in a more general way.

  • 1
    $\begingroup$ Thanks for the accept but you might want to wait a day or two before accepting an answer because someone might give the general answer (and I'd certainly like to see that, too). $\endgroup$
    – JimB
    Commented Jun 7, 2023 at 15:34

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.