title: "Stats 13 Lab 3" author: "Brooklyn Duran" date: "2024-08-27" output: html_document ---
```{r load-packages, message=FALSE}
library(tidyverse) library(openintro) library(infer)
set.seed(42) sample.int(n = 100, size = 1) # 49 set.seed(42) sample.int(n = 100, size = 1) # same result ```
```{r exercise-1}
globalmonitor <- tibble( scientistwork = c(rep("Benefits", 80000), rep("Doesn't benefit", 20000)) )
ggplot(globalmonitor, aes(x = scientistwork)) + geombar() + labs( x = "", y = "", title = "Do you believe that the work scientists do benefit people like you?" ) + coordflip()
globalmonitor %>% count(scientistwork) %>% mutate(p = n /sum(n))
set.seed(42)
samp1 <- globalmonitor %>% samplen(50)
ggplot(samp1, aes(x = scientistwork)) + geombar() + labs( x = "", y="", title = "Do you believe that the work scientists do benefit people like you?") + coord_flip()
samp1 %>% count(scientist_work) %>% mutate(p = n / sum(n)) ```
```{r exercise-2}
```
```{r exercise-3}
set.seed(0)
samp2 <- globalmonitor %>% samplen(50)
samp2 %>% count(scientist_work) %>% mutate(p = n / sum(n))
samp3 <- globalmonitor %>% samplen(100)
samp3 %>% count(scientist_work) %>% mutate(P = n / sum(n))
samp4 <- globalmonitor %>% samplen(1000)
samp4 %>% count(scientist_work) %>% mutate(p= n /sum(n))
```
```{r exercise-4}
sampleprops50 <- globalmonitor %>% repsamplen(size = 50, reps = 15000, replace = TRUE) %>% count(scientistwork) %>% mutate(phat = n /sum(n)) %>% filter(scientist_work == "Doesn't benefit")
ggplot(data = sampleprops50, aes(x = phat)) + geomhistogram(binwidth = 0.02) + labs( x = "phat (Doesn't benefit)", title = "Sampling distribution of p_hat", subtitle = "Sample size = 50, Number of samples = 15000" )
sampleprops100 <- globalmonitor %>% repsamplen(size = 100, reps = 15000, replace = TRUE) %>% count(scientistwork) %>% mutate(phat = n /sum(n)) %>% filter(scientist_work == "Doesn't benefit")
ggplot(data = sampleprops100, aes(x = phat)) + geom_histogram(binwidth = 0.02) + labs(x = "phat (doesnt benefit)",title = "samp dist of phat", subtitle = "samp size = 100, num of samples = 15000")
```
```{r exercise-5}
samplepropssmall <- globalmonitor %>% repsamplen(size = 10, reps = 25, replace = TRUE) %>% count(scientistwork) %>% mutate(phat = n / sum(n)) %>% filter(scientistwork == "Doesn't benefit")
ggplot(data = samplepropssmall, aes(x = phat)) + geomhistogram(binwidth = 0.02) + labs( x = "p_hat (Doesnt benefit", title = "Samp dist. of phat", subtitle = "samp size = 10, num of samples = 25")
```
{r submission-instructions} # Knit (or generate) the R Markdown file and submit as your TA instructs.