SigmaAnalytics & Tech
F1PythonAdvancedAbout 180 min to complete

Linear Regression

Section 5 taught you to compare groups and measure associations. Now we start modelling — building an equation that describes how one variable depends on another and lets us predict.

Notebook

About 180 minutes to complete

Enrol to read the notebook and download it to run.

What this module covers

Section 5 taught you to compare groups and measure associations. Now we start modelling — building an equation that describes how one variable depends on another and lets us predict.

By the end of it

  • Write the linear model y = β₀ + β₁x + ε and interpret the intercept and slope in real units
  • Explain ordinary least squares (OLS) — fitting by minimising the sum of squared residuals
  • Fit a model three ways — scipy.stats.linregress, numpy.polyfit, and statsmodels OLS — and read the statsmodels summary table
  • Interpret R², coefficient standard errors, t-tests, p-values, and confidence intervals
  • Produce predictions with the correct uncertainty: confidence intervals (for the mean) vs prediction intervals (for a new observation)
  • Check the four regression assumptions (L·I·N·E) with residual diagnostic plots
  • Recognise the traps: extrapolation, influential points, and reading causation into a fit