0

The code is like the following:

> d <- data.frame(a=c(1,1,1,1,2,2,2,2), b=c(1,1,2,2,1,1,2,2),v=1:8)
> anova(lm(v~a*b, data=d))
Analysis of Variance Table

Response: v
          Df Sum Sq Mean Sq F value   Pr(>F)   
a          1     32    32.0      64 0.001324 **
b          1      8     8.0      16 0.016130 * 
a:b        1      0     0.0       0 1.000000   
Residuals  4      2     0.5                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> anova(lm(v~a, data=d))
Analysis of Variance Table

Response: v
          Df Sum Sq Mean Sq F value   Pr(>F)   
a          1     32  32.000    19.2 0.004659 **
Residuals  6     10   1.667                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

My question is why "a" has different value of F and Pr between lm(v~ab) and lm(v~a)? As far as I think anova(v~ab) will test avona(v~a), anova(v~b) and anova for a and b together.

  • 8
    My sincere suggestion is learn/read about method you are trying to implement. – Koundy Dec 21 '15 at 09:04
  • 1
    Possible duplicate of [Coefficient changes sign when adding a variable in logistic regression](http://stats.stackexchange.com/questions/116804/coefficient-changes-sign-when-adding-a-variable-in-logistic-regression) and https://stats.stackexchange.com/questions/41633/sign-flipping-when-adding-one-more-variable-in-regression-and-with-much-greater – Tim Dec 21 '15 at 12:07

0 Answers0