# Different output between summary(lm()) and anova(lm()) in R

I tried to find out similar previous questions but, got no good result. I see some discrepancy between the lm() summary output; and anova(lm()) output. In the below R output, summary(lm()) tells that disp variable is not significant statistically, while anova(lm()) tells that both variables are significant. Could anyone shed me a light on this?

The below is summary of lm() in R.

> summary(lm(mpg~disp+wt,mtcars))

Call:
lm(formula = mpg ~ disp + wt, data = mtcars)

Residuals:
Min      1Q  Median      3Q     Max
-3.4087 -2.3243 -0.7683  1.7721  6.3484

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 34.96055    2.16454  16.151 4.91e-16 ***
disp        -0.01773    0.00919  -1.929  0.06362 .
wt          -3.35082    1.16413  -2.878  0.00743 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.917 on 29 degrees of freedom
Multiple R-squared:  0.7809,    Adjusted R-squared:  0.7658
F-statistic: 51.69 on 2 and 29 DF,  p-value: 2.744e-10

>


and the below is the output of anova(lm()).

> anova(lm(mpg~disp+wt,mtcars))
Analysis of Variance Table

Response: mpg
Df Sum Sq Mean Sq F value    Pr(>F)
disp       1 808.89  808.89 95.0929 1.164e-10 ***
wt         1  70.48   70.48  8.2852  0.007431 **
Residuals 29 246.68    8.51
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


@Noah helped me a lot. Since I am a newbie here, I made some stupid things such as I making an answer thread to ask an additional question. While doing that I noticed low quality answer mark (or something like that). So, I am adding this part to clarify Noah's explanation and why it completes my question.

The initial Noah's answer was like this:

For t-test for an individual IV in multiple regression (lm()), R compares the whole model to the the model without the individual model. That is, for t-testing disp IV, R compares the whole model lm(mpg ~ disp + wt) to lm(mpg ~ wt) (less disp) and see how much additional part is explained by the disp. This is another way of saying t-test in lm function is to see the 'pure regression' part (with the other IVs' parts out).

So, I did spcor.test to see if Noah's answer is working; and, found out that it's not. But, Noah explained that R uses pcor.test instead of spcor.test. And I confirmed that. both pcor and spcor test are ways of seeing the unique contribution of IVs in a regression test. By unique contribution, I am talking about Some of Square part (SS) of IVs, which is usually referred as $$SS_{regression}$$. The difference is the denominator part. In the picture, red circle is mpg; blue circle is disp; and black is wt. (2) is semipartial correlation squared value; and the denominator part is a+b+c+d (the while SS of y, that is, SS total). 3) is partial correlation squared value; the the denominator is a+b (less the shared part). In the below picture, d/a+d is significant, which is unique explanation of wt without the whole influence of disp part. And for the disp part, b/a+b is not significant, since b is not big enough compared to a+b part. When Noah answered my question, I initially thought he meant (2) instead of (3); and Noah corrected me R uses (3) method in t-testing for each IV.

• ANOVA evaluates the terms in the sequence you provided. Try anova(lm(mpg~wt+disp,mtcars)). Dec 3, 2020 at 7:30

The t-tests from summary() are added-last tests; they test whether the addition of the variable explains variance with all other variables already in the model. The F-tests from anova() are added-in-order tests; they test whether the addition of the variable explains variance beyond only the variables that were entered before that variable.

It's easy to think of it in terms of model comparison. Consider the four following models:

1. lm(mpg~1)

2. lm(mpg~disp)

3. lm(mpg~wt)

4. lm(mpg~disp+wt)

For summary(), the t-test for disp compares model 4 to model 3, and the t-test for wt compares model 4 to model 2. Each test compares a model with all variables except the variable of interest in it with a model with all variables including the variable of interest in it.

For anova(), the order the variables were entered matters. The F-test for disp compares model 2 and model 1. The F-test for wt compares model 4 to model 2.

In both cases, the test for wt compares model 4 to model 2, which is why the p-value is the same. Because these are 1-df tests, the F-statistic is the square of the corresponding t-statistic (when the tests compare the same models).

If you want added-last tests from an ANOVA, you need to use car::Anova(lm(mpg~disp+wt), type = 3).

• It actually refers to the partial correlations. pcor.test() yields the same p-values as summary().
– Noah
Dec 3, 2020 at 8:20
• Oh, okay @Noah. I deleted my comment and created answer thread since my comment looked messy. I did pcor.test() instead of spcor.test() and got the exact output! Thanks again @Noah Dec 3, 2020 at 8:25