---
title: "Lab 5: Hypothesis Tests"
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)
library(dplyr)
```

## 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) 
```


## Pseudoscorpions data

```{r}
data(Pseudoscorpions)
```

### Exercise 1 

What is the mean number of successful broods for each treatment group? What is the difference in the mean number of successful broods between the two groups

```{r}

 
```

### Exercise 2

Use the **shuffle** function to create a randomization distribution for the difference in means. Plot the randomization distribution.

```{r}

 
```

### Exercise 3 

QUESTION: Where is the distribution centered? Why?

ANSWER:  



### Exercise 4

Calculate the p-value.

```{r}

 


```

QUESTION:   Is this difference statistically significant? What can you conclude based on how the data were collected?

ANSWER:

 
## Comparison of GPS and VHF estimates of home range size

```{r}
hrests<-read.csv("hrests.csv")
hrests<-mutate(hrests, GPSminusVHF.KDE=gps.kde-vhf.kde)   
```


### Exercise 1

Generate a scatterplot relating VHF-based and GPS-based estimates of home range size when using the KDE method.  Comment on the relationship between the GPS and VHF estimates of home-range size (are they associated, and if so, in what way?).

```{r}
 
```

### Exercise 2

The code below creates an object with the paired differences and also creates 1 observation from the randomization distribution:

Our test statistic:
```{r}
sample.meandiff<-mean(~GPSminusVHF.KDE, data=hrests) # test statistic used to calculate the pvalue! 
```

One value of the randomization distribution:
```{r}
# Create 1 observation from the randomization distribution
signs<-sample(c(-1,1), nrow(hrests), replace=T)
mean(hrests$GPSminusVHF.KDE*signs)
```

Now, use the do function to create 1000 samples from the randomization distribution. If you get stuck, have a look back at the introductory presentation.

```{r}

 
```



### Exercise 3

Are these differences statistically significant? State your null and alternative hypotheses, plot the randomization distribution, generate a p-value, and interpret the results in the context of the problem.

```{r}
 
```


Null hypothesis:   

Alternative hypothesis:   

CONCLUSION:    

### Exercises 4 and 5

Now, create a bootstrap distribution of the mean differences in VHF- and GPS-based estimates of home range size. Calculate a 95% confidence interval for the mean difference.

```{r}
 
```

CONCLUSION of the hypothesis test:   



### Exercise 6

QUESTION:  What information does the confidence interval give that the p-value doesn't? 

ANSWER:     

QUESTION:  What information does the p-value give that the confidence interval doesn't?

ANSWER:   

### Exercise 7

QUESTION:  Which procedure (hypothesis test or confidence interval) is most useful in this case?  Justify your answer.

ANSWER:   
