drinks

references:
- ISI, example 2.1b, p.116

hypotheses

Define \(\pi\).

SOLUTION:

\[H_0 : \pi = 0.50\] \[H_a : \pi < 0.50\]

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

pi <- 0.50          # proportion of successes
alpha <- 0.05       # level of significance

observed proportion

p.hat.observed <- 0.46
n <- 1093               # sample size

simulation

Success means that a person voted ‘yes’

Select a random sample of 1093 opinions … assume that \(\pi = 0.5\) … report the proportion of successes.

drinks1093 <- function(){
  samp <- sample(0:1, size = n, replace = TRUE)
  p.hat <- mean(samp)
  return(p.hat)
}

Select 10 random samples.

replicate(10, drinks1093())
##  [1] 0.5068618 0.5269899 0.4986276 0.5013724 0.4931382 0.4803294 0.4995425
##  [8] 0.5379689 0.5169259 0.5187557

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

n.experiments <- 1000
df <- data.frame(p.hat = replicate(n.experiments, drinks1093()))
str(df)
## 'data.frame':    1000 obs. of  1 variable:
##  $ p.hat: num  0.5 0.5 0.495 0.497 0.495 ...
draw.sampling.distribution.p.hat(df)