# Two-Way ANOVA calculation using summary data (mean, SD, sample size)

I want to perform a two-way ANOVA using the groups' means, standard deviations, and sizes. There is this website but just for one-way ANOVA. Also there are R packages and other programs that can do one-way ANOVA from summary data. However, I do not know any packages, macros, programs, or codes that can perform a two-way ANOVA from summary data.

If you know one, please guide me. If not, please guide me to make an R package for it.

Well, if it's a one-off you can always do the calculation "by hand" (in R or any other suitable calculation tool) -- it's not hard to find the formulas for a two-way ANOVA and rewrite those in terms of summary statistics.

However, I'm going to suggest simple simulation. Since the answers can in-principle be obtained from suitable summary statistics, simply construct samples of the appropriate sizes that exactly reproduce the summary statistics (this is relatively straightforward and is addressed in a couple of questions on site). You do this individually for each cell of your two-way table. You can then call any function that can do the calculation.

To make the answer generically useful I'll describe the approach in general terms first.

A basic algorithm for a given cell with known mean $m$ and standard deviation $s$ and cell-sample-size $n$ is:

1. generate a normal sample of size n

2. standardize it to z-scores, $z_i$, $i=1,2,...,n$

3. compute $y_i=m+s\,z_i$

Repeat for every cell, and you're done. This works as long as $n>1$ in every cell.

In R, step 1 would use rnorm, step 2 would use scale and step 3 is straight calculation, operating inside a double loop to fill out the full data and row/column group vectors, though there are ways to avoid loops if you have gigantic numbers of cells.

If you have the summary statistics (sample mean, sample standard deviation, and sample size), you should be able to reconstruct the ANOVA table directly without simulation.

There is a 1:1 relationship between $SS$ and $s$: $$s = \sqrt{s^2} = \sqrt{\frac{SS}{n-1}}$$ Therefore: $$SS_A=s_A^2\left(n_A-1\right)$$ $$SS_B=s_B^2\left(n_B-1\right)$$ $$SS_{AB}=s_{AB}^2\left(n_{AB}-1\right)$$

If you do not already have $s_{AB}$, I believe that $s_{pooled}$ would provide an acceptable alternative, which is defined based upon a series of samples, $s^2_i$, the $i$th sample variance, and $n_i$, the $i$th sample size (which does not need to be constant): $$s_{pooled}=\sqrt{\frac{\sum^m_{i=1} \left (n_i-1 \right )s^2_i}{\sum^m_{i=1}\left ( n_i-1 \right )}}$$

In doing some additional research, I found this web page which claims to conduct 2-way ANOVAS from summary data:

http://vassarstats.net/anova2u.html

This presentation discusses the method for using summary data to create a 2-way ANOVA:

www.stat.ufl.edu/~winner/cases/ethicgen.ppt

This paper discusses the math and then proposes a STATA macro to perform a 2-way ANOVA from summary data: https://www.pjsor.com/index.php/pjsor/article/download/87/64

In addition, https://www.google.com/#safe=active&q=%222-way+ANOVA+from+summary+data%22 yields a large number of answers to this question on multiple platforms. (It is interesting to note that your question is the only result if you keep the quotes but spell out "Two-way.")