Studying the complex ecological systems across both space and time is imperative in understanding the full dynamics of species. This vignette illustrates the construction of a spatiotemporal ISDM using PointedSDMs, using data of species Colinus virginianus across Alabama (United States of America). The first step in this vignette is to load the required packages:
library(PointedSDMs)
library(inlabru)
library(ggplot2)
library(spocc)
library(INLA)
library(dplyr)
library(sp)
library(sf)
as well as define some objects required by the model to run.
<- CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
proj
<- USAboundaries::us_states(states = "Alabama")
AL <- as(AL, "Spatial")
AL
<- inla.mesh.2d(boundary = inla.sp2segment(AL),
mesh cutoff = 0.1,
max.edge = c(0.2, 0.8),
offset = c(0.1, 0.2))
$crs <- proj mesh
The first dataset we consider is obtained from the North American Breeding Bird Survey. This dataset may be loaded directly from the package, and contains observations of the species between 2015 and 2017. This dataset is treated as replicate present-absent, where every point is assumed to be a visited site (or route).
data("BBSColinusVirginianus")
The second dataset considered is obtained via the citizen science program, eBird. These data are obtained via the R package, spocc using the script below, where a separate object of data points was created for each year to ensure that the number of records per year is equal.
<- spocc::occ(
eBird2015 query = 'Colinus virginianus',
from = 'gbif',
date = c("2015-01-01", "2015-12-31"),
geometry = AL@bbox
$gbif
)
<- spocc::occ(
eBird2016 query = 'Colinus virginianus',
from = 'gbif',
date = c("2016-01-01", "2016-12-31"),
geometry = AL@bbox
$gbif
)
<- spocc::occ(
eBird2017 query = 'Colinus virginianus',
from = 'gbif',
date = c("2017-01-01", "2017-12-31"),
geometry = AL@bbox
$gbif
)
<- data.frame(eBird2015$data[[1]]) %>%
eBird bind_rows(data.frame(eBird2016$data[[1]])) %>%
bind_rows(data.frame(eBird2017$data[[1]]))
<- SpatialPointsDataFrame(coords = cbind(Longitude = eBird$longitude, Latitude = eBird$latitude),
eBird data = data.frame(Year = eBird$year),
proj4string = proj)
<- eBird[c(!is.na(over(eBird, AL[1]))),] eBird
We then get onto the model description, which in this case includes a
shared spatial field between the two datasets. This shared spatial field
is characterized by an ar1 process. To add this structure into
the model, we specify the parameter temporalModel in the
function intModel
appropriately, Furthermore we specified
the hyper parameters for both the random field and the temporal
effect.
<- list(rho = list(prior = "pc.prec", param = c(0.01, 0.01)))
hyperParams
<- intModel(eBird, BBSColinusVirginianus,
modelSetup Coordinates = c('Longitude', 'Latitude'), temporalName = 'Year',
Projection = proj, Mesh = mesh,
responsePA = 'NPres', trialsPA = 'Ntrials',
temporalModel = list(model = 'ar1', hyper = hyperParams))
$specifySpatial(sharedSpatial = TRUE, prior.sigma = c(0.2, 0.01),
modelSetupprior.range = c(0.4, 0.01))
The data is spread across the map like this
$plot() modelSetup
The components for this model look like this:
$changeComponents() modelSetup
Next we run the model, using the function fitISDM
. Due
to time considerations, inference for this model is not completed in the
vignette. However, both the data and script is provided for the user to
complete the analysis.
<- fitISDM(modelSetup,
mod options = list(control.inla = list(int.strategy = 'eb')))
And finally create predictions for the three time periods, and plot them.
$crs <- proj
mesh
<- predict(mod, mask = AL, mesh = mesh, temporal = TRUE, fun = '')
preds
<- plot(preds, whattoplot = 'median', plot = FALSE)
plot_preds
+
plot_preds gg(AL, lwd = 1.2) +
::scale_fill_scico(palette = "lajolla") +
scicotheme_minimal()