Chapter 6 Habitat use

Camera traps are well suited for the quantification of habitat use across multiple species. To assess habitat use, we typically quantify the detection rate - the number of dections divided by the time interval of interest. Detection rates are fairly simple to estimate and understand thus their use is widespread.

In its simplest form this represents the number of independent events (or individuals within independent events) of a given species at a given camera, divided by the number of days that camera was active during that period of interest.

Such detection rates are thought to reflect the habitat use of a species at a given location - extreme care should be taken if you want to use it as an indesx of abundance. Detection rates are typically analysed in a linear modelling framework for single species, and increasingly for multispecies too.

We will use the "processed_data/Algar_30min_Independent_Monthly_counts.csv" dataframe as the starting point for this data analysis. Which looks like this:

monCount <- read.csv("data/processed_data/Algar_30min_Independent_Monthly_counts.csv", header=T)

Which, as a quick reminder, looks like this:

Deployment.Location.ID Date Effort Alces.alces Canis.latrans Canis.lupus Cervus.canadensis Grus.canadensis Lepus.americanus Lynx.canadensis Martes.americana Odocoileus.virginianus Rangifer.tarandus Tamiasciurus.hudsonicus Ursus.americanus
Algar08 2018-11 14 0 0 0 0 0 0 0 0 0 0 0 0
Algar08 2018-12 31 0 0 0 0 0 0 0 0 1 0 0 0
Algar08 2019-01 31 0 0 0 0 0 0 0 0 0 0 0 0
Algar08 2019-02 28 0 0 0 0 0 0 0 0 0 0 0 0
Algar08 2019-03 31 0 0 0 0 0 0 0 0 0 0 0 0
Algar08 2019-04 30 4 0 0 0 0 0 0 0 0 0 0 0

So our rows represent a month at each given site, and we have the number of camera days each location was trapped. This is also the format which most liner model analysis packages require you to have your data in. Easy!

Our next step to create the relative abundance index. We will divide each count by the number of days the station was active in each month then multiply by the a standardized number of days - often people use 100.

In R this would look like:

# Create a dataframe to store these detection rates
monDR <- monCount
# Divide the species abundances (which start in column four), by the amount of camera effort
monDR[ , 4:ncol(monCount)] <- (monDR[ , 4:ncol(monCount)]/monDR$Effort)*100

We can then examine the relationship between raw counts (on the x-axis) with our detection rate (on the y-axis), using Odocoileus virginianus as an example:

plot(monDR$Odocoileus.virginianus ~ monCount$Odocoileus.virginianus,
     las=1, pch=19, ylab="DR", xlab="Raw")
abline(a=0, b=3.22, lty=2, col="grey")

So in months where we have an incomplete sample (say 20 days in January instead of 31), the DR will be higher than the dashed grey line.

6.1 Single species habitat use model

The most common way to analyse habitat use data is through linear models. There are a variety if different frameworks to fit and compare different linear models to address a host of different hypotheses, but if you are just starting out you should be aware of two widely used packages:

  • lme4 -> frequentest and information theoretic approaches
  • brms -> Bayesian approaches

There is no right or wrong about which package and which approach you use to test your hypotheses, just make sure you understand the implications of your choices!

Example in lme4

In this worked example we will analyse how habitat use varies using a mixed effects model. We will not test the model assumptions or interrogate the findings, there are better resources to allow you to do that! Here we simply demonstrate how to use our camera data to fit the model.

First we must install the packages we require: 'lme4' and `tidyr':

 library(lme4); library(tidyr)

The lme4 package requires a dataframe format (as above), with the response term and the predictor variables all included in the same location. In this example we will explore if the habitat use of Odocoileus virginianus varied based on treatment strata.

Preparing our data

Recall that the information about each camera is recorded in the Station_covariates file:

sta <- read.csv("data/raw_data/Example_station_data.csv", header=T)

kbl(head(sta))%>%
  kable_paper() %>%
  scroll_box(width = "750px", height = "200px")
Deployment.Location.ID Longitude Latitude Treatment LOW500 LOS
Algar08 -112.4152 56.24259 HumanUse 0.3991810 112.7500
Algar27 -112.4735 56.33280 HumanUse 0.8345277 252.9583
Algar29 -112.5483 56.39474 HumanUse 0.6542558 206.5278
Algar31 -112.4820 56.30899 HumanUse 0.6180393 334.2778
Algar32 -112.3968 56.40197 HumanUse 0.5678142 83.0000
Algar34 -112.4012 56.22248 HumanUse 0.5492762 337.7917

So we have three variables to pick from:

  • Treatment a catagorical variable which reflects strata where the camera trap was deployed: HumanUse = a camera on a seismic line used and maintained in an "open" state by humans; Offline = a camera in contiguous forest >200m from a seismic line
  • LOW500 is a continuous variable reflecting the proportion of surrounding habitat 500m around the camera which is classified as "Lowland"
  • LOS is a continuous variable reflecting the average stDRght line distance (in metres) which you can view from the camera trap location.

In this example we will start by keeping things simple and just exploring if LOW500 (the proportion of lowland habitat) influences the habitat use of Odocoileus virginianus. We expect that it would, as White-tailed deer prefer upland habitat types in this landscape.

Our first task is to link the information in the sta dataframe, with that in the monCount dataframe. To do this we will use left_join() in the dplyr package - using the camera stations (Deployment.Location.ID column) to link the data.

library(dplyr)
modDat <- left_join(monCount, sta[c("Deployment.Location.ID", "LOW500")])
## Joining, by = "Deployment.Location.ID"

Lets check it has worked, the LOW500 column should be added on the right hand side:

kbl(head(modDat))%>%
  kable_paper() %>%
  scroll_box( height = "200px")
Deployment.Location.ID Date Effort Alces.alces Canis.latrans Canis.lupus Cervus.canadensis Grus.canadensis Lepus.americanus Lynx.canadensis Martes.americana Odocoileus.virginianus Rangifer.tarandus Tamiasciurus.hudsonicus Ursus.americanus LOW500
Algar08 2018-11 14 0 0 0 0 0 0 0 0 0 0 0 0 0.399181
Algar08 2018-12 31 0 0 0 0 0 0 0 0 1 0 0 0 0.399181
Algar08 2019-01 31 0 0 0 0 0 0 0 0 0 0 0 0 0.399181
Algar08 2019-02 28 0 0 0 0 0 0 0 0 0 0 0 0 0.399181
Algar08 2019-03 31 0 0 0 0 0 0 0 0 0 0 0 0 0.399181
Algar08 2019-04 30 4 0 0 0 0 0 0 0 0 0 0 0 0.399181

Next we will fit a mixed effects model to this data set using lme4. You may have noticed that we haven't used the monDR dataframe we made earlier! That is because we can create a relative abundance index within the model itself by providing an offset() term . An offset functions to scale the response term based on the amount of survey effort, and perseveres the original units of the observations (counts).

The model takes the form:

Response term ~ fixed effect + offset() + (1|random intercept), data frame, distribution

We include Deployment.Locaion.ID as the random intercept, as camera stations are repeatedly sampled at monthly intervals and thus our data (rows in the dataframe) are not independent. We use the poisson family, as our response term is a count.

m1 <- glmer(Odocoileus.virginianus ~ LOW500 + offset(log(Effort)) + (1|Deployment.Location.ID) , data=modDat, family="poisson")

We can view a summary of the model fit using:

summary(m1)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: poisson  ( log )
## Formula: Odocoileus.virginianus ~ LOW500 + offset(log(Effort)) + (1 |  
##     Deployment.Location.ID)
##    Data: modDat
## 
##      AIC      BIC   logLik deviance df.resid 
##    540.8    551.3   -267.4    534.8      245 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1896 -0.4391 -0.2499 -0.1293  4.2043 
## 
## Random effects:
##  Groups                 Name        Variance Std.Dev.
##  Deployment.Location.ID (Intercept) 4.002    2       
## Number of obs: 248, groups:  Deployment.Location.ID, 20
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)  
## (Intercept)   -1.957      1.778  -1.101   0.2710  
## LOW500        -4.807      2.598  -1.850   0.0643 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## LOW500 -0.953

As stated at the start of this guide, we are not focusing on whether the models we apply are appropriate or finding "the best" models for this datasheet, so do not spend too much time trying to interpret this information!

We can plot the relationship between by keeping things simple and just exploring if LOW500 influences the habitat use of Odocoileus virginianus habitat using the predict function and ggplot2.

To do this we create a dummy dataframe of "new" data (newDat):

newDat <- cbind(expand.grid(LOW500=seq(min(sta$LOW500),max(sta$LOW500), length.out=50)),Effort=100)

# Type "response" gives predictions on the original (count) scale.
newDat$Pred <- predict(m1,newdata=newDat,re.form=NA,
                  type="response")

plot(newDat$Pred~newDat$LOW500, type="l",
     ylim=c(0, max(newDat$Pred)), lwd=2,
     las=1, ylab="Predicted habitat use",
     xlab="Proportion lowland habitat")

So our model suggests that the habitat use of Odocoileus virginianus decreases as the proportion of lowland habitat increases. This is consistent with our understanding of White-tailed deer, which prefer upland habitats!

If you want more applied examples of generating predictions from mixed effects models, check out Ben Bolkers workbook

6.1.1 Future additions

  • Bayesian models - brms materials
  • model fit
  • over dispersion`
  • standardizing input variables
  • continuous and catagorical examples
  • Spatial and temporal non-independence
  • Confidence/credible intervals

6.1.2 Further reading

6.2 Example multispecies model

Given advances in computer power and analytic approaches, it is becoming increasingly popular to model multiple species within the same framework. This opens up a variety of things not previously possible.

As with single species linear models, there are many choices available for modeling multiple species in the same framework. Two notable options are:

In this example we will use the Hmsc package.

library(Hmsc)

Preparing our data

The format of data required for joint species distribution models is different to that of traditional linear models.

Rather than lumping the response term and fixed effects within the the same dataframe, we need a separate Y matrix of site.time x species, and an Xdata dataframe of your fixed and random effects variables.

# Pull the count data into its own matrix
Y <- as.matrix(monCount[, 4:ncol(monCount)])
# You can make the rown names the Site.Date values 
# (just incase you want to check things)
row.names(Y) <- paste(monCount$Deployment.Location.ID, monCount$Date, sep=".")

Which looks like this:

kbl(Y)%>%
  kable_paper() %>%
  scroll_box(height = "200px")
Alces.alces Canis.latrans Canis.lupus Cervus.canadensis Grus.canadensis Lepus.americanus Lynx.canadensis Martes.americana Odocoileus.virginianus Rangifer.tarandus Tamiasciurus.hudsonicus Ursus.americanus
Algar08.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar08.2018-12 0 0 0 0 0 0 0 0 1 0 0 0
Algar08.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar08.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar08.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar08.2019-04 4 0 0 0 0 0 0 0 0 0 0 0
Algar08.2019-05 0 0 0 0 0 0 0 0 1 2 0 0
Algar08.2019-06 0 0 0 0 0 0 0 0 0 0 0 0
Algar08.2019-07 0 0 0 0 0 0 0 0 0 0 0 0
Algar08.2019-08 5 0 0 0 0 1 0 0 0 0 0 0
Algar08.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar08.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar08.2019-11 0 0 1 0 0 0 0 0 0 0 0 0
Algar27.2018-11 0 1 0 1 0 0 0 0 1 0 0 0
Algar27.2018-12 0 0 2 0 0 0 0 0 0 0 0 0
Algar27.2019-01 2 2 1 0 0 0 0 0 0 0 0 0
Algar27.2019-02 0 0 1 0 0 0 1 0 0 0 0 0
Algar27.2019-03 0 0 0 0 0 0 3 0 0 0 0 0
Algar27.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar29.2018-11 0 0 0 0 0 0 0 0 5 0 0 0
Algar29.2018-12 0 0 3 0 0 0 1 0 3 0 0 0
Algar29.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar29.2019-02 1 0 0 0 0 0 0 0 0 0 0 0
Algar29.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar29.2019-04 2 0 0 0 4 0 0 0 5 0 0 1
Algar29.2019-05 2 0 0 0 7 0 0 0 8 0 0 0
Algar29.2019-06 2 0 0 0 0 0 0 0 1 0 0 2
Algar29.2019-07 0 0 0 0 5 0 0 0 0 0 0 0
Algar29.2019-08 0 0 0 0 5 0 0 0 2 0 0 1
Algar29.2019-09 0 0 0 0 0 0 0 0 1 0 0 2
Algar29.2019-10 0 0 0 0 0 0 0 0 2 0 0 1
Algar29.2019-11 0 0 0 0 0 0 0 0 5 0 0 0
Algar31.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar31.2018-12 2 0 0 0 0 0 0 0 0 0 0 0
Algar31.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar31.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar31.2019-03 1 0 0 0 0 0 0 2 0 0 0 0
Algar31.2019-04 0 0 9 0 2 0 0 0 0 0 0 0
Algar31.2019-05 0 0 0 0 3 0 0 1 0 0 0 0
Algar31.2019-06 1 0 1 0 7 0 0 0 1 3 0 0
Algar31.2019-07 0 0 0 0 3 0 0 0 0 2 0 3
Algar31.2019-08 0 0 0 0 5 0 0 0 0 1 0 0
Algar31.2019-09 0 0 0 0 0 0 0 0 0 11 0 0
Algar31.2019-10 0 0 0 0 0 0 0 0 0 1 0 1
Algar31.2019-11 0 0 0 0 0 1 0 1 0 0 0 0
Algar32.2018-11 1 0 0 0 0 0 0 0 0 0 0 0
Algar32.2018-12 0 0 0 0 0 0 0 0 0 0 0 0
Algar32.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar32.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar32.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar32.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar32.2019-05 0 0 0 0 1 0 0 0 0 0 0 0
Algar32.2019-06 0 0 0 0 2 0 0 0 1 0 0 0
Algar32.2019-07 0 0 0 0 0 0 0 0 0 1 0 0
Algar32.2019-08 0 0 0 0 0 0 0 0 0 0 0 0
Algar32.2019-09 0 0 0 0 0 0 0 0 0 1 0 0
Algar32.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar32.2019-11 0 0 0 0 0 0 1 0 0 0 0 0
Algar34.2018-11 0 0 0 0 0 0 0 0 1 0 0 0
Algar34.2018-12 0 0 0 0 0 0 0 0 0 0 0 0
Algar34.2019-01 0 0 0 0 0 0 2 0 2 0 0 0
Algar34.2019-02 0 0 0 0 0 0 1 0 0 0 0 0
Algar34.2019-03 2 0 0 0 0 0 1 0 0 0 0 0
Algar34.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar34.2019-05 0 0 0 0 0 0 0 0 0 0 0 0
Algar34.2019-06 0 0 0 0 0 0 0 0 0 0 0 0
Algar34.2019-07 0 0 0 0 0 0 0 0 0 0 0 0
Algar34.2019-08 0 0 0 0 0 0 0 0 0 0 0 0
Algar34.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar34.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar34.2019-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar35.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar35.2018-12 0 0 0 0 0 1 0 0 0 1 0 0
Algar35.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar35.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar35.2019-03 0 0 0 0 0 5 0 0 0 0 0 0
Algar35.2019-04 1 0 0 0 0 0 0 0 0 0 0 0
Algar35.2019-05 1 0 0 0 5 0 0 0 0 0 0 0
Algar35.2019-06 3 0 0 0 3 0 0 0 1 0 0 0
Algar35.2019-07 1 0 0 0 11 0 0 0 0 1 0 1
Algar35.2019-08 1 0 0 0 3 0 0 0 0 0 3 1
Algar35.2019-09 0 0 0 0 0 0 0 0 0 1 0 0
Algar35.2019-10 0 0 0 0 0 0 1 0 0 1 0 0
Algar35.2019-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar37.2018-11 0 0 0 0 0 0 0 0 0 1 0 0
Algar37.2018-12 0 0 0 0 0 0 0 0 0 1 0 0
Algar37.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar37.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar37.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar37.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar37.2019-05 0 0 0 0 16 0 0 0 0 1 0 0
Algar37.2019-06 0 0 0 0 24 0 0 0 0 0 0 1
Algar37.2019-07 0 0 0 0 26 0 0 0 0 0 0 0
Algar37.2019-08 0 0 0 0 29 0 0 0 0 0 0 0
Algar37.2019-09 0 0 0 0 2 0 0 0 0 0 0 0
Algar37.2019-10 0 0 0 0 0 0 0 0 0 0 0 1
Algar37.2019-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar38.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar38.2018-12 0 0 0 0 0 0 0 1 0 0 0 0
Algar38.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar38.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar38.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar38.2019-04 0 0 0 0 3 0 0 0 0 1 0 0
Algar38.2019-05 0 0 0 0 15 0 0 0 0 1 0 0
Algar38.2019-06 0 0 0 0 9 0 0 0 0 0 0 0
Algar38.2019-07 0 0 0 0 1 0 0 0 0 7 0 0
Algar38.2019-08 0 0 0 0 5 0 0 0 0 1 0 0
Algar38.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar38.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar38.2019-11 0 0 0 0 0 0 0 0 0 3 0 0
Algar39.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar39.2018-12 0 0 4 0 0 0 0 0 0 0 0 0
Algar39.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar39.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar39.2019-03 0 0 1 0 0 0 0 0 0 0 0 0
Algar39.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar39.2019-05 0 0 0 0 5 0 0 0 0 0 0 2
Algar39.2019-06 0 0 1 0 0 0 0 0 0 0 0 0
Algar39.2019-07 0 0 0 0 9 0 0 0 0 0 0 0
Algar39.2019-08 0 0 0 0 0 0 0 0 0 0 0 1
Algar39.2019-09 0 0 0 0 0 0 0 0 0 4 0 0
Algar39.2019-10 0 0 0 0 0 0 0 0 0 2 0 0
Algar39.2019-11 1 0 0 0 0 0 0 0 0 0 0 0
Algar61.2018-11 0 0 0 0 0 0 0 0 6 0 0 0
Algar61.2018-12 0 0 0 0 0 0 0 0 9 0 0 0
Algar61.2019-01 0 0 0 0 0 0 0 1 1 0 0 0
Algar61.2019-02 0 0 0 0 0 0 0 0 8 0 0 0
Algar61.2019-03 0 0 0 0 0 0 0 0 3 0 0 0
Algar61.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar61.2019-05 0 0 0 0 0 0 0 0 0 0 0 0
Algar61.2019-06 0 0 0 0 0 0 0 0 5 0 0 1
Algar61.2019-07 0 0 0 0 0 0 0 0 4 0 0 0
Algar61.2019-08 0 0 0 0 0 0 0 0 2 0 0 0
Algar61.2019-09 0 0 0 0 0 0 0 0 1 0 0 0
Algar61.2019-10 0 0 0 0 0 0 0 1 0 0 0 0
Algar61.2019-11 0 0 0 0 0 0 0 0 3 0 0 0
Algar62.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar62.2018-12 0 0 0 0 0 0 0 0 10 0 0 0
Algar62.2019-01 0 0 0 0 0 0 0 0 8 0 0 0
Algar62.2019-02 0 0 0 0 0 0 0 0 1 0 0 0
Algar62.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar62.2019-04 0 0 0 0 0 0 0 0 3 0 0 0
Algar62.2019-05 0 0 0 0 0 0 0 0 6 0 0 0
Algar62.2019-06 0 0 0 0 0 0 0 0 9 0 0 4
Algar62.2019-07 0 0 2 0 0 0 0 0 1 0 0 1
Algar62.2019-08 0 0 1 0 0 0 0 0 8 0 0 0
Algar62.2019-09 0 0 0 0 0 0 0 0 2 0 0 6
Algar62.2019-10 0 0 0 0 0 0 1 0 0 0 0 0
Algar62.2019-11 0 0 0 0 0 1 0 0 0 0 0 0
Algar63.2018-11 0 0 0 0 0 0 0 0 4 0 0 0
Algar63.2018-12 0 0 0 0 0 0 0 0 3 0 0 0
Algar63.2019-01 0 0 0 0 0 0 0 0 3 0 0 0
Algar63.2019-02 0 0 0 0 0 0 0 1 1 0 0 0
Algar63.2019-03 0 0 0 0 0 1 0 0 0 0 0 0
Algar63.2019-04 0 0 1 0 0 0 0 0 1 0 0 0
Algar63.2019-05 0 0 0 0 0 0 0 0 2 0 0 0
Algar63.2019-06 0 0 0 0 0 0 0 0 3 0 0 0
Algar63.2019-07 0 0 0 0 0 0 0 0 4 3 0 0
Algar63.2019-08 0 0 0 0 0 0 0 0 4 0 0 0
Algar63.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar63.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar63.2019-11 0 0 0 0 0 0 0 0 1 0 0 0
Algar64.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar64.2018-12 0 0 0 0 0 0 0 0 0 0 0 0
Algar64.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar64.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar64.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar64.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar64.2019-05 1 0 0 0 0 0 0 0 0 0 0 0
Algar64.2019-06 3 0 0 0 1 0 0 0 0 2 0 0
Algar64.2019-07 0 0 0 0 0 0 0 0 0 3 0 0
Algar64.2019-08 0 0 0 0 0 0 0 0 0 3 0 0
Algar64.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar64.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar64.2019-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar65.2018-11 6 0 0 0 0 0 0 0 0 0 0 0
Algar65.2018-12 15 0 0 0 0 0 0 0 0 0 0 0
Algar65.2019-01 3 0 0 0 0 0 0 0 0 0 0 0
Algar65.2019-02 6 0 0 0 0 0 0 0 0 0 0 0
Algar65.2019-03 0 0 0 0 0 0 0 1 0 0 0 0
Algar65.2019-04 2 0 0 0 0 0 0 0 0 0 0 0
Algar65.2019-05 0 0 0 0 0 0 0 0 0 0 0 0
Algar65.2019-06 0 0 0 0 1 0 0 0 0 0 0 0
Algar66.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar66.2018-12 0 0 0 0 0 0 0 0 0 0 0 0
Algar66.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar66.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar66.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar66.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar66.2019-05 0 0 0 0 0 0 0 0 0 1 0 0
Algar66.2019-06 0 0 0 0 1 0 0 0 0 1 0 0
Algar66.2019-07 0 0 0 0 0 0 0 0 1 0 0 0
Algar66.2019-08 0 0 0 0 1 0 0 0 0 0 0 0
Algar66.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar66.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar66.2019-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar67.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar67.2018-12 0 0 0 0 0 0 0 0 0 0 0 0
Algar67.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar67.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar67.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar67.2019-04 0 0 0 0 2 0 0 0 0 0 0 0
Algar67.2019-05 1 0 0 0 1 0 0 0 1 0 0 0
Algar67.2019-06 0 0 0 0 10 0 0 0 2 0 0 0
Algar67.2019-07 3 0 0 0 8 0 0 0 1 0 0 0
Algar67.2019-08 0 0 0 0 4 0 0 0 0 0 0 0
Algar67.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar67.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar67.2019-11 0 0 3 0 0 0 0 0 0 0 0 0
Algar68.2018-11 1 0 0 0 0 0 0 0 0 0 0 0
Algar68.2018-12 1 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-05 0 0 0 0 5 0 0 0 0 0 0 0
Algar68.2019-06 0 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-07 0 0 0 0 0 0 0 0 0 0 0 1
Algar68.2019-08 0 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar68.2019-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar69.2018-11 0 0 0 0 0 0 1 0 6 0 0 0
Algar69.2018-12 0 0 0 0 0 0 1 0 7 0 0 0
Algar69.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar69.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar69.2019-03 0 0 0 0 0 0 0 0 0 0 0 0
Algar69.2019-04 0 0 0 0 0 0 0 0 8 0 0 2
Algar69.2019-05 4 0 0 0 0 0 0 0 1 0 0 5
Algar69.2019-06 0 0 0 0 0 0 0 0 2 0 0 9
Algar69.2019-07 0 0 0 0 0 0 0 0 8 0 0 4
Algar69.2019-08 0 0 0 0 0 0 0 0 7 0 0 0
Algar69.2019-09 1 0 0 0 0 0 0 0 2 0 0 1
Algar69.2019-10 0 0 0 0 0 0 1 0 14 0 0 0
Algar69.2019-11 0 0 0 0 0 0 1 0 3 0 0 0
Algar70.2018-11 0 0 0 0 0 0 0 0 0 0 0 0
Algar70.2018-12 0 0 0 0 0 0 0 0 0 0 0 0
Algar70.2019-01 0 0 0 0 0 0 0 0 0 0 0 0
Algar70.2019-02 0 0 0 0 0 0 0 0 0 0 0 0
Algar70.2019-03 0 0 0 0 0 0 0 0 0 1 0 0
Algar70.2019-04 0 0 0 0 0 0 0 0 0 0 0 0
Algar70.2019-05 1 0 0 0 0 0 0 1 0 0 0 1
Algar70.2019-06 0 0 0 0 0 0 0 0 2 0 0 0
Algar70.2019-07 0 0 0 0 0 0 0 0 1 0 0 0
Algar70.2019-08 0 0 0 0 7 0 0 0 2 0 0 0
Algar70.2019-09 0 0 0 0 0 0 0 0 0 0 0 0
Algar70.2019-10 0 0 0 0 0 0 0 0 0 0 0 0
Algar70.2019-11 0 0 0 0 0 0 0 0 0 3 0 0

We then create the XData in a similar way to before, but this time dropping the species information:

Xdat <- left_join(monCount[c("Deployment.Location.ID", "Date", "Effort")], sta[c("Deployment.Location.ID", "LOW500")])
## Joining, by = "Deployment.Location.ID"

Which looks like:

kbl(Xdat)%>%
  kable_paper() %>%
  scroll_box(height = "200px")
Deployment.Location.ID Date Effort LOW500
Algar08 2018-11 14 0.3991810
Algar08 2018-12 31 0.3991810
Algar08 2019-01 31 0.3991810
Algar08 2019-02 28 0.3991810
Algar08 2019-03 31 0.3991810
Algar08 2019-04 30 0.3991810
Algar08 2019-05 31 0.3991810
Algar08 2019-06 30 0.3991810
Algar08 2019-07 31 0.3991810
Algar08 2019-08 31 0.3991810
Algar08 2019-09 30 0.3991810
Algar08 2019-10 31 0.3991810
Algar08 2019-11 21 0.3991810
Algar27 2018-11 16 0.8345277
Algar27 2018-12 31 0.8345277
Algar27 2019-01 31 0.8345277
Algar27 2019-02 28 0.8345277
Algar27 2019-03 31 0.8345277
Algar27 2019-04 3 0.8345277
Algar29 2018-11 16 0.6542558
Algar29 2018-12 31 0.6542558
Algar29 2019-01 31 0.6542558
Algar29 2019-02 28 0.6542558
Algar29 2019-03 31 0.6542558
Algar29 2019-04 30 0.6542558
Algar29 2019-05 31 0.6542558
Algar29 2019-06 30 0.6542558
Algar29 2019-07 31 0.6542558
Algar29 2019-08 31 0.6542558
Algar29 2019-09 30 0.6542558
Algar29 2019-10 31 0.6542558
Algar29 2019-11 20 0.6542558
Algar31 2018-11 15 0.6180393
Algar31 2018-12 31 0.6180393
Algar31 2019-01 31 0.6180393
Algar31 2019-02 28 0.6180393
Algar31 2019-03 31 0.6180393
Algar31 2019-04 30 0.6180393
Algar31 2019-05 31 0.6180393
Algar31 2019-06 30 0.6180393
Algar31 2019-07 31 0.6180393
Algar31 2019-08 31 0.6180393
Algar31 2019-09 30 0.6180393
Algar31 2019-10 31 0.6180393
Algar31 2019-11 21 0.6180393
Algar32 2018-11 17 0.5678142
Algar32 2018-12 31 0.5678142
Algar32 2019-01 31 0.5678142
Algar32 2019-02 28 0.5678142
Algar32 2019-03 31 0.5678142
Algar32 2019-04 30 0.5678142
Algar32 2019-05 31 0.5678142
Algar32 2019-06 30 0.5678142
Algar32 2019-07 31 0.5678142
Algar32 2019-08 31 0.5678142
Algar32 2019-09 30 0.5678142
Algar32 2019-10 31 0.5678142
Algar32 2019-11 19 0.5678142
Algar34 2018-11 14 0.5492762
Algar34 2018-12 31 0.5492762
Algar34 2019-01 31 0.5492762
Algar34 2019-02 28 0.5492762
Algar34 2019-03 31 0.5492762
Algar34 2019-04 30 0.5492762
Algar34 2019-05 31 0.5492762
Algar34 2019-06 30 0.5492762
Algar34 2019-07 31 0.5492762
Algar34 2019-08 31 0.5492762
Algar34 2019-09 30 0.5492762
Algar34 2019-10 31 0.5492762
Algar34 2019-11 21 0.5492762
Algar35 2018-11 16 0.6898255
Algar35 2018-12 31 0.6898255
Algar35 2019-01 31 0.6898255
Algar35 2019-02 28 0.6898255
Algar35 2019-03 31 0.6898255
Algar35 2019-04 30 0.6898255
Algar35 2019-05 31 0.6898255
Algar35 2019-06 30 0.6898255
Algar35 2019-07 31 0.6898255
Algar35 2019-08 31 0.6898255
Algar35 2019-09 30 0.6898255
Algar35 2019-10 31 0.6898255
Algar35 2019-11 22 0.6898255
Algar37 2018-11 14 0.9594975
Algar37 2018-12 31 0.9594975
Algar37 2019-01 31 0.9594975
Algar37 2019-02 28 0.9594975
Algar37 2019-03 31 0.9594975
Algar37 2019-04 30 0.9594975
Algar37 2019-05 31 0.9594975
Algar37 2019-06 30 0.9594975
Algar37 2019-07 31 0.9594975
Algar37 2019-08 31 0.9594975
Algar37 2019-09 30 0.9594975
Algar37 2019-10 31 0.9594975
Algar37 2019-11 21 0.9594975
Algar38 2018-11 15 0.9534252
Algar38 2018-12 31 0.9534252
Algar38 2019-01 31 0.9534252
Algar38 2019-02 28 0.9534252
Algar38 2019-03 31 0.9534252
Algar38 2019-04 30 0.9534252
Algar38 2019-05 31 0.9534252
Algar38 2019-06 30 0.9534252
Algar38 2019-07 31 0.9534252
Algar38 2019-08 31 0.9534252
Algar38 2019-09 30 0.9534252
Algar38 2019-10 31 0.9534252
Algar38 2019-11 21 0.9534252
Algar39 2018-11 15 0.9804302
Algar39 2018-12 31 0.9804302
Algar39 2019-01 31 0.9804302
Algar39 2019-02 28 0.9804302
Algar39 2019-03 31 0.9804302
Algar39 2019-04 30 0.9804302
Algar39 2019-05 31 0.9804302
Algar39 2019-06 30 0.9804302
Algar39 2019-07 31 0.9804302
Algar39 2019-08 31 0.9804302
Algar39 2019-09 30 0.9804302
Algar39 2019-10 31 0.9804302
Algar39 2019-11 19 0.9804302
Algar61 2018-11 14 0.3439682
Algar61 2018-12 31 0.3439682
Algar61 2019-01 31 0.3439682
Algar61 2019-02 28 0.3439682
Algar61 2019-03 31 0.3439682
Algar61 2019-04 30 0.3439682
Algar61 2019-05 31 0.3439682
Algar61 2019-06 30 0.3439682
Algar61 2019-07 31 0.3439682
Algar61 2019-08 31 0.3439682
Algar61 2019-09 30 0.3439682
Algar61 2019-10 31 0.3439682
Algar61 2019-11 19 0.3439682
Algar62 2018-11 14 0.8144920
Algar62 2018-12 31 0.8144920
Algar62 2019-01 31 0.8144920
Algar62 2019-02 28 0.8144920
Algar62 2019-03 31 0.8144920
Algar62 2019-04 30 0.8144920
Algar62 2019-05 31 0.8144920
Algar62 2019-06 30 0.8144920
Algar62 2019-07 31 0.8144920
Algar62 2019-08 31 0.8144920
Algar62 2019-09 30 0.8144920
Algar62 2019-10 31 0.8144920
Algar62 2019-11 21 0.8144920
Algar63 2018-11 15 0.8031606
Algar63 2018-12 31 0.8031606
Algar63 2019-01 31 0.8031606
Algar63 2019-02 28 0.8031606
Algar63 2019-03 31 0.8031606
Algar63 2019-04 30 0.8031606
Algar63 2019-05 31 0.8031606
Algar63 2019-06 30 0.8031606
Algar63 2019-07 31 0.8031606
Algar63 2019-08 31 0.8031606
Algar63 2019-09 30 0.8031606
Algar63 2019-10 31 0.8031606
Algar63 2019-11 21 0.8031606
Algar64 2018-11 14 0.6981936
Algar64 2018-12 31 0.6981936
Algar64 2019-01 31 0.6981936
Algar64 2019-02 28 0.6981936
Algar64 2019-03 31 0.6981936
Algar64 2019-04 30 0.6981936
Algar64 2019-05 31 0.6981936
Algar64 2019-06 30 0.6981936
Algar64 2019-07 31 0.6981936
Algar64 2019-08 31 0.6981936
Algar64 2019-09 30 0.6981936
Algar64 2019-10 31 0.6981936
Algar64 2019-11 21 0.6981936
Algar65 2018-11 15 0.5220356
Algar65 2018-12 31 0.5220356
Algar65 2019-01 31 0.5220356
Algar65 2019-02 28 0.5220356
Algar65 2019-03 31 0.5220356
Algar65 2019-04 30 0.5220356
Algar65 2019-05 31 0.5220356
Algar65 2019-06 28 0.5220356
Algar66 2018-11 15 0.8367344
Algar66 2018-12 31 0.8367344
Algar66 2019-01 31 0.8367344
Algar66 2019-02 28 0.8367344
Algar66 2019-03 31 0.8367344
Algar66 2019-04 30 0.8367344
Algar66 2019-05 31 0.8367344
Algar66 2019-06 30 0.8367344
Algar66 2019-07 31 0.8367344
Algar66 2019-08 31 0.8367344
Algar66 2019-09 30 0.8367344
Algar66 2019-10 31 0.8367344
Algar66 2019-11 19 0.8367344
Algar67 2018-11 16 0.3665866
Algar67 2018-12 31 0.3665866
Algar67 2019-01 31 0.3665866
Algar67 2019-02 28 0.3665866
Algar67 2019-03 31 0.3665866
Algar67 2019-04 30 0.3665866
Algar67 2019-05 31 0.3665866
Algar67 2019-06 30 0.3665866
Algar67 2019-07 31 0.3665866
Algar67 2019-08 31 0.3665866
Algar67 2019-09 30 0.3665866
Algar67 2019-10 31 0.3665866
Algar67 2019-11 20 0.3665866
Algar68 2018-11 16 0.9913344
Algar68 2018-12 31 0.9913344
Algar68 2019-01 31 0.9913344
Algar68 2019-02 28 0.9913344
Algar68 2019-03 31 0.9913344
Algar68 2019-04 30 0.9913344
Algar68 2019-05 31 0.9913344
Algar68 2019-06 30 0.9913344
Algar68 2019-07 31 0.9913344
Algar68 2019-08 31 0.9913344
Algar68 2019-09 30 0.9913344
Algar68 2019-10 31 0.9913344
Algar68 2019-11 20 0.9913344
Algar69 2018-11 17 0.4999456
Algar69 2018-12 31 0.4999456
Algar69 2019-01 31 0.4999456
Algar69 2019-02 28 0.4999456
Algar69 2019-03 31 0.4999456
Algar69 2019-04 30 0.4999456
Algar69 2019-05 31 0.4999456
Algar69 2019-06 30 0.4999456
Algar69 2019-07 31 0.4999456
Algar69 2019-08 31 0.4999456
Algar69 2019-09 30 0.4999456
Algar69 2019-10 31 0.4999456
Algar69 2019-11 19 0.4999456
Algar70 2018-11 17 0.9055726
Algar70 2018-12 31 0.9055726
Algar70 2019-01 31 0.9055726
Algar70 2019-02 28 0.9055726
Algar70 2019-03 31 0.9055726
Algar70 2019-04 30 0.9055726
Algar70 2019-05 31 0.9055726
Algar70 2019-06 30 0.9055726
Algar70 2019-07 31 0.9055726
Algar70 2019-08 31 0.9055726
Algar70 2019-09 30 0.9055726
Algar70 2019-10 31 0.9055726
Algar70 2019-11 19 0.9055726

With Bayesian approaches we need to set up our sampling conditions

nChains   = 2 
thin      = 2 
samples   = 100 
transient = 10*thin
verbose   = T

Setup our random effect:

# Add a station-level random effect (for the covariances)
studyDesign = data.frame(station = as.factor(Xdat$Deployment.Location.ID))
rL = HmscRandomLevel(units = studyDesign$station)

Specify our model""

# Model specification
m = Hmsc(Y = Y, XData = Xdat[,c("LOW500", "Effort")], 
         XFormula = ~LOW500 + log(Effort),
         studyDesign = studyDesign, ranLevels = list(station = rL), 
         distr="poisson")


m = sampleMcmc(m, thin = thin, samples = samples, transient = transient,
               nChains = nChains, verbose = verbose)
## Computing chain 1
## Computing chain 2

We can plot a basic summary of the modelled effects using the following code.

postBeta = getPostEstimate(m, parName = "Beta")
par(mar=c(8,12,1,1))
plotBeta(m, post = postBeta, param = "Support", supportLevel = 0)

We the colours denote the size and magnitude of the effect of proportion of lowland habitat. NOTE treat these results with cauthion as the number of model runs is very low (to increase speed) and the model assumptions have not been interrograted.

6.3 Further reading

Palmer, Meredith S., et al. "Evaluating relative abundance indices for terrestrial herbivores from largeā€scale camera trap surveys." African journal of ecology 56.4 (2018): 791-803.