Link Search Menu Expand Document

Linear regression

This material is presented as a series of short videos that show

  • how to fit a straight line to data by minimizing the sum of squares error
  • one (of many) ways of calculating a regression line in MATLAB
  • a demonstration of finding a low p value when you fit a line to random data

Irrespective of how you decide to fit a straight line data (and pointing and clicking in a program like Excel or Prism is easier for simple data than the approaches outlined here), you should know how to interpret the:

  • slope
  • intercept
  • p value
  • r2 value

These videos should explain the concepts.

Accessing files

See GitHub for instructions on how to download the course material to your local computer.

The source files for this lecture are at <repo>/lectures/linear_regression

Other useful material

Core materials

  • Lecture videos

Calculating the sum of squares error

A demo showing how to calculate the sum of squares error for a straight line and then minimize it.

Using MATLAB fit_lm() to fit a straight line

Using the fit_lm() function to automate the line-fitting

Demonstration of p values

Calculates p values for points selected from random data, demonstrating that low p values can occur in a data that really has no relation between x and y.


Table of contents