knitr::opts_chunk$set(echo = TRUE)
library(SDS100)

$\$

Hypothesis test for a single proportion with a known SE

Do goalies guess the direction of a penalty shot less than 50% of the time?

From 1982 to 1994 there were 128 penalty shots in the World Cup.
Goal keepers correctly guessed the direction 41% of the time With SE* = 0.043

Step 1:

$H_0$: $H_A$:

Step 2-5:

# step 2: calculate the z-statistic




# step 3-4: use the pnorm function to get the p-value

Make a decision!

$\$

A formula for the SE for proportions

The standard error for a single proportion is given by the formula:

$$SE = \sqrt{\frac{\pi(1-\pi)}{n}} $$

When running a hypothesis test for a single proportion, we assume that $\pi$ is equal to the value specified by the null hypothesis ($\pi_0$) so we can calculate the standard error as:

$$SE = \sqrt{\frac{\pi_0(1-\pi_0)}{n}}$$

Let's calculate the SE for the soccer example...


$\$

Another example of a hypothesis test for a single proportion

Does the AstraZeneca vaccine cause blood clots?

A study found that 79 people experienced clots after receiving a first vaccine dose. More than 20 million AstraZeneca vaccines doses had been administered across the UK by the end of March.

About four people in a million would normally be expected to develop this particular kind of blood clot - though the fact they are so rare makes the usual rate hard to estimate.

Step 1:

# Step 2: calculate the observed z-statistic







# Step 2b: Are these conditions met? 




# Step 3: visualize the null distribution









# Step 4: get the p-value




# Step 5: conclusion!

$\$

CI for a single proportion

What is the probability of having a blood clot if you take the AstraZeneca vaccine?

# calculate the SE



# get the critical value z* for a 95% confidence interval



# create the confidence interval

Is it likely you will get a blood clot?

$\$

Confidence interval for a single proportion using the bootstrap

library(tictoc)


has_clot <- rep(TRUE, 79)
no_clot <- rep(FALSE, (20 * 10^6) - 79)

data_vec <- c(has_clot, no_clot)





# Time how long it takes to create 10 bootstrap statistics... 
tic()








toc()


emeyers/SDS100 documentation built on April 28, 2024, 5:07 p.m.