- 1 Generalized Additive Modells
- 2 Modeling Species Richness
- 2.1 Data
- 2.2 Preprocessing
- 2.2.1 Loading required packages
- 2.2.2 Loading occurence - and environmental data sets
- 2.2.3 Loading and transforming people density data set
- 2.2.4 Removing predictors with high collinearity
- 2.2.5 Letâ€™s take a look at our preditors
- 2.2.6 Creating absence points
- 2.2.7 Remove points outside of the raster extend
- 2.2.8 Remove all cells with no preditors
- 2.2.9 seperating the different butterflyspecies and saving them in a list

- 3 Using GAMs to predict species distributions
- 4 References
- 5 Session Info

```
library(mgcv)
<- gam(presence ~ s(x1) + s(x2) + s(x3) + # one dimensional smooths
model s(x4, x5), # two dimensional smooths
data = __, # your data
family = ___, # your distribution (e.g. gaussian)
method = "REML" # sets parameter for your smooths
...)
```

Generalized Additive Models use **spline functions** (smooths).

The spline functions are composed of simpler **basis functions** witch are weighted and summed up.

\[s(x) = \sum_{k = 1}^K \beta_k b_k(x)\]

The more *basis functions* a smooth is made of, the more complex of a relationship the smooth can model (Simpson 2020). With the parameter **k** in `s(x1, k = __)`

you can pick the number of *basis functions*.