In this project we use the Palmer Penguins data set and formal statistical inference to answer questions about penguins.
The project has two parts. In Part 1, we work through four complete
examples together: a hypothesis test and a confidence interval using
prop.test(), followed by a hypothesis test and a confidence
interval using t.test(). In Part 2, we carry out two
additional analyses, one involving a proportion and one involving a
mean.
Question: Is the proportion of Chinstrap penguins in the dataset different from one-third (what we would expect if all three species were equally common)?
We count the number of Chinstrap penguins and the total number of penguins with non-missing species data, then run the test.
n_total <- penguins %>% filter(!is.na(species)) %>% nrow()
n_chinstrap <- penguins %>% filter(species == "Chinstrap") %>% nrow()
n_total
## [1] 344
n_chinstrap
## [1] 68
Our null hypothesis is that \(p = 1/3\) (Chinstrap penguins make up one-third of the population). Our alternative hypothesis is that \(p \ne 1/3\) (two-sided).
prop.test(x = n_chinstrap, n = n_total, p = 1/3,
alternative = "two.sided", correct = FALSE)
##
## 1-sample proportions test without continuity correction
##
## data: n_chinstrap out of n_total, null probability 1/3
## X-squared = 28.488, df = 1, p-value = 9.426e-08
## alternative hypothesis: true p is not equal to 0.3333333
## 95 percent confidence interval:
## 0.1590290 0.2429974
## sample estimates:
## p
## 0.1976744
The p-value is very small (well below 0.05), so we reject the null hypothesis. There is strong evidence that Chinstrap penguins do not make up one-third of the population represented by this sample. They appear to be underrepresented relative to the other two species.
Question: What is a plausible range for the true proportion of Chinstrap penguins in the population?
prop.test(x = n_chinstrap, n = n_total, conf.level = 0.95, correct = FALSE)
##
## 1-sample proportions test without continuity correction
##
## data: n_chinstrap out of n_total, null probability 0.5
## X-squared = 125.77, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.1590290 0.2429974
## sample estimates:
## p
## 0.1976744
We are 95% confident that the true proportion of Chinstrap penguins is between roughly 0.1590290 and 0.2429974. Because this interval does not include 1/3, it is consistent with the conclusion from Part 1A that the three species are not equally represented.
Question: A field guide published in 2010 reports that the mean flipper length for Chinstrap penguins is 200 mm. Does the Palmer Station sample support this claim?
We isolate the Chinstrap flipper lengths, then check the normality assumption with a histogram before running the test.
chinstrap_flipper <- penguins %>%
filter(species == "Chinstrap", !is.na(flipper_length_mm)) %>%
pull(flipper_length_mm)
length(chinstrap_flipper)
## [1] 68
mean(chinstrap_flipper)
## [1] 195.8235
sd(chinstrap_flipper)
## [1] 7.131894
ggplot(data.frame(flipper = chinstrap_flipper), aes(x = flipper)) +
geom_histogram(binwidth = 3, fill = "steelblue", color = "white") +
labs(title = "Chinstrap Penguin Flipper Length",
x = "Flipper Length (mm)", y = "Count") +
theme_minimal()
The histogram shows no extreme skew or outliers. The normality assumption is reasonable.
Our null hypothesis is that the true population mean is equal to 200 mm. Our alternative hypothesis is that the true population mean is not equal to 200 mm. This is a two-sided alternative.
t.test(chinstrap_flipper, mu = 200, alternative = "two.sided", conf.level = 0.95)
##
## One Sample t-test
##
## data: chinstrap_flipper
## t = -4.829, df = 67, p-value = 8.31e-06
## alternative hypothesis: true mean is not equal to 200
## 95 percent confidence interval:
## 194.0972 197.5498
## sample estimates:
## mean of x
## 195.8235
The p-value is very small (well below 0.05), so we reject the null hypothesis. The Palmer penguin dataset provides strong evidence that the mean Chinstrap flipper length differs from the 200 mm value reported in the field guide. The sample mean of approximately 195.8 mm suggests flipper lengths are shorter than previously reported.
Question: What is a plausible range for the true mean flipper length of Chinstrap penguins?
t.test(chinstrap_flipper, conf.level = 0.95)
##
## One Sample t-test
##
## data: chinstrap_flipper
## t = 226.42, df = 67, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 194.0972 197.5498
## sample estimates:
## mean of x
## 195.8235
We are 95% confident that the true mean flipper length for Chinstrap penguins is between approximately 194.1 mm and 197.5 mm. Notice that this interval does not include 200 mm, which is consistent with our conclusion in Part 1C.
State which option you chose:
Option 2: Is there evidence that the proportion of penguins with body mass above 4200 g differs from 0.50?
State your null and alternative hypotheses:
Our null hypothesis is that p = 0.50. Our alternative hypothesis is that p is not equal to 0.50 (two-sided).
Set up the counts and run the test. Include a clear code chunk:
n_body_total <- penguins %>%
filter(!is.na(body_mass_g)) %>%
nrow()
n_above <- penguins %>%
filter(!is.na(body_mass_g), body_mass_g > 4200) %>%
nrow()
n_body_total
## [1] 342
n_above
## [1] 149
prop.test(x = n_above, n = n_body_total, p = 0.50,
alternative = "two.sided", conf.level = 0.95, correct = FALSE)
##
## 1-sample proportions test without continuity correction
##
## data: n_above out of n_body_total, null probability 0.5
## X-squared = 5.6608, df = 1, p-value = 0.01735
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.3841239 0.4886502
## sample estimates:
## p
## 0.4356725
Interpret the output. Your answer should address:
(1) What are x and n in your test?
x = 149, which is the number of penguins weighing more than 4200 g. n = 342, which is the number of penguins with non-missing body mass data.
(2) What is the p-value, and what does it tell you? (Use alpha = 0.05.)
The p-value is about 0.0173. Because this is less than 0.05, we reject the null hypothesis. There is evidence that the proportion of penguins weighing more than 4200 g is different from 50%.
(3) Report and interpret the 95% confidence interval from the output.
We are 95% confident that the true proportion of penguins weighing more than 4200 g is between approximately 0.3841 and 0.4887 (38.4% to 48.9%). Since the interval does not include 0.50, it agrees with our hypothesis test.
State which option you chose:
Option 1: The literature suggests that Adelie penguins have a mean bill length of 39 mm. Does the Palmer Station sample support this claim?
State your null and alternative hypotheses:
Our null hypothesis is that the true population mean bill length is 39 mm. Our alternative hypothesis is that the mean bill length is not 39 mm (two-sided).
Use dplyr to isolate your data, make a histogram to check the normality assumption, and run the test:
adelie_bill <- penguins %>%
filter(species == "Adelie", !is.na(bill_length_mm)) %>%
pull(bill_length_mm)
length(adelie_bill)
## [1] 151
mean(adelie_bill)
## [1] 38.79139
sd(adelie_bill)
## [1] 2.663405
ggplot(data.frame(bill = adelie_bill), aes(x = bill)) +
geom_histogram(binwidth = 2, fill = "steelblue", color = "white") +
labs(title = "Adelie Penguin Bill Length",
x = "Bill Length (mm)", y = "Count") +
theme_minimal()
The distribution does not show extreme skew, and the sample size is large, so a t-test is reasonable.
t.test(adelie_bill, mu = 39, alternative = "two.sided", conf.level = 0.95)
##
## One Sample t-test
##
## data: adelie_bill
## t = -0.96246, df = 150, p-value = 0.3374
## alternative hypothesis: true mean is not equal to 39
## 95 percent confidence interval:
## 38.36312 39.21966
## sample estimates:
## mean of x
## 38.79139
Interpret the output. Your answer should address:
(1) What is the sample mean (or difference in sample means)?
The sample mean bill length for Adelie penguins is approximately 38.79 mm.
(2) What is the t statistic and degrees of freedom?
The t statistic is about -0.9625 and the degrees of freedom are 150.
(3) What is the p-value, and what is your decision at alpha = 0.05?
The p-value is approximately 0.3374. Since this is greater than 0.05, we fail to reject the null hypothesis. There is not enough evidence that the mean bill length of Adelie penguins differs from 39 mm.
(4) Report and interpret the 95% confidence interval. Does it contain your null value? Is this consistent with your decision in (3)?
We are 95% confident that the true mean bill length of Adelie penguins is between approximately 38.36 mm and 39.22 mm. The interval includes 39 mm, which is consistent with our decision to fail to reject the null hypothesis.