Factorial ANOVA, Main Effects, Interaction Effect and Partial Eta Squared
Two Way ANOVA: Formula, Interpretation, SPSS, Python, R and Excel Guide
Two Way ANOVA tests whether one continuous outcome differs across two categorical factors and whether those two factors interact. In this worked Salar Cafe example, the dependent variable is G3 final grade, and the two factors are studytime and school. The results show significant main effects for studytime and school, but the studytime × school interaction is not statistically significant.
Google AdSense top placement reserved here
Quick Answer: Two Way ANOVA Result
The worked Two Way ANOVA tests three effects. The first main effect is studytime. The second main effect is school. The third effect is the studytime × school interaction.
The summary table reports a significant studytime effect, F = 12.43, p = 6.557e-08, partial η² = 0.05498. The school effect is also significant, F = 46.2, p = 2.445e-11, partial η² = 0.06723. The studytime × school interaction is not significant, F = 0.3636, p = 0.7793, partial η² = 0.001699.
Final interpretation: Mean G3 differs by studytime group and by school. GP students generally have higher mean G3 scores than MS students, and higher studytime groups generally have higher G3 scores. The studytime × school interaction is not significant, so the evidence does not show that the studytime effect changes meaningfully across GP and MS schools.
Important reporting point: The interaction plot may show non-perfectly parallel lines, but the formal interaction p-value is 0.7793. Therefore, the interaction should be reported as non-significant, and the article should focus on the two significant main effects.
Table of Contents
- What Is Two Way ANOVA?
- Two Way ANOVA Formula
- Two Way ANOVA Hypotheses
- Dataset and Variables Used
- Two Way ANOVA Assumptions
- SPSS Output Interpretation
- Python Chart-by-Chart Interpretation
- R Chart-by-Chart Validation
- SPSS, R, Python and Excel Workflows
- Code Blocks for Two Way ANOVA
- APA Reporting Wording
- Common Mistakes
- When to Use Two Way ANOVA
- Downloads and Resources
- Related Guides
- FAQs
What Is Two Way ANOVA?
Two Way ANOVA is a factorial ANOVA test used when one continuous dependent variable is compared across two categorical independent variables. It answers three questions in one model: whether factor A has a main effect, whether factor B has a main effect, and whether factor A and factor B interact.
In this example, G3 final grade is the continuous dependent variable. Studytime is the first factor, with four levels. School is the second factor, with GP and MS groups. The model asks whether mean G3 differs across studytime levels, whether mean G3 differs by school, and whether the studytime difference depends on school.
The result is a clear main-effects pattern. Studytime matters, school matters, but the combined studytime × school interaction does not matter statistically. This means the final report should explain the overall studytime difference and the overall school difference without claiming a meaningful interaction.
Simple definition: Two Way ANOVA compares group means across two factors and tests whether the factors interact. Here, it compares G3 final grade across studytime groups and schools.
This guide connects naturally with One Way ANOVA, Factorial ANOVA, Fixed Effects ANOVA, Balanced ANOVA, Brown Forsythe ANOVA, ANOVA Effect Size, Eta Squared, Omega Squared, Cohen’s F Formula and F Distribution.
Two Way ANOVA Formula
A two-factor ANOVA model separates each outcome score into the grand mean, the first factor effect, the second factor effect, the interaction effect and random error.
In this formula, Y is the dependent variable, μ is the grand mean, A is the first factor, B is the second factor, AB is the interaction and e is the residual error. In this example, Y is G3, A is studytime and B is school.
F Statistic Formula
Each effect has its own F statistic. Studytime has an F statistic, school has an F statistic, and the studytime × school interaction has an F statistic. The p-value attached to each F statistic tells whether that model effect is statistically significant.
Partial Eta Squared Formula
Partial eta squared describes the practical size of each effect. In this output, school has the largest partial eta squared at 0.06723. Studytime is slightly smaller at 0.05498. The interaction is very small at 0.001699.
| Effect | df | SS | F | p | Partial η² | Decision |
|---|---|---|---|---|---|---|
| studytime | 3 | 341.2 | 12.43 | 6.557e-08 | 0.05498 | Reject H0 |
| school | 1 | 422.8 | 46.2 | 2.445e-11 | 0.06723 | Reject H0 |
| studytime × school | 3 | 9.982 | 0.3636 | 0.7793 | 0.001699 | Fail to reject H0 |
Two Way ANOVA Hypotheses
Two Way ANOVA has separate hypotheses for the first main effect, the second main effect and the interaction. The interaction is especially important because it tells whether the effect of one factor depends on the level of the other factor.
| Effect | Null Hypothesis | Alternative Hypothesis | Decision in This Output |
|---|---|---|---|
| studytime | Mean G3 is equal across studytime groups. | At least one studytime group has a different mean G3. | Reject H0. |
| school | Mean G3 is equal for GP and MS schools. | Mean G3 differs by school. | Reject H0. |
| studytime × school | The studytime effect is the same across schools. | The studytime effect depends on school. | Fail to reject H0. |
Decision for this example: Studytime and school are statistically significant. The studytime × school interaction is not significant. Report the two main effects and avoid claiming that studytime works differently in GP and MS schools.
Dataset and Variables Used
The worked example uses student performance data. The dependent variable is G3 final grade. The two factors are studytime and school. Studytime has four groups, while school has two groups, GP and MS.
| Variable | Role | Levels / Type | Why It Matters |
|---|---|---|---|
| G3 | Dependent variable | Numeric final grade | The outcome whose means are compared. |
| studytime | Factor A | 1, 2, 3, 4 | Tests whether final grade differs by studytime category. |
| school | Factor B | GP, MS | Tests whether final grade differs by school. |
| studytime × school | Interaction | Eight cells | Tests whether the studytime pattern changes by school. |
Cell Mean Pattern
| Pattern | Visible Result | Interpretation |
|---|---|---|
| School pattern | GP is above MS across all studytime levels. | The school main effect is strong and statistically significant. |
| Studytime pattern | Mean G3 increases from studytime 1 toward studytime 3 and remains high at studytime 4. | The studytime main effect is statistically significant. |
| Interaction pattern | The lines are not identical, but they follow broadly similar movement. | The interaction is not statistically significant. |
For supporting concepts, review Descriptive Statistics, Mean Median and Mode, Standard Deviation, Variance, Confidence Interval, P Value, Null and Alternative Hypothesis and Effect Size.
Two Way ANOVA Assumptions
Two Way ANOVA assumes a numeric outcome, categorical factors, independent observations, approximate residual normality and reasonably similar residual variance across cells. These assumptions should be checked before relying on the final F tests.
| Assumption | What It Means | How This Example Checks It |
|---|---|---|
| Continuous outcome | The dependent variable should be numeric. | G3 is a numeric final grade. |
| Categorical factors | The independent variables should define groups. | studytime and school define factor cells. |
| Independence | Each case should contribute one independent observation. | Each student contributes one G3 score. |
| Homogeneity of variance | Cell variances should be reasonably similar. | Cell boxplots and SPSS variance tests should be reviewed. |
| Residual normality | Residuals should be approximately normal. | The Q-Q plot shows visible tail departure, so report cautiously. |
| No extreme influential cases | Outliers should not dominate the model. | Residual plots show some large negative residuals requiring review. |
For deeper assumption checks, use Levene Test, Bartlett’s Test, Q-Q Plot Normality Check, P-P Plot Normality Check, Shapiro-Wilk Test, Anderson-Darling Test, Studentized Residuals, Cook’s Distance and Outlier Detection.
Google AdSense middle placement reserved here
SPSS Output Interpretation for Two Way ANOVA
The SPSS output for Two Way ANOVA should be read from the factorial model table. The dependent variable is G3, and the fixed factors are studytime and school. The important rows are the studytime main effect, the school main effect and the studytime × school interaction.
SPSS Reading Order
| SPSS Output Area | What to Read | Why It Matters |
|---|---|---|
| Between-subject factors | studytime and school levels. | Confirms the factorial design. |
| Descriptive statistics | Mean G3 for each studytime × school cell. | Shows the pattern behind the graphs. |
| Tests of between-subject effects | studytime, school and studytime × school rows. | Main ANOVA decision table. |
| Effect sizes | Partial eta squared values. | Shows practical importance of each effect. |
| Homogeneity tests | Levene or related variance checks. | Assumption context. |
| Residual diagnostics | Residual plot and Q-Q plot. | Checks model fit and residual shape. |
SPSS Result Summary
| Effect | Decision | Plain Interpretation |
|---|---|---|
| studytime | Significant | Mean G3 differs across studytime groups. |
| school | Significant | Mean G3 differs between GP and MS schools. |
| studytime × school | Not significant | The studytime pattern is not statistically different across schools. |
SPSS interpretation summary: The Two Way ANOVA supports significant main effects for studytime and school. The studytime × school interaction is not significant. This means the final SPSS report should describe overall differences across studytime groups and schools, but it should not claim that studytime works differently in GP and MS schools.
Python Chart-by-Chart Interpretation
The Python chart sequence explains the Two Way ANOVA result through interaction lines, cell means, p-values, effect sizes, boxplots, residual diagnostics and a summary table.
Python Chart 1: Two Way ANOVA Interaction Plot

The interaction plot shows that GP is higher than MS across every studytime level. Both school lines rise from studytime 1 toward studytime 3, then slightly decline or flatten at studytime 4.
The lines are not perfectly parallel, but the formal interaction test is not significant. This means the plot should be used to explain the main effects, not to claim a statistically supported interaction.
Python Chart 2: Two Way ANOVA Cell Means

The cell mean chart confirms that GP is higher than MS in each studytime category. The highest GP and MS means appear around studytime group 3, while the lowest means appear in studytime group 1.
This chart clearly supports the significant main effects. It also shows why the interaction is weak: the school difference remains in the same direction across studytime groups.
Python Chart 3: p-value Decision Summary

The p-value chart shows that studytime and school are far below alpha = .05. The interaction p-value is far above alpha at 0.7793.
This is the clearest decision chart. The model supports two significant main effects and one non-significant interaction.
Python Chart 4: Partial Eta Squared by Effect

The effect-size chart shows school as the largest practical effect, with partial eta squared around 0.067. Studytime is close behind at about 0.055.
The interaction effect is very small, about 0.002. This supports a main-effects interpretation and prevents overstatement of the interaction plot.
Python Chart 5: Distribution by Cell

The boxplots show that cell distributions vary in center and spread. GP cells generally sit higher than MS cells, and higher studytime groups generally have higher centers.
Some low outlying values are visible, including very low scores in several cells. These values explain why residual diagnostics should be reviewed before final reporting.
Python Chart 6: Residuals vs Fitted Values

The residual plot shows vertical fitted-value bands because the model uses categorical cell means. Most residuals are scattered around zero, but there are several strong negative residuals.
This diagnostic suggests that the model captures average cell differences, but some individual students have much lower G3 scores than their fitted cell means. These cases should be acknowledged as residual diagnostic context.
Python Chart 7: Residual Q-Q Plot

The Q-Q plot shows visible departure from the reference line, especially in the lower tail. The center of the distribution is closer to the expected pattern than the extremes.
This means residual normality is approximate rather than perfect. The large sample and clear main effects support interpretation, but the residual tail behavior should be reported transparently.
Python Chart 8: Two Way ANOVA Summary Table

The summary table gives the final decision in one place. Studytime and school are significant. The studytime × school interaction is not significant.
This table is the best source for final reporting because it includes the model effects, F values, p-values, effect sizes and decisions.
R Chart-by-Chart Validation
The R validation charts repeat the same Two Way ANOVA workflow in a second software environment. They confirm the interaction pattern, cell means, p-value decisions, effect sizes, distribution checks, residual diagnostics and final summary table.
R Chart 1: Two Way ANOVA Interaction Plot

The R interaction plot confirms the same pattern as Python. GP remains above MS across the studytime levels, and both schools show a broadly upward pattern toward studytime group 3.
The R plot supports the same interpretation: use the graph descriptively, but do not report a significant interaction because the formal interaction test is non-significant.
R Chart 2: Two Way ANOVA Cell Means

The R cell mean chart confirms that GP cell means are consistently higher than MS cell means.
This agreement between R and Python strengthens the main-effect interpretation for school and studytime.
R Chart 3: p-value Decision Summary

The R p-value chart confirms that studytime and school are statistically significant and the studytime × school interaction is not.
This validates the final decision structure across software tools.
R Chart 4: Partial Eta Squared by Effect

The R effect-size chart confirms that school has the largest practical effect, studytime has a meaningful smaller effect, and the interaction is very small.
This supports the same practical interpretation as Python: the article should discuss main effects, not an interaction story.
R Chart 5: Distribution by Cell

The R boxplots confirm the same distribution pattern as Python. Higher studytime and GP cells tend to have higher central values.
Some low outliers remain visible, so assumption and residual diagnostics should be included in the final report.
R Chart 6: Residuals vs Fitted Values

The R residual plot confirms the same fitted-value bands and residual spread seen in Python.
The model explains the group mean structure, but some individual cases deviate strongly from their cell means.
R Chart 7: Residual Q-Q Plot

The R Q-Q plot confirms that residual normality is approximate. Tail departures are visible.
This validates the diagnostic conclusion and supports transparent assumption reporting.
R Chart 8: Two Way ANOVA Summary Table

The R summary table confirms the final result. Studytime and school are significant, while the interaction is not significant.
This software agreement makes the final interpretation stable and suitable for SPSS, R, Python and Excel teaching.
Google AdSense in-content placement reserved here
SPSS, R, Python and Excel Workflows for Two Way ANOVA
The same Two Way ANOVA workflow can be reproduced in SPSS, R, Python and Excel. SPSS uses the General Linear Model univariate procedure. R can use aov() or lm(). Python can use statsmodels. Excel can create summaries and interaction charts, but SPSS, R or Python is better for the full factorial ANOVA table.
SPSS Workflow
| Step | SPSS Menu or Syntax | Purpose |
|---|---|---|
| Open dataset | File > Open > Data | Load G3, studytime and school. |
| Run GLM | Analyze > General Linear Model > Univariate | Open the factorial ANOVA procedure. |
| Set dependent variable | Dependent Variable: G3 | Define the numeric outcome. |
| Set fixed factors | studytime and school | Define the two categorical factors. |
| Model | Full factorial | Includes main effects and interaction. |
| Options | Descriptives, effect size and homogeneity tests | Get means, partial eta squared and assumptions. |
| Profile plot | studytime × school | Create the interaction plot. |
| Export output | OUTPUT EXPORT | Save SPSS output as PDF. |
R Workflow
| Step | R Action | Purpose |
|---|---|---|
| Read data | read.csv("dataset.csv") | Load the data. |
| Convert factors | factor(studytime), factor(school) | Define categorical factors. |
| Fit model | aov(G3 ~ studytime * school, data = df) | Run Two Way ANOVA. |
| Read table | summary(model) | Check F values and p-values. |
| Effect sizes | effectsize::eta_squared() | Report partial eta squared. |
| Diagnostics | Residual plots and Q-Q plot | Check assumptions. |
Python Workflow
| Step | Python Action | Purpose |
|---|---|---|
| Read data | pandas.read_csv() | Load G3 and factor columns. |
| Clean data | Drop missing G3, studytime and school rows | Use complete cases. |
| Fit OLS model | G3 ~ C(studytime) * C(school) | Run full two-way factorial model. |
| ANOVA table | anova_lm(model, typ=2) | Get model effect tests. |
| Effect sizes | Calculate partial eta squared | Report practical effect strength. |
| Charts | Interaction plot, p-values, effect sizes and diagnostics | Explain the output visually. |
Excel Workflow
| Excel Task | Formula or Tool | Purpose |
|---|---|---|
| Prepare data | Columns for G3, studytime and school | Organize the factorial dataset. |
| Create PivotTable | Rows = studytime, Columns = school, Values = Average G3 | Summarize cell means. |
| Create interaction chart | Line chart from PivotTable means | Visualize the studytime × school pattern. |
| Create boxplots | Box and whisker chart by cell | Inspect spread and outliers. |
| Formal ANOVA | Use SPSS, R or Python | Excel is limited for full factorial ANOVA reporting. |
Code Blocks for Two Way ANOVA
SPSS Syntax for Two Way ANOVA
* Two Way ANOVA in SPSS.
* Dependent variable: G3.
* Factors: studytime and school.
TITLE "Two Way ANOVA: G3 by Studytime and School".
UNIANOVA G3 BY studytime school
/METHOD=SSTYPE(3)
/INTERCEPT=INCLUDE
/PRINT=DESCRIPTIVE ETASQ HOMOGENEITY
/PLOT=PROFILE(studytime*school)
/EMMEANS=TABLES(studytime) COMPARE ADJ(BONFERRONI)
/EMMEANS=TABLES(school)
/EMMEANS=TABLES(studytime*school)
/CRITERIA=ALPHA(.05)
/DESIGN=studytime school studytime*school.
OUTPUT EXPORT
/CONTENTS EXPORT=VISIBLE
/PDF DOCUMENTFILE="two_way_anova_spss_output.pdf".Python Code for Two Way ANOVA
import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm
df = pd.read_csv("dataset.csv")
df["G3"] = pd.to_numeric(df["G3"], errors="coerce")
df["studytime"] = df["studytime"].astype("category")
df["school"] = df["school"].astype("category")
data = df[["G3", "studytime", "school"]].dropna().copy()
model = ols("G3 ~ C(studytime) * C(school)", data=data).fit()
anova_table = anova_lm(model, typ=2)
error_ss = anova_table.loc["Residual", "sum_sq"]
anova_table["partial_eta_sq"] = anova_table["sum_sq"] / (anova_table["sum_sq"] + error_ss)
print(anova_table)
# Cell means
cell_means = data.groupby(["studytime", "school"])["G3"].mean()
print(cell_means)
# Main effect means
print(data.groupby("studytime")["G3"].mean())
print(data.groupby("school")["G3"].mean())
# Residual diagnostics
data["fitted"] = model.fittedvalues
data["residual"] = model.resid
print(data[["G3", "studytime", "school", "fitted", "residual"]].head())R Code for Two Way ANOVA
# Two Way ANOVA in R
library(tidyverse)
df <- read.csv("dataset.csv")
df$G3 <- as.numeric(df$G3)
df$studytime <- as.factor(df$studytime)
df$school <- as.factor(df$school)
data <- df %>%
select(G3, studytime, school) %>%
drop_na()
model <- aov(G3 ~ studytime * school, data = data)
summary(model)
# Cell means
data %>%
group_by(studytime, school) %>%
summarise(
n = n(),
mean_G3 = mean(G3),
sd_G3 = sd(G3),
.groups = "drop"
)
# Optional Type III ANOVA
# install.packages("car")
# library(car)
# Anova(lm(G3 ~ studytime * school, data = data), type = 3)
# Optional effect sizes
# install.packages("effectsize")
# library(effectsize)
# eta_squared(model, partial = TRUE)
# Diagnostics
par(mfrow = c(1, 2))
plot(fitted(model), residuals(model),
xlab = "Fitted values", ylab = "Residuals",
main = "Residuals vs Fitted")
abline(h = 0, lty = 2)
qqnorm(residuals(model))
qqline(residuals(model))Excel Notes for Two Way ANOVA
Excel support workflow:
1. Arrange the data:
G3 | studytime | school
2. Create a PivotTable:
Rows = studytime
Columns = school
Values = average of G3
3. Create an interaction chart:
X-axis = studytime
Lines = school
Y-axis = mean G3
4. Create a cell mean chart:
Clustered bar chart by studytime and school.
5. Create cell boxplots:
Separate G3 values by studytime and school cell.
6. Formal Two Way ANOVA:
Use SPSS, R or Python for the complete factorial ANOVA table,
p-values, interaction test and partial eta squared.APA Reporting Wording
When reporting Two Way ANOVA, include the dependent variable, both factors, the two main effects, the interaction test, effect sizes and assumption notes. Because the interaction is non-significant, avoid reporting a complex interaction pattern as the main result.
APA-style report: A two-way ANOVA was conducted to examine the effects of studytime and school on G3 final grade. There was a significant main effect of studytime, F(3, error df) = 12.43, p = 6.557e-08, partial η² = 0.05498, and a significant main effect of school, F(1, error df) = 46.20, p = 2.445e-11, partial η² = 0.06723. The studytime × school interaction was not significant, F(3, error df) = 0.3636, p = 0.7793, partial η² = 0.001699. These results indicate that G3 differs by studytime and school, but the studytime pattern is not significantly different across schools.
Short reporting version: Studytime and school were significant main effects for G3. The studytime × school interaction was not significant, so the final interpretation should focus on the two main effects.
Common Mistakes
| Mistake | Why It Is Wrong | Correct Practice |
|---|---|---|
| Ignoring the interaction test | Two Way ANOVA tests both main effects and interaction. | Always report studytime, school and studytime × school. |
| Calling non-parallel lines significant | The formal interaction p-value is 0.7793. | Use the p-value before claiming an interaction. |
| Reporting only p-values | P-values do not show practical size. | Report ANOVA Effect Size, Eta Squared or Omega Squared. |
| Using many one-way ANOVAs instead | Separate tests ignore the factorial model. | Use one full Two Way ANOVA first. |
| Skipping assumptions | ANOVA depends on residual and variance assumptions. | Review ANOVA Assumptions, Levene Test and residual plots. |
| Overstating a small interaction effect | The interaction partial eta squared is about 0.002. | Describe it as very small and non-significant. |
When to Use Two Way ANOVA
Use Two Way ANOVA when you have one numeric outcome and two categorical factors. It is common in education, psychology, agriculture, medicine, business experiments and social science research where the researcher wants to test two factors and their interaction in one model.
| Situation | Use Two Way ANOVA? | Reporting Note |
|---|---|---|
| One numeric outcome and two categorical factors | Yes | Use a full factorial two-way model. |
| One numeric outcome and one categorical factor | No | Use One Way ANOVA. |
| Two factors plus a covariate | No | Use ANCOVA or Two Way ANCOVA. |
| Repeated measurements are involved | No | Use Mixed ANOVA or repeated-measures logic. |
| Multiple dependent variables are involved | No | Compare with One Way MANOVA or Mixed MANOVA. |
Two Way ANOVA should be compared with Factorial ANOVA, One Way ANOVA, Fixed Effects ANOVA, Nested ANOVA, Balanced ANOVA, Brown Forsythe ANOVA, ANOVA Effect Size, ANOVA in SPSS, ANOVA in R and ANOVA in Python.
Downloads and Resources for Two Way ANOVA
Use these resources to reproduce the Two Way ANOVA workflow. The Python report, R report and SPSS output PDF are included as verification files. Script and workbook placeholders can be replaced after the final downloadable files are uploaded to the WordPress Media Library.
Download Dataset
Practice dataset with G3, studytime and school variables.
Download Two Way ANOVA Python Report PDF
Python report PDF for interaction plots, p-values, effect sizes and diagnostics.
Download Two Way ANOVA R Report PDF
R validation PDF for two-way ANOVA interpretation.
Download Two Way ANOVA SPSS Output PDF
SPSS output PDF for factorial ANOVA reporting and interpretation.
Download Python Script
Python code for Two Way ANOVA tables, effect sizes and charts.
Download R Script and Excel Workbook
R workflow and Excel support workbook for Two Way ANOVA summaries.
FAQs About Two Way ANOVA
What is Two Way ANOVA?
Two Way ANOVA is a factorial ANOVA method used to test one numeric dependent variable across two categorical factors, including both main effects and their interaction.
What variables were used in this example?
The dependent variable was G3 final grade. The two factors were studytime and school.
Was the studytime effect significant?
Yes. Studytime was statistically significant, with p = 6.557e-08.
Was the school effect significant?
Yes. School was statistically significant, with p = 2.445e-11.
Was the studytime by school interaction significant?
No. The studytime × school interaction was not significant, with p = 0.7793.
Which effect was strongest?
School had the largest partial eta squared value, about 0.067, followed by studytime at about 0.055.
How is Two Way ANOVA different from One Way ANOVA?
One Way ANOVA tests one factor. Two Way ANOVA tests two factors and their interaction in the same model.
Can Two Way ANOVA be done in Excel?
Excel can create PivotTables and interaction charts, but SPSS, R or Python is recommended for the full factorial ANOVA table and effect-size reporting.
Do I need post hoc tests after Two Way ANOVA?
Post hoc tests are useful for significant factors with more than two levels. In this example, studytime has four levels, so follow-up comparisons may be useful.
How do I report this Two Way ANOVA in APA style?
A concise report is: Studytime and school were significant main effects for G3, while the studytime × school interaction was not significant.
