Learning Objectives

  • Practice 1- and 2-sample t-tests and non-parametric versions

Data

We’ll use the penguins dataset for these exercises.

Chinstrap Penguins: Sex

For the first few questions, we’ll use just the Adelie penguin data.
Here’s some R-code to create a dataset containing only the Adelie penguins:

require(palmerpenguins)
## Loading required package: palmerpenguins
dat_ade = droplevels(subset(penguins, species == "Adelie"))

Let’s look at a histogram:

hist(dat_ade$body_mass_g, main = "Adelie Penguins: Body Mass", xlab = "body mass (g)")

That seems like a weird distribution… Let’s see if we can figure out what’s going on.

Here’s my version of some boxplots, conditioned on sex:

  • Q1 (2 pts.): Create separate boxplots of body mass for male and female Adelie penguins. Your boxplots do not have to be in the same panel like mine. Show the R-code you used to make the plots.

One-sample t-test

For practice, let’s do a one-sample t-test. Recall that by default, when you provide the t.test() function with a group of measurements, it performs a one-sample t-test of the null hypothesis that the mean of the the group is equal to zero.

  • Q2 (1 pt.): Perform a one-sample t-test of the alternative hypothesis that female Adelie penguins have a body mass different from zero grams. Note that this is a very silly alternative hypothesis. Is this a one- or two-tailed test? Show your R-code.
  • You’ll need to do some subsetting.
  • Check the help entry for t.test(). Specifically, check out the mu and alternative arguments.
  • Q3 (1 pt.): Describe your conclusions based on the p-value of the t-test.

  • Q4 (1 pt.): Now, conduct a slightly less silly test: perform a one-sample t-test of the alternative hypothesis that male Adelie penguins have a mean body mass greater than 4000 grams. Is this a one- or two-tailed test?

  • Q5 (1 pt.): Describe your conclusions based on the p-value of the t-test.

Two-sample t-test

Now, let’s compare male and female Adelie penguins.

  • Q6 (2 pts.): Conduct a two-sample t-test of the alternative hypothesis that male and female Adelie penguins have different mean body masses. Show your R code.
  • Q7 (1 pt.): Describe your conclusions based on the p-value of the t-test.

For the sake of completeness, let’s try a directional hypothesis too:

  • Q8 (2 pts.): Conduct a two-sample (one-tailed) t-test of the directional alternative hypothesis that male Adelie penguins are heavier than females. Show your R code.

Finally, just to cover all of our bases and gain some intuition about two-tailed tests, let’s try the other possible direction: Test the alternative hypothesis that male Adelie penguins are lighter than females.

  • Q9 (2 pts.): Conduct a two-sample (one-tailed) t-test of the directional alternative hypothesis that male Adelie penguins are lighter than females. Show your R code.
  • Q10 (2 pts.): Speculate on why the p-values are so drastically different in the two directions.