Hypothesis Testing — ANOVA, Chi-Square, Correlation and Regression
Prerequisite Knowledge
This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.
Previously Covered in This Subject
- Hypothesis testing fundamentals — covered in Lecture 10 (Sampling, Sampling Distributions, and Estimation)
- Normal distribution and Z-scores — covered in Lecture 8 (Bernoulli, Binomial, Poisson, and Normal Distributions)
- Central Limit Theorem and sampling distributions — covered in Lecture 10
- Confidence intervals and significance levels — covered in Lecture 10
Hypothesis Testing: ANOVA, Chi-Square, Correlation and Regression
This lecture completes your hypothesis testing toolkit. You already know how to test one mean (Z-test, t-test), compare two means, and handle one or two proportions. Now you add three powerful extensions: the chi-square test for categorical association, ANOVA for comparing three or more means, and covariance/correlation for measuring relationships between continuous variables. By the end, you will have a complete decision tree: means → Z/t, proportions → Z/chi-square, several proportions → chi-square, several means → ANOVA, and relationships → correlation and regression.
12.1 P-value Approach to Hypothesis Testing
Hook. You run a regression in Python. The summary spits out a column labelled P > |t|. A number like 0.032 sits there. Is it small enough? What is it even telling you? You already know how to reject a hypothesis by checking whether a test statistic crosses a critical value. The P-value gives you the same answer — but from the opposite direction. Instead of asking "is my statistic extreme?", you ask "how surprised should I be if the null is true?"
Intuition + Analogy. Imagine you claim a coin is fair. I flip it 100 times and get 62 heads. That feels like evidence against fairness. But how much evidence? The P-value is the probability of seeing 62 or more heads — or 62 or fewer tails on the other extreme — from a fair coin. If that probability is tiny (say, 0.01), you think: "A fair coin almost never does this. I don't believe the coin is fair." If the probability is large (say, 0.40), you think: "Fair coins do this all the time. Nothing to see here."
The P-value is your surprise meter. The smaller it is, the more surprised you are — and the less you trust the null hypothesis.
When the analogy breaks: The coin flip gives a two-sided P-value naturally. In practice you must decide whether your test is one-tailed or two-tailed. The P-value computation changes accordingly.
12.1.1 The Two Approaches to Decision Making
Formalize. Every hypothesis test boils down to the same structure. You have a null hypothesis (the default claim) and an alternative (what you suspect might be true instead). You gather data and compute a test statistic — a single number that summarizes the evidence. Then you have two ways to decide:
Approach 1 — Critical region. You pick a significance level (say, 0.05). You find the critical value that cuts off the outer of the null distribution. You check whether your test statistic lands in that rejection region.
Approach 2 — P-value. You compute your test statistic. You ask: "If were true, how often would I see a test statistic this extreme — or more?" That probability is the P-value. Then:
Both approaches always agree. A test statistic inside the critical region means . A test statistic outside means . They are two sides of the same coin.
Worked Example — Z-test with P-value. Suppose you run a Z-test on some data and get a test statistic . You chose and this is a two-tailed test.
From the Z-table, the area to the right of is about 0.0085. Since this is two-tailed, the P-value is twice that: .
Now compare: . Reject .
Sense-check: A Z of 2.387 is nearly 2.4 standard deviations from the mean. Values this far out are rare — about 1.7% of the time under the null. That is less than our 5% tolerance, so we reject. The conclusion makes sense.
12.1.2 Symbol Registry — P-value Approach
- — level of significance — the threshold probability you set before seeing data (commonly 0.05, 0.01, or 0.10)
- — P-value — the probability, assuming is true, of observing a test statistic at least as extreme as the one you computed
- — null hypothesis — the default claim you are testing (e.g., "no effect," "no difference")
- — alternative hypothesis — the claim you accept if you reject
12.1.3 When to Use Each Approach
Scope. The critical-region approach shines in textbook problems — you are handed a table, you look up a number, you draw a line. The P-value approach is what every software package reports (R, Python statsmodels, SPSS, Excel). Why? Because the P-value gives you more information. Instead of a binary "reject / don't reject," you get a continuous measure of evidence strength. A P-value of 0.049 and 0.001 both say "reject at ," but the second is far stronger evidence. The critical-region approach hides that gradient.
Both approaches assume you have correctly identified the test (Z, t, F, ) and the tail type (one-tailed vs. two-tailed). Get either wrong, and both approaches give the wrong answer.
Visual Intuition. Picture the bell curve of the null distribution. Mark your test statistic on the horizontal axis. The P-value is the area under the curve beyond that mark — the tail probability. For a two-tailed test, it is the area in both tails combined. The smaller that shaded area, the further your statistic sits from the center, and the harder it is to believe is true. The threshold is a vertical line on the area scale: if the shaded region is smaller than -worth of area, you reject.
Pitfalls.
- "The P-value is the probability that is true." Wrong. The P-value assumes is true. It tells you how unusual your data are under that assumption. It does not tell you the probability that is correct.
- "A large P-value proves ." Wrong. A large P-value means the data are consistent with — not that is true. You might just have too little data to detect a real effect.
- "P < 0.05 means the result is practically important." Wrong. Statistical significance is not the same as practical significance. With a huge sample, a tiny, meaningless effect can produce a tiny P-value.
- One-tailed vs. two-tailed confusion. If you run a two-tailed test and report a one-tailed P-value (or vice versa), your conclusion flips. Always be explicit about which tail you are using.
Recap. The P-value is the probability of seeing data like yours (or more extreme) if the null were true. Compare it against : smaller → reject, larger → don't reject. It is the software era's answer to the critical-region approach — same logic, richer output. Bridge: The P-value appears in every test that follows — chi-square, ANOVA, and regression all report P-values. The rule reject is universal.
Real-World & Domain Connection. Every regression table in economics, every clinical trial result in medicine, every A/B test dashboard in tech reports P-values. When you run model.fit() in scikit-learn and then inspect the summary via statsmodels, the P>|t| column tells you whether each coefficient is statistically different from zero. In ML, P-values help you decide which features to keep — and which might just be noise. But remember: a feature with a high P-value could still matter. The P-value does not replace thinking. It supplements it.
12.2 Chi-Square Test
Hook. You have a spreadsheet with 400 accident records. Each row says: "early hours? yes/no" and "fatal? yes/no." You stare at the numbers and wonder — are late-night accidents really more deadly, or is it just random noise? A Z-test can compare one proportion. A t-test compares means. But here you have several proportions tangled together in a table. You need a test built for categorical grids. That test is the chi-square () test.
Intuition + Analogy. Picture a jury pool. The court expects the pool to match the community's demographics: same proportions of age groups, genders, ethnicities. If the pool has 80% men when the community is 50% men, you get suspicious. The chi-square test does exactly this comparison — but for any number of categories. It asks: "If the two variables really were independent, what counts would I expect to see in each cell?" Then it measures how far the actual counts are from those expectations. The bigger the gap, the more evidence that the variables are linked.
Think of it like checking a restaurant bill. You ordered three dishes. The items and prices are listed. You multiply each item's quantity by its price. You sum them up. The total should match. If it does not, the bill has a problem. Chi-square works the same way: it computes an "expected bill" from the row and column totals. Then it checks whether the "observed bill" matches. The mismatch, squared and scaled, is .
When the analogy breaks: The restaurant bill analogy captures the proportional-allocation logic. But chi-square does not test for errors in arithmetic — it tests whether the pattern of mismatch is too large to be chance. Also, chi-square works with counts, not prices — every cell must be a frequency.
12.2.1 Overview and When to Use
Formalize. The chi-square test handles categorical data. Where Z and t tests deal with means, and Z tests for proportions handle one or two groups, the chi-square test handles several proportions at once. It is classified as a non-parametric test — it does not assume your data come from a normal distribution or any specific distribution.
The chi-square () distribution arises from summing squared standard normal variables. If are independent standard normal variables, then:
follows a chi-square distribution with degrees of freedom. This is why the test statistic squares differences and divides by expectation — it turns count discrepancies into a quantity that, under , follows a known distribution.
There are two main types of chi-square tests:
- Chi-square test for independence — tests whether two categorical variables are associated or independent. Example: "Is smoking habit related to hypertension?"
- Chi-square test for goodness of fit — tests whether observed frequency data follows a particular theoretical distribution (binomial, Poisson, normal, etc.).
12.2.2 Chi-Square Test for Independence
Purpose. You have data organized in a contingency table — rows are one categorical variable, columns are another. Each cell contains a count (frequency). You want to know: are these two variables related, or not?
Hypotheses. The convention is always the same:
- : The two variables are independent (no association).
- : The two variables are not independent (they are associated).
Never swap these. Putting "they are associated" as leads to logical confusion. The test is built to detect departures from independence — so independence is the null.
12.2.3 Chi-Square Test for Goodness of Fit
Purpose. You have frequency data and you suspect it follows a known distribution — binomial, Poisson, normal, etc. The goodness-of-fit test lets you check this formally.
Heuristic. A practical shortcut: if the sample mean is larger than the sample variance, the binomial distribution might be a reasonable fit. The chi-square goodness-of-fit test gives you a rigorous yes/no instead of a heuristic guess.
How it works: You compute expected frequencies under the hypothesized distribution. Then you apply the same formula: sum of across all categories. The degrees of freedom are . Compare against the chi-square table.
12.2.4 Formula and Computation
The chi-square statistic:
Symbol Registry — Chi-Square Test
- — observed frequency for the cell in row , column — the actual count from your data
- — expected frequency for that same cell — the theoretical count if (independence) were true
- — number of rows (do not count the "Total" row)
- — number of columns (do not count the "Total" column)
- Degrees of freedom —
How to compute expected frequencies. Under independence, the proportion of observations in row should be the same across all columns. So:
This is proportional allocation. The grand total is spread across cells in proportion to the row and column shares. This is exactly what you would expect if the two classification variables had nothing to do with each other.
Decision rule: Compare the computed to the critical value from the chi-square table at your chosen and degrees of freedom . If computed is greater than the critical value, reject .
The chi-square distribution is not symmetric like Z or t. It is right-skewed, and the skew lessens as degrees of freedom increase. The rejection region is always on the right tail. When your computed exceeds the critical value, it falls in the rejection region — the observed counts are too far from expected to be chance.
12.2.5 Worked Example 1 — Accident Timing and Fatality
Problem: A study of 400 accident cases produced the following data. Does the data indicate any association between the time of the accident and its fatality? Test at .
Observed Data:
| Early Hours (Yes) | Early Hours (No) | Total | |
|---|---|---|---|
| Fatal | 80 | 19 | 99 |
| Non-Fatal | 200 | 101 | 301 |
| Total | 280 | 120 | 400 |
Step 1 — Hypotheses:
- : Time of accident and fatality are independent.
- : Time of accident and fatality are not independent (they are associated).
Step 2 — Compute expected frequencies. For each cell, :
- Fatal, Early Hours Yes:
- Fatal, Early Hours No:
- Non-Fatal, Early Hours Yes:
- Non-Fatal, Early Hours No:
Step 3 — Compute . For each cell, :
Step 4 — Critical value. Degrees of freedom = . From the chi-square table at and df = 1: .
Step 5 — Decision. . The test statistic falls in the rejection region. Reject .
Conclusion: There is a significant association between the time of the accident and its fatality. The two variables are not independent.
Sense-check: In the observed data, 80 out of 99 fatal accidents (about 81%) happened in early hours, versus 200 out of 301 non-fatal accidents (about 66%). The gap is large enough that random chance cannot explain it. The test confirms what the raw percentages suggest.
12.2.6 Worked Example 2 — Smoking Habits and Hypertension
Problem: A study of 180 individuals collected data on smoking habits (non-smoker, moderate smoker, heavy smoker) and whether they have hypertension. Test whether smoking habit and hypertension are associated.
Observed Data:
| Non-Smoker | Moderate Smoker | Heavy Smoker | Total | |
|---|---|---|---|---|
| Hypertension (Yes) | 21 | 36 | 30 | 87 |
| Hypertension (No) | 48 | 26 | 19 | 93 |
| Total | 69 | 62 | 49 | 180 |
Step 1 — Hypotheses:
- : Smoking habit and hypertension are independent.
- : Smoking habit and hypertension are not independent.
Step 2 — Compute expected frequencies for all six cells:
Step 3 — Compute for each cell, :
Step 4 — Critical value. rows, columns. df = . At and df = 2: .
Step 5 — Decision. . Reject .
Conclusion: Smoking habit and hypertension are significantly associated.
Sense-check: Look at the row percentages. Among those with hypertension: 24% non-smokers, 41% moderate, 34% heavy. Among those without: 52% non-smokers, 28% moderate, 20% heavy. The pattern reverses — non-smokers dominate the no-hypertension group while moderate/heavy smokers dominate the hypertension group. The test confirms this is not random noise.
12.2.7 Student Questions and Answers — Chi-Square
Q: How was the chi-square formula derived? Is there a logic behind it?
A: The chi-square distribution comes from summing squared standard normal variables: if are independent, then . The test statistic approximates this sum because each cell's standardized residual behaves roughly like a standard normal under when sample sizes are large. The full derivation involves the multinomial distribution and a Taylor expansion — but for application purposes, knowing how to compute and interpret the statistic is what matters.
Q: How do I know when to use chi-square versus a t-test or Z-test?
A: Use the decision tree. Means (one mean, two means) → Z or t. Proportions (one proportion, two proportions) → Z. Several proportions, or testing association between categorical variables → chi-square. Chi-square is non-parametric — it makes no normality assumption. The key question: am I comparing counts in categories, or am I comparing numerical averages? Counts → chi-square. Averages → Z/t/ANOVA.
Q: Can we exchange and ? Make the hypothesis of association the null?
A: No. The convention in chi-square is fixed: says "the two variables are independent," and says "they are not independent." This is the standard framing for a test of independence. Swapping them leads to confusion about what the test is measuring. The chi-square statistic is built to measure departures from independence — so independence must be the baseline ().
Q: What is the ideal chi-square value?
A: There is no "ideal" value. The statistic is computed from data and compared against the critical value from the table. The critical value depends on your chosen and degrees of freedom. A small means the data fits the independence assumption well. A large means it doesn't. The decision (reject or not) comes from the comparison, not from the raw number. Think of it like a thermometer — 98.6°F is "normal" but the number itself has no moral weight.
Q: How do we arrive at the degrees of freedom? Why ?
A: Degrees of freedom for chi-square independence is . Here is why. In a contingency table with fixed row and column totals, once you fill rows and columns, the remaining cells are determined — they are not free to vary. So you have independent cells. For a table: . For a table: .
Q: What if is not given in the problem?
A: You are free to choose. Common choices are 1% (0.01), 5% (0.05), or 10% (0.10). State your choice explicitly: "I am testing at a 5% level of significance." Be aware that the conclusion can change with a different . A result significant at 5% may not be significant at 1%. This is normal — different confidence thresholds can lead to different decisions.
Q: How do we know the rejection region for chi-square? Is it right-tailed?
A: The chi-square distribution is right-skewed and always positive, so the concept of "left-tailed" does not apply naturally. The rejection region is on the right side. If computed is greater than the critical value, reject . If less, do not reject. For example, at df = 1 and : critical = 3.841. A computed value of 7.31 → reject. A computed value of 2.14 → do not reject. The logic: larger means larger mismatch between observed and expected — exactly what you would see if the variables were not independent.
Q: Is chi-square only for two proportions? The smoking example has three categories.
A: No. Chi-square handles several proportions. The smoking example involves multiple proportions simultaneously: 87/180 have hypertension, 69/180 are non-smokers, 21/69 non-smokers have hypertension, and so on. All these proportions collectively test whether the variables are independent. This is why chi-square sits at the "several proportions" branch of the decision tree.
Q: Is a contingency table similar to a confusion matrix?
A: Structurally, yes — both are grids of counts with rows and columns. But a confusion matrix serves a different purpose: it compares predicted labels against true labels in classification. The chi-square test asks a different question: are the row and column classifications independent? The structural resemblance is helpful for recognizing contingency tables, but chi-square has its own statistical framework. Don't mix up the two contexts.
Scope. The chi-square test for independence assumes:
- Random sampling. The data come from a random sample.
- Independent observations. Each subject contributes to exactly one cell.
- Adequate expected frequencies. A common rule of thumb: no expected cell frequency should be below 1, and no more than 20% of cells should have expected frequencies below 5. If this rule is violated, the approximation to the true sampling distribution deteriorates. For tables with small samples, use Fisher's exact test instead.
- Categorical data. Both variables must be categorical (nominal or ordinal). Chi-square does not work with continuous variables unless they are binned — and binning loses information.
Visual Intuition. Imagine a grid of four bars. The height of each bar is the observed count. Superimpose a second set of bars — shorter or taller — representing the expected counts under independence. The chi-square statistic is the sum, over all four bars, of (squared height difference) divided by expected height. A bar where observed is 80 and expected is 69 contributes . A bar where observed is 101 and expected is 90 contributes . The final is the total squared-and-scaled mismatch across the whole grid.
Pitfalls.
- Small expected frequencies. If any is too small (below 5, and especially below 1), the chi-square approximation breaks down. The test may give a significant result when it shouldn't, or fail to detect a real association. Always check the expected frequency table before trusting the result.
- Chi-square does not measure strength of association. A significant result tells you the variables are probably related. It does not tell you how strongly. For that, use measures like Cramér's V or the phi coefficient.
- Causation is not implied. "Smoking is associated with hypertension" does not mean "smoking causes hypertension." Chi-square only detects association, not causation.
- The test is sensitive to sample size. With a huge sample, even a very small association becomes statistically significant. With a tiny sample, a large real association might be missed. Always report effect size alongside the P-value.
- Don't confuse goodness-of-fit with independence. They use the same formula but answer different questions. Independence = two variables in a contingency table. Goodness-of-fit = one variable compared to a theoretical distribution.
Recap. The chi-square test compares observed counts to expected counts under the assumption of independence. . If the computed value exceeds the critical value at df = , reject and conclude the variables are associated. Bridge: Chi-square handles several proportions. The next test — ANOVA — handles several means, using a similar "compare two kinds of variation" logic.
Real-World & Domain Connection. Chi-square tests appear everywhere categorical decisions are made. Market researchers use them to see if purchase intent differs by age group. Medical researchers test whether a treatment response varies by genetic marker. In A/B testing, chi-square tests whether conversion rates differ across multiple landing page variants. In ML, chi-square is used as a feature selection method — sklearn.feature_selection.chi2 scores each feature against the target to identify the most relevant categorical predictors. The chi-square test of independence is one of the oldest statistical tools still in wide use. Karl Pearson invented it in 1900, and it has never gone out of style.
12.3 ANOVA — Analysis of Variance
Hook. You are testing three different fertilizers on crop yield. Fertilizer A averages 10 bushels, B averages 8, C averages 12. Are these differences real, or just random variation? A t-test compares two means. But you have three. You could run three separate t-tests — A vs B, B vs C, A vs C — but each test carries its own risk of a false positive. Run enough t-tests and you are practically guaranteed to "find" something that isn't there. You need a single test that asks: "Are all these means the same?" That test is ANOVA.
Intuition + Analogy. Imagine three archers shooting at their own targets. Each archer has a spread (their shots cluster around their own bullseye). The three bullseyes might also be at different positions. ANOVA separates the total variation into two buckets:
- Within-group variation: How much does each archer's own spread vary? This is natural noise — shooting inconsistency.
- Between-group variation: How far apart are the three bullseyes? If the bullseyes are far apart relative to each archer's spread, you conclude the archers are aiming at different targets.
The F-statistic is the ratio: between-group variation divided by within-group variation. A large F means the bullseyes are far apart compared to the spread — the group means are genuinely different. A small F means the bullseyes might as well be in the same place — any apparent differences could just be random wobble.
When the analogy breaks: Real data can have unequal group sizes and unequal within-group variances. The basic ANOVA assumes equal variances (homoscedasticity) and normality within each group. When these break, you need Welch's ANOVA or non-parametric alternatives like the Kruskal-Wallis test.
12.3.1 Overview and When to Use
Formalize. ANOVA stands for ANalysis Of VAriance. The name is honest: although the goal is to compare means, the method works by analyzing variances. Specifically, it partitions the total variation in the data into components attributable to different sources.
The decision tree:
- One mean → single-mean Z or t test
- Two means → two-sample Z or t test
- Three or more means → ANOVA (F-test)
Just as chi-square handles several proportions, ANOVA handles several means. Both use a single test to avoid the multiple-comparisons problem — the inflation of Type I error that comes from running many pairwise tests.
The null hypothesis in ANOVA is always:
The alternative:
Note: does not say all means differ. It says at least one differs. ANOVA tells you there is a difference somewhere. It does not tell you which groups differ. For that, you need post-hoc tests (Tukey's HSD, Bonferroni, etc.).
12.3.2 The Two Kinds of Variance
Think about what happens when you have groups (samples from populations). There are two sources of variation:
- Between-group variance (treatment variance). How different are the group means from one another? If the population means truly differ, the group means will be spread out. This is captured by the Sum of Squares due to Treatment (SSTR) — also called SSB (Sum of Squares Between).
- Within-group variance (error variance). How much do individual observations vary within each group? This is the natural noise — measurement error, individual differences, uncontrolled factors. It is captured by the Sum of Squares due to Error (SSE) — also called SSW (Sum of Squares Within).
The F-statistic is the ratio:
MSTR is the Mean Square for Treatment — the average between-group variation per degree of freedom. MSE is the Mean Square for Error — the average within-group variation per degree of freedom.
If the between-group variation is large relative to the within-group variation, F is large, and you reject . If the groups overlap heavily (within-group spread dominates), F is close to 1 or less, and you fail to reject .
12.3.3 The ANOVA Computation Framework
Symbol Registry — One-Way ANOVA
- — number of groups (populations being compared)
- — number of observations in group
- — total number of observations across all groups
- — grand mean (mean of all observations combined)
- — mean of group
- — the -th observation in group
- SSTR — Sum of Squares due to Treatment (between groups)
- SSE — Sum of Squares due to Error (within groups)
- SST — Total Sum of Squares = SSTR + SSE
- MSTR — Mean Square Treatment = SSTR /
- MSE — Mean Square Error = SSE /
- — test statistic = MSTR / MSE
- Degrees of freedom: numerator = , denominator =
SSTR formula. For each group, take the group mean's deviation from the grand mean. Square it. Multiply by the number of observations in that group. Sum across all groups:
SSE formula. For each group, take each observation within that group, find its deviation from that group's mean, square it, and sum across all observations:
The partition identity. The total sum of squares always decomposes as:
where . This identity says: total deviation from the grand mean equals the deviation explained by group membership plus the unexplained deviation within groups. It is the same logic as in regression — and in fact, ANOVA is a special case of linear regression with categorical predictors.
12.3.4 Worked Example — Three Groups
Problem: Three groups with five observations each. Test at whether there is a significant difference in the means of the three populations (assume normal populations with equal variances).
| Group 1 | Group 2 | Group 3 |
|---|---|---|
| 8 | 7 | 12 |
| 10 | 5 | 9 |
| 10 | 8 | 12 |
| 10 | 10 | 15 |
| 12 | 10 | 12 |
Step 1 — Group means and grand mean:
Step 2 — SSTR (Between-groups):
Step 3 — SSE (Within-groups):
Group 1:
Group 2:
Group 3:
Step 4 — SST check: . ✓
Step 5 — Degrees of freedom:
- SSTR df:
- SSE df:
Step 6 — Mean squares:
Step 7 — F-statistic:
Step 8 — Critical value. From the F-table at , with numerator df = 2 and denominator df = 12: .
Step 9 — Decision. . Reject . There is a significant difference among the three group means.
Sense-check: Group 2's mean (8) is notably lower than Group 1 (10) and Group 3 (12). The within-group spreads are moderate (SSE = 44). The between-group spread (SSTR = 40) is large enough relative to the within-group noise to conclude these differences are real. The F of 5.45 comfortably clears the 3.89 threshold.
12.3.5 Understanding the F-Table
The F-distribution has two degrees of freedom — one for the numerator () and one for the denominator (). The F-table is two-dimensional:
- The numerator degrees of freedom () usually runs across the top row as column headers.
- The denominator degrees of freedom () usually runs down the first column as row labels.
- The body of the table gives F critical values for a specific (typically separate tables for 0.05 and 0.01).
To look up a critical value: first pick the table with your chosen . Then find the column for your numerator df. Then find the row for your denominator df. The number at that intersection is your critical F.
The F-distribution is right-skewed and always positive (it is a ratio of variances, which are always non-negative). The rejection region is always on the right tail. A larger F means stronger evidence against .
12.3.6 Two-Way ANOVA
Comparison: One-Way vs. Two-Way ANOVA. Sometimes you have two independent classification variables. For example: you are testing three kinds of fertilizers (Factor A: treatment) across four different soil types (Factor B: blocks). You want to know if either factor affects yield.
| Feature | One-Way ANOVA | Two-Way ANOVA |
|---|---|---|
| Number of factors | 1 | 2 |
| Hypotheses tested | 1 (are all group means equal?) | 2 (is Factor A significant? is Factor B significant?) |
| SS components | SSTR + SSE = SST | SSTR + SSBL + SSE = SST |
| F-statistics computed | 1 (MSTR/MSE) | 2 ( and ) |
| When to use | One categorical predictor | Two categorical predictors simultaneously |
In two-way ANOVA, you compute two F-statistics:
Each F has its own degrees of freedom: for Factor A, and for Factor B. Compare each against its respective critical value from the F-table. Make two independent decisions — one for each factor.
The Correction Factor (CF) sometimes appears in computational formulas. It is:
where is the grand total of all observations (sum, not mean) and is the total number of observations. CF simplifies the sums-of-squares arithmetic by pre-computing the "baseline" term that appears in every SS formula.
12.3.7 ANOVA in the Machine Learning Context
This is where ANOVA becomes directly relevant to your ML workflow. When you train a multiple regression model:
The model summary (from statsmodels or R's lm) shows an F-statistic and its P-value. The hypothesis being tested is:
This is an ANOVA problem — testing whether any of several coefficients differ from zero. The F-test tells you whether the overall regression model explains a significant amount of variance in the response. If the F-statistic is large and the P-value is small, at least one predictor has a genuine relationship with the target.
This is the overall F-test for model significance — one of the most important diagnostics you will read in any regression output.
Note: ANOVA is computationally heavy. In exams, you will typically not be asked to solve a full ANOVA numerical from scratch. The emphasis is on understanding the concept, knowing when to apply it, and interpreting results. Assignments may include ANOVA computations.
12.3.8 Student Questions and Answers — ANOVA
Q: In ANOVA, is always about means being equal, unlike chi-square where is about independence?
A: Yes. The null hypothesis changes with the test because each test is designed to answer a different kind of question. In ANOVA, is that all population means are equal: . In chi-square, is that the variables are independent. In a single-mean Z-test, is . Each test type has its own standard formulation tied to what the test evaluates.
Q: Can ANOVA be used to choose batch sizes in stochastic gradient descent — checking whether different groups have the same variance?
A: That is an interesting angle, but it is not a standard application. The F-test in ANOVA assumes normality and equal variances (homoscedasticity). In the SGD batch context, the gradient variance across batches depends on the data distribution and mini-batch composition in complex ways. Levene's test or Bartlett's test — which directly test equality of variances — would be more appropriate for comparing batch variances. ANOVA compares means, not variances, despite its name.
Q: What does stand for in the ANOVA formulas?
A: is the number of groups or populations being compared. is the total number of observations across all groups. Individual group sizes are , so .
Q: How do we read the F-table when there are two degrees of freedom?
A: The F-table is two-dimensional. The numerator degrees of freedom () is typically the column index across the top. The denominator degrees of freedom () is the row index down the side. To look up: identify the table for your (0.05, 0.01, etc.). Find your column. Find your row. The number at that intersection is your critical F-value. Always double-check which axis is which — different textbooks flip them.
Q: What is CF in the ANOVA calculation?
A: CF stands for Correction Factor. It equals , where is the grand total (sum of all observations, not the mean). It appears in the shortcut formulas for sums of squares. For example, . It simplifies the arithmetic by pre-computing a term that would otherwise be subtracted repeatedly.
Scope. One-way ANOVA assumes:
- Independence. Observations within and between groups are independent.
- Normality. Each group's population is roughly normally distributed. ANOVA is fairly resistant to moderate violations of normality, especially with equal sample sizes.
- Homogeneity of variance (homoscedasticity). All groups have equal population variances. This is the most critical assumption. If variances differ substantially (especially with unequal sample sizes), use Welch's ANOVA instead.
- Random sampling. Data are random samples from their respective populations.
What breaks when assumptions fail:
- Unequal variances with unequal sample sizes → inflated Type I error (you reject too often).
- Severe non-normality with small samples → the F-distribution approximation degrades.
- Dependent observations (e.g., repeated measures on the same subjects) → use repeated-measures ANOVA instead.
Visual Intuition. Draw three bell curves side by side on the same axis, representing the three group distributions. The horizontal axis is the measurement scale. Each curve is centered at its group mean. The width of each curve reflects the within-group standard deviation. If the three curves overlap heavily — their peaks are close and their tails intermingle — you cannot tell them apart. The F is small. If the three curves are well-separated — their peaks are far apart relative to their widths — you can easily distinguish the groups. The F is large. The F-statistic quantifies this visual judgment: separation between peaks divided by average width.
Pitfalls.
- ANOVA tells you that groups differ, not which groups differ. A significant F means at least one mean is different. To find which pairs differ, run post-hoc tests (Tukey's HSD is the most common). Don't just run pairwise t-tests — that inflates the familywise error rate.
- Don't use ANOVA for two groups. A two-sample t-test and a one-way ANOVA with give the same P-value (the F is exactly ). But the t-test is simpler and can be one-tailed. Use the right tool for the job size.
- "Analysis of Variance" does not mean you are testing variances. You are testing means. The name refers to the method, not the hypothesis.
- A non-significant F does not mean all means are equal. It means you lack evidence to conclude they differ. The sample sizes might be too small. Absence of evidence is not evidence of absence.
- Confusing SSTR and SSE. SSTR = between-group variation (the signal you want to detect). SSE = within-group variation (the noise). If you swap them, your F is inverted and your conclusion is nonsense.
Recap. ANOVA compares three or more means by partitioning total variation into between-group (SSTR) and within-group (SSE) components. . If F exceeds the critical value from the F-table at df = , reject — at least one group mean differs. Bridge: ANOVA uses the F-test. The next concepts — covariance and correlation — shift focus from comparing groups to measuring relationships between two continuous variables.
Real-World & Domain Connection. ANOVA is the workhorse of experimental design. Pharmaceutical companies use it to compare drug dosages. Manufacturing engineers use it to compare production line outputs. Agricultural scientists use it to compare crop varieties (this is where ANOVA was born — R.A. Fisher developed it at the Rothamsted agricultural research station in the 1920s). In ML, the overall F-test in regression summaries is ANOVA. Every time you run statsmodels.api.OLS and look at the top of the summary output for "F-statistic" and "Prob (F-statistic)," you are reading an ANOVA result. In tech, A/B tests with more than two variants (A/B/C/D tests) use ANOVA to determine whether any variant outperforms the others before running pairwise comparisons.
12.4 Covariance
Hook. You have two columns of numbers — say, age and weight for five children. As age goes up, weight goes up. You can see it in the table. But how do you put a single number on that "moving together" pattern? Before you can measure the strength of a relationship, you need to measure its direction. Covariance is that first number.
Intuition + Analogy. Think of two dance partners. When one steps forward, the other also steps forward — that is positive covariance. When one steps forward and the other steps back — that is negative covariance. When their steps have no pattern at all — that is zero covariance.
Now, here is the math picture. Take each data point and ask: "Is X above or below its average? Is Y above or below its average?" Multiply those two deviations. If both are above-average (positive × positive = positive) or both below-average (negative × negative = positive), the product is positive — the pair agrees in direction. If one is above and the other below (positive × negative = negative), the product is negative — the pair disagrees. Sum all these products. Divide by . That is covariance.
When the analogy breaks: The dance partners analogy captures direction only. It says nothing about how tightly they move together. A couple doing a formal waltz (tightly synchronized) and a couple casually swaying (loosely synchronized) could have the same direction but different strength. Covariance cannot tell you the difference — its magnitude is scale-dependent.
12.4.1 Definition and Formula
Formalize. Covariance measures how two variables move together. It is the expected value of the product of their deviations from their respective means:
Symbol Registry — Covariance
- — two random variables (or two columns of data)
- — sample mean of
- — sample mean of
- — number of observations (use for sample covariance, for population covariance)
A key identity. If you set , then:
Variance is just covariance of a variable with itself. This is why covariance is the more fundamental concept — variance is a special case.
12.4.2 Worked Example — Age and Weight
Data:
| Age (X) | Weight (Y) |
|---|---|
| 1 | 8 |
| 3 | 14 |
| 5 | 18 |
| 7 | 24 |
| 9 | 31 |
Step 1 — Means:
Step 2 — Deviations and products:
| Product | ||
|---|---|---|
Sum of products = .
Step 3 — Covariance (sample):
(Some formulations divide by instead of , giving . The version is the sample covariance — the unbiased estimator of the population covariance.)
Sense-check: Age and weight both increase. Every product term is non-negative. The covariance is positive — that matches the visible pattern in the data.
12.4.3 Interpretation of Covariance
- Positive covariance (): X and Y tend to move in the same direction. When X is above its mean, Y tends to be above its mean.
- Negative covariance (): X and Y tend to move in opposite directions. When X is above its mean, Y tends to be below its mean.
- Zero covariance (): No consistent linear pattern of co-movement.
The critical limitation. Only the sign of covariance is interpretable. The magnitude is meaningless on its own. A covariance of 28 versus 280 tells you nothing about relationship strength. If you change units — pounds to kilograms, inches to centimeters — the covariance changes by a multiplicative factor. The number 28 is tied to the specific units of age (years) and weight (kg, or whatever units were used). Change the units and you change the covariance. There is no upper or lower bound — covariance can be any real number.
This is why covariance gives you direction but not strength. For strength, you need to normalize. That normalization is the correlation coefficient.
Visual Intuition. Plot the five (age, weight) points on a scatterplot. Draw a vertical line at and a horizontal line at . These lines divide the plot into four quadrants. Points in the top-right quadrant (both above average) and bottom-left quadrant (both below average) contribute positive products. Points in the top-left and bottom-right contribute negative products. In this dataset, all five points fall in quadrants that yield positive products — four in top-right/bottom-left and one on the boundary (the point at the means gives zero). The covariance is the average of these signed quadrant contributions.
Pitfalls.
- Covariance magnitude is uninterpretable. Never say "a covariance of 28 means a strong relationship." It means nothing about strength. Always convert to correlation for strength.
- Zero covariance does not mean independence. Two variables can have a perfect non-linear relationship (a circle, a parabola) and zero covariance. Covariance only detects linear co-movement.
- Outliers distort covariance heavily. A single extreme point in one quadrant can dominate the sum and flip the sign. Always plot your data before computing covariance.
- Don't confuse sample and population covariance. Dividing by vs. changes the value. For inference about a population, use . For describing a complete dataset (the entire population), use .
Recap. Covariance measures the direction of linear co-movement between two variables. → move together; → move opposite; → no linear pattern. The magnitude is scale-dependent and uninterpretable. Bridge: To fix the scale problem, divide covariance by the product of the two standard deviations. That gives you Pearson's correlation coefficient — a pure, unitless number between and .
Real-World & Domain Connection. Covariance is the building block of modern portfolio theory in finance. The covariance matrix of asset returns tells you how stocks move together — and diversification works precisely by combining assets with low or negative covariance. In ML, the covariance matrix appears in Principal Component Analysis (PCA): PCA diagonalizes the covariance matrix to find the directions of maximum variance. In deep learning, batch normalization implicitly uses covariance structure to stabilize training. Covariance is also the numerator of the slope in simple linear regression: .
12.5 Correlation Coefficient — Pearson's r
Hook. Covariance told you age and weight move together — a positive number, direction confirmed. But is the relationship tight? Loose? Covariance cannot say. You need a number that always lives between and , where means "perfectly opposite," means "no linear pattern," and means "perfectly in sync." That number is Pearson's .
Intuition + Analogy. Think of covariance as a raw score on a test — "28 points." Without knowing the maximum possible score, 28 means nothing. Correlation is like converting that raw score to a percentage. You divide by the maximum possible spread — the product of the two standard deviations. Now the number is always between and . A correlation of is like scoring 90% on the "how-linear-is-this-relationship" test.
Another analogy: covariance is like measuring the distance between two cities in "hours of travel." It depends on whether you walk, drive, or fly. Correlation is like measuring distance in "fraction of the Earth's circumference" — it is unitless and comparable everywhere.
When the analogy breaks: The percentage analogy works for interpretability but not for the math. Unlike a test score, can be exactly or — those are achievable with perfectly linear data. Also, is not a "percentage of relationship explained." For that, use (the coefficient of determination), which tells you the fraction of variance in Y explained by X.
12.5.1 Definition and Formula
Formalize. Pearson's is covariance normalized by the product of the two standard deviations:
Expanding both numerator and denominator:
Symbol Registry — Correlation Coefficient
- — Pearson correlation coefficient — a pure number (no units), always in
- — sample standard deviation of
- — sample standard deviation of
- — sample means
Why the bounds? The Cauchy-Schwarz inequality guarantees that . The numerator can never exceed the denominator in absolute value. So is mathematically guaranteed, not just a convention.
Derivation for the age-weight example. From Section 12.4, we have:
Let us compute the denominator:
Sense-check: is extremely close to 1. The data points are five ages and weights that grow almost perfectly together. A near-perfect positive correlation is exactly what the scatterplot would show.
12.5.2 Interpretation of r Values
- : Perfect positive linear relationship — all points lie exactly on a line with positive slope.
- : Perfect negative linear relationship — all points lie exactly on a line with negative slope.
- : No linear relationship (but possibly a strong non-linear one — see 12.5.5).
- The sign of tells the direction (same as covariance).
- The absolute value tells the strength.
Strength guidelines (approximate, not hard rules):
- from 0.75 to 1.0: Strong correlation
- from 0.5 to 0.75: Moderate correlation
- from 0 to 0.5: Weak correlation
12.5.3 Using Correlation for Feature Selection in ML
This is where correlation becomes a direct tool in your ML workflow. Suppose you have a target and five features . You compute:
- — strong
- — weak
- — moderate
- — negligible
- — weak
and are the most promising features. and look like noise — at least from a linear perspective.
The correlation heat map. You have seen this. It is an grid of colored cells. Each cell shows . The diagonal is always 1 (a variable correlates perfectly with itself). Dark red often means strong positive, dark blue strong negative, white means near zero. Heat maps are typically the first thing you generate in exploratory data analysis — sns.heatmap(df.corr()) in Python.
Feature-vs-feature correlation (multicollinearity). If two features are strongly correlated with each other (e.g., and have ), they are redundant. Keeping both can:
- Introduce instability. The model cannot decide which feature to assign the effect to — small data changes flip the coefficients.
- Inflate standard errors. The coefficient estimates become unreliable.
- Add unnecessary complexity. More features without more information.
When two features are strongly correlated, consider removing one. The choice of which to remove involves domain expertise, not just the correlation number.
12.5.4 The Domain Expert Override — When Statistics Is Not Enough
A critical principle: statistical measures guide you, but they do not make the final decision. You must consult domain experts.
The brother-in-law problem. You are inviting 20 people to a party from a social circle of 1,000. Statistically, your brother-in-law might not rank in the top 20 by friendship score. But socially, you cannot exclude him. The domain expert — your spouse — overrides the statistical ranking.
The brake-pedal problem. You analyze driving data for an SUV driven mostly on highways. The brake pedal shows very low usage — low correlation with anything. Can you tell the manufacturer to remove the brakes? No. The automotive engineer knows brakes are critical for safety, even if the current dataset happens not to highlight them.
In ML terms: a feature with low correlation to the target may still be critically important for reasons the data alone cannot capture. Always validate feature-elimination decisions with the stakeholder who understands the domain.
12.5.5 Linear vs Non-Linear Relationships — A Critical Warning
When , it means there is no linear relationship. It does NOT mean there is no relationship at all.
Consider data points that form a perfect circle centered at the origin. For every point , there is a point and also a point — the products cancel perfectly. The correlation is exactly 0. Yet the relationship is perfectly deterministic.
Or consider a U-shaped parabola: . As increases from 0 to 10, first decreases then increases. The correlation can be near zero, but the relationship is exact.
This is the biggest limitation of Pearson's : it only detects linear relationships. In the real world, most relationships are non-linear. If , do not conclude the variables are unrelated. There may be a strong curved, periodic, or otherwise non-linear pattern.
This is also why regression — which lets you model non-linear relationships by choosing polynomial, exponential, or other functional forms — is the natural next step after correlation.
12.5.6 Student Questions and Answers — Correlation
Q: Is the correlation coefficient computed as a single value or an array?
A: For one pair of variables (X, Y), you get a single number . But when you have many features, you compute for every pair. If you have 10 variables, you compute pairwise correlations (only 45 are unique — the matrix is symmetric, and the diagonal is always 1). That is why the correlation heat map is an grid. Each cell is a single value for one pair of variables.
Q: In real-world problems, most relationships are non-linear. How do we handle that if Pearson's only measures linear relationships?
A: This is exactly the limitation of Pearson's . The answer leads into regression, where you can model non-linear relationships by choosing appropriate functional forms — polynomial (), exponential (), logarithmic, and so on. There are also rank-based correlation measures like Spearman's and Kendall's that can detect monotonic (but not necessarily linear) relationships. Spearman's is Pearson's applied to the ranks of the data instead of the raw values — it captures any monotonic trend, not just straight lines.
Q: If , is that weakly or moderately correlated?
A: 0.2 is generally considered a weak positive correlation. Rough guidelines: 0 to 0.5 is weak, 0.5 to 0.75 is moderate, and 0.75 to 1.0 is strong. These are not hard rules — they are heuristics. Context matters. In some fields (like psychology), can be considered meaningful. In physics, you might expect for a well-established law. Always interpret in the context of your domain.
Q: Does mean the variables are independent?
A: No. means there is no linear relationship. The variables could still be related through a non-linear pattern — a circle, a parabola, a sine wave. Independence is a stronger condition: it means knowing X tells you nothing at all about the distribution of Y. Zero correlation is necessary for independence (if variables are independent, ), but it is not enough — you can have with strong dependence. This is one of the most important distinctions in the course and a classic exam question.
Q: Can we get more practice problems on covariance and correlation?
A: Yes. The computational part is straightforward — find means, deviations, products, sum, and divide. The interpretation is what exam questions usually target. Focus on four key exam points. (1) What the sign of tells you about direction. (2) What the magnitude of tells you about strength. (3) Why does not imply independence. (4) Why covariance's magnitude is uninterpretable while 's magnitude is.
Scope. Pearson's assumes:
- Linear relationship. It only measures linear association. If the true relationship is curved, will underestimate the strength of association.
- Interval or ratio data. Both variables should be continuous and measured on scales where differences are meaningful.
- No extreme outliers. A single outlier can dramatically change . Always plot the data first.
- Bivariate normality (for inference). If you want to test whether is significantly different from zero, the standard test assumes both variables are normally distributed. For large samples, this assumption relaxes.
What breaks when assumptions fail:
- Non-linear relationships → is misleadingly close to zero. Use Spearman's or fit a non-linear model.
- Outliers → can be pulled toward or away from zero dramatically. Use resistant correlation measures.
- Ordinal data → Pearson's is inappropriate. Use Spearman's or Kendall's rank correlation.
Visual Intuition. Imagine a scatterplot with on the horizontal axis and on the vertical axis. : all points lie on a straight line sloping upward. : a tight upward-pointing cigar shape. : a diffuse upward-pointing cloud. : a round, shapeless cloud — or a perfect circle, or a U-shape. : a tight downward-pointing cigar. The tighter the cigar, the closer is to 1. The rounder the cloud, the closer is to 0.
Pitfalls.
- Correlation is not causation. close to 1 does not mean X causes Y. Ice cream sales and drowning deaths are positively correlated — because both increase in summer. A third variable (temperature) drives both.
- Restricted range hides correlation. If you only look at a narrow slice of X values, can appear near zero even when the full-range relationship is strong. SAT scores and college GPA correlate about 0.5 overall — but within a single highly selective university, the correlation can be near zero because everyone has high SAT scores.
- Ecological correlation (aggregation bias). Correlations computed on group averages can be much larger than correlations on individuals. The correlation between income and education at the country level is not the same as at the individual level.
- Don't use for binary or categorical data. Pearson's requires continuous variables. For categorical data, use chi-square, Cramér's V, or the phi coefficient.
- , not , measures "variance explained." An of 0.7 sounds impressive — but , meaning only 49% of the variance in Y is explained by X. The other 51% is unexplained. Always square to get the proportion of shared variance.
Recap. Pearson's is covariance normalized to . The sign gives direction, the absolute value gives linear strength. means no linear relationship — but potentially a strong non-linear one. Correlation is the first tool in any data exploration workflow — it ranks features, exposes redundancy, and tells you where to look next. Bridge: Correlation measures association. The next step — regression — models the functional form of the relationship and lets you predict Y from X, including non-linear forms that Pearson's cannot capture.
Real-World & Domain Connection. Correlation is everywhere in data science. Finance: the correlation matrix of stock returns drives portfolio optimization. Genomics: gene co-expression networks are built from pairwise correlations. Recommender systems: user-user and item-item correlations power collaborative filtering. In ML pipelines, df.corr() is often the very first line of code after loading data — it surfaces which features might matter, which are redundant, and where to investigate further. The correlation heat map is the most common figure in any Kaggle notebook's exploratory data analysis section. But the most important lesson is the one this lecture emphasized: correlation measures linear association only. The real world is curved. Use your eyes — always plot the data.
Exam Guidance Summary
Exam note: ANOVA numerical problems are unlikely in exams due to heavy computation. The focus is on conceptual understanding: when to use ANOVA, what the F-test does, the two kinds of variance (between-group and within-group), and interpreting results. ANOVA may appear in assignments where you have time to work through the computations.
Exam note: Chi-square computations may appear in exams, especially for or contingency tables. Know how to compute expected frequencies, the chi-square statistic, degrees of freedom , and how to compare the computed against the critical value from the table. The worked examples in Section 12.2 are representative of what you might see.
Exam note: Covariance and correlation computational problems are very likely in exams. They are computationally straightforward — find means, deviations, products, sum, and divide. Focus your study on interpretation. Know what the sign of means for direction. Know what the magnitude means for strength. Know why "zero correlation" does not mean "no relationship." And know why covariance magnitude is uninterpretable while correlation magnitude is.
Exam note: The P-value approach may appear as a conceptual question. Know the decision rule cold: if , reject ; if , do not reject. Understand that the P-value is the probability of the observed result (or more extreme) assuming is true — NOT the probability that is true.
Exam note: Know the decision tree for selecting the correct test:
- Means (one or two) → Z-test or t-test
- Proportions (one or two) → Z-test
- Several proportions / categorical association → Chi-square test
- Several means (three or more) → ANOVA (F-test)
This framework is a likely exam question — either as a direct "which test would you use" question or embedded in a larger problem.
Exam note: The distinction between "no linear relationship" () and "no relationship at all" is a classic exam question. Be prepared to explain why does not imply independence, and give a concrete example (a circle, a parabola, a sine wave). Similarly, "correlation does not imply causation" is a perennial favorite — have a clear example ready.
Exam note: Domain expertise as a complement to statistical measures is an important conceptual point. The professor's thought experiments (brother-in-law problem, brake-pedal problem) illustrate that statistical metrics alone are not enough — domain knowledge must guide feature selection and model interpretation.
Key Industry Applications
Chi-square. Testing associations in survey data and market research — does gender relate to product preference? A/B testing with categorical outcomes — do conversion rates differ across multiple landing page variants? Medical studies — does a treatment group show different recovery patterns than a control group? Quality control — are defect types independent of production shifts? In ML, sklearn.feature_selection.chi2 scores categorical features against the target for feature selection. The chi-square test of independence, invented by Karl Pearson in 1900, remains one of the most widely used statistical tools across all industries.
ANOVA. Validating regression models in ML — the overall F-test in any statsmodels regression summary is ANOVA. Comparing A/B test variants when there are more than two treatment arms. Quality control in manufacturing — comparing outputs across multiple production lines or shifts. Agricultural experiments — comparing crop yields across different treatments, fertilizers, or seed varieties (this is where R.A. Fisher invented ANOVA at Rothamsted Research in the 1920s). Pharmaceutical trials — comparing drug efficacy across multiple dosage levels. In tech, any experiment with more than two variants (A/B/C/D testing) uses ANOVA before pairwise post-hoc comparisons.
Covariance. Portfolio theory in finance — the covariance matrix of asset returns is the foundation of diversification and modern portfolio optimization. Principal Component Analysis (PCA) — PCA diagonalizes the covariance matrix to find directions of maximum variance in the data. Linear regression — the slope coefficient . Batch normalization in deep learning implicitly uses covariance structure to stabilize training. Covariance is the fundamental building block — every multivariate statistical method starts with the covariance matrix.
Correlation. Feature selection in ML — df.corr() is often the very first line of code after loading data, surfacing which features relate to the target and which are redundant. Heat-map visualizations — sns.heatmap(df.corr()) appears in most exploratory data analysis notebooks. Finance — correlations between asset returns drive portfolio risk calculations. Genomics — gene co-expression networks are built from pairwise correlations. Recommender systems — user-user and item-item correlations power collaborative filtering. Pearson's remains the most commonly reported measure of association across all scientific fields. This holds despite its limitation to linear relationships. It is simple, interpretable, and serves as the starting point for deeper modeling.
ISM Lecture 12 notes · Hypothesis Testing — ANOVA, Chi-Square, Correlation and Regression
Sections Breakdown
The P-value as an alternative to critical-region testing — computing tail probabilities and making decisions by comparing p against the significance level.
Testing association between categorical variables using contingency tables, expected frequencies, and the chi-square statistic with worked examples.
Comparing three or more group means by partitioning total variation into between-group and within-group components, using the F-test.
Measuring the direction of linear co-movement between two variables — understanding why only the sign, not the magnitude, is interpretable.
Normalizing covariance to a unitless number between -1 and 1 — interpreting strength, handling non-linear relationships, and using correlation for feature selection in ML.
Exam strategy and likely question patterns for hypothesis testing, chi-square, ANOVA, covariance, and correlation.
Real-world uses of chi-square, ANOVA, covariance, and correlation across finance, healthcare, ML, and technology.
Exam Revision Notes
Below is the distilled, exam-ready core of this lecture. Every entry is built from the full textbook notes above. Use this section for rapid review — but if something doesn't make sense, go back to the full explanation in the main content.
P-value Approach to Hypothesis Testing
Must-know: The P-value is the probability of observing data at least as extreme as yours, assuming H0 is true. The decision rule: reject H0 if p ≤ α, do not reject if p > α. The P-value is NOT the probability that H0 is true.
⚠️ Top pitfall: Confusing the P-value with the probability that the null hypothesis is true. The P-value always assumes H0 is true — it does not tell you whether H0 is correct.
Self-check: If your P-value is 0.03 and α = 0.05, do you reject H0? What if α = 0.01?
Connects to: Chi-square test, ANOVA (both report P-values); decision tree for hypothesis testing
Chi-Square Test for Independence
Must-know: The chi-square test assesses whether two categorical variables are independent. H0: variables are independent. The test statistic is χ² = Σ (O − E)² / E with df = (R−1)(C−1). Reject H0 if computed χ² exceeds the critical value from the chi-square table.
⚠️ Top pitfall: Using chi-square when expected frequencies are too small (below 5). This breaks the approximation. Also: a significant result does not imply causation or tell you the strength of association.
Self-check: In a 3×4 contingency table, what are the degrees of freedom for the chi-square test?
Connects to: P-value approach (same decision rule), ANOVA (both compare observed vs. expected patterns), feature selection in ML
ANOVA — Analysis of Variance
Must-know: ANOVA compares three or more group means using the F-test. H0: all means are equal. Total variation is partitioned into between-group (SSTR) and within-group (SSE) components. F = MSTR / MSE = [SSTR/(k−1)] / [SSE/(n−k)]. Reject H0 if F exceeds the critical value from the F-table.
⚠️ Top pitfall: ANOVA only tells you that at least one mean differs — it does not identify which groups differ. Use post-hoc tests (Tukey’s HSD) for pairwise comparisons. Also: ANOVA tests means, not variances, despite the name.
Self-check: With 4 groups and 40 total observations, what are the numerator and denominator degrees of freedom for the F-test?
Connects to: Chi-square (both avoid multiple comparisons), F-test in regression summaries, two-way ANOVA extends to two factors
Covariance
Must-know: Covariance measures the direction of linear co-movement between two variables. Cov > 0 means they move together; Cov < 0 means they move opposite. Only the sign is interpretable — the magnitude is scale-dependent and meaningless on its own. Zero covariance does not imply independence.
⚠️ Top pitfall: Saying “a covariance of 28 means a strong relationship.” The magnitude is uninterpretable without context. Always convert to correlation for strength. Also: zero covariance means no linear relationship, not no relationship.
Self-check: If Cov(X,Y) = −15, what does the sign tell you? What does the magnitude not tell you?
Connects to: Pearson’s r (covariance normalized), linear regression slope β₁ = Cov(X,Y)/Var(X), PCA (covariance matrix diagonalization)
Pearson’s Correlation Coefficient (r)
Must-know: Pearson’s r is covariance normalized to [−1, 1]. The sign gives direction, the absolute value gives linear strength. r = 0 means no linear relationship — but potentially a strong non-linear one (circle, parabola). r = 0 does NOT imply independence. Correlation is not causation.
⚠️ Top pitfall: Assuming r ≈ 0 means no relationship. It only means no linear relationship. Always plot the data. Also: r², not r, measures the proportion of variance explained (r = 0.7 means r² = 0.49, so only 49% of variance is shared).
Self-check: If r = 0 for X and Y, does it mean X and Y are independent? Give a counterexample.
Connects to: Covariance (unnormalized counterpart), chi-square (alternative for categorical data), feature selection in ML, multicollinearity detection
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.