# How to make an F test between two models?

Here is a linear regression

m1 = lm(data=mtcars, mpg~wt)
anova(m1)
Analysis of Variance Table

Response: mpg
Df Sum Sq Mean Sq F value    Pr(>F)
wt         1 847.73  847.73  91.375 1.294e-10 ***
Residuals 30 278.32    9.28
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


I understand that to compute this F value, one must compare the mean within group variance to the mean residual variance and therefore compute

$$\frac{\frac{847.73}{1}}{\frac{278.32}{30}} = 91.375$$

Let's now consider another model

m2 = lm(data=mtcars, mpg~wt + cyl)


And we will compare these two models

anova(m1,m2)

Analysis of Variance Table

Model 1: mpg ~ wt
Model 2: mpg ~ wt + cyl
Res.Df    RSS Df Sum of Sq     F   Pr(>F)
1     30 278.32
2     29 191.17  1     87.15 13.22 0.001064 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


I don't understand how the F value is computed here. I understand RSS are the sum of square of residuals and that Sum of sq is the sum of square of the difference between the predicted values between the two models.

I first tried

$$\frac{87.15} {\frac{\frac{278.32}{30}+\frac{191.17}{29}}{2}} ≈ 10$$

but obviously it does not work.

• The formula can be found here, for example. In your example, it's: $\frac{87.15}{191.17/29} = 13.22$. – COOLSerdash Feb 4 '18 at 21:26