When Linear Regression Works

The Linearity Assumption

Linear Models for Linear Effects

  • Linear regression fits a straight line through data
  • Assumes constant effect: each unit increase in \(X\) changes \(Y\) by the same amount
  • Works when the relationship is linear

\[ Y = \beta_0 + \beta_1X + \epsilon \]

Linear Relationships in the Real World

But Real Data Isn’t Always Linear

  • Growth curves (exponential, logistic)
  • Binary outcomes (survived/died, yes/no)
  • Count data (number of events)
  • Bounded outcomes (proportions, rates)
  • Curved relationships (U-shaped, S-shaped)

The Problem with Forcing Linearity

When Straight Lines Don’t Fit

Probability of Disease by Age

Fitting a Straight Line Fails

The Problem is the Scale

  • Linear regression assumes outcomes can take any value
  • But many outcomes are constrained:
    • Probabilities must be between 0 and 1
    • Counts must be non-negative integers
    • Proportions are bounded
  • Forcing a straight line violates these constraints

Transform the Scale

Link Functions Make Non-Linear Data Linear

The Core Insight

  • Don’t force data onto a straight line
  • Transform the scale so linear regression works
  • Fit the line on the transformed scale
  • Transform back to get predictions
  • This is what link functions do.

Visualising the Transformation

Logistic Regression Fits an S-Curve

Generalised Linear Models

The Family of Link Functions

Wrapping Up

Key Takeaways

What We’ve Learned

  • Real data often doesn’t fit straight lines.
  • Link functions transform non-linear problems into linear ones.
  • Logistic regression (logit link) handles binary outcomes.
  • Poisson regression (log link) handles count data.
  • Linear regression isn’t limited to linear relationships.

The Power of This Approach

  • Simplicity - Same core idea (fit a line) works everywhere.
  • Flexibility - Adapts to different data types and structures.
  • Interpretability - Coefficients still represent effects.
  • Extensibility - Once you know linear regression, you can learn anything.

Further Learning

Thank You!

Contact:

Code & Slides:

/NHS-South-Central-and-West/code-club

… And don’t forget to give us your feedback.