---
title: "Binary response"
output: html_document
---

```{r setup, include=TRUE, message=FALSE}
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

```{r}
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

```{r}
pi_hat <- sum(samples)/N
pi_hat
```

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

```{r}
var_pi_hat <- pi*(1-pi)/N
sd_pi_hat <- sqrt(var_pi_hat)
sd_pi_hat
```

The CI is:
```{r}
c(pi_hat-qnorm(.975)*sd_pi_hat, pi_hat+qnorm(.975)*sd_pi_hat)
```

Since the CI doesn't include the true value of $\pi$, we can reject the Null Hypothesis.

