Chapter 13 Hypothesis Tests

Sadly, this still counts as just one tattoo.

Figure 13.1: Sadly, this still counts as just one tattoo.

In this chapter we’ll cover 1 and 2 sample null hypothesis tests: like the t-test, correlation test, and chi-square test:

library(yarrr) # Load yarrr to get the pirates data

# 1 sample t-test
# Are pirate ages different than 30 on average?
t.test(x = pirates$age, 
       mu = 30)

# 2 sample t-test
# Do females and males have different numbers of  tattoos?
sex.ttest <- t.test(formula = tattoos ~ sex,
                    data = pirates, 
                    subset = sex %in% c("male", "female"))
sex.ttest # Print result

## Access specific values from test

# Correlation test
# Is there a relationship between age and height?
 cor.test(formula = ~ age + height,
          data = pirates)

# Chi-Square test
# Is there a relationship between college and favorite pirate?
chisq.test(x = pirates$college,
           y = pirates$favorite.pirate)

Do we get more treasure from chests buried in sand or at the bottom of the ocean? Is there a relationship between the number of scars a pirate has and how much grogg he can drink? Are pirates with body piercings more likely to wear bandannas than those without body piercings? Glad you asked, in this chapter, we’ll answer these questions using 1 and 2 sample frequentist hypothesis tests.

As this is a Pirate’s Guide to R, and not a Pirate’s Guide to Statistics, we won’t cover all the theoretical background behind frequentist null hypothesis tests (like t-tests) in much detail. However, it’s important to cover three main concepts: Descriptive statistics, Test statistics, and p-values. To do this, let’s talk about body piercings.