In: Math
How can I do one-way ANOVA in RStudio?
Sol
tthere is an nbuilt datset in R iris.
It has 150 observations and 5 variables.
variable names are:
"Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
species has 3 levels namely setosa", "versicolor", "virginica
we want to performNAOVA that
H0:all species mean sepal length are equal.
H1:atleast one of the species mean sepal length is different.
with aov function in R you will do one way anova
and with summary function you get anova table
Rcode to do anova is
dim(iris)
names(iris)
unique(iris$Species)
iris$Species <- ordered(iris$Species,
levels = c("setosa", "versicolor", "virginica"))
result.anova <- aov(Sepal.Length ~ Species, data = iris)
# Summary of the analysis
summary(result.anova)
Df Sum Sq Mean Sq F value Pr(>F)
Species 2 63.21 31.606 119.3 <2e-16 ***
Residuals 147 38.96 0.265
Intrepretation
F(2,147)=119.3
p=<2e-16 ***
p=0.0000
p<0.05
we conclude that atleast one of the species sepal length is different