# Arne pine densities

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

## Introduction

The RSPB reserve at Arne is one of the most high profile conservation sites in the UK. The area has hosted the BBC series autumn watch on several occasions. The reserve consists of a mosaic of habitats including salt marsh and woodland. The reserve also contains around 1% of the total extent of lowland heath in England according to this interesting blog post from the BBC.

<https://www.bbc.co.uk/blogs/natureuk/entries/0e25d226-a6ed-47d9-9611-d20a09b593d2>

In order to prepare for the assignment, you should research some of the characteristics of lowland heath and the challenges involved in its management.

Those deciding on management options for the heathland face a dilemma. Heathland is an open habitat that was traditionally maintained through a variety of human activities. The heathland at Arne is surrounded by areas which were planted with scots pine (*Pinus sylvestris*) in the past. This has resulted in a source of pine seeds that fall into the heathland. In order to increase the value of the heathland for conservation, some pine trees have been left to mature within the heath itself. If the heath were left with no management it is likely that it would gradually convert into closed pine forest.

In order to prevent the loss of heathland to woodland young pines that regenerate in the heath are removed. There are several options available. Pines may be removed mechanically. However this leads to intense disturbance of the habitat which affects ecosystem function and is aesthetically unappealing. The use of herbicides is also an undesirable option within a reserve. Pine regeneration in Scottish heathland is often restricted through grazing by deer. However although Arne has a population of both Sika deer and Roe deer grazing has comparatively little impact on pine regeneration.

Removal of young pines through manually pulling the trees out of the ground is the least disruptive option. However this is time consuming and potentially costly. Pine pulling provides the managers with a chance for public engagement. Each year the reserve offers the public the chance to engage with management by "pulling a pine for Christmas".


```{r, warning=FALSE,message=FALSE}
library(tidyverse)
library(aqm)
library(giscourse)
library(raster)
library(sf)
library(tmap)
library(mapview)
library(leaflet.extras)
library(mgcv)
```

## The field data

In 2017 students on this unit visited Grip heath at Arne in order to collect data on the pine regeneration for analysis in R. 
At the time, very little removal of pines had been undertaken. Young pines appeared to be quite randomly scattered across the site. Most of the young pines were estimated to be between 5 and 7 years of age (young pines can be aged by counting whorls). Students were told to design their own sampling scheme in order to obtain a representative sample from the area. As the area is quite large they decided to undertake transects that consisted of "random walks". This sampling scheme has various weaknesses that can be discussed in the assignment.

In 2018 students returned to the site. Since 2017 some systematic removal of pines had been undertaken together with pine pulling to reduce the density elsewhere. The study therefore concentrated on an undisturbed area of the site. 

In 2019 more pines had been removed and another relatively undisturbed area was selected for study.

The variable being measured was the density of pines expressed in mumber of pines per square meter. This was measured through placing a peg in the ground with attached to a rope and drawing a circle defined by the radius of the rope. Pines falling within the circle were counted and the area calculated as $\pi r^2$.

The data can be loaded from the aqm package.

```{r}
data("grip")
dt(grip)
```

One simple question could be addressed through one way analysis of variance. Is there significant variability in the mean pine density between the studies?



```{r}
grip$Year<-as.factor(grip$Year)
ggplot(grip,aes(x=Year,y=pine_density)) -> g0
ci(g0)
```

In order to interpret this it would be useful to see a map showing where the measurements were taken.

To turn the data frame into a spatial object we need to tell R which columns represent the x and y coordinates and also to provide the EPSG code for the coordinate reference system. As the data were collected with latitudes and longitudes the CRS is EPSG code 4326.


```{r}
quadrats<-st_as_sf(grip,coords = c("lon","lat"),crs=4326)
```

We can now produce a map. The following code will set up the map without showing it.

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

```

The map can be shown with some additions from the leaflet.extras package. These are a full screen control, a minimap in the corner showing the position of the site and a measuring tool.

Note that the zoom level of the minimap can be changed in the code order to zoom in an out.


```{r}
map1@map %>% 
    addFullscreenControl() %>%
    addMiniMap(position = "bottomleft",tiles="OpenStreetMap.HOT",zoomLevelOffset = -5, toggleDisplay=TRUE) %>%
    addMeasure(primaryLengthUnit ='meters', secondaryLengthUnit='kilometers',
               primaryAreaUnit='hectares',
               position="topleft")
```

## How many pines need to be pulled?

One way to answer this question would be to find confidence intervals for the pine densities, either overall using all the data or for specific years. This is easy in R. All we need to do is fit a linear model for the intercept of a subset of the data and ask for the confidence interval.

```{r}
grip %>% filter(Year==2017)->d
confint(lm(data=d,pine_density~1))
```

Now, if the sample points were representative of an area in which they may have fallen the estimated number of pines would be the intervals for the mean multiplied by the area in square meters. Note that a hectare is 10,000 square meters.

### Exercise

Use the measuring tool to find some areas that appear visually to be reasonable candidates for the area within which the quadrats may have been placed. Estimate the total number of young pines.

Would the public pine pulling for Christmas make a notable impact on the total number of pines?
How many pines might possibly be expected to regenerate each year?




