I'm comparing the addition of a variable in my linear model using R and "anova F-test":
anova(fit1,fit2)
What I noticed is that this F-test produces different results when comparing a model with a categorical value in factor()
form and in continuous form.
So I do the anova comparisons:
> anova(fit3,fit4)
Analysis of Variance Table
Model 1: dta$X.U.FEFF..mpist. ~ relevel(factor(dta$matem), 7) + relevel(factor(dta$aidink),
7) + factor(dta$sukup)
Model 2: dta$X.U.FEFF..mpist. ~ relevel(factor(dta$matem), 7) + relevel(factor(dta$aidink),
7) + factor(dta$sukup) + factor(dta$HISEI)
Res.Df RSS Df Sum of Sq F Pr(>F)
1 985 3067966
2 929 2857404 56 210562 1.2225 0.1314
Since Pr(>F)
> 0.05, then fit3 and fit4 are not significantly different.
However, with the continuous model:
> anova(fit3,fit5)
Analysis of Variance Table
Model 1: dta$X.U.FEFF..mpist. ~ relevel(factor(dta$matem), 7) + relevel(factor(dta$aidink),
7) + factor(dta$sukup)
Model 2: dta$X.U.FEFF..mpist. ~ relevel(factor(dta$matem), 7) + relevel(factor(dta$aidink),
7) + factor(dta$sukup) + dta$HISEI
Res.Df RSS Df Sum of Sq F Pr(>F)
1 985 3067966
2 984 3049605 1 18361 5.9244 0.01511 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
You see that fit5
is the same as fit4
but just with the categorical variable HISEI
as continuous. So switching from factored to continuous is enough to make F-test give Pr(>F)
< 0.05, which means that fit5
is significantly different from fit3
.
Why does it produce differing results for factor()
variables and continuous variables?
Res.Df
column in the output). $\endgroup$ – amoeba Oct 15 '16 at 21:20