---
title: "Lab 4"
author: "Name here"
output: html_document
---

Please use D2L to turn in both the DOC or Word output and your R Markdown file in. 

We will be conducting a Bayesian analyis using using data from Switzerland.  More details on the dataset are provided here. The Swiss breeding bird survey ("Monitoring Häufige Brutvögel" MHB) has monitored the populations of 150 common species since 1999. The MHB sample consists of 267 1-km squares that are laid out as a grid across Switzerland. Fieldwork is conducted by about 200 skilled birdwatchers, most of them volunteers. Avian populations are monitored using a simplified territory mapping protocol, where each square is surveyed up to three times during the breeding season (only twice above the tree line). Surveys are conducted along a transect that does not change over the years.



### Q1. (4 pts) 
In two or three sentences summarize the sampling procedure for determining whether a bird resides in a unit square. Avoid statistical jargon and pretent you are explaining this to a kindergartener.

### Q2. (4 pts) 
Download the data from [http://www.math.montana.edu/ahoegh/teaching/stat491/data/willowtit2013.csv](http://www.math.montana.edu/ahoegh/teaching/stat491/data/willowtit2013.csv). The wiki page contains information about the willow tit: [https://en.wikipedia.org/wiki/Willow_tit](https://en.wikipedia.org/wiki/Willow_tit).

```{r}
birds <- read.csv('http://www.math.montana.edu/ahoegh/teaching/stat491/data/willowtit2013.csv')
```
This dataset contains 242 sites and 6 variables:
- siteID, a unique identifier for the site, some were not sampled during this period
- elev, mean elevation of the quadrant in meters
- rlength, the length of the route walked by the birdwatcher, in kilometers
- forest, percent forest cover
- birds, binary variable for whether a bird is observed, 1 = yes
- searchDuration, time birdwatcher spent searching the site, in minutes

Summarize how the variables the other variables in the dataset may be related to whether a bird was observed.

### Q3. (6 pts)
For now, we will not consider the covariates (we will get back to that later). Use a beta distribution to construct your prior belief on the probability of observing a willow tit at a site ,$p(\theta)$. 

- construct a plot showing your distribution,
- report the parameters in this distribution, and
- justify your choice of a prior.

### Q4. (4 pts)
Write out the sampling model $p(y_1, \dots, y_n|\theta)$ to reflect whether a bird is observed in the n^${th}$ sampling unit.

### Q5. (6 pts)
Given your sampling model for the dataset and your prior stated before:

- what are the parameters for your posterior distribution?
- plot your posterior distribution

### Q6. (4 pts)
Summarize your findings from this analysis. Assume you are talking to a birdwatcher and not a statistician.


