Overview

In your group, you’ll conduct some tests for differences using the penguin dataset.

Instructions

  1. Load the palmerpenguins package.
  2. Create a boxplot of penguins bill length, grouped by sex.
  3. Create a boxplot of penguins bill length, grouped by species.
  4. Conduct a two-tailed t-test of the alternative hypothesis that penguin bill length differs by sex.
  5. Conduct a one-tailed t-test of the alternative hypothesis that penguin bill length is larger for male penguins.
  6. Conduct an ANOVA for the alternative hypothesis that penguin bill length differs by penguin species.

Check out the template code below if you need help getting started.

R template code

T-tests

I can use the t.test() function to conduct a simple two-tailed test for the hypothesis that penguin body mass is different between male and female penguins. Note the use of the alternative argument.

t.test(body_mass_g ~ sex, data = penguins, alternative = "two.sided")
## 
##  Welch Two Sample t-test
## 
## data:  body_mass_g by sex
## t = -8.5545, df = 323.9, p-value = 4.794e-16
## alternative hypothesis: true difference in means between group female and group male is not equal to 0
## 95 percent confidence interval:
##  -840.5783 -526.2453
## sample estimates:
## mean in group female   mean in group male 
##             3862.273             4545.685

If I want to test the hypothesis that female penguins weighed less, I could use:

t.test(body_mass_g ~ sex, data = penguins, alternative = "less")
## 
##  Welch Two Sample t-test
## 
## data:  body_mass_g by sex
## t = -8.5545, df = 323.9, p-value = 2.397e-16
## alternative hypothesis: true difference in means between group female and group male is less than 0
## 95 percent confidence interval:
##       -Inf -551.6295
## sample estimates:
## mean in group female   mean in group male 
##             3862.273             4545.685
  • Note the use of the alternative argument.

ANOVA

As an example, I could also use ANOVA to test the alternative hypothesis that penguins observed on different islands have different bill lengths:

  • To conduct an ANOVA, I first fit a linear model using lm().
  • Then I use anova() with my fitted model to produce the ANOVA table.
  • Note: this is a slightly different procedure than your book uses. We’ll see why this is better later in the course.
fit_bill_island = lm(bill_length_mm ~ island, data = penguins)
anova(fit_bill_island)
## Analysis of Variance Table
## 
## Response: bill_length_mm
##            Df Sum Sq Mean Sq F value   Pr(>F)    
## island      2 1565.6  782.80  30.862 4.86e-13 ***
## Residuals 339 8598.6   25.36                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The example is for bill length and island, but you need to conduct an analysis on the alternative hypothesis that penguin bill length differs by penguin species.

Questions

Compile your answers to the following into a single document and upload to the file input box on Moodle.

  1. Include your group members’ names.
  2. Include your 2 boxplots.
  3. What were the p-values of your 1- and 2- tailed t-tests?
  4. Did you conclude that bill length is greater for males?
  5. What is the p-value for the null hypothesis that penguin bill length is the same in the three penguin species.
  6. Do you conclude that there are species differences?