# Notes Example

```{r}

getwd()
data("penguins")


dream_pen <- subset(penguins, island == 'Dream')
tor_pen <- subset(penguins, island == 'Torgersen')

hist(dream_pen$flipper_len)
hist(tor_pen$flipper_len)


t.test(dream_pen$flipper_len, #first subgroup
       tor_pen$flipper_len, #second subgroup
       alternative = 'two.sided', #indicate the alt hypohtesis direction
       mu = 0,
       conf.level = .95)

```


# Example to try on your own

We are ignoring tension for the moment if you are wondering. 

```{r}
data("warpbreaks")

yarn_a <- subset(warpbreaks, wool == 'A')
yarn_b <- subset(warpbreaks, wool == 'B')

```

1) State you null and alternative hypothesis

H_0: mu_a = mu_b
H_A: mu_a (not equal) mu_b


2) Visualize your data


```{r}
library(ggplot2)

ggplot(warpbreaks,
       aes(breaks)) + 
  geom_histogram() +
  facet_grid(~wool) +
  theme_bw()

nrow(yarn_a)
nrow(yarn_b)
```

3) Check your assumptions (random, independent and identically distributed)

Normality or large N: yes...apporximately normal
Random: Yes, type of yarn was assigned to the bundles of wool
Independent and Identcally Distributed: Yes (ignoring tension for now)

4) Regardless if we fail our assumptions, let's continue. Using R, calculate the test-statistic and the p-value

```{r}
t.test(yarn_a$breaks,
       yarn_b$breaks,
       mu = 0,
       conf.level = .95)
```

t = 1.6335,
df = 42.006,
p-value = 0.1098



5) Give a decision for your test

We have little to no evidence that the mean number of breaks per type of yarn is different

6) State and interpret a 95\% confidence interval for the difference in their means
(-1.360096 12.915652)

We are 95\% confident the true difference in means of number of breaks for yarn A vs yarn B is -1.39 and 12.91 breaks.
