library(palmerpenguins)
##
## Attaching package: 'palmerpenguins'
## The following objects are masked from 'package:datasets':
##
## penguins, penguins_raw
getwd()
## [1] "/Users/owner/Downloads"
setwd("/Users/owner/Desktop/Lab_Assignment_10")
getwd()
## [1] "/Users/owner/Desktop/Lab_Assignment_10"
data <- read.csv("/Users/owner/Desktop/Lab_Assignment_10/cake_data.csv")
head(data)
## cakeid recipe angle
## 1 1 A 42.44988
## 2 2 A 42.69705
## 3 3 A 33.50886
## 4 4 A 43.60376
## 5 5 A 54.89232
## 6 6 A 37.27297
str(data)
## 'data.frame': 100 obs. of 3 variables:
## $ cakeid: int 1 2 3 4 5 6 7 8 9 10 ...
## $ recipe: chr "A" "A" "A" "A" ...
## $ angle : num 42.4 42.7 33.5 43.6 54.9 ...
summary(data)
## cakeid recipe angle
## Min. : 1.00 Length :100 Min. :18.87
## 1st Qu.: 25.75 N.unique : 4 1st Qu.:32.25
## Median : 50.50 N.blank : 0 Median :37.43
## Mean : 50.50 Min.nchar: 1 Mean :37.83
## 3rd Qu.: 75.25 Max.nchar: 1 3rd Qu.:43.86
## Max. :100.00 Max. :57.97
Your answer: ## Null hypothesis: The mean breakage angle is equal for cake recipes. ## Alternative hypothesis: At least one cake recipe has a different mean breakage angle.
cake_anova <- aov(angle ~ recipe, data = data)
summary(cake_anova)
## Df Sum Sq Mean Sq F value Pr(>F)
## recipe 3 3310 1103.4 39.1 <2e-16 ***
## Residuals 96 2709 28.2
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Your answer: ## The resulting f-statistic is 39.1, the df between is 3, the df within is 96, and the p-value is less than 0.001.
Load the palmerpenguins package (install it first with install.packages(“palmerpenguins”) if needed). Does penguin body mass (body_mass_g) differ by species?
library(palmerpenguins)
penguin_anova <- aov(body_mass_g ~ species, data = penguins)
summary(penguin_anova)
## Df Sum Sq Mean Sq F value Pr(>F)
## species 2 146864214 73432107 343.6 <2e-16 ***
## Residuals 339 72443483 213698
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 2 observations deleted due to missingness
Your answer: ## The within df ar 339, not 341, because two of the observations have missing body mass measurements. These observations were excluded, leaving 342 penguins in the analysis. With 3 species, the df within = 342-3 = 339.
anova_results <- summary(penguin_anova)[[1]]
MS_B <- anova_results["species", "Sum Sq"] / anova_results["species", "Df"]
MS_W <- anova_results["Residuals", "Sum Sq"] / anova_results["Residuals", "Df"]
F_value <- MS_B / MS_W
MS_B
## [1] 73432107
MS_W
## [1] 213697.6
F_value
## [1] 343.6263
Your answer: ## Based on my results, the MS_B = 73,432,107, the MS_W = 213,697.6, and the F_value = 343.6263. The calculated F-value matches the ANOVA output of 343.6. The slight decimal differences are likely due to rounding.
boxplot(body_mass_g ~ species, data = penguins,
xlab = "Species",
ylab = "Body Mass (g)",
main = "Penguin Body Mass by Species")
Your answer: ## The Gentoo penguins appear to have higher body mass in comparison to the Adelie and Chinstrap penguins. The ANOVA alone does not tell us which specific species differ from one another because it only tell us whether or not at least one group mean is significantly different. A post-hoc test, such as Tukey’s HSD, may help to identify which specific groups differ.