# How to correct the degrees of freedom?

I'm running mixed design ANOVA using R.
Somehow, I got incorrect values for the degrees of freedom (Df). There are two factors: temperature (2 levels) and identity (7 levels) and when I perform this command :

aov4<- aov(NO3.means~temperature*identity,data=mydata)

I get:

                     Df  Sum Sq Mean Sq F value   Pr(>F)
temperature           1 3936158 3936158  24.519 1.54e-05 ***
identity              1   71125   71125   0.443  0.50967
temperature:identity  1 1363345 1363345   8.493  0.00595 **
Residuals            38 6100236  160533
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


the degrees of freedom for identity should be 6 rather than 1. What is the problem?

• is.numeric(mydata$identity) will presumably give TRUE when it should give FALSE (you need it to be a factor). See ?factor and ?as.factor. – Glen_b Aug 20 '14 at 4:01 ## 1 Answer It looks like your identity variable is treated like a numerical variable instead of a factor (categorical) variable. Using your code, one way to fix this would be: mydata$identity <- as.factor(mydata\$identity)
aov4 <- aov(NO3.means ~ temperature*identity, data=mydata)
summary(aov4)

• Unfortunately, same thing as the poster faced happened to me but your suggestion does not seem to be working. – Kevin Kang May 11 '18 at 17:44