Degrees of freedom Anova R
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 this data. Therefore, DF (degree of freedom) or degrees of freedom from treatments should be 7-1 = 6, but R me presents DF as 1. I don't understand what's going on. Can anyone clarify this doubt for me?
> 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
3
Author: Marcus Nunes, 2018-02-16
1 answers
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, 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 ...
Also, only the aov
Command will not give you the ANOVA table you want. You must first fit a model with the function aov
and then ask for the summary
from 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
7
Author: Marcus Nunes, 2018-02-16 19:09:00