cancer

references:
- ISI, example 3.1, p.164

library(tidyverse)
library(knitr)

hypotheses

\[H_0 : \pi = 0.20\] \[H_0 : \pi > 0.20\]

State \(\pi\) and \(\alpha\).

pi <- 0.20
alpha <- 0.05

observed statistic

x <- 30
n <- 33
(p.hat.observed <- x / n)
## [1] 0.9090909

simulation

guess33 <- function(){
  samp <- sample(c(0, 1), size = n, prob = c(1 - pi, pi), replace = TRUE)
  p.hat <- mean(samp)
  return(p.hat)
}

10 trials

replicate(10, guess33())
##  [1] 0.21212121 0.12121212 0.09090909 0.24242424 0.15151515 0.18181818
##  [7] 0.21212121 0.30303030 0.12121212 0.30303030

simulated sampling distribution of \(\widehat{p}\)

df1 <- data.frame(p.hat = replicate(1000, guess33()))
str(df1)
## 'data.frame':    1000 obs. of  1 variable:
##  $ p.hat: num  0.2424 0.2424 0.0909 0.1818 0.303 ...
draw.sampling.distribution(df1)