exceptionalism

references:
- ISI, exploration 3.2, p.177

library(tidyverse)
library(knitr)

hypotheses

Define \(\pi_0\).

SOLUTION:

\[H_0 : \pi = \pi_0\] \[H_0 : \pi \not= \pi_0\]

observed \(\widehat{p}\)

n <- 1019
p.hat.observed <- 0.80

possibility for \(\pi_0\)

Could \(\pi_0 = 0.775\)?

simulation

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

10 trials

replicate(10, exceptionalism1019(p.null))
##  [1] 0.7595682 0.7742885 0.7801766 0.7684004 0.7988224 0.8105986 0.7811580
##  [8] 0.7752699 0.7585868 0.7939156

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

n.experiments <- 1000
df <- data.frame(p.hat = replicate(n.experiments, exceptionalism1019(p.null)))
str(df)
## 'data.frame':    1000 obs. of  1 variable:
##  $ p.hat: num  0.771 0.78 0.765 0.764 0.779 ...
ggplot(df, aes(p.hat)) +
  geom_histogram(binwidth = 0.01, color = "saddlebrown", fill = "wheat") +
  labs(title = "Sampling Distribution of Test Statistic")