1. Home
  2. Explore
  3. Statistics
  4. One-Way and Two-Way ANOVA

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

One-Way and Two-Way ANOVA

ANOVA, Correlation, and Regression Significance Tests

Why ANOVA is used

When a study compares more than two group means, performing repeated pairwise ttt-tests increases the chance of a false-positive result. For example, comparing four groups requires six pairwise tests. If each test has a false-positive risk of 5%5\%5%, the approximate chance of at least one false alarm is

1−(1−0.05)6≈0.265,1-(1-0.05)^6 \approx 0.265,1−(1−0.05)6≈0.265,

or about 26%26\%26% under the simplifying assumption that the tests are independent. The tests are not generally independent, but the example illustrates how repeated testing inflates error risk.

Analysis of variance (ANOVA) tests whether several population means are equal in a single overall test. It does this by comparing variation among the group means with variation among observations within the groups.

ANOVA asks whether the means scatter more than the noise within the groups can explain.

A significant ANOVA result establishes that at least one mean differs; it does not identify which specific groups differ. If the overall test is significant and the particular differences matter, a post-hoc procedure such as Tukey’s test can compare pairs while controlling the multiple-comparison error rate.


One-way ANOVA

Purpose and hypotheses

One-way ANOVA examines one factor at several levels. Examples include comparing:

  • Several formulations

  • Different dose levels

  • Multiple storage conditions

  • Different machines or analysts

For kkk groups, the hypotheses are:

  • Null hypothesis: H0:μ1=μ2=⋯=μkH_0: \mu_1=\mu_2=\cdots=\mu_kH0​:μ1​=μ2​=⋯=μk​.

  • Alternative hypothesis: H1:H_1:H1​: at least one population mean differs from the others.

The alternative does not claim that every mean differs.

Assumptions

One-way ANOVA assumes that:

  • Observations are selected randomly and are independent.

  • Each group’s population is approximately normally distributed.

  • The group populations have approximately equal variances (homogeneity of variance).

How variation is partitioned

Let NNN be the total number of observations, kkk the number of groups, nin_ini​ the number of observations in group iii, xˉi\bar{x}_ixˉi​ the mean of group iii, and xˉ\bar{x}xˉ the grand mean of all observations.

The total variation around the grand mean is the total sum of squares, SSTSSTSST. It partitions exactly into between-group and within-group variation:

SST=SSB+SSW.SST=SSB+SSW.SST=SSB+SSW.
  • Between-group sum of squares, SSBSSBSSB: variation of group means around the grand mean. It reflects differences among the groups as well as random variation.

    SSB=∑i=1kni(xˉi−xˉ)2SSB=\sum_{i=1}^{k} n_i(\bar{x}_i-\bar{x})^2SSB=∑i=1k​ni​(xˉi​−xˉ)2
  • Within-group sum of squares, SSWSSWSSW: variation of individual observations around their own group means. It estimates background or error variation.

    SSW=∑i=1k∑j=1ni(xij−xˉi)2SSW=\sum_{i=1}^{k}\sum_{j=1}^{n_i}(x_{ij}-\bar{x}_i)^2SSW=∑i=1k​∑j=1ni​​(xij​−xˉi​)2
  • Total sum of squares, SSTSSTSST: variation of every observation around the grand mean.

    SST=∑i=1k∑j=1ni(xij−xˉ)2SST=\sum_{i=1}^{k}\sum_{j=1}^{n_i}(x_{ij}-\bar{x})^2SST=∑i=1k​∑j=1ni​​(xij​−xˉ)2

Under the null hypothesis, between-group variation and within-group variation estimate the same underlying variance. If the means genuinely differ, between-group variation is inflated.

Degrees of freedom, mean squares, and the FFF statistic

For kkk groups and NNN observations:

  • Between groups: dfB=k−1df_B=k-1dfB​=k−1

  • Within groups: dfW=N−kdf_W=N-kdfW​=N−k

  • Total: dfT=N−1df_T=N-1dfT​=N−1

The degrees of freedom add up:

N−1=(k−1)+(N−k).N-1=(k-1)+(N-k).N−1=(k−1)+(N−k).

Dividing each sum of squares by its degrees of freedom gives a mean square:

MSB=SSBk−1,MSW=SSWN−k.MSB=\frac{SSB}{k-1}, \qquad MSW=\frac{SSW}{N-k}.MSB=k−1SSB​,MSW=N−kSSW​.

The test statistic is:

F=MSBMSW.F=\frac{MSB}{MSW}.F=MSWMSB​.

When the null hypothesis is true, FFF tends to be near 111. A sufficiently large value indicates that the differences among the means are too large to be readily explained by within-group variation.

One-way ANOVA procedure

  1. State H0H_0H0​ and H1H_1H1​.

  2. Choose the significance level, commonly α=0.05\alpha=0.05α=0.05.

  3. Calculate each group mean and the grand mean.

  4. Calculate SSBSSBSSB and SSWSSWSSW.

  5. Check that SST=SSB+SSWSST=SSB+SSWSST=SSB+SSW.

  6. Calculate the degrees of freedom and mean squares, then form the ANOVA table.

  7. Find the critical table value using numerator degrees of freedom k−1k-1k−1 and denominator degrees of freedom N−kN-kN−k.

  8. Reject H0H_0H0​ if the calculated FFF exceeds the critical value; state the conclusion in context.

A complete one-way ANOVA table contains:

  • Between groups: SSBSSBSSB, k−1k-1k−1 degrees of freedom, and MSB=SSB/(k−1)MSB=SSB/(k-1)MSB=SSB/(k−1).

  • Within groups (error): SSWSSWSSW, N−kN-kN−k degrees of freedom, and MSW=SSW/(N−k)MSW=SSW/(N-k)MSW=SSW/(N−k).

  • Total: SSTSSTSST and N−1N-1N−1 degrees of freedom.

The FFF ratio uses only the between-groups and within-groups rows. Two useful checks are SST=SSB+SSWSST=SSB+SSWSST=SSB+SSW and N−1=(k−1)+(N−k)N-1=(k-1)+(N-k)N−1=(k−1)+(N−k).

Worked example: disintegration times

Four tablets from each of three formulations have the following disintegration times, in minutes:

  • Formulation A: 8,9,7,88, 9, 7, 88,9,7,8

  • Formulation B: 10,11,9,1010, 11, 9, 1010,11,9,10

  • Formulation C: 12,13,11,1212, 13, 11, 1212,13,11,12

Test whether their mean disintegration times differ at the 5%5\%5% significance level.

The hypotheses are H0:μA=μB=μCH_0:\mu_A=\mu_B=\mu_CH0​:μA​=μB​=μC​ and H1:H_1:H1​: at least one mean differs.

The group means are:

xˉA=8,xˉB=10,xˉC=12.\bar{x}_A=8,\qquad \bar{x}_B=10,\qquad \bar{x}_C=12.xˉA​=8,xˉB​=10,xˉC​=12.

The total of all observations is 120120120, so the grand mean is xˉ=120/12=10\bar{x}=120/12=10xˉ=120/12=10.

The between-group sum of squares is:

SSB=4[(8−10)2+(10−10)2+(12−10)2]=32.SSB=4[(8-10)^2+(10-10)^2+(12-10)^2]=32.SSB=4[(8−10)2+(10−10)2+(12−10)2]=32.

For each group, the squared deviations from its own mean sum to 222. Therefore:

SSW=2+2+2=6.SSW=2+2+2=6.SSW=2+2+2=6.

The total sum of squares is SST=38SST=38SST=38, and the partition check holds:

SSB+SSW=32+6=38.SSB+SSW=32+6=38.SSB+SSW=32+6=38.

The ANOVA results are:

  • Between groups: SS=32SS=32SS=32, df=2df=2df=2, MS=32/2=16MS=32/2=16MS=32/2=16.

  • Within groups: SS=6SS=6SS=6, df=9df=9df=9, MS=6/9≈0.667MS=6/9\approx0.667MS=6/9≈0.667.

  • Total: SS=38SS=38SS=38, df=11df=11df=11.

Thus,

F=160.667≈24.0.F=\frac{16}{0.667}\approx24.0.F=0.66716​≈24.0.

For df=(2,9)df=(2,9)df=(2,9) at the 5%5\%5% level, the critical value is 4.264.264.26. Since 24.0>4.2624.0>4.2624.0>4.26, H0H_0H0​ is rejected. The formulations differ significantly in mean disintegration time. Their sample means indicate that formulation A disintegrates fastest and formulation C slowest.

The overall ANOVA does not establish which individual pairs differ; that requires an appropriate post-hoc test.


Two-way ANOVA

Purpose and factors

Two-way ANOVA studies two factors in one experiment. For example, a stability study might examine:

  • Factor A: formulation

  • Factor B: storage temperature

This approach can estimate the effects of both factors using one experiment. With replicated observations in each factor combination, it can also test whether the effect of one factor depends on the level of the other. This dependence is called an interaction.

For a replicated design, total variation is partitioned as:

SST=SSA+SSB+SSAB+SSE,SST=SSA+SSB+SSAB+SSE,SST=SSA+SSB+SSAB+SSE,

where SSASSASSA and SSBSSBSSB represent the two factor effects, SSABSSABSSAB represents interaction, and SSESSESSE represents residual error.

Two-way ANOVA with one observation per combination

With only one observation for each combination of factor levels, a separate interaction estimate cannot be obtained. The variation left after accounting for the two factor effects serves as error:

SST=SSA+SSB+SSE.SST=SSA+SSB+SSE.SST=SSA+SSB+SSE.

In this unreplicated case, interaction cannot be separated from residual error. The factor effects are tested with separate FFF ratios:

FA=MSAMSE,FB=MSBMSE.F_A=\frac{MS_A}{MS_E}, \qquad F_B=\frac{MS_B}{MS_E}.FA​=MSE​MSA​​,FB​=MSE​MSB​​.

Degrees of freedom in an unreplicated design

For aaa levels of one factor and bbb levels of the other:

  • Factor A: a−1a-1a−1

  • Factor B: b−1b-1b−1

  • Error: (a−1)(b−1)(a-1)(b-1)(a−1)(b−1)

  • Total: ab−1ab-1ab−1

For three machines and four operators, the degrees of freedom are:

  • Machines: 3−1=23-1=23−1=2

  • Operators: 4−1=34-1=34−1=3

  • Error: (3−1)(4−1)=6(3-1)(4-1)=6(3−1)(4−1)=6

  • Total: 3(4)−1=113(4)-1=113(4)−1=11

With one observation per machine–operator combination, interaction is included in the error term and cannot be tested separately.

Worked example: formulation and storage temperature

The assay results, as a percentage of label claim, are:

  • Formulation A: 969696 at 25∘C25^\circ\mathrm{C}25∘C, 939393 at 40∘C40^\circ\mathrm{C}40∘C, and 878787 at 60∘C60^\circ\mathrm{C}60∘C

  • Formulation B: 919191 at 25∘C25^\circ\mathrm{C}25∘C, 888888 at 40∘C40^\circ\mathrm{C}40∘C, and 858585 at 60∘C60^\circ\mathrm{C}60∘C

  • Formulation C: 898989 at 25∘C25^\circ\mathrm{C}25∘C, 838383 at 40∘C40^\circ\mathrm{C}40∘C, and 808080 at 60∘C60^\circ\mathrm{C}60∘C

There is one determination for each formulation–temperature combination.

The row means for formulations A, B, and C are 929292, 888888, and 848484. The column means for 25∘C25^\circ\mathrm{C}25∘C, 40∘C40^\circ\mathrm{C}40∘C, and 60∘C60^\circ\mathrm{C}60∘C are also 929292, 888888, and 848484. The grand mean is 888888.

For formulations:

SSA=3[(92−88)2+(88−88)2+(84−88)2]=96.SSA=3[(92-88)^2+(88-88)^2+(84-88)^2]=96.SSA=3[(92−88)2+(88−88)2+(84−88)2]=96.

For temperatures:

SSB=3[(92−88)2+(88−88)2+(84−88)2]=96.SSB=3[(92-88)^2+(88-88)^2+(84-88)^2]=96.SSB=3[(92−88)2+(88−88)2+(84−88)2]=96.

The total sum of squares is SST=198SST=198SST=198, so:

SSE=198−96−96=6.SSE=198-96-96=6.SSE=198−96−96=6.

The ANOVA results are:

  • Formulations: SS=96SS=96SS=96, df=2df=2df=2, MS=48MS=48MS=48, F=48/1.5=32.0F=48/1.5=32.0F=48/1.5=32.0.

  • Temperatures: SS=96SS=96SS=96, df=2df=2df=2, MS=48MS=48MS=48, F=48/1.5=32.0F=48/1.5=32.0F=48/1.5=32.0.

  • Error: SS=6SS=6SS=6, df=4df=4df=4, MS=1.5MS=1.5MS=1.5.

  • Total: SS=198SS=198SS=198, df=8df=8df=8.

For each factor, the critical value at df=(2,4)df=(2,4)df=(2,4) and the 5%5\%5% level is 6.946.946.94. Both calculated values, F=32.0F=32.0F=32.0, exceed the critical value. Both formulation and temperature significantly affect assay. The observed pattern shows assay falling as temperature rises, while formulation A has the highest assay at each temperature.

Each factor requires its own stated FFF decision and conclusion.


The FFF distribution and decisions

The FFF distribution describes the ratio of two variance estimates. Because a variance cannot be negative, FFF cannot be negative. Its distribution is right-skewed, begins at zero, and extends into a long right-hand tail.

An FFF distribution is determined by two degrees of freedom:

  • Numerator degrees of freedom: those of the mean square in the numerator, such as MSBMSBMSB.

  • Denominator degrees of freedom: those of the error mean square in the denominator.

The FFF table is entered with the numerator degrees of freedom first, followed by the denominator degrees of freedom. For example:

  • In the three-formulation one-way problem, df=(2,9)df=(2,9)df=(2,9) and the 5%5\%5% critical value is 4.264.264.26.

  • In the two-way stability problem, each factor has df=(2,4)df=(2,4)df=(2,4) and the 5%5\%5% critical value is 6.946.946.94.

The critical value increases when error degrees of freedom decrease because an error variance estimated from fewer observations is more uncertain. Stronger evidence is then required to reject the null hypothesis.

Results should report both degrees of freedom, for example, F(2,9)=24.0F(2,9)=24.0F(2,9)=24.0. A bare FFF value cannot be checked against the correct table entry.

Relationship between ANOVA and the ttt-test

When a one-way ANOVA compares exactly two independent groups, its test is equivalent to the corresponding pooled-variance two-sample ttt-test:

F=t2.F=t^2.F=t2.

The ANOVA numerator degrees of freedom are 111, and its denominator degrees of freedom equal those of the pooled two-sample ttt-test. Because FFF is the square of ttt, the test statistic is nonnegative, but the tests lead to the same decision when used for the same comparison.

Statistical significance and practical importance

A significant FFF indicates evidence that means differ; it does not establish that the difference is large enough to matter in practice. After a significant result, an investigator should consider:

  • Which means differ, using a suitable post-hoc test where appropriate

  • Whether assumptions appear reasonable, including through examination of residuals

  • Whether the size of the difference matters for the pharmaceutical application

Statistical significance and practical importance are related but separate questions.


Testing the significance of a correlation coefficient

A sample correlation can appear large but still be consistent with chance, especially when there are few observations. To test whether the population correlation is zero, use:

  • Null hypothesis: H0:ρ=0H_0:\rho=0H0​:ρ=0.

  • Alternative hypothesis: H1:ρ≠0H_1:\rho\ne0H1​:ρ=0 for a two-sided test.

For sample correlation coefficient rrr and nnn pairs of observations:

t=rn−21−r2,df=n−2.t=\frac{r\sqrt{n-2}}{\sqrt{1-r^2}}, \qquad df=n-2.t=1−r2​rn−2​​,df=n−2.

The calculated ttt is compared with the critical ttt value for n−2n-2n−2 degrees of freedom and the chosen significance level.

Worked example: dissolution and bioavailability

A study of 121212 formulations gives r=0.85r=0.85r=0.85. Then df=12−2=10df=12-2=10df=12−2=10, and:

t=0.85101−0.852=0.85101−0.7225≈5.10.t=\frac{0.85\sqrt{10}}{\sqrt{1-0.85^2}} =\frac{0.85\sqrt{10}}{\sqrt{1-0.7225}} \approx5.10.t=1−0.852​0.8510​​=1−0.7225​0.8510​​≈5.10.

The 5%5\%5% critical value at 101010 degrees of freedom is 2.2282.2282.228. Because 5.10>2.2285.10>2.2285.10>2.228, H0H_0H0​ is rejected. The correlation is statistically significant, supporting an in vitro–in vivo relationship in this example.

A correlation should not be reported as evidence of a relationship without considering its significance, particularly when the sample size is small.


Testing the significance of a regression slope

For a simple linear regression, the slope measures the expected change in the response for a one-unit change in the predictor. To test whether there is no linear relationship:

  • Null hypothesis: H0:β=0H_0:\beta=0H0​:β=0.

  • Alternative hypothesis: H1:β≠0H_1:\beta\ne0H1​:β=0.

For estimated slope bbb and its standard error SE(b)SE(b)SE(b):

t=bSE(b),df=n−2.t=\frac{b}{SE(b)}, \qquad df=n-2.t=SE(b)b​,df=n−2.

A slope significantly different from zero indicates evidence of a linear relationship between predictor and response.

Worked example: calibration regression

A regression based on 121212 points gives b=1.85b=1.85b=1.85 and SE(b)=0.37SE(b)=0.37SE(b)=0.37. The test statistic is:

t=1.850.37=5.00.t=\frac{1.85}{0.37}=5.00.t=0.371.85​=5.00.

At 101010 degrees of freedom, the 5%5\%5% critical value is 2.2282.2282.228. Since 5.00>2.2285.00>2.2285.00>2.228, the slope is significantly different from zero.

Connection among correlation, slope, and regression ANOVA

In simple linear regression, the test of the slope and the test of the correlation are two forms of the same test. When calculated from the same data, their ttt statistics agree, apart from rounding. The overall regression can also be tested with an FFF test in a regression ANOVA table, using the same general comparison of mean squares described for ANOVA.

An intercept can also be tested against a specified hypothesised value using its estimate and standard error.


Practice problems: worked answers

Four tablet presses

Four tablet presses each contribute five tablets. The analysis gives SSB=40SSB=40SSB=40 with 333 degrees of freedom and SSW=60SSW=60SSW=60 with 161616 degrees of freedom.

  • Between-groups mean square: MSB=40/3≈13.33MSB=40/3\approx13.33MSB=40/3≈13.33.

  • Within-groups mean square: MSW=60/16=3.75MSW=60/16=3.75MSW=60/16=3.75.

  • Test statistic: F=13.33/3.75≈3.56F=13.33/3.75\approx3.56F=13.33/3.75≈3.56.

  • Degrees of freedom: F(3,16)F(3,16)F(3,16).

  • Critical value at 5%5\%5%: 3.243.243.24.

Because 3.56>3.243.56>3.243.56>3.24, the null hypothesis that all four press means are equal is rejected at the 5%5\%5% level.

Five brands of a drug

For five brands:

  • Null hypothesis: H0:μ1=μ2=μ3=μ4=μ5H_0:\mu_1=\mu_2=\mu_3=\mu_4=\mu_5H0​:μ1​=μ2​=μ3​=μ4​=μ5​.

  • Alternative hypothesis: H1:H_1:H1​: at least one brand mean differs.

  • The number of pairwise comparisons is (52)=10\binom{5}{2}=10(25​)=10.

Repeated pairwise ttt-tests are not preferred because each test adds to the overall false-positive risk. ANOVA first tests all five means in one overall test.

Correlation based on ten pairs

For n=10n=10n=10 and r=0.62r=0.62r=0.62:

  • The test is H0:ρ=0H_0:\rho=0H0​:ρ=0 versus H1:ρ≠0H_1:\rho\ne0H1​:ρ=0.

  • The statistic is t=rn−2/1−r2t=r\sqrt{n-2}/\sqrt{1-r^2}t=rn−2​/1−r2​.

  • The degrees of freedom are df=8df=8df=8.

  • The given 5%5\%5% critical value is 2.3062.3062.306.

The calculated statistic is:

t=0.6281−0.622≈2.24.t=\frac{0.62\sqrt{8}}{\sqrt{1-0.62^2}}\approx2.24.t=1−0.622​0.628​​≈2.24.

Since 2.24<2.3062.24<2.3062.24<2.306, the correlation is not significant at the 5%5\%5% level using the given critical value.

Two-way ANOVA for machines and operators

For three machines and four operators with one observation per combination:

  • Machines: 222 degrees of freedom

  • Operators: 333 degrees of freedom

  • Error: 666 degrees of freedom

  • Total: 111111 degrees of freedom

Because there is only one observation in each combination, the interaction cannot be separated from error.

Two-group ANOVA and F=t2F=t^2F=t2

If the corresponding two-sample ttt statistic is t=2.92t=2.92t=2.92, then:

F=t2=(2.92)2=8.5264≈8.53.F=t^2=(2.92)^2=8.5264\approx8.53.F=t2=(2.92)2=8.5264≈8.53.

For a one-way ANOVA comparing two independent groups, the numerator degrees of freedom are 111 and the denominator degrees of freedom are the pooled ttt-test degrees of freedom, N−2N-2N−2 for NNN total observations.


Key ideas to retain

  • One-way ANOVA compares several means for one factor; two-way ANOVA examines two factors in one experiment.

  • One-way total variation partitions as SST=SSB+SSWSST=SSB+SSWSST=SSB+SSW.

  • Two-way ANOVA with replicated combinations can distinguish factor effects, interaction, and error. With one observation per combination, interaction cannot be estimated separately.

  • The FFF statistic compares a factor or between-groups mean square with an error mean square.

  • For exactly two independent groups, the equivalent one-way ANOVA gives F=t2F=t^2F=t2.

  • Correlation is tested using t=rn−2/1−r2t=r\sqrt{n-2}/\sqrt{1-r^2}t=rn−2​/1−r2​, and a regression slope is tested using t=b/SE(b)t=b/SE(b)t=b/SE(b); both use n−2n-2n−2 degrees of freedom in simple linear regression.

  • A significant overall test indicates evidence of a difference or relationship, but does not by itself establish which groups differ or whether the effect is practically important.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent