Linear Regression
Fit a line to the data
Calculate
R²
Calculate F-Test
Fit a line to the data
Weight
Size
Weight
Size
Which one fits best?
Fit a line to the data
Weight
Size
Weight
Size
Weight
Size
Line 1
Line 2
Line 3
Weight
Size
Weight
Size
Weight
Size
Line 1
Line 2
Line 3
Residuals 1
Residuals 2
Residuals 3
The best line is the one that minimizes the sum of the squared residuals!
RSS 2 > RSS 1 > RSS 3
Fit a line to the data
Ordinary Least Squares
How to find the best line?
x
y
y = b + a*x
Fit a line to the data
What is a line?
What is a linear model?
Weight
Size
Parameters: b and a
How to find the best line?
Fit a line to the data
Weight
Size
sizeSS = size_fitSS + residualsSS
Fit a line to the data
RSS
It is time for derivatives!
Fit a line to the data
Linear Model in matrix notation
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Fit a line to the data
Linear Model in matrix notation
Fit a line to the data
Parameters estimation
Equating to zero:
Ordinary Least Squares
Fit a line to the data
Parameters estimation
Maximum likelihood
Gaussian distribution
Multivariate Gaussian distribution
Fit a line to the data
Parameters estimation
Maximum likelihood
Weight
Size
Any Size value belongs to a Gaussian distribution, the mean is the fitted value.
Fit a line to the data
Parameters estimation
Maximum likelihood
Linear Regression
Calculate
R²
Calculate F-Test
Fit a line to the data
Ordinary Least Squares
Maximum likelihood
Derivatives
Calculate R²
How good is that prediction?
R²
Calculate R²
Size
Size
Weight
Weight
Calculate R²
Size
Weight
Weight
Size
Calculate R²
Size
Weight
Weight
Size
Calculate R²
Size
Weight
Weight
Size
SS(mean) = 1080
Var(mean) = 12
SS(fit) = 720
Var(fit) = 4
Calculate R²
Size
Weight
Weight
Size
SS(mean) = 1080
Var(mean) = 12
SS(mean) = 120
Var(fit) = 1.34
Calculate R²
Weight
Size
Water consumption
Size
Fur Softness
Size
SS(mean) = equal for all
SS(fit) = different for each
SS(fit3) > SS(fit2) > SS(fit1)
R²(fit1) > R²(fit2) > R²(fit3)
Calculate R²
Pearson correlation coefficient
r
r
R²
2
Linear Regression
Calculate F-Test
Fit a line to the data
Ordinary Least Squares
Maximum likelihood
Derivatives
Calculate
R²
r
R²
2
Person’s correlation
Calculate F-Test
Hypotheses Testing
Which model (reduced or full) does a better job?
SSE(R) can never be smaller than SSE(F)
If SSE(R) is close to SSE(F): new parameter reduces little of the variation
If SSE(R) and SSE(F) differ greatly: new parameter substantially reduces the variance
How different does SSE(R) have to be from SSE(F) in order to justify using the full model?
Calculate F-Test
Transforming into variances
Calculate F-Test
The F distribution
Weight
Size
Weight
Size
Generate sets of random data (n=9)
Calculate SS(mean) and SS(fit)
Weight
Size
Weight
Size
Weight
Size
Weight
Size
Calculate F
F = 2
F = 3
F = 4
Plot the results in a histogram
F
Frequency
Calculate F-Test
The F distribution
The F distribution depends on two parameters (d1 and d2), which are the degrees of freedom of the numerator and denominator.
F
Frequency
Numerator = (9-1) – (9-2) = 8 – 7 = 1
Denominator = (9-2) = 7
Shiny
Calculate F-Test
p-value for F-distribution
In this situation, a model with one predictor variable and 9 samples would need a F value higher than 5.59 to show a p-value < 0.05 and the null hypothesis would be rejected.
Linear Regression
Fit a line to the data
Ordinary Least Squares
Maximum likelihood
Derivatives
Calculate
R²
r
R²
2
Pearson’s correlation
Calculate F-Test