0

I'm trying to figure out why the anova function in R gives me the same results (for the p-value) regardless of the order of the models.

> anova(lm.fit ,lm.fit2)
Analysis of Variance Table

Model 1: medv ~ lstat
Model 2: medv ~ lstat + I(lstat^2)
  Res.Df   RSS Df Sum of Sq     F    Pr(>F)    
1    504 19472                                 
2    503 15347  1    4125.1 135.2 < 2.2e-16 ***
---
Signif. codes:  
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

> anova(lm.fit2,lm.fit)
Analysis of Variance Table

Model 1: medv ~ lstat + I(lstat^2)
Model 2: medv ~ lstat
  Res.Df   RSS Df Sum of Sq     F    Pr(>F)    
1    503 15347                                 
2    504 19472 -1   -4125.1 135.2 < 2.2e-16 ***
---
Signif. codes:  
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

I can't understand why the p-value is so low in both cases. The way I'm understanding I should interpret the result of the anova is that the model 2 is better than model 1 if the p-value is very low, but in this case I'm getting exactly the same no matter the order.

I'm trying to read ?anova to check what this all means, but the help page is very succinct, is there another help where it states what the Df parameter means for instance?

jbssm
  • 121
  • 4
  • Are you familiar with the concept "degrees of freedom" in a statistical test? – EdM Jul 02 '15 at 22:07
  • I see different results: the second comparison yields a negative "Sum of Sq" value as well as a negative DF, neither of which are mathematically possible in a correct ANOVA application. It's harmless--the magnitudes are correct--but I believe the user of `anova` is expected to order the arguments in a meaningful way. – whuber Jul 02 '15 at 22:08
  • @EdM Yes, I am. (edit): Although now I'm not sure cause I'm not used to see negative degree of freedom. I was looking at them like I look in physics, the difference between the number of parameters in the observables and the degrees of the fitting model. – jbssm Jul 02 '15 at 22:09
  • @whuber Yes, but I can't understand what that means about the hypotesis that Model 1 fits the training data better than Model 2 or vice versa. I'm being told to look at the p-value but in both cases it gives the same probability. – jbssm Jul 02 '15 at 22:12
  • 1
    As it should. If you're unsure how to interpret p-values, take a look at http://stats.stackexchange.com/questions/31. A search on [nested F test](http://stats.stackexchange.com/search?q=nested+F+test) also turns up many threads you might find of interest. – whuber Jul 02 '15 at 22:13

0 Answers0