---
title: "Arne assignment 2020"
author: "Duncan Golicher"
date: "16/11/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Introduction

In previous year's this section of the assignment has been based on fieldwork conducted at the RPB reserve at Arne. This year we are unfortunately unable to visit the field site. This reduces direct engagagement with t the data and cuts back some of the intended learning objectives.  

The instructions are therefore simlpified. 

You should write up this section in the style of a simple mamagement report. Screenshots of web maps can be used to illustrate your findings. 

## Management of heathland

Lowland heath in the Soth of England is generally regarded as an anthropenic habitat type. Lowland heathland occurs in area with poor fertility of its soils which are unsuited to most forms of agriculture with the exception of rough grazing.
However heathlland has a long history of human management through cutting, burning and rough grazing. Without mamanegemtnatural succession results in heathland eventually developing into birch or pine woodland. 
There are some potentially competing theories regarding how succession may occur. 

1. Succession occurs more rapidly first on favourable micro-sites where nutrients have accumulated and conditions are best suited for trees to establish,
2. Succession is limted by propagule (seed) availability. Proximity to a suitable seed sources therefore a major factor determing spatial patterns of succession.

In order to produce data that may be used to provide evidence to evaluate the relative contributions of these two potential processes students were asked to design a simple study using circular quadrats and hand held GPS. The numbers of young pines found within each of the circular quadrats were scred as the resonse variable. Inuts to the analsis were then derived from satial data using GIS techniques.

This week we will start looking at the data using simple web maps.


```{r, warning=FALSE,message=FALSE}
library(aqm)
library(giscourse)
library(raster)
library(ggplot2)
library(sf)
library(tmap)
library(mapview)
library(dplyr)
library(mgcv)
```

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



```{r}
dt(arne_pines)
```


### Points to notice

1. Notice that the site is a factor with two levels. Heath and restoration. In other words all the quadrats in Coombe's heath are labeled as coming from heath and those in the restoration site are labeled. The restoration site was only measured in the last survey, so this will be treated rather differently in the analysis.  
2. The pine_density variable has been calculated by dividing the number of pines by the area of the quadrat. Last year the students decided to use smaller quadrats, so the counts of pine numbers are not directly comparable until they have been standardised in this way. The pine density multipied by an area in square meters produces an estimate of the total number of pines.  
3. There are coordinates of the quadrats as longitude (lon) and lattitude (lat). This is the most universal way of storing spatial data. It is easy to convert these to national grid when we need to measure areas and distances.

```{r}
write.csv(arne_pines, file="Arne_pines.csv", row.names = FALSE)
```


```{r}
quadrats<-st_as_sf(arne_pines,coords = c("lon","lat"),crs=4326)
write_sf(quadrats, "qudrats.kml")
```

```{r}
mapview(quadrats, zcol="Year", burst=TRUE) -> map1
map1 %>% extras() 
```

### Action 

You should spend some time investigating this map. Go full screen and change some of the options. You can experiment with the measuring tool. For the purposes of this assignment if you want to use this or any leaflet web map as a static figure in a word document you may take a screen shot of the map.  There are other more formal ways of making static maps directly in R but these take time and some nowledge of R to get right. A screenshot is good enough for the asssignment.

### Comparing density in the heathland and restoration site.

The restoration site was only measured this year. If we only want to use this year's data then we will need to apply a filter. 

```{r}
arne_pines %>% filter(Year==2019) -> d
```

If you look in the Environnment panel  in RStudio you will now see an object with only 35 observations. These are the data that you collected.

### Question: How does the pine density differ between the heathland and the restoration site?

This is a site specific question. The analysis may be relevant tothe assignment. Finding an answer to this question does not directly answer any broader scientific questions regarding the processes taking place. However it may still be useful for management at Arne and there may be broader implications that are suggested by the answer. If the conversion of former pine forest to heathland is difficult as a result of rapid regeneration this has broader implictaions. 

So how do we address this question statistically?

The first step is always to visualise the data. Let's use ggplots.

See the chapter on making figures.

### Boxplot of pine density

```{r}
g0<-ggplot(d,aes(x=site,y=pine_density)) 
g0 +geom_boxplot()
```

### Action

1. Write a brief explanation of the pattern you observe in the boxplots. 
2. Are the data approximately normal? How can you tell from the boxplots?
3. Should you remove any outliers? If not, why not?

### Inferential confidence interval plot

The quick way to make this is to use the ci function that has been included in the aqm package. Just use the ci funcion on the base plot with the aesthetics set (g0). This adds 95% confidence intervals based on the assumption that the variability around the means follows an approximately gaussian (normal) distribution.

```{r}
g1<-ci(g0)
g1 
```

You can add labels and customize this plot in other ways. See the handout on ggplots. You should label the axes and caption the figure with an explanation of how confidence intervals have been calculated.

### Action

1. Write your own interpretation of the figure.
2. Run an appropriate statistical test. (Hint .. there is a traditional and widely used test that finds the statistical significance of a difference between two means)
3. What is being assumed by this test? Are these assumptions reasonable?

```{r}
t.test(d$pine_density~d$site)
```



