Title: | Fit a Spatial Occupancy Model via Gibbs Sampling |
---|---|
Description: | Fit a spatial-temporal occupancy models using a probit formulation instead of a traditional logit model. |
Authors: | Devin S. Johnson |
Maintainer: | Devin S. Johnson <[email protected]> |
License: | CC0 |
Version: | 1.4 |
Built: | 2025-01-23 04:09:31 UTC |
Source: | https://github.com/dsjohnson/stocc |
This package contains functions that fit a spatial occupancy model where the true occupancy is a function of a spatial process. An efficient Gibbs sampling algorithm is used by formulating the detection and occupancy process models with a probit model instead of the traditional logit based model.
Package: | stocc |
Type: | Package |
Version: | 1.4 |
Date: | October 5, 2022 |
License: | CC0 |
LazyLoad: | yes |
Devin S. Johnson
Maintainer: Devin S. Johnson <[email protected]>
This data represents a simulated study area. The study area is a 40 x 40 grid of pixels. There are two variables, a factor variable (e.g., a habitat layer), as well as, a continuous covariate.
A data frame with 1600 observations on the following 5 variables.
Site labels
Longitude coordinate
Latitude coordinate
a
factor with levels 1
2
3
a numeric vector
data(habData) image(x=seq(0.5,39.5,1), y=seq(0.5,39.5,1), z=t(matrix(as.numeric(habData$habCov1),40)), main="habData: Factor environmental covariate", xlab="x", ylab="y", col=rainbow(3)) dev.new() image(x=seq(0.5,39.5,1), y=seq(0.5,39.5,1), z=t(matrix(habData$habCov2,40)), main="habData: Continuous environmental covariate", xlab="x", ylab="y", col=terrain.colors(50))
data(habData) image(x=seq(0.5,39.5,1), y=seq(0.5,39.5,1), z=t(matrix(as.numeric(habData$habCov1),40)), main="habData: Factor environmental covariate", xlab="x", ylab="y", col=rainbow(3)) dev.new() image(x=seq(0.5,39.5,1), y=seq(0.5,39.5,1), z=t(matrix(habData$habCov2,40)), main="habData: Continuous environmental covariate", xlab="x", ylab="y", col=terrain.colors(50))
This function creates the ICAR precision matrices used in the spatial models
icar.Q(xy, threshold, rho = 1, fun = FALSE)
icar.Q(xy, threshold, rho = 1, fun = FALSE)
xy |
An n x 2 matrix of spatial coordinates |
threshold |
Distance threshold for neighborhood definition |
rho |
The autoregressive parameter. Defaults to 1, which is the Intrinsic Conditionally AutoRegressive model (ICAR) |
fun |
If |
Constructs the inverse covariance matrix (aside from scaling) for the ICAR model
An n x n matrix
Devin S. Johnson <[email protected]>
spatialOccupancy
functionThis function takes an observation data frame and a data frame of site
characteristics and combines them together for analysis with the
spatial.occupancy
function.
make.so.data(visit.data, site.data, names)
make.so.data(visit.data, site.data, names)
visit.data |
A data frame that contains the observed occupancy for each site and any detection related covariates. |
site.data |
A data frame that contains the site id, coordinates, and any habitat related covariates that might influence the occupancy process |
names |
A named list with the following elements: (1) |
This function combines the two data frames and assigns names so that
spatial.occupancy
knows which columns to use. It also performs
some rudimentary error checking to make sure the data is in the proper form
(e.g., the site IDs in the visit data frame must be contained in the site
IDs for the site data frame)
An so.data
object is a list with elements equal to the two
data frames. Attributes are set giving the names of columns of interest
Devin S. Johnson <[email protected]>
This data represnts truth with regards to occupancy in the simulated study
area. The probability of occupancy was simulated as pnorm(0, X
+ K alpha, 1, lower=FALSE)
, where K
and alpha
were constructed
from a reduced rank is an ICAR process with precision
(tau
) = 0.3 and gamma = c(-1, 0, 0, 1)
A data frame with 1600 observations on the following 5 variables.
Site labels
Longitude coordinate
Latitude coordinate
True probability of occupancy
The fixed effects portion of the occupancy process map
True realized occupancy
data(occupancyData) ## ## Blue points represent realized occupancy. ## image(x=seq(0.5,39.5,1), y=seq(0.5,39.5,1), z=t(matrix(occupancyData$psi,40)), xlab="x", ylab="y", main="Occupancy process with realized occupancy") points(occupancyData$x[occupancyData$occ==1], occupancyData$y[occupancyData$occ==1], pch=20, cex=0.25, col="blue")
data(occupancyData) ## ## Blue points represent realized occupancy. ## image(x=seq(0.5,39.5,1), y=seq(0.5,39.5,1), z=t(matrix(occupancyData$psi,40)), xlab="x", ylab="y", main="Occupancy process with realized occupancy") points(occupancyData$x[occupancyData$occ==1], occupancyData$y[occupancyData$occ==1], pch=20, cex=0.25, col="blue")
This function fits a spatial occupancy model where the true occupancy is a function of a spatial process. An efficient Gibbs sampling algorithm is used by formulating the detection and occupancy process models with a probit model instead of the traditional logit based model.
spatial.occupancy( detection.model, occupancy.model, spatial.model, so.data, prior, control, initial.values = NULL )
spatial.occupancy( detection.model, occupancy.model, spatial.model, so.data, prior, control, initial.values = NULL )
detection.model |
A formula object describing the detection portion of
the occupancy model. The variables described by the detection model are
located in the |
occupancy.model |
A formula object describing the fixed effects portion
of the spatial occupancy process. The variables described by the occupancy
model are located in the |
spatial.model |
A named list object describing the spatial component of
the occupancy process. Currently the only possible models are ICAR, restricted spatial regression,
process convolution models, and no spatial model (i.e., eta = 0). Thus, |
so.data |
An |
prior |
A named list that provides the parameter values for the prior
distributions. At the current time the elements of the list must contain
|
control |
A named list with the control parameters for the MCMC. The
elements of the list must include: (1) |
initial.values |
A named list that can include any or all of the following vectors or scalers
(1) |
A Gibbs sampler is run to draw an MCMC sample of the spatial occupancy
parameters beta
(detection parameters), gamma
(the occupancy
parameters), psi
(the model occupancy generating process), and the
realized occupancy.
A list with the following elements:
beta |
An object of class
|
gamma |
An object of
class |
psi |
An object of
class |
real.occ |
An
object of class |
tau |
An object of
class |
occupancy.df |
A data frame with the spatial coordinates, site id, and posterior mean and variance of psi, eta, and real.occ |
D.m |
The posterior predictive loss criterion of Gelfand and Ghosh (1998; Biometrika 85:1-11) for model selection. The criterion is a combination of a goodness-of-fit measure, G.m, and a complexity measure, P.m, similar information criteria such as AIC and BIC. D.m = G.m + P.m. Lower values of D.m imply lower expected loss in predicting new data with the posterior model parameters. |
G.m |
The goodness-of-fit portion of D.m |
P.m |
The model complexity component of D.m |
detection.model |
The detection model call. |
occupancy.model |
The occupancy model call. |
model |
A character version of the joint occupancy and detection model call. This is useful for saving results. |
Devin S. Johnson <[email protected]>
Data set representing a simulated survey of the 40 x 40 study area.
Approximately 1/3 of the 1600 sites were visited at least once. Those sites
that were surveyed were visited a random number of times with an average of
2.5 visits. Detection was simulated as a function of 2 covariates, a
continuous one (cov1) and a factor (cov2). These are NOT the same as the
cov1 and cov2 of the habData data frame. The coefficients used were
beta = c(1, 0, 0.5, 1, 0)
. Thus detection given occupancy of site i
at time j = pnorm(0,X%*%beta,lower=FALSE)
.
A data frame with 1340 observations on the following 6 variables.
Site labels
Longitude coordinate
Latitude coordinate
a numeric vector
a factor with levels 0
1
2
3
a numeric vector
data(visitData) data(occupancyData) ## ## Blue points represent visited sites and green circles represent confirmed occupancy. ## image(x=seq(0.5,39.5,1), y=seq(0.5,39.5,1), z=t(matrix(occupancyData$psi,40)), xlab="x", ylab="y", main="Occupancy process with visits") points(visitData$x[visitData$obs==1], visitData$y[visitData$obs==1], col="green") points(visitData$x, visitData$y, col="blue", pch=20, cex=0.25)
data(visitData) data(occupancyData) ## ## Blue points represent visited sites and green circles represent confirmed occupancy. ## image(x=seq(0.5,39.5,1), y=seq(0.5,39.5,1), z=t(matrix(occupancyData$psi,40)), xlab="x", ylab="y", main="Occupancy process with visits") points(visitData$x[visitData$obs==1], visitData$y[visitData$obs==1], col="green") points(visitData$x, visitData$y, col="blue", pch=20, cex=0.25)