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, the F Distribution, and Tests of Correlation and Regression

Why ANOVA is needed

When a study compares only two group means, a t-test is often appropriate. But pharmaceutical studies commonly compare several formulations, storage conditions, doses, or analysts. Repeating t-tests for every pair is a poor solution: each test creates another opportunity to report a difference that is actually due to chance.

For four groups, there are six possible pairs to compare. If each test uses a false-positive risk of 5%5\%5%, the combined risk can reach about 26%26\%26% under a simple independence approximation. The tests are not necessarily independent, but the example shows why repeated pairwise testing inflates the chance of a false alarm.

Analysis of variance, or ANOVA, addresses this problem by testing several means together in a single overall test. Rather than asking whether each pair differs, it asks whether the observed differences among the means are too large to be explained by ordinary variation within the groups.

ANOVA tests whether the group means scatter more than the variation within the groups can reasonably explain.

Think About It: If tablet measurements vary even when all tablets come from the same formulation, why might small differences among formulation means not prove that the formulations truly differ?

The central idea: separating two kinds of variation

Imagine that three formulations have slightly different average disintegration times. There are two possible explanations:

  1. The formulations genuinely differ.
  2. The observed differences among their averages arise from the natural variation between individual tablets.

ANOVA measures both kinds of variation so that they can be compared.

  • Within-group variation describes how much observations from the same group differ from their group mean. It estimates background or random variation.
  • Between-group variation describes how much the group means differ from the overall, or grand, mean.

If all population means are equal, both kinds of variation estimate the same underlying noise. Their ratio should usually be near 111. If group means are genuinely separated, between-group variation tends to be larger, making the ratio increase.

The total variation in all observations around the grand mean divides exactly into between-group and within-group variation:

SStotal=SSbetween+SSwithinSS_{\text{total}} = SS_{\text{between}} + SS_{\text{within}}SStotal​=SSbetween​+SSwithin​

The source commonly labels these quantities SSTSSTSST, SSBSSBSSB, and SSWSSWSSW, respectively. The equality holds whether or not the group means truly differ.

For kkk groups and NNN total observations, the degrees of freedom are:

dfbetween=k−1df_{\text{between}} = k - 1dfbetween​=k−1 dfwithin=N−kdf_{\text{within}} = N - kdfwithin​=N−k dftotal=N−1df_{\text{total}} = N - 1dftotal​=N−1

These degrees of freedom also partition consistently:

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

A mean square is a sum of squares divided by its degrees of freedom:

MSbetween=SSbetweenk−1MS_{\text{between}} = \frac{SS_{\text{between}}}{k - 1}MSbetween​=k−1SSbetween​​ MSwithin=SSwithinN−kMS_{\text{within}} = \frac{SS_{\text{within}}}{N - k}MSwithin​=N−kSSwithin​​

The ANOVA test statistic is the ratio of these two estimates:

F=MSbetweenMSwithinF = \frac{MS_{\text{between}}}{MS_{\text{within}}}F=MSwithin​MSbetween​​

A value near 111 is consistent with the null hypothesis. A sufficiently large value suggests that between-group differences are too large to be explained by within-group variation alone.

Hypotheses and assumptions

For a comparison of kkk group means, the hypotheses are:

H0:μ1=μ2=⋯=μkH_0: \mu_1 = \mu_2 = \cdots = \mu_kH0​:μ1​=μ2​=⋯=μk​ H1:at least one population mean differs from the othersH_1: \text{at least one population mean differs from the others}H1​:at least one population mean differs from the others

The alternative does not state that every mean differs from every other mean. It requires only that at least one mean is different.

The standard assumptions are:

  • Observations are independent and randomly obtained.
  • Each population is approximately normal.
  • The group variances are approximately equal, a condition called homogeneity of variance.

Think About It: Why does ANOVA compare a measure of variation between groups with a measure of variation within groups, rather than simply comparing the largest and smallest means?

One-way ANOVA

One-way ANOVA examines one factor at several levels. For example, formulation could be the single factor, with formulations A, B, and C as its levels. Other possible factors include dose level or storage condition.

Procedure

A standard one-way ANOVA follows these steps:

  1. State the null and alternative hypotheses.
  2. Choose a significance level, commonly α=0.05\alpha = 0.05α=0.05.
  3. Find each group mean and the grand mean of all observations.
  4. Calculate the between-group and within-group sums of squares.
  5. Check that their sum equals the total sum of squares.
  6. Construct the ANOVA table and calculate the FFF statistic.
  7. Compare the calculated FFF value with the table value for the appropriate degrees of freedom, then state the conclusion in context.

If group iii has nin_ini​ observations and mean xˉi\bar{x}_ixˉi​, and the grand mean is xˉ\bar{x}xˉ, then:

SSbetween=∑i=1kni(xˉi−xˉ)2SS_{\text{between}} = \sum_{i=1}^{k} n_i(\bar{x}_i - \bar{x})^2SSbetween​=i=1∑k​ni​(xˉi​−xˉ)2

The within-group sum of squares adds the squared deviations of each observation from its own group mean:

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

The total sum of squares is the sum of squared deviations of all observations from the grand mean:

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

The calculation should satisfy:

SStotal=SSbetween+SSwithinSS_{\text{total}} = SS_{\text{between}} + SS_{\text{within}}SStotal​=SSbetween​+SSwithin​

This equality and the matching degrees of freedom are valuable arithmetic checks. If either fails, the calculations need to be reviewed before drawing a conclusion.

The one-way ANOVA table

Source of variationSum of squaresDegrees of freedomMean squareTest statistic
Between groupsSSbetweenSS_{\text{between}}SSbetween​k−1k-1k−1SSbetweenk−1\frac{SS_{\text{between}}}{k-1}k−1SSbetween​​F=MSbetweenMSwithinF=\frac{MS_{\text{between}}}{MS_{\text{within}}}F=MSwithin​MSbetween​​
Within groups (Error)SSwithinSS_{\text{within}}SSwithin​N−kN-kN−kSSwithinN−k\frac{SS_{\text{within}}}{N-k}N−kSSwithin​​—
TotalSStotalSS_{\text{total}}SStotal​N−1N-1N−1——

The FFF ratio uses the mean squares from the first two rows only.

Worked example: disintegration times

Four tablets from each of three formulations have these 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

The question is whether the formulations differ in mean disintegration time at the 5%5\%5% level.

The hypotheses are:

H0:μA=μB=μCH_0: \mu_A = \mu_B = \mu_CH0​:μA​=μB​=μC​ H1:at least one formulation mean differsH_1: \text{at least one formulation mean differs}H1​:at least one formulation mean differs

There are k=3k=3k=3 groups and N=12N=12N=12 observations. The group means are:

xˉA=324=8,xˉB=404=10,xˉC=484=12\bar{x}_A = \frac{32}{4} = 8,\qquad \bar{x}_B = \frac{40}{4} = 10,\qquad \bar{x}_C = \frac{48}{4} = 12xˉA​=432​=8,xˉB​=440​=10,xˉC​=448​=12

The grand mean is:

xˉ=12012=10\bar{x} = \frac{120}{12} = 10xˉ=12120​=10

The between-group sum of squares is:

SSbetween=4[(8−10)2+(10−10)2+(12−10)2]=32SS_{\text{between}} =4\left[(8-10)^2+(10-10)^2+(12-10)^2\right] =32SSbetween​=4[(8−10)2+(10−10)2+(12−10)2]=32

Within each group, the squared deviations from that group’s mean sum to 222. Therefore:

SSwithin=2+2+2=6SS_{\text{within}} = 2+2+2 = 6SSwithin​=2+2+2=6

The check gives:

SStotal=32+6=38SS_{\text{total}} = 32+6 = 38SStotal​=32+6=38

Calculating the total directly from all observations’ deviations from the grand mean also gives 383838.

The ANOVA table is:

Source of variationSum of squaresDegrees of freedomMean squareFFF
Between groups32323222216161624.024.024.0
Within groups (Error)6669990.6670.6670.667—
Total383838111111——

The degrees of freedom are k−1=2k-1=2k−1=2 between groups and N−k=9N-k=9N−k=9 within groups. The calculated statistic is:

F=160.667≈24.0F = \frac{16}{0.667} \approx 24.0F=0.66716​≈24.0

At the 5%5\%5% level, the table value for degrees of freedom (2,9)(2,9)(2,9) is 4.264.264.26. Since 24.0>4.2624.0 > 4.2624.0>4.26, the null hypothesis is rejected. The data support a difference in mean disintegration time among the formulations.

The means—888, 101010, and 121212 minutes—show that A has the shortest average time and C the longest. However, the overall ANOVA result does not identify exactly which pairs differ. If that is important, a post-hoc procedure such as Tukey’s test can be used after a significant overall result.

A significant result also does not automatically mean the difference is important in practice. The size and pharmaceutical relevance of the difference must be considered separately from statistical significance.

Think About It: What information does the significant overall FFF test provide, and what pair-specific information does it leave unanswered?

Two-way ANOVA

Two-way ANOVA studies two factors in one experiment. For example, a stability study could examine both formulation and storage temperature. This approach can show whether either factor is associated with changes in the outcome, and—when the design includes replication—whether the effect of one factor depends on the level of the other.

That dependence is called an interaction. For instance, an interaction would mean that the change in assay with temperature is not the same for every formulation.

With replicated observations for each combination of factor levels, total variation can be partitioned into:

SStotal=SSA+SSB+SSAB+SSerrorSS_{\text{total}} = SS_A + SS_B + SS_{AB} + SS_{\text{error}}SStotal​=SSA​+SSB​+SSAB​+SSerror​

Here, SSASS_ASSA​ and SSBSS_BSSB​ measure variation associated with the two factors, SSABSS_{AB}SSAB​ measures interaction, and SSerrorSS_{\text{error}}SSerror​ measures residual variation.

When there is only one observation for each combination, as in the example below, there is no separate replication-based estimate of interaction. The remaining variation after accounting for the two factors is used as error:

SStotal=SSA+SSB+SSerrorSS_{\text{total}} = SS_A + SS_B + SS_{\text{error}}SStotal​=SSA​+SSB​+SSerror​

Each factor is tested with its own FFF ratio:

FA=MSAMSerror,FB=MSBMSerrorF_A = \frac{MS_A}{MS_{\text{error}}},\qquad F_B = \frac{MS_B}{MS_{\text{error}}}FA​=MSerror​MSA​​,FB​=MSerror​MSB​​

Thus, one experiment can provide separate tests for both factors. Conclusions about each factor should be stated separately.

Worked example: formulation and storage temperature

The assay, as a percentage of label claim, is measured once for each combination of three formulations and three temperatures:

Formulation25∘C25^\circ\mathrm{C}25∘C40∘C40^\circ\mathrm{C}40∘C60∘C60^\circ\mathrm{C}60∘C
A969696939393878787
B919191888888858585
C898989838383808080

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:

xˉ=7929=88\bar{x} = \frac{792}{9} = 88xˉ=9792​=88

There are three observations contributing to each row mean and each column mean. The sum of squares for formulations is:

SSA=3[(92−88)2+(88−88)2+(84−88)2]=96SS_A = 3\left[(92-88)^2+(88-88)^2+(84-88)^2\right] = 96SSA​=3[(92−88)2+(88−88)2+(84−88)2]=96

The sum of squares for temperature is:

SSB=3[(92−88)2+(88−88)2+(84−88)2]=96SS_B = 3\left[(92-88)^2+(88-88)^2+(84-88)^2\right] = 96SSB​=3[(92−88)2+(88−88)2+(84−88)2]=96

The total sum of squares, calculated from all nine observations around the grand mean, is 198198198. Therefore:

SSerror=198−96−96=6SS_{\text{error}} = 198-96-96 = 6SSerror​=198−96−96=6

The degrees of freedom are 222 for formulations, 222 for temperatures, and (3−1)(3−1)=4(3-1)(3-1)=4(3−1)(3−1)=4 for error. Total degrees of freedom are 9−1=89-1=89−1=8.

Source of variationSum of squaresDegrees of freedomMean squareFFF
Formulations96969622248484832.032.032.0
Temperatures96969622248484832.032.032.0
Error6664441.51.51.5—
Total198198198888——

The critical value at the 5%5\%5% level for degrees of freedom (2,4)(2,4)(2,4) is 6.946.946.94. Both calculated values, 32.032.032.0, exceed this value. The null hypothesis for formulations is rejected, and the null hypothesis for temperatures is also rejected. In this study, both factors are associated with significant differences in assay. The measurements show that assay falls as temperature rises, and formulation A has the highest assay at each temperature.

Think About It: Why does a two-factor experiment offer more information than two separate experiments that each study only one factor?

The F distribution and the decision rule

The FFF statistic is a ratio of variance estimates, so it cannot be negative. Its distribution begins at zero and is right-skewed, with a long tail extending toward larger values.

There is not one single FFF distribution. Each curve depends on two degrees of freedom:

  • The numerator degrees of freedom belong to the mean square in the numerator of the FFF ratio.
  • The denominator degrees of freedom belong to the error mean square in the denominator.

An FFF table is therefore entered with the numerator degrees of freedom first and the denominator degrees of freedom second. For example, the one-way problem uses (2,9)(2,9)(2,9), while the two-way example uses (2,4)(2,4)(2,4) for each factor’s test.

When the null hypothesis is true, the ratio tends to be near 111. Larger values can occur by chance, but values beyond the critical table value are sufficiently unlikely—at the chosen significance level—to justify rejecting the null hypothesis. A critical value tends to increase when the error degrees of freedom decrease because an error variance estimated from fewer observations is less precise. That uncertainty calls for stronger evidence before rejection.

The decision rule is:

Reject H0 if Fcalculated>Fcritical\text{Reject }H_0 \text{ if } F_{\text{calculated}} > F_{\text{critical}}Reject H0​ if Fcalculated​>Fcritical​

Results should include both degrees of freedom, such as F(2,9)=24.0F(2,9)=24.0F(2,9)=24.0. Without those degrees of freedom, the value cannot be checked against the correct table entry.

A useful connection links ANOVA and the t-test. When there are exactly two groups, the tests give the same decision, and:

F=t2F = t^2F=t2

The square appears because an FFF statistic is nonnegative, while a t statistic can be positive or negative.

A significant FFF test is usually the beginning of further analysis. The next steps may include identifying which means differ with a suitable post-hoc test, checking whether the assumptions are reasonable by examining residuals, and deciding whether the size of the difference matters in the pharmaceutical setting.

Think About It: Why would a bare statement such as “F=24.0F=24.0F=24.0” be incomplete without the two degrees of freedom?

Testing the significance of correlation

A sample correlation coefficient can look large yet still be unreliable when it is based on few paired observations. A significance test evaluates whether the population correlation could be zero.

For the null hypothesis H0:ρ=0H_0:\rho=0H0​:ρ=0, the test statistic is:

t=rn−21−r2t = \frac{r\sqrt{n-2}}{\sqrt{1-r^2}}t=1−r2​rn−2​​

Here, rrr is the sample correlation coefficient and nnn is the number of paired observations. The test uses:

df=n−2df = n-2df=n−2

For a test of whether correlation differs from zero in either direction, the alternative is H1:ρ≠0H_1:\rho\ne 0H1​:ρ=0.

Worked example

A study of dissolution and bioavailability in 121212 formulations gives r=0.85r=0.85r=0.85. The degrees of freedom are 12−2=1012-2=1012−2=10. Substitution gives:

t=0.85101−0.852=0.85100.2775≈5.10t = \frac{0.85\sqrt{10}}{\sqrt{1-0.85^2}} = \frac{0.85\sqrt{10}}{\sqrt{0.2775}} \approx 5.10t=1−0.852​0.8510​​=0.2775​0.8510​​≈5.10

The 5%5\%5% table value for 101010 degrees of freedom is 2.2282.2282.228. Since 5.10>2.2285.10>2.2285.10>2.228, the null hypothesis is rejected. The correlation is statistically significant, supporting an association between dissolution and bioavailability in these data. A large rrr should not be reported as evidence of a reliable relationship without considering its significance, particularly when nnn is small.

Testing the significance of a regression slope

In simple linear regression, the slope describes how the predicted response changes as the predictor changes. Testing whether the population slope is zero tests whether there is evidence of a linear relationship.

For H0:β=0H_0:\beta=0H0​:β=0, the test statistic is:

t=bSE(b)t = \frac{b}{SE(b)}t=SE(b)b​

Here, bbb is the calculated sample slope and SE(b)SE(b)SE(b) is its standard error. The degrees of freedom are again:

df=n−2df=n-2df=n−2

Worked example

A regression of response on concentration uses 121212 points and gives b=1.85b=1.85b=1.85 with SE(b)=0.37SE(b)=0.37SE(b)=0.37. Then:

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

With 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 null hypothesis that the slope is zero is rejected. The slope is significantly different from zero.

In simple linear regression, the test of the slope and the test of correlation are two forms of the same test. When both are calculated from the same data, their t statistics agree, apart from differences caused by rounding. The overall regression can also be tested using an FFF test in a regression ANOVA table, connecting regression testing to the same FFF-test framework used for group comparisons.

Think About It: Why can a correlation coefficient of 0.850.850.85 still require a significance test before a conclusion is drawn?

Practice applications with answers

Comparing four tablet presses

An ANOVA for four tablet presses, with five tablets per press, gives SSbetween=40SS_{\text{between}}=40SSbetween​=40 and SSwithin=60SS_{\text{within}}=60SSwithin​=60. The degrees of freedom are 333 between groups and 161616 within groups. Thus:

MSbetween=403≈13.33,MSwithin=6016=3.75MS_{\text{between}}=\frac{40}{3}\approx 13.33,\qquad MS_{\text{within}}=\frac{60}{16}=3.75MSbetween​=340​≈13.33,MSwithin​=1660​=3.75 F=13.333.75≈3.56F=\frac{13.33}{3.75}\approx 3.56F=3.7513.33​≈3.56

The total sum of squares is 100100100, and the total degrees of freedom are 191919. The critical value for (3,16)(3,16)(3,16) degrees of freedom at 5%5\%5% is 3.243.243.24. Since 3.56>3.243.56>3.243.56>3.24, the null hypothesis is rejected.

Comparing five brands

For five brands, the hypotheses are:

H0:μ1=μ2=μ3=μ4=μ5H_0:\mu_1=\mu_2=\mu_3=\mu_4=\mu_5H0​:μ1​=μ2​=μ3​=μ4​=μ5​ H1:at least one brand mean differsH_1:\text{at least one brand mean differs}H1​:at least one brand mean differs

The number of pairwise comparisons is:

(52)=5(4)2=10\binom{5}{2}=\frac{5(4)}{2}=10(25​)=25(4)​=10

Repeated t-tests are avoided because conducting many tests increases the overall false-positive risk.

Testing a correlation from ten pairs

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

df=10−2=8df=10-2=8df=10−2=8 t=0.6281−0.622≈2.23t=\frac{0.62\sqrt{8}}{\sqrt{1-0.62^2}}\approx 2.23t=1−0.622​0.628​​≈2.23

The critical value at 5%5\%5% for 888 degrees of freedom is 2.3062.3062.306. Since the calculated value is smaller, the correlation is not significant at that level.

Two-way degrees of freedom for machines and operators

For 333 machines and 444 operators with one observation per combination:

  • Machines: 3−1=23-1=23−1=2 degrees of freedom.
  • Operators: 4−1=34-1=34−1=3 degrees of freedom.
  • Error: (3−1)(4−1)=6(3-1)(4-1)=6(3−1)(4−1)=6 degrees of freedom.
  • Total: (3)(4)−1=11(3)(4)-1=11(3)(4)−1=11 degrees of freedom.

With one observation per combination, the error term cannot be separated from an independently estimated interaction.

Checking F=t2F=t^2F=t2 for two groups

If a two-group comparison gives t=2.92t=2.92t=2.92, the equivalent ANOVA statistic is:

F=2.922=8.5264F=2.92^2=8.5264F=2.922=8.5264

For a two-group ANOVA, the numerator degrees of freedom are 111. If the total sample size is NNN, the denominator degrees of freedom are N−2N-2N−2. A numerical denominator cannot be specified without knowing NNN.

Comprehensive review

ANOVA compares several means by partitioning total variation into components and asking whether variation between groups is large relative to variation within groups. In one-way ANOVA, the central partition is:

SStotal=SSbetween+SSwithinSS_{\text{total}}=SS_{\text{between}}+SS_{\text{within}}SStotal​=SSbetween​+SSwithin​

The test statistic is the ratio of the corresponding mean squares. Its reference distribution is the right-skewed FFF distribution, selected using numerator and denominator degrees of freedom.

Two-way ANOVA evaluates two factors in the same study. With replication, it can also assess interaction; without replication, the remaining variation is used as error and cannot be separated into an independent interaction estimate. The same general testing ideas apply to correlation and regression: a correlation test uses rrr, while a slope test uses the estimated slope divided by its standard error. In simple linear regression, these are equivalent tests expressed in different ways.

Careful interpretation depends on more than a calculated statistic. The hypotheses, assumptions, degrees of freedom, complete ANOVA table, decision, and conclusion in the context of the study all contribute to a sound result.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent