Statistics - UCSC
20 Nov 2025
Quick Recap:
Today’s Question: What if we want to compare MORE than two groups?
By the end of this lecture, you will be able to:
Scenario: An e-commerce company tests four marketing channels:
Question: Do different marketing channels lead to different average customer acquisition costs (CAC)?
Sample: 100 customers from each channel (400 total)
Why not just do 6 t-tests?
The problem: Multiple comparisons inflate Type I error rate!
With \(\alpha = 0.05\) per test: \(P(\text{at least one false positive}) = 1 - 0.95^6 = 0.265\)
26.5% chance of false positive!
Analysis of Variance (ANOVA):
Key Idea: If group means truly differ, variation between groups should be larger than variation within groups
Notation: k groups with means \(\mu_1, \mu_2, \ldots, \mu_k\)
Hypotheses:
Important: \(H_a\) does NOT say which means differ or how many differ!
For our example: \(H_0: \mu_{Email} = \mu_{Social} = \mu_{SEM} = \mu_{Affiliate}\)
Requirements for valid ANOVA:
Good news: ANOVA is fairly robust to violations when:
Total variation = Between-group variation + Within-group variation
Total Sum of Squares (SST):
\[SST = \sum_{i=1}^{k} \sum_{j=1}^{n_i} (x_{ij} - \bar{x})^2\]
Measures total variability from grand mean \(\bar{x}\)
Between-Group Sum of Squares (SSB):
\[SSB = \sum_{i=1}^{k} n_i (\bar{x}_i - \bar{x})^2\]
Measures variability of group means from grand mean
Within-Group Sum of Squares (SSW):
\[SSW = \sum_{i=1}^{k} \sum_{j=1}^{n_i} (x_{ij} - \bar{x}_i)^2\]
Measures variability within each group
The fundamental equation:
\[SST = SSB + SSW\]
Total variation = Explained variation + Unexplained variation
We convert sums of squares to mean squares (variances):
Mean Square Between (MSB):
\[MSB = \frac{SSB}{df_B} = \frac{SSB}{k-1}\]
Variance of group means (adjusted by sample size)
Mean Square Within (MSW):
\[MSW = \frac{SSW}{df_W} = \frac{SSW}{N-k}\]
Average variance within groups (pooled)
where N = total sample size, k = number of groups
Test statistic:
\[F = \frac{MSB}{MSW} = \frac{\text{Between-group variance}}{\text{Within-group variance}}\]
Interpretation:
Distribution: Under \(H_0\), \(F \sim F_{df_B, df_W}\)
Properties:
Facts about F distribution:
Data (Customer Acquisition Cost in $):
| Channel | n | Mean | SD |
|---|---|---|---|
| 100 | $45.20 | $12.50 | |
| Social | 100 | $52.80 | $14.20 |
| SEM | 100 | $48.30 | $13.10 |
| Affiliate | 100 | $55.70 | $15.30 |
Grand mean: \(\bar{x} = \frac{45.20 + 52.80 + 48.30 + 55.70}{4} = 50.50\)
\[SSB = \sum_{i=1}^{k} n_i (\bar{x}_i - \bar{x})^2\]
\[SSB = 100(45.20-50.50)^2 + 100(52.80-50.50)^2\] \[+ 100(48.30-50.50)^2 + 100(55.70-50.50)^2\]
\[= 100(28.09) + 100(5.29) + 100(4.84) + 100(27.04)\]
\[= 2,809 + 529 + 484 + 2,704 = 6,526\]
For each group: \(SS_i = (n_i - 1)s_i^2\)
Email: \((100-1)(12.50)^2 = 99 \times 156.25 = 15,468.75\)
Social: \((100-1)(14.20)^2 = 99 \times 201.64 = 19,962.36\)
SEM: \((100-1)(13.10)^2 = 99 \times 171.61 = 16,989.39\)
Affiliate: \((100-1)(15.30)^2 = 99 \times 234.09 = 23,174.91\)
\[SSW = 15,468.75 + 19,962.36 + 16,989.39 + 23,174.91 = 75,595.41\]
Degrees of freedom:
Mean Square Between:
\[MSB = \frac{SSB}{df_B} = \frac{6,526}{3} = 2,175.33\]
Mean Square Within:
\[MSW = \frac{SSW}{df_W} = \frac{75,595.41}{396} = 190.90\]
\[F = \frac{MSB}{MSW} = \frac{2,175.33}{190.90} = 11.39\]
Interpretation: Between-group variance is 11.39 times larger than within-group variance!
This suggests the group means are different.
Critical value: For \(\alpha = 0.05\), \(df_1 = 3\), \(df_2 = 396\)
Critical value \(\approx 2.63\) (from Google Sheets)
Our test statistic: \(F = 11.39 > 2.63\)
Decision: Reject \(H_0\)
Conclusion: There is significant evidence that average customer acquisition costs differ across marketing channels.
But which channels differ? ANOVA doesn’t tell us! Need post-hoc tests (next course).
Standard format for presenting results:
| Source | SS | df | MS | F | p-value |
|---|---|---|---|---|---|
| Between | 6,526 | 3 | 2,175.33 | 11.39 | <0.001 |
| Within | 75,595 | 396 | 190.90 | ||
| Total | 82,121 | 399 |
Reading the table:
Question: A retail chain tests 3 store layouts. Sales data (in $1000s):
Calculate:
Discuss with your partner (4 minutes), then submit!
What would a large F-statistic tell us?
Function: =F.TEST(array1, array2)
Only compares two arrays - not ideal for ANOVA!
Better approach: Construct your own table in Google Sheets
For k groups with equal sample sizes n:
// Grand mean
=AVERAGE(all_data_range)
// SSB
=n*SUMSQ(group_means_range - grand_mean)
// SSW
=(n-1)*SUMSQ(group1_SD, group2_SD, ...)
// MSB
=SSB/(k-1)
// MSW
=SSW/(n*k-k)
// F-statistic
=MSB/MSW
// P-value
=F.DIST.RT(F_stat, k-1, n*k-k)
What we’ve covered:
Now: F distribution and practical considerations
The F distribution appears in many contexts:
Always: \(F = \frac{\text{Variance explained by model}}{\text{Variance not explained (error)}}\)
Key relationships:
If \(X \sim \chi^2_{df_1}\) and \(Y \sim \chi^2_{df_2}\), then: \[F = \frac{X/df_1}{Y/df_2} \sim F_{df_1, df_2}\]
If \(t \sim t_{df}\), then \(t^2 \sim F_{1,df}\)
As \(df_2 \to \infty\): \(df_1 \times F_{df_1,df_2} \to \chi^2_{df_1}\)
\(F_{df_1,df_2,\alpha}\) (critical value) depends on BOTH degrees of freedom
Special case: When k = 2 (two groups), ANOVA = two-sample t-test
Mathematical relationship:
\[F_{1,df} = t_{df}^2\]
The F-test with 1 numerator df is equivalent to a squared t-test!
Example: Two-sample t-test gives \(t = 2.5\) with df = 58
ANOVA would give \(F = 2.5^2 = 6.25\) with \(df_1 = 1\), \(df_2 = 58\)
Both give identical p-values!
Statistical significance doesn’t tell magnitude!
Eta-squared (\(\eta^2\)): Proportion of total variance explained
\[\eta^2 = \frac{SSB}{SST}\]
Ranges from 0 to 1 (like R-squared in regression)
Cohen’s f: Standardized effect size for ANOVA
\[f = \sqrt{\frac{\eta^2}{1-\eta^2}}\]
Interpretation: Small (0.10), Medium (0.25), Large (0.40)
Marketing channel data:
\[\eta^2 = \frac{SSB}{SST} = \frac{6,526}{82,121} = 0.0795\]
Interpretation: About 7.95% of total variation in CAC is explained by marketing channel.
Cohen’s f:
\[f = \sqrt{\frac{0.0795}{1-0.0795}} = \sqrt{0.0864} = 0.294\]
Medium effect size - practically meaningful difference!
Question: An ANOVA comparing 4 training programs has:
Calculate:
Work with your neighbor (4 minutes), then share your answer!
Interpret the practical significance
ANOVA tells us: “At least one mean differs”
ANOVA does NOT tell us:
Solution: Post-hoc tests
Covered in more advanced courses!
Our marketing channels (ordered by mean CAC):
With post-hoc tests, might find:
Business decision: Prioritize Email and SEM channels for cost efficiency
Using multiple t-tests instead of ANOVA → inflates Type I error
Ignoring assumptions → check normality, equal variances, independence
Confusing significance with importance → always report effect sizes
Stopping at ANOVA → need post-hoc tests to know which groups differ
Wrong df → \(df_B = k-1\), \(df_W = N-k\) (not n-k!)
Causation claims → ANOVA shows association, not causation
Normality violated:
Unequal variances:
Small samples:
Common applications:
This week’s journey:
Lecture 1: Two-sample tests (t-tests, proportion tests) amd Chi-square test.
Lecture 2: ANOVA for multiple groups
Unifying theme: Compare groups, control error rates, report effect sizes, make informed decisions
Next unit: Regression
This builds on:
Rate your confidence (1-5) on Ed Discussion:
Post on Ed Discussion!
Need help? Office hours are your friend!
Sums of Squares:
\[SSB = \sum_{i=1}^{k} n_i (\bar{x}_i - \bar{x})^2\]
\[SSW = \sum_{i=1}^{k} (n_i-1)s_i^2\]
\[SST = SSB + SSW\]
Mean Squares:
\[MSB = \frac{SSB}{k-1}, \quad MSW = \frac{SSW}{N-k}\]
Test Statistic:
\[F = \frac{MSB}{MSW} \sim F_{k-1, N-k}\]
Effect Size:
\[\eta^2 = \frac{SSB}{SST}, \quad f = \sqrt{\frac{\eta^2}{1-\eta^2}}\]
Questions? I have office hours right after class today!
Next up: ANOVA and Linear Regression
Remember:
Keep practicing!
STAT 17 – Fall 2025