knitr::opts_chunk$set(echo = TRUE)
require(Sleuth3)
require(ggplot2)
require(tigerstats)
require(xtable)
require(lattice)

Let’s get a sample of 100 Bernoulli variables. Really that’s the same as Binomial variables with just 1 trial

pi <- .6
N <- 100
samples <- rbinom(n=N, size=1, prob=pi)

Now, we can get \(\hat{\pi}\), the estimator for the probability of preferring the new blend

pi_hat <- sum(samples)/N
pi_hat
## [1] 0.7

The variance and the SD, assuming the Null Hypothesis is true:

var_pi_hat <- pi*(1-pi)/N
sd_pi_hat <- sqrt(var_pi_hat)
sd_pi_hat
## [1] 0.04898979

The CI is:

c(pi_hat-qnorm(.975)*sd_pi_hat, pi_hat+qnorm(.975)*sd_pi_hat)
## [1] 0.6039818 0.7960182

Since the CI doesn’t include the true value of \(\pi\), we can reject the Null Hypothesis.