1 Overview & Learning Objectives

The Week 8 readings cover Chapter 11 (Analysis of Variance) and Chapter 12, Sections 1–3 (Simple Linear Regression) from Ken Black’s Business Statistics. By the end of this module, you should be able to:

  1. Understand the logic of Analysis of Variance (ANOVA) and why multiple \(t\)-tests inflate Type I error (\(\alpha\)).
  2. Conduct and interpret a One-Way ANOVA (completely randomized design), including constructing the ANOVA summary table and calculating the \(F\)-statistic.
  3. Perform multiple comparison tests (Tukey’s HSD) when the null hypothesis in ANOVA is rejected.
  4. Distinguish between Randomized Block Designs and Two-Way ANOVA (factorial designs with interaction effects).
  5. Formulate a Simple Linear Regression model, compute Ordinary Least Squares (OLS) slope and intercept estimates, and interpret their business meaning.
  6. Partition total variation into \(SSR\), \(SSE\), and \(SST\) to compute the Coefficient of Determination (\(R^2\)) and the Standard Error of the Estimate (\(s_e\)).

2 Chapter 11: Analysis of Variance (ANOVA)

ANOVA is a statistical technique used to test whether the means of three or more populations are equal by analyzing sample variances.

2.1 Why Not Multiple \(t\)-Tests?

If you want to compare \(k = 4\) group means, there are \(\binom{4}{2} = 6\) pairwise comparisons. Conducting each test at \(\alpha = 0.05\) compounds the experiment-wise Type I error rate: \[\alpha_{\text{overall}} = 1 - (1 - \alpha)^c\] For \(c = 6\) comparisons, \(\alpha_{\text{overall}} = 1 - (0.95)^6 \approx 0.265\) (a \(26.5\%\) chance of at least one false positive). ANOVA tests all means simultaneously at a single \(\alpha\) level.

2.2 One-Way ANOVA (Completely Randomized Design)

2.2.1 Hypotheses & Assumptions

  • Null Hypothesis (\(H_0\)): \(\mu_1 = \mu_2 = \dots = \mu_k\) (All population means are equal).
  • Alternative Hypothesis (\(H_a\)): At least one population mean differs from the others.
  • Assumptions:
    1. Observations are independent within and across groups.
    2. Populations are normally distributed.
    3. Homoscedasticity: Population variances are equal (\(\sigma_1^2 = \sigma_2^2 = \dots = \sigma_k^2\)).

2.2.2 Partitioning Sum of Squares

Total variability in the data (\(SST\)) is partitioned into variability between treatment groups (\(SSC\)) and variability within treatment groups (\(SSE\)):

\[SST = SSC + SSE\]

  • Sum of Squares Between Columns / Treatments (\(SSC\)): \[SSC = \sum_{j=1}^{k} n_j (\bar{x}_j - \bar{\bar{x}})^2\]
  • Sum of Squares Error / Within (\(SSE\)): \[SSE = \sum_{j=1}^{k} \sum_{i=1}^{n_j} (x_{ij} - \bar{x}_j)^2\]
  • Total Sum of Squares (\(SST\)): \[SST = \sum_{j=1}^{k} \sum_{i=1}^{n_j} (x_{ij} - \bar{\bar{x}})^2\]

(where \(k\) is the number of groups, \(n_j\) is the sample size of group \(j\), \(N = \sum n_j\) is total observations, \(\bar{x}_j\) is the group mean, and \(\bar{\bar{x}}\) is the grand mean).

2.2.3 One-Way ANOVA Summary Table

Source of Variation Sum of Squares (\(SS\)) Degrees of Freedom (\(df\)) Mean Square (\(MS\)) \(F\)-Ratio
Between (Treatments) \(SSC\) \(k - 1\) \(MSC = \frac{SSC}{k - 1}\) \(F = \frac{MSC}{MSE}\)
Within (Error) \(SSE\) \(N - k\) \(MSE = \frac{SSE}{N - k}\)
Total \(SST\) \(N - 1\)
  • Decision Rule: Reject \(H_0\) if \(F > F_{\alpha, \, df_1 = k-1, \, df_2 = N-k}\) (or if \(p\text{-value} < \alpha\)). Note that ANOVA \(F\)-tests are always right-tailed.

2.3 Multiple Comparisons (Post-Hoc Analysis)

If \(H_0\) is rejected, ANOVA tells us that a difference exists, not where it exists. Tukey’s Honestly Significant Difference (HSD) tests all pairwise differences \(|\bar{x}_i - \bar{x}_j|\) against a critical range (for equal sample sizes \(n\)):

\[\text{HSD} = q_{\alpha, \, k, \, N-k} \sqrt{\frac{MSE}{n}}\]

where \(q\) is obtained from the Studentized Range Distribution table. If \(|\bar{x}_i - \bar{x}_j| > \text{HSD}\), the two group means differ significantly.

2.4 Randomized Block Design & Two-Way ANOVA

  • Randomized Block Design (Section 11.3): Controls for an extraneous source of variation (a blocking variable, such as store location or shift) by partitioning \(SST\) into three components: \[SST = SSC + SSB + SSE\] where \(SSB\) is the Sum of Squares for Blocks (\(df_{\text{blocks}} = b - 1\), \(df_{\text{error}} = (k-1)(b-1)\)).
  • Two-Way ANOVA / Factorial Design (Section 11.4): Examines the simultaneous effects of two independent categorical factors (Factor A and Factor B) plus their interaction effect (\(A \times B\)): \[SST = SSA + SSB + SS_{AB} + SSE\]
    • Interaction Effect: Occurs when the effect of one factor on the response variable depends on the level of the second factor. Always test the interaction term first before interpreting main effects.
k_groups <- 4
c_pairs <- choose(k_groups, 2)
alpha_overall <- 1 - (1 - 0.05)^c_pairs
print(sprintf("Experiment-wise Type I Error (k = %d, c = %d comparisons, alpha = 0.05): %.4f",
              k_groups, c_pairs, alpha_overall))
## [1] "Experiment-wise Type I Error (k = 4, c = 6 comparisons, alpha = 0.05): 0.2649"
display_data <- data.frame(
  design = factor(rep(c("Endcap", "Aisle", "Checkout"), each = 5)),
  sales  = c(42, 45, 40, 46, 44,
             35, 38, 34, 37, 36,
             50, 54, 49, 52, 55)
)

grand_mean <- mean(display_data$sales)
grp_means <- tapply(display_data$sales, display_data$design, mean)
grp_ns <- tapply(display_data$sales, display_data$design, length)
ssc <- sum(grp_ns * (grp_means - grand_mean)^2)
sse <- sum((display_data$sales - grp_means[display_data$design])^2)
sst <- sum((display_data$sales - grand_mean)^2)
df_between <- length(grp_means) - 1
df_within <- nrow(display_data) - length(grp_means)
msc <- ssc / df_between
mse <- sse / df_within
f_ratio <- msc / mse
hsd_crit <- qtukey(0.95, nmeans = length(grp_means), df = df_within) * sqrt(mse / grp_ns[1])

print(sprintf("Manual ANOVA -> SSC = %.2f | SSE = %.2f | SST = %.2f | F(%d,%d) = %.4f",
              ssc, sse, sst, df_between, df_within, f_ratio))
## [1] "Manual ANOVA -> SSC = 641.20 | SSE = 59.20 | SST = 700.40 | F(2,12) = 64.9865"
print(sprintf("Manual Tukey HSD critical difference (alpha = 0.05): %.4f", hsd_crit))
## [1] "Manual Tukey HSD critical difference (alpha = 0.05): 3.7477"
anova_model <- aov(sales ~ design, data = display_data)
print(summary(anova_model))
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## design       2  641.2   320.6   64.99 3.65e-07 ***
## Residuals   12   59.2     4.9                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
print(TukeyHSD(anova_model, conf.level = 0.95))
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = sales ~ design, data = display_data)
## 
## $design
##                 diff        lwr       upr     p adj
## Checkout-Aisle  16.0  12.252308 19.747692 0.0000002
## Endcap-Aisle     7.4   3.652308 11.147692 0.0005378
## Endcap-Checkout -8.6 -12.347692 -4.852308 0.0001413
rbd_data <- data.frame(
  method = factor(rep(c("Method A", "Method B", "Method C"), times = 4)),
  store = factor(rep(paste("Store", 1:4), each = 3)),
  productivity = c(72, 78, 84,
                   68, 74, 79,
                   75, 81, 88,
                   70, 76, 82)
)
rbd_model <- aov(productivity ~ method + store, data = rbd_data)
print(summary(rbd_model))
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## method       2 288.00  144.00   648.0 9.79e-08 ***
## store        3  94.92   31.64   142.4 5.78e-06 ***
## Residuals    6   1.33    0.22                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
two_way_data <- data.frame(
  promo = factor(rep(c("Coupon", "No_Coupon"), each = 6)),
  tier = factor(rep(rep(c("Budget", "Standard", "Premium"), each = 2), times = 2)),
  units = c(48, 52, 55, 59, 60, 64,
            34, 38, 46, 50, 58, 62)
)
two_way_model <- aov(units ~ promo * tier, data = two_way_data)
print(summary(two_way_model))
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## promo        1  208.3   208.3  26.042 0.002215 ** 
## tier         2  648.7   324.3  40.542 0.000327 ***
## promo:tier   2   72.7    36.3   4.542 0.062945 .  
## Residuals    6   48.0     8.0                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

3 Chapter 12 (Sections 1–3): Simple Linear Regression

Simple linear regression models the linear relationship between a single independent (predictor) variable (\(X\)) and a dependent (response) variable (\(Y\)).

3.1 Correlation vs. Regression (Section 12.1)

  • Correlation (\(r\)): Measures the strength and direction of a linear association symmetrically (\(X\) and \(Y\) are interchangeable).
  • Regression: Establishes a directional functional equation to predict \(Y\) from \(X\) and quantify how much \(Y\) changes per unit change in \(X\).

3.1.1 Population vs. Sample Regression Model

  • Population Regression Model: \[Y_i = \beta_0 + \beta_1 X_i + \epsilon_i\] where \(\beta_0\) is the population \(Y\)-intercept, \(\beta_1\) is the population slope, and \(\epsilon_i\) is the random error term.
  • Estimated Sample Regression Line: \[\hat{y}_i = b_0 + b_1 x_i\] where \(\hat{y}_i\) is the predicted value of \(Y\), \(b_0\) is the sample intercept, and \(b_1\) is the sample slope.

3.2 Determining the Equation of the Regression Line (Section 12.2)

The Ordinary Least Squares (OLS) method finds \(b_0\) and \(b_1\) by minimizing the Sum of Squared Errors (Residuals): \[\min \sum_{i=1}^{n} e_i^2 = \sum_{i=1}^{n} (y_i - \hat{y}_i)^2\]

3.2.1 OLS Formulas

  • Sample Slope (\(b_1\)): \[b_1 = \frac{SS_{xy}}{SS_{xx}} = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2} = \frac{\sum x_i y_i - \frac{(\sum x_i)(\sum y_i)}{n}}{\sum x_i^2 - \frac{(\sum x_i)^2}{n}}\]
  • Sample \(Y\)-Intercept (\(b_0\)): \[b_0 = \bar{y} - b_1 \bar{x}\]

3.2.2 Business Interpretation

  • \(b_1\) (Slope): For every \(1\)-unit increase in \(X\), \(Y\) is predicted to change by \(b_1\) units on average.
  • \(b_0\) (Intercept): The predicted value of \(Y\) when \(X = 0\) (only meaningful if \(X = 0\) falls within the relevant scope of the data).

3.3 Residual Analysis & Standard Error of the Estimate (Section 12.3)

3.3.1 Line Assumptions (LINE)

  1. Linearity: The relationship between \(X\) and \(Y\) is linear.
  2. Independence: Residuals (\(\epsilon_i\)) are independent of one another.
  3. Normality: For any given \(X\), the residuals are normally distributed with mean \(0\).
  4. Equal Variance (Homoscedasticity): The variance of residuals (\(\sigma_\epsilon^2\)) is constant across all values of \(X\).

3.3.2 Partitioning Variance & Goodness of Fit

Just like ANOVA, regression partitions total variation in \(Y\) (\(SST\)) into explained variation (\(SSR\)) and unexplained variation (\(SSE\)):

\[SST = SSR + SSE\]

  • Total Sum of Squares (\(SST\)): \(\sum (y_i - \bar{y})^2\)
  • Regression Sum of Squares (\(SSR\)): \(\sum (\hat{y}_i - \bar{y})^2\)
  • Error Sum of Squares (\(SSE\)): \(\sum (y_i - \hat{y}_i)^2\)

3.3.3 Key Fit Metrics

  1. Standard Error of the Estimate (\(s_e\)): Measures the typical dispersion of observed data points around the regression line (in the units of \(Y\)): \[s_e = \sqrt{\frac{SSE}{n - 2}}\] (Note: \(df = n - 2\) because two parameters, \(b_0\) and \(b_1\), are estimated).

  2. Coefficient of Determination (\(R^2\)): Represents the proportion of total variation in \(Y\) explained by \(X\): \[R^2 = \frac{SSR}{SST} = 1 - \frac{SSE}{SST}\]

    • Bounds: \(0 \le R^2 \le 1\). In simple linear regression, \(R^2 = r^2\).
ad_data <- data.frame(
  ad_spend = c(2, 4, 5, 6, 8, 10, 11, 14),
  revenue  = c(15, 22, 24, 29, 34, 41, 43, 52)
)

x_bar_ad <- mean(ad_data$ad_spend)
y_bar_rev <- mean(ad_data$revenue)
ss_xy <- sum((ad_data$ad_spend - x_bar_ad) * (ad_data$revenue - y_bar_rev))
ss_xx <- sum((ad_data$ad_spend - x_bar_ad)^2)
b1_manual <- ss_xy / ss_xx
b0_manual <- y_bar_rev - b1_manual * x_bar_ad
y_hat <- b0_manual + b1_manual * ad_data$ad_spend
sst_reg <- sum((ad_data$revenue - y_bar_rev)^2)
ssr_reg <- sum((y_hat - y_bar_rev)^2)
sse_reg <- sum((ad_data$revenue - y_hat)^2)
se_manual <- sqrt(sse_reg / (nrow(ad_data) - 2))
r2_manual <- ssr_reg / sst_reg

reg_model <- lm(revenue ~ ad_spend, data = ad_data)
print(summary(reg_model))
## 
## Call:
## lm(formula = revenue ~ ad_spend, data = ad_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7991 -0.5312 -0.1607  0.4107  1.1205 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.39732    0.58528   16.06 3.71e-06 ***
## ad_spend     3.08036    0.06983   44.11 9.09e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.739 on 6 degrees of freedom
## Multiple R-squared:  0.9969, Adjusted R-squared:  0.9964 
## F-statistic:  1946 on 1 and 6 DF,  p-value: 9.087e-09
b0 <- coef(reg_model)[1]
b1 <- coef(reg_model)[2]
r_sq <- summary(reg_model)$r.squared
s_e  <- summary(reg_model)$sigma

print(sprintf("Manual OLS -> b0 = %.4f, b1 = %.4f | lm() -> b0 = %.4f, b1 = %.4f",
              b0_manual, b1_manual, b0, b1))
## [1] "Manual OLS -> b0 = 9.3973, b1 = 3.0804 | lm() -> b0 = 9.3973, b1 = 3.0804"
print(sprintf("SST = %.2f | SSR = %.2f | SSE = %.2f | s_e = %.4f | R^2 = %.4f (r^2 = %.4f)",
              sst_reg, ssr_reg, sse_reg, se_manual, r_sq, cor(ad_data$ad_spend, ad_data$revenue)^2))
## [1] "SST = 1066.00 | SSR = 1062.72 | SSE = 3.28 | s_e = 0.7390 | R^2 = 0.9969 (r^2 = 0.9969)"
ggplot(ad_data, aes(x = ad_spend, y = revenue)) +
  geom_point(color = "darkblue", size = 3) +
  geom_smooth(method = "lm", se = FALSE, color = "red") +
  labs(title = "Simple Linear Regression: Ad Spend vs. Revenue",
       x = "Ad Spend ($100s)",
       y = "Weekly Revenue ($1000s)") +
  theme_minimal()


4 Week 8 Key Formula Summary Sheet

Concept / Metric Formula Notes
Experiment-Wise Error \(\alpha_{\text{overall}} = 1 - (1 - \alpha)^c\) \(c = \frac{k(k-1)}{2}\) pairwise comparisons
One-Way ANOVA \(F\)-Stat \(F = \frac{MSC}{MSE} = \frac{SSC / (k - 1)}{SSE / (N - k)}\) Always right-tailed
Tukey’s HSD \(\text{HSD} = q_{\alpha, \, k, \, N-k} \sqrt{\frac{MSE}{n}}\) Equal group sizes \(n\)
OLS Slope (\(b_1\)) \(b_1 = \frac{SS_{xy}}{SS_{xx}} = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}\) Marginal change in \(\hat{y}\) per unit \(x\)
OLS Intercept (\(b_0\)) \(b_0 = \bar{y} - b_1 \bar{x}\) Line always passes through \((\bar{x}, \bar{y})\)
Standard Error (\(s_e\)) \(s_e = \sqrt{\frac{SSE}{n - 2}}\) Standard deviation of residuals
Coeff. of Determination (\(R^2\)) \(R^2 = \frac{SSR}{SST} = 1 - \frac{SSE}{SST}\) Proportion of variance in \(Y\) explained