---
title: "Lab 4: Confidence Intervals"
author:  "ADD YOUR NAME HERE"
date: now
date-format: "DD/MM/YYYY HH:MM"
format:
    pdf
#    html:
#      theme: a11y
#      highlight-style: a11y
#      self-contained: true
---


## Load R libraries

```{r}
#| warning = FALSE,
#| message = FALSE
library(mosaic)
library(knitr)
library(abd)
```

## Setting the seed of the random number generator

Use the set.seed() function in R to initialize the random number generator.   

```{r}
set.seed(02041971)
```

## Pike data

```{r}
pike<-read.csv("Pikedata.csv")
pike$year<-as.factor(pike$year) # this will tell R we want to treat year as categorical
```


Let's look at a summary of the length observations.

```{r}
favstats(~lenght.inches, data = pike)
```

Write code, below, to filter out the observation with length = 0.
```{r}
pike <- filter(  )
```


### Exercise 1: produce side-by-side histograms showing the length data form 1988 and 1993

```{r}


```

Comment on what you see: 


### Exercise 2: use densityplot to visualize the length data form 1988 and 1993

```{r}



```


### Exercise 3: What is the mean length of pike sampled in 1988 and 1993?

```{r}



```

###  Exercise 4:  Use diffmean to calculate the difference in means.

```{r}



```


 
### Exercise 5:  Create a bootstrap distribution for the difference in means

```{r}


```


### Exercise 6: Using the bootstrap standard error method, calculate a 95% CI
 

```{r}
 

```

### Exercise 7: Using the bootstrap percentile method, calculate a 95% CI

Using the percentile method, create a 95% confidence interval for the mean difference in mean lengths.

```{r}


```

### Exercise 8:  Visualizing the bootstrap distribution

```{r}



```

### Exercise 9: Comparing the intervals

QUESTION:  How do your answers in [6] and [7] compare? Choose one of the two intervals, above, and interpret the result in the context of the problem.

ANSWER:   


### Exercise 10:  Using confint

```{r}



```

 
QUESTION:  How do these intervals compare to those in steps 6 and 7?  And, what happens if you increase the confidence level?

ANSWER:

### Exercise 11:  

QUESTION: Do these results prove that the regulation has led to larger pike? Why or why not?

ANSWER:  


## Sampling Distribution:  Lincoln-Petersen Estimator

```{r}
#| include = FALSE
# Source a file that contains the functions to simulate data
# This will make the codes available to you
source("lpfuncs.R")

# You can see what the functions look like by typing their name
lp.est

```

### Exercise 1

Create a sampling distribution for $\hat{N}$, assuming a population size of 2000 individuals, an initial sample of 50 individuals, and a second sample of 100 individuals.  Specifically, generate 5000 different estimates using *do* and the *lpest* function with $N=2000$, $n_1$ = 50, and $n_2$ = 100. Then calculate the mean $\hat{N}$ and plot a histogram of the resulting estimates.  

```{r}




```

 


### Exercise 2: 

Repeat the process, but with N = 2000, n1 = 300, and n2 = 300.

```{r}



```


### Exercise 3:

QUESTION:  Compare your results from [1] and [2]. What happened when we increased the size of the samples, n1
and n2?

ANSWER:  




## Assumption Violations

```{r}
#| include = FALSE
# Lets look at what this new function looks like
lp.est.het
```



### Exercise 1

Use the **lp.est.het** function to generate 1000 samples, and thus a sampling distribution for the case
where N = 2000, n1 = 300, n2 = 300, and ps = c(2,1) (animals are trap-happy). Calculate the mean $\hat{N}$ and plot a histogram of the resulting estimates.

```{r}


```

### Exercise 2:

Repeat the process, but in this case with ps = c(1,2) (animals are trap-shy).

```{r}
 
```

### Exercise 3

Calculate the bias for the Lincoln-Petersen estimator in the case of trap-shy and trap-happy individuals simulated
in [1] and [2], above. 

QUESTION:  How does heterogeneous detection probabilities (trap-happy or trap-shy individuals)
impact our estimates?

```{r}


```

ANSWER:  




#### Exercise 4

QUESTION: Come up with at least one reason why animals might exhibit a trap-happy response. 

ANSWER:  

 
