# smoking

references:
- ISI, exploration 2.1b, p.118

## 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.55
n <- 1421                 # sample size

## simulation

Success means that ‘yes’ (= 1) was given as that participant’s opinion.

Assume that $$\pi = 0.5$$ … select a random sample of 1421 opinions … report the proportion of successes.

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

Select 10 random samples.

replicate(10, smoking1421())
##  [1] 0.5059817 0.5066854 0.4996481 0.5045742 0.4799437 0.4904996 0.5045742
##  [8] 0.4968332 0.4862773 0.4848698

## sampling distribution of $$\widehat{p}$$

n.experiments <- 1000
df <- data.frame(p.hat = replicate(n.experiments, smoking1421()))
str(df)
## 'data.frame':    1000 obs. of  1 variable:
##  \$ p.hat: num  0.508 0.521 0.486 0.481 0.5 ...
draw.sampling.distribution.p.hat(df)