From the free course Statistics and Probability on Lykke

Advanced Regression and ANOVA

Key concepts: Inference for Slope · T-test for Regression · Nonlinear Transformations · Analysis of Variance (ANOVA) · F-statistic

Inference for regression slopes and comparing means across more than two groups.

Advanced Regression and ANOVA

In the preceding stages of statistical analysis, we focused on descriptive bivariate relationships—calculating the correlation coefficient $r$ and fitting a least-squares regression line (LSRL) to a sample. However, in the professional and academic spheres, we are rarely interested in the sample for its own sake. Instead, we seek to make inferences about the underlying population.

Advanced Regression and ANOVA (Analysis of Variance) represent the transition from mere data fitting to rigorous hypothesis testing. This section explores how we determine if a relationship is statistically significant, how we handle complex non-linear trends through mathematical transformations, and how we compare the means of multiple groups simultaneously without inflating our risk of false positives.

Inference for Slope

When we calculate a sample slope $b_1$, we are providing a point estimate for the true population slope $\beta_1$. Because of sampling variability, a different sample from the same population would yield a different $b_1$. To determine if the observed relationship between $x$ and $y$ is "real" or merely a product of chance, we perform Inference for Slope.

What it is

Inference for slope involves constructing confidence intervals and performing hypothesis tests for the parameter $\beta_1$. The most common test is the T-test for Regression, which evaluates the null hypothesis that there is no linear relationship between the variables in the population.

The Regression Model: $y_i = \beta_0 + \beta_1 x_i + \epsilon_i$ Where $\epsilon_i$ is the random error term, assumed to be normally distributed with mean 0 and constant variance $\sigma^2$.

The LINE Assumptions

Before proceeding with inference, four critical conditions must be met, often remembered by the acronym LINE:

  1. Linearity: The relationship between $x$ and $y$ is linear.
  2. Independence: The observations are independent of one another.
  3. Normality: For any fixed $x$, the responses $y$ vary according to a Normal distribution.
  4. Equal Variance (Homoscedasticity): The variance of $y$ (the spread of residuals) is the same for all values of $x$.

The T-Statistic for Slope

The test statistic for the slope is calculated as: $$t = \frac{b_1 - \beta_{1, \text{null}}}{SE_{b_1}}$$ Where $SE_{b_1}$ is the Standard Error of the Slope, defined as: $$SE_{b_1} = \frac{s_e}{s_x \sqrt{n-1}}$$ Here, $s_e$ is the standard deviation of the residuals (the "typical" error), and $s_x$ is the standard deviation of the $x$ values.

Parameter Symbol Purpose
Population Slope $\beta_1$ The true rate of change in the population.
Sample Slope $b_1$ The estimated rate of change from the data.
Standard Error ($SE_{b_1}$) $SE_{b_1}$ Measures how much $b_1$ varies across samples.
Degrees of Freedom $df = n - 2$ Used to find the critical value $t^*$ or p-value.

Nonlinear Transformations

In many real-world scenarios, the relationship between variables is not linear. For instance, the growth of bacteria over time is exponential, and the relationship between a car's speed and its braking distance is quadratic. To apply linear regression techniques to these datasets, we must perform Nonlinear Transformations.

Why it matters

Linear models are mathematically "well-behaved" and easy to interpret. By transforming the data (applying a function to $x$, $y$, or both), we can "straighten" a scatterplot. This allows us to use the standard OLS machinery on data that would otherwise violate the linearity assumption.

Common Transformation Strategies

The "Ladder of Powers" provides a systematic way to choose a transformation. If a scatterplot shows a "bowed" shape, we typically look at logarithms or power functions.

Transformation Type Model Equation Interpretation of $b_1$
Exponential $\ln(y) = a + bx$ A 1-unit increase in $x$ multiplies $y$ by $e^b$.
Power $\ln(y) = a + b \ln(x)$ A 1% increase in $x$ results in a $b$% increase in $y$.
Logarithmic $y = a + b \ln(x)$ A 1% increase in $x$ results in a $b/100$ unit increase in $y$.
Quadratic $y = a + bx + cx^2$ Relationship depends on the level of $x$ (curvilinear).

Mathematical Derivation: The Power Model

Suppose we suspect a power relationship of the form $y = \alpha x^\beta$. We can linearize this by taking the natural logarithm of both sides:

\begin{aligned}
y &= \alpha x^\beta \\
\ln(y) &= \ln(\alpha x^\beta) \\
\ln(y) &= \ln(\alpha) + \beta \ln(x)
\end{aligned}

By substituting $Y' = \ln(y)$, $X' = \ln(x)$, and $A = \ln(\alpha)$, we arrive at the linear form: $$Y' = A + \beta X'$$ Now, a standard linear regression on the logged variables will yield an estimate for $\beta$ (the power) and $A$ (the intercept).

Common Pitfall: Back-Transforming Residuals

A common mistake is calculating the $R^2$ or residuals on the transformed data and assuming they apply directly to the original units. When you transform $y$, the distance between points changes non-linearly. Always back-transform your predictions to the original scale before reporting the final "typical error" in context.

Analysis of Variance (ANOVA)

While regression looks at the relationship between quantitative variables, Analysis of Variance (ANOVA) is used when the predictor is categorical. Specifically, One-Way ANOVA tests whether the means of three or more independent groups are significantly different.

Why not multiple T-tests?

If you have four groups (A, B, C, D) and you want to see if any of their means differ, you could perform six separate t-tests (A vs B, A vs C, etc.). However, if each test has a significance level of $\alpha = 0.05$, the probability of making at least one Type I error (finding a difference where none exists) across six tests is approximately $1 - (0.95)^6 \approx 0.26$. This is known as alpha inflation. ANOVA solves this by performing a single "omnibus" test at the $\alpha = 0.05$ level.

How it works: The F-Statistic

ANOVA works by partitioning the total variation in the data into two components:

  1. Variation Between Groups (SSB): How much the group means differ from the overall "grand mean."
  2. Variation Within Groups (SSW): How much individual observations differ from their own group mean (error).

The F-statistic is the ratio of these variances, adjusted for degrees of freedom: $$F = \frac{MS_{\text{Between}}}{MS_{\text{Within}}} = \frac{SSB / (k-1)}{SSW / (n-k)}$$ Where $k$ is the number of groups and $n$ is the total number of observations.

Key Insight: If the null hypothesis is true (all means are equal), the variation between groups should be roughly the same as the variation within groups, resulting in an F-statistic near 1. If the group means are significantly different, the "Between" variation will dwarf the "Within" variation, resulting in a large F-statistic and a small p-value.

The ANOVA Source Table

The results of an ANOVA are traditionally organized into a standard table:

Source of Variation Sum of Squares (SS) df Mean Square (MS) F
Between (Groups) $SSB$ $k - 1$ $MSB = SSB / df_B$ $MSB / MSW$
Within (Error) $SSW$ $n - k$ $MSW = SSW / df_W$
Total $SST$ $n - 1$

The F-Distribution and Post-hoc Analysis

The F-statistic follows an F-distribution, which is right-skewed and defined by two separate degrees of freedom: $df_{numerator}$ (groups - 1) and $df_{denominator}$ (observations - groups).

Assumptions for ANOVA

ANOVA is a parametric test and requires:

  • Independence: Observations are independent within and between groups.
  • Normality: The data in each group are approximately normally distributed.
  • Homogeneity of Variance: The populations have the same variance ($\sigma^2$). This is often checked using Levene's Test.

Post-hoc Testing

A significant ANOVA result only tells you that at least one group mean is different. It does not tell you which one. To find the specific differences, we use post-hoc tests like Tukey’s HSD or Bonferroni Correction. These tests adjust the p-values to maintain the family-wise error rate at the desired $\alpha$.

Comparison: Regression vs. ANOVA

While they seem different, Regression and ANOVA are both part of the General Linear Model (GLM). In fact, an ANOVA can be computed using a regression model with "dummy variables" (0/1 coding) for the categories.

Feature Linear Regression One-Way ANOVA
Predictor (X) Quantitative (Continuous) Categorical (Discrete)
Response (Y) Quantitative Quantitative
Test Statistic T-statistic (for slope) F-statistic (for group variance)
Goal Predict $y$ and find rate of change. Compare group means.

Summary of Advanced Modeling Workflow

  1. Visualize: Start with a scatterplot (Regression) or Boxplot (ANOVA).
  2. Check Assumptions: Look at residual plots for linearity and constant variance.
  3. Transform (if needed): If residuals show a curve, apply $\ln(y)$ or $\ln(x)$.
  4. Execute Test: Calculate the T-statistic for slope or the F-statistic for means.
  5. Interpret P-value: If $p < \alpha$, reject the null hypothesis.
  6. Post-hoc/Effect Size: For ANOVA, run Tukey HSD. For Regression, calculate $r^2$ to determine the proportion of explained variance.

Study Statistics and Probability on Lykke

This course page is free to open: signed out, you can read its first two sections, and signing in, on any plan, opens the rest. The free Lykke Chrome extension syncs your own Canvas courses, so ChatGPT, Claude and Muse can answer from your classes and deadlines. It only reads Canvas.

Add the free extensionSign in to open every section

All sections of Statistics and Probability · Browse more course pages

Advanced Regression and ANOVA — Statistics and Probability | Lykke