3. Introduction to hypothesis testing via binomial tests

Remember you should

Overview

This practice reviews the Hypothesis testing starting with binomial tests lecture.

Hypothesis Testing and the Binomial Distribution

Example

Using the bat paper from class (Geipel et al. 2021), let’s consider how to analyze data showing all 10 bats chose the walking over the motionless model.

binom.test(10,10)

    Exact binomial test

data:  10 and 10
number of successes = 10, number of trials = 10, p-value = 0.001953
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
 0.6915029 1.0000000
sample estimates:
probability of success 
                     1 

We use the binom.test function. We only need arguments for # of succeses and # of trials. By default it runs a 2-sided test against a null hypothesis value of p = .5. You can see how to update thee options by looking at the help file.

?binom.test

Note the confidence interval is assymetric since its estimated to be 1! We can see other options using the binom.confint function from the binom package.

library(binom)
binom.confint(10,10)
          method  x  n      mean     lower    upper
1  agresti-coull 10 10 1.0000000 0.6791127 1.043355
2     asymptotic 10 10 1.0000000 1.0000000 1.000000
3          bayes 10 10 0.9545455 0.8292269 1.000000
4        cloglog 10 10 1.0000000 0.6915029 1.000000
5          exact 10 10 1.0000000 0.6915029 1.000000
6          logit 10 10 1.0000000 0.6915029 1.000000
7         probit 10 10 1.0000000 0.6915029 1.000000
8        profile 10 10 1.0000000 0.7303058 1.000000
9            lrt 10 10 1.0000000 0.8252466 1.000000
10     prop.test 10 10 1.0000000 0.6554628 1.000000
11        wilson 10 10 1.0000000 0.7224672 1.000000

All of these correct for the fact that most intervals use a normal approximation, which as you remember from our earlier discussions is not good when sample sizes are small and/or the p parameter is extreme (close to 0 or 1).

Swirl lesson

Swirl is an R package that provides guided lessons to help you learn and review material. These lessons should serve as a bridge between all the code provided in the slides and background reading and the key functions and concepts from each lesson. A full course lesson (all lessons combined) can also be downloaded using the following instructions.

THIS IS ONE OF THE FEW TIMES I RECOMMEND WORKING DIRECTLY IN THE CONSOLE! THERE IS NO NEED TO DEVELOP A SCRIPT FOR THESE INTERACTIVE SESSIONS, THOUGH YOU CAN!

  • install the “swirl” package

  • run the following code once on the computer to install a new course

    library(swirl)
    install_course_github("jsgosnell", "JSG_swirl_lessons")
  • start swirl!

    swirl()
  • then follow the on-screen prompts to select the JSG_swirl_lessons course and the lessons you want

    • Here we will focus on the Hypothesis testing starting with binomial tests lesson
  • TIP: If you are seeing duplicate courses (or odd versions of each), you can clear all courses and then re-download the courses by

    • exiting swirl using escape key or bye() function

      bye()
    • uninstalling and reinstalling courses

      uninstall_all_courses()
      install_course_github("jsgosnell", "JSG_swirl_lessons")
    • when you restart swirl with swirl(), you may need to select

      • No. Let me start something new

Practice!

Make sure you are comfortable with null and alternative hypotheses for all examples.

1

Are people eared (do they prefer one ear or another)? Of 25 people observed while in conversation in a nightclub, 19 turned their right ear to the speaker and 6 turn their left ear to the speaker. How strong is the evidence for eared-ness given this data (adapted from Analysis of Biological Data)?

  • state a null and alternative hypothesis
  • calculate a test statistic (signal) for this data
    • Make sure you understand how to construct a null distribution
      • using sampling/simulation (code or written explanation)
      • by using an appropriate distribution (code or written explanation)
  • Calculate and compare p-values obtained using
    • simulation (calculation won’t be required on test, but make sure you understand!) (code or written explanation)
    • equations for binomial distribution (code or written explanation) + R functions (required)(code)
  • Calculate a 95% confidence interval for the proportion of people who are right-eared
    • How do your 95% confidence interval and hypothesis test compare?

2

A professor lets his dog take every multiple-choice test to see how it compares to his students (I know someone who did this). Unfortunately, the professor believes undergraduates in the class tricked him by helping the dog do better on a test. It’s a 100 question test, and every questions has 4 answer choices. For the last test, the dog picked 33 questions correctly. How likely is this to happen, and is there evidence the students helped the dog?

MAKE SURE TO THINK ABOUT YOUR TEST OPTIONS