---
title: "Midterm2 Review"
author: "Nate Wells"
date: "4/2/2021"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(infer)
library(moderndive)
library(palmerpenguins)
```



```{r}
penguins <- penguins %>% drop_na()
```

Can we distinguihs between Adelie and Gentoo penguin based on bodymass?

```{r}
penguins_ag <- penguins %>% filter(species %in% c("Adelie", "Gentoo"))
```

```{r}
penguins_ag %>% ggplot( aes(x  = species, y = body_mass_g))+geom_boxplot()
```

Perform hypothesis test to determine whether body mass for two species is equal

Case I

Null is $$H_0:\mu_a  = \mu_g$$

Alt Hyp is $$H_a: \mu_a \neq \mu_g$$


Case II

Null is $$H_0:\mu_a  = \mu_g$$

Alt Hyp is $$H_a: \mu_a <  \mu_g$$


Case III

Null is $$H_0:\mu_a  = \mu_g$$

Alt Hyp is $$H_a: \mu_a >  \mu_g$$


```{r}
penguin_stats<-penguins_ag %>% 
  specify(response = body_mass_g, explanatory = species ) %>% 
  hypothesise(null = "independence") %>% 
  generate(reps = 2000, type= "permute") %>% 
  calculate(stat ="diff in means", order = c("Gentoo", "Adelie"))
```

```{r}
og_stat <-penguins_ag %>% 
    specify(response = body_mass_g, explanatory = species ) %>% 
  calculate(stat ="diff in means", order = c("Gentoo", "Adelie"))
```

```{r}
penguin_stats %>% get_p_value(obs_stat = og_stat, direction = "both")
```

Compare p-value to significance level a. Standard choice a = 0.05. In this case, P-value < .05, we reject H_0 in favor of the H_a.