Formulate simple linear regression as a matrix equation Aβ=y and find the coefficients of the line of best fit by solving the normal equations ATAβ=ATy.
Step 1 of 119%
Tutorial
The Matrix Form of Linear Regression
Linear regression seeks to model a linear relationship between an independent variable x and a dependent variable y:
y=β0+β1x,
where β0 is the intercept and β1 is the slope.
Given n data points (x1,y1),(x2,y2),…,(xn,yn), we want to find the coefficients β0 and β1. Substituting each data point into the model gives n equations:
β0+β1x1β0+β1x2β0+β1xn=y1=y2⋮=yn.
We can write this system compactly as Aβ=y, where
A=11⋮1x1x2⋮xn,β=[β0β1],y=y1y2⋮yn.
The matrix A is called the design matrix. Its first column is all 1s (these multiply the intercept β0), and its second column holds the x-values of the data.
For example, the data points (2,5),(4,6),(7,10) give the matrix equation