# Finding degrees of freedom with two-way ANOVA in R [closed]

I ran an ANOVA test on the following dataset and had R output a df value that didn't seem right to me.

Here's a piece of the dataset:

NOISE   SIZE    TYPE
810     1       1
820     1       1
820     1       1
840     2       1
840     2       1
845     2       1
785     3       1
790     3       1
785     3       1
835     1       1
835     1       1


And here's the ANOVA output:

air.df = aov(NOISE ~ SIZE*TYPE, data = air)
summary(air.df)
Df Sum Sq Mean Sq F value   Pr(>F)
SIZE         1  16017   16017  40.050 4.21e-07 ***
TYPE         1   1056    1056   2.641    0.114
SIZE:TYPE    1      4       4   0.010    0.919
Residuals   32  12797     400
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


I'm having trouble understanding why the value of degrees of freedom for the "SIZE" variable is 1. There are three different sizes (1,2,3) so shouldn't df be calculated as I - 1 = 2?

If size is an interval- or ratio-scaled variable then it is treated as a linear term in the model with a single slope coefficient - so one df.

If you mean for size to be a categorical variable then you need to declare it a factor before running your analysis. Then it will have two df as it takes two dummy variables (and thus two slope coefficients) to code a 3-level categorical variable in the general linear model.