I've encountered several times the situation where ANOVA gives drastically different results depending on whether the variable is entered as a factor or as a numeric variable. Why is this the case?
I understand somewhat that this classification evokes different analyses in the case where the variable has more than two levels - for example, say the variable is "grade level" and has levels 5, 6, 7. But, I sometimes get quite different results even when the variable has only two levels, say "grade level" with levels 5 and 6. Should I ever get different results in this case? Why? And how should I decide which result to use?
If it matters, I'm using ezANOVA in R with type 3 SS and the variable in question is between-subject, but the analysis also includes other between- and within-subjects variables. I'm not sure if this phenomenon reflects normal behavior of ANOVA or potentially a problem with ezANOVA.
In this reproducible example, ANOVA finds a significant effect of the within-subjects factor when the between-subjects variable is treated as a factor, but not when it is treated as numeric.
library(ez) set.seed(1) N = 60 subjid = factor( rep(1:N,each=2) ) between = c( rep(7,N), rep(8,N) ) within = factor( rep(c("A","B"),N) ) x = as.numeric( between ) y = as.numeric( within=="A" ) dv = x + 0.5*y + runif(length(between)) D = data.frame( subjid=subjid, between=between, within=within, dv=dv ) D$betweenF = factor( D$between ) ezANOVA( data=D, wid=subjid, dv=dv, between=between, within=within, type=3 ) ## Warning: "between" will be treated as numeric. ## $ANOVA ## Effect DFn DFd F p p<.05 ges ## 2 between 1 58 380.47083320 3.725618e-27 * 0.7765827418 ## 3 within 1 58 0.85506909 3.589537e-01 0.0068830702 ## 4 between:within 1 58 0.02700153 8.700494e-01 0.0002188134 ezANOVA( data=D, wid=subjid, dv=dv, between=betweenF, within=within, type=3 ) ## $ANOVA ## Effect DFn DFd F p p<.05 ges ## 2 betweenF 1 58 380.47083320 3.725618e-27 * 0.7765827418 ## 3 within 1 58 130.79260911 1.701170e-16 * 0.5145964337 ## 4 betweenF:within 1 58 0.02700153 8.700494e-01 0.0002188134