liveBook · Manning

Analysis of variance

As explained in Causal AI

Analysis of variance is a statistical technique for testing whether the means of multiple groups differ.

Analysis of variance (ANOVA) tests whether group means differ by comparing variation explained by a categorical variable with residual variation. Here, it evaluates whether distributions of h(L, C, T) change across cost levels, as required by an independence constraint. section 4.5.3

A practical ANOVA workflow connects visualization, model fitting, and hypothesis testing:

  • Group the outcome by the categorical variable and inspect overlapping distributions with a box plot. section 4.5.3
  • Fit an ordinary least-squares model such as h_func ~ C, then obtain the ANOVA table with an F-test. section 4.5.3
  • Interpret PR(>F) as the probability of observing an F-statistic at least this large under the independence null hypothesis. section 4.5.3
  • A p-value near 0.1876 for cost does not reject independence, while smaller values for treatment and location indicate dependence. section 4.5.3
Listing 4.18 Using ANOVA to evaluate independence
from statsmodels.formula.api import ols
import statsmodels.api as sm

model = ols('h_func ~ C', data=df_mod).fit()    #1
aov_table = sm.stats.anova_lm(model, typ=2)   #1
print(aov_table["PR(>F)"]["C"])   #1

model = ols('h_func ~ T', data=df_mod).fit()    #2
aov_table = sm.stats.anova_lm(model, typ=2)    #2
print(aov_table["PR(>F)"]["T"])    #2

model = ols('h_func ~ L', data=df_mod).fit()     #3
aov_table = sm.stats.anova_lm(model, typ=2)  #3
print(aov_table["PR(>F)"]["L"])   #3

Inspect executable statsmodels code that fits separate ordinary least-squares models and extracts ANOVA p-values for C, T, and L. section 4.5.3

How Causal AI covers it

How deep it goes
Provides a worked visualization, regression specification, F-test, and p-value interpretation, without deriving ANOVA mathematically.
Examples
Compares h(L, C, T) across low, medium, and high cost, treatment, and location levels.
What it assumes
Assumes categorical data and hypothesis-testing vocabulary while demonstrating the modeling and interpretation steps explicitly.
What you can do after
Diagnose independence by fitting statsmodels models, reading ANOVA p-values, and comparing them with a rejection threshold.
How it connects
Connects independence, null hypothesis, p-values, F-tests, box plots, and ordinary least-squares models.

Also explained in

Compare how 3 books explain analysis of variance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.