# Statistical analysis of the pine density data


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

```

## Introduction

In the last handout we extracted variables that may (or may not) be associated with the densities of pines that were measured in the quadrats at Arne. To do this we used R as a Geographical Information system. 
Now that we have built a data table we can return to using R for statistical analysis.

It is probably a good idea to start a new markdown document for this part of the assignment work. 
To prevent confusion clear the Environment using the "sweeping brush" in the top right panel.

### Loading libraries


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

We are not going to make maps, so we don't need as many libraries.

```{r}
library(aqm)
library(ggplot2)

library(dplyr)
library(mgcv)

```

You now just need to read in the data.

```{r}
d<-read.csv(file="arne_quadrats.csv")
 
# Alternative data load. Only use these lines if you have problems loading the csv
# Uncommenting (removing the # activates the code)
# data(arne_quads)
# d<-arne_quads
```


```{r}
dt(d)
```

## Running analyses


OK, so now you have the data. It is up to you to design some relevant analyses. These do not need to be very complex for this assignment. You should produce relevant scatterplots with fitted lines. Don't worry if you can't actually find any clear cut relationships between variables. This is a common occurence when conducting real life field work. If there are no clear relationships then you need to think carefully about why they are not clear. 

As an example of one possible analysis I have included code for plotting figure to investigate the relationship between pine density and topographic wetness index.

```{r}
g0<-ggplot(d, aes(x=twi,y=pine_density)) 
g1<-g0 + geom_point() 
```


```{r}
g1 + geom_smooth()
```


```{r}
g1 + geom_smooth(method="lm")
```


```{r}
mod<-lm(data=d, pine_density~twi)
summary(mod)
```

