Degrees of freedom anova R

3

I'm trying to run a basic one-way ANOVA in R.

library(drc)
data=S.alba
aov(DryMatter~Dose,data=S.alba)

However, there are 7 treatments in these data. Therefore, DF (degree of freedom) should be 7-1 = 6, but R shows DF as 1. I do not understand what is going on. Can anyone clarify this doubt?

> aov(DryMatter~Dose,data=S.alba)
Call:
   aov(formula = DryMatter ~ Dose, data = S.alba)

Terms:
                    Dose Residuals
Sum of Squares  65.62088  75.12662
Deg. of Freedom        1        66

Residual standard error: 1.066903
Estimated effects may be unbalanced
    
asked by anonymous 16.02.2018 / 19:41

1 answer

7

The Dose column is a numeric value of type int , not a factor:

dados <- S.alba
str(dados)
'data.frame':   68 obs. of  3 variables:
 $ Dose     : int  0 0 0 0 0 0 0 0 10 10 ...
 $ Herbicide: Factor w/ 2 levels "Bentazone","Glyphosate": 2 2 2 2 2 2 2 2 2 2 ...
 $ DryMatter: num  4.7 4.6 4.1 4.4 3.2 3 3.8 3.9 3.8 3.8 ...

Thus, the R will not understand that the explanatory variable is a factor. Convert the column Dose , so that it turns a categorical variable:

dados$Dose <- as.factor(dados$Dose)
str(dados)
'data.frame':   68 obs. of  3 variables:
 $ Dose     : Factor w/ 8 levels "0","10","20",..: 1 1 1 1 1 1 1 1 2 2 ...
 $ Herbicide: Factor w/ 2 levels "Bentazone","Glyphosate": 2 2 2 2 2 2 2 2 2 2 ...
 $ DryMatter: num  4.7 4.6 4.1 4.4 3.2 3 3.8 3.9 3.8 3.8 ...

In addition, only the aov command will not give you the ANOVA table you want. You must first fit a template with the aov function and then ask for summary of it:

ajuste <- aov(DryMatter~Dose, data=dados)
summary(ajuste)

            Df Sum Sq Mean Sq F value Pr(>F)    
Dose         7 121.17  17.310   53.04 <2e-16 ***
Residuals   60  19.58   0.326                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
16.02.2018 / 20:09