One-Way and Two-Way ANOVA


One-Way and Two-Way ANOVA

Anna
Welcome to TPS Pharmacy Lab. Today we’re connecting several important hypothesis tests: one-way and two-way ANOVA, the F distribution, and tests of significance for correlation and regression. The central question is how to compare groups without letting a pile of separate tests create a pile of false alarms.

Michael
That matters in pharmacy because a study might compare several formulations, storage conditions, or analysts—not just two groups. With four groups, six pairwise t-tests would be needed, and the combined chance of at least one false alarm is about 26 percent when each test uses a 5 percent significance level. ANOVA addresses the group comparison in one overall test.

Anna
The key idea is to compare two kinds of variation. Variation within a group—such as differences among tablets made with the same formulation—estimates background noise. Variation between groups measures how far the group means scatter around the grand mean.

Michael
Under the null hypothesis that all population means are equal, both kinds of variation reflect that same background noise. If the group means really differ, though, the between-groups variation is inflated. So ANOVA asks whether the means scatter more than the noise inside the groups can explain.

Anna
That comparison is expressed as F equals mean square between groups divided by mean square within groups: F equals MSB over MSW. When the null hypothesis is true, F tends to be near 1; if the group means separate sufficiently, F grows and may be large enough to reject the null.

Michael
The variation has an exact accounting identity: total sum of squares, SST, equals sum of squares between groups, SSB, plus sum of squares within groups, SSW. For k groups and N total observations, the degrees of freedom are k minus 1 between groups, N minus k within groups, and N minus 1 total. Those degrees of freedom add up too.

Anna
Divide each sum of squares by its degrees of freedom to get the corresponding mean square. So MSB is SSB divided by k minus 1, and MSW is SSW divided by N minus k. The assumptions are that observations are random and independent, each population is approximately normal, and group variances are approximately equal.

Michael
The one-way ANOVA hypotheses need to be stated precisely. The null is that mu one equals mu two and so on through mu k. The alternative is that at least one mean differs—not that every mean differs from every other mean.

Anna
One-way ANOVA means one factor is being studied across several levels. Formulation is one possible factor; dose level or storage condition could also be the factor. The standard procedure starts by stating those hypotheses and choosing alpha, usually 0.05.

Michael
Then calculate the grand mean from all N observations. Calculate SSB by adding, for each group, its sample size times the squared difference between that group mean and the grand mean. Calculate SSW by adding the squared differences between each observation and its own group mean.

Anna
Before building the table, check that SST equals SSB plus SSW. Then make the standard ANOVA table with rows for Between Groups, Within Groups or Error, and Total, and columns for sum of squares, degrees of freedom, and mean square where applicable. The F ratio uses only the between-groups and within-groups rows.

Michael
For the decision, find the critical F value at the chosen alpha using numerator degrees of freedom k minus 1 and denominator degrees of freedom N minus k. Reject the null if calculated F exceeds that table value, and give the conclusion in words. Also check that total degrees of freedom equal the two component degrees of freedom.

Anna
Let’s work the disintegration example. Four tablets from formulation A have times 8, 9, 7, and 8 minutes; B has 10, 11, 9, and 10; and C has 12, 13, 11, and 12. We’re testing at the 5 percent level whether the mean times differ.

Michael
The group means are 8, 10, and 12 minutes. The total of all twelve observations is 120, so the grand mean is 10. With four observations in each group, SSB is 4 times the sum of the squared differences between 8, 10, and 12 and the grand mean 10: that gives 4 times 8, or 32.

Anna
For SSW, the squared deviations from each group’s own mean add to 2 for A, 2 for B, and 2 for C. So SSW is 6. The direct total sum of squares about the grand mean is 38, and the check works: 32 plus 6 equals 38.

Michael
Now the table. Between groups has SS 32, df 2, and MS 16. Within groups has SS 6, df 9, and MS 6 divided by 9, or about 0.667. Total has SS 38 and df 11. The degrees of freedom check too: 2 plus 9 equals 11.

Anna
The calculated F is 16 divided by 0.667, which is 24.0. The 5 percent table value for degrees of freedom 2 and 9 is 4.26. Since 24.0 exceeds 4.26, we reject the null: the formulations differ significantly in mean disintegration time.

Michael
The means show A has the shortest time and C the longest. But the overall ANOVA result does not tell us which particular pairs differ. If that is important, follow a significant F with a multiple-comparison method such as Tukey’s test, which has its own error control.

Anna
That is why the complete table and the arithmetic check matter in an exam and in real analysis. Don’t give only an F value: show the sums of squares, degrees of freedom, mean squares, and decision. It’s also good practice to report F with both degrees of freedom, as in F with 2 and 9 degrees of freedom equals 24.0.

Michael
Two-way ANOVA studies two factors at once—for example, formulation and storage temperature in a stability study. That can make one experiment more informative: it can estimate the effects of both factors, and with replicated combinations it can also examine whether the effect of one factor depends on the level of the other. That dependence is called an interaction.

Anna
With replication, the total variation can be partitioned into the variation due to factor A, factor B, their interaction, and error: SST equals SSA plus SSB plus SSAB plus SSE. In the unreplicated case we’ll use here, there is only one observation per factor combination, so a separate interaction estimate is not available. The remaining variation after the two factor sums of squares serves as error: SST equals SSA plus SSB plus SSE.

Michael
Here’s the stability example: three formulations are assayed at 25, 40, and 60 degrees Celsius, with one determination for each combination. The results are A: 96, 93, 87; B: 91, 88, 85; and C: 89, 83, 80 percent of label claim.

Anna
The formulation means are 92, 88, and 84; the temperature means are also 92, 88, and 84. The grand mean is 88. For formulations, SSA is three times the sum of the squared differences of those row means from 88, which gives 96. The same calculation for the temperature means gives SSB of 96.

Michael
The total sum of squares for the nine observations about 88 is 198. Therefore SSE is 198 minus 96 minus 96, or 6. The degrees of freedom are 2 for formulations, 2 for temperatures, 4 for error, and 8 total.

Anna
The error mean square is 6 divided by 4, or 1.5. Each factor has mean square 96 divided by 2, or 48, so each F ratio is 48 divided by 1.5, which equals 32.0. The 5 percent critical value for degrees of freedom 2 and 4 is 6.94.

Michael
Both calculated F values exceed 6.94, so we reject the null hypothesis separately for formulation and for temperature. Both factors significantly affect assay in this example. The pattern shows potency falling as temperature rises, and formulation A has the highest assay at every temperature.

Anna
The F distribution explains how these decisions work. Because F is a ratio of variance estimates, it cannot be negative. Its distribution is right-skewed, starting at zero and extending in a long tail. Under the null, values tend to be near 1; sufficiently large values fall in the rejection region.

Michael
An F distribution is identified by two degrees of freedom: numerator degrees of freedom for the mean square on top of the ratio, and denominator degrees of freedom for the error mean square below it. Enter an F table with the numerator first and the denominator second, along with the chosen significance level.

Anna
For our one-way example, the pair is 2 and 9, and the 5 percent critical value is 4.26. For the two-way example, it is 2 and 4, and the value is 6.94. The critical value is higher with fewer error degrees of freedom because the error variance is estimated less precisely, so stronger evidence is required.

Michael
Two useful connections finish the ANOVA picture. With exactly two groups, ANOVA and the t-test agree: F equals t squared. And a significant F is a starting point, not the end—check assumptions using residuals, identify which means differ if needed, and consider whether the size of the difference matters pharmaceutically. Statistical significance and practical importance are separate questions.

Anna
The same hypothesis-testing story applies to correlation. A sample correlation r might look large, but if there are few pairs, it could still arise by chance from a population with no correlation. To test the null that population correlation rho equals zero, use t equals r times the square root of n minus 2, divided by the square root of 1 minus r squared. The degrees of freedom are n minus 2.

Michael
For 12 formulations, suppose dissolution and bioavailability have r equal to 0.85. The test statistic is 0.85 times the square root of 10 divided by the square root of 1 minus 0.85 squared. That works out to about 5.10. At 10 degrees of freedom, the 5 percent critical t is 2.228, so we reject the null and conclude the correlation is significant.

Anna
That result supports an in vitro–in vivo relationship in this example. But remember the caution: never draw a conclusion from a large-looking r alone. Its significance depends on the number of pairs as well as the size of r.

Michael
For a regression line, the null hypothesis that the population slope beta is zero means there is no linear relationship. Test it with t equals b divided by the standard error of b, where b is the estimated slope. Again, the degrees of freedom are n minus 2.

Anna
In the example, the estimated slope is 1.85 and its standard error is 0.37, so t is 5.00. That exceeds 2.228 at 10 degrees of freedom, and the slope is significantly different from zero. An intercept can also be tested against a hypothesized value.

Michael
In simple linear regression, testing whether the slope is zero and testing whether the correlation is zero are two forms of the same test. With the same data, their t values agree apart from rounding. Regression can also be tested overall by an F test in its ANOVA table, connecting it directly to the F methods we’ve just discussed.

Anna
Let’s use a few practice questions to check the mechanics. Four tablet presses each contribute five tablets; SSB is 40 with 3 degrees of freedom, and SSW is 60 with 16 degrees of freedom. The mean squares are 40 divided by 3, or about 13.33, and 60 divided by 16, or 3.75.

Michael
So F is about 13.33 divided by 3.75, or 3.56. The given critical value for degrees of freedom 3 and 16 is 3.24, so the result is significant at 5 percent and the null is rejected. The total SS is 100 and total degrees of freedom are 19, which also checks: 3 plus 16 equals 19.

Anna
For five brands, the ANOVA null says all five population potency means are equal; the alternative says at least one differs. Comparing all brand pairs would require ten t-tests, which is why an overall ANOVA is preferred instead of accumulating false-alarm risk through repeated tests.

Michael
For a correlation study with 10 pairs and r equal to 0.62, set up the same test with 8 degrees of freedom. The statistic is 0.62 times the square root of 8, divided by the square root of 1 minus 0.62 squared, which is about 2.24. Since the given 5 percent critical value is 2.306, it does not exceed the cutoff, so the correlation is not significant at that level.

Anna
For an unreplicated two-way ANOVA with three machines and four operators, the machine degrees of freedom are 3 minus 1, or 2. Operator degrees of freedom are 4 minus 1, or 3; error degrees of freedom are 2 times 3, or 6; and total degrees of freedom are 12 minus 1, or 11.

Michael
And if a two-group comparison has t equal to 2.92, the corresponding ANOVA F is t squared: 2.92 squared is about 8.53. Its numerator degrees of freedom are 1; its denominator degrees of freedom are the same as the t-test’s degrees of freedom. That is the practical meaning of F equals t squared.

Anna
For exam preparation, be ready to explain why ANOVA is preferred to repeated t-tests, partition SST and describe each component, state the assumptions and hypotheses exactly, and reproduce the one-way ANOVA table. Practise the three-formulation disintegration calculation and explain why a significant overall result doesn’t identify the differing pairs by itself.

Michael
Also prepare to distinguish one-way from two-way ANOVA, complete a two-factor table and test each factor separately, describe the F distribution and table lookup, and explain why its critical value changes as error degrees of freedom change. Finally, practise the significance tests for r and for a regression slope, including how those tests connect.

Anna
The big picture is that ANOVA partitions variation and compares mean squares with F, while correlation and regression use t tests to assess whether their coefficients differ from zero. These are connected tools for turning observed differences and relationships into carefully checked conclusions.

Michael
Revise the formulas, draw and label the variation-partitioning diagram, and practise writing complete tables and conclusions. Next time, the focus moves to non-parametric tests: Mann–Whitney U, Wilcoxon signed-rank, Kruskal–Wallis, Friedman, and chi-square tests. Thanks for studying with us.

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