mcmc.2side: Spatial partial identity MCMC algorithm.

View source: R/mcmc.2side.R

mcmc.2sideR Documentation

Spatial partial identity MCMC algorithm.

Description

This function runs the MCMC algorithm for the spatial partial identity model. The data list should have the following elements: 1. both, a n_both x 3 x K x J both side data array. If n_both=0 as in an all single camera study, the first dimension is 0 and the data set should still have 4 dimensions, 0 x 3 x K x J. 2. left, a n_left x 3 x K x J left side data array. 3. right, a n_right x 3 x K x J left side data array. 4. IDknown a vector listing the index of complete identity individuals. It is assumed individuals are sorted such that the complete identity individuals are listed first. So if there are 7 complete identity individuals, IDknown=1:7. 5. X a matrix with the X and Y trap locations in the first two columns and the number of cameras (1 or 2) at each trap in the third. 6. either buff or vertices. buff is the fixed buffer for the traps to produce the state space. It is applied to the minimum and maximum X and Y locations, producing a square or rectangular state space. vertices is a matrix with the X and Y coordinates of a polygonal state space. 7. an optional tf ,a vector or matrix indicating trap operation. If not accounting for operation across occasions, tf is a 1 x J vector indicating the number of occasions each trap was operational. In this scenario, single or double camera stations are either on or off. If accounting for operation across occasions, tf is a J x K matrix with entries 2 if 2 cameras were operational, 1 if a single camera was operational, and 0 if no cameras were operational.

Usage

mcmc.2side(data, niter = 2400, nburn = 1200, nthin = 5, M = 200,
  inits = inits, swap = 10, swap.tol = 1, proppars = list(lam01 =
  0.05, lam02 = 0.05, sigma = 0.1, sx = 0.2, sy = 0.2),
  storeLatent = TRUE, Rcpp = TRUE)

Arguments

data

a list produced by sim2side or in the same format

niter

number of MCMC iterations to run

nburn

number of MCMC iterations to discard as burn in

nthin

MCMC thinning parameter. Record output on every nthin iterations. nthin=1 corresponds to no thinning

M

The size of the augmented superpopulation

inits

a list of user-supplied initial values. inits=list(psi=psi,lam01=lam01,lam02=lam02,sigma=sigma)

swap

number of IDs to swap on each MCMC iteration

swap.tol

the search radius within which to search for partial ID activity centers to match with

proppars

a list of tuning parameters for the proposal distributions

storeLatent

a logical indicating whether or not to keep the posteriors for z, s, ID_L, and ID_R

Rcpp

a logical indicating whether or not to use Rcpp

Value

a list with the posteriors for the SCR parameters (out), s, z, ID_L and ID_R

Author(s)

Ben Augustine, Andy Royle

Examples

## Not run: N=50
p01=0.13
p02=0.2
lam01=-log(1-p01)
lam02=-log(1-p02)
sigma=0.50
K=5
buff=2
niter=1000 #should run more than this and discard a burn in
nburn=1
nthin=1
xlim<- c(1,10)
ylim<- c(1,10)
X<- expand.grid(3:8,3:8) #6x6 trapping array
X=cbind(X,1) #add number of cameras at each trap
X[which(X[,2]%in%c(4,7)),3]=2 #switch the second and fifth row of traps to double cameras
#Simulate some data
data=sim2side(N=N,lam01=lam01,lam02=lam02,sigma=sigma,K=K,X=X,buff=buff)
inits=list(psi=0.5,lam01=lam01,lam02=lam02,sigma=sigma)
proppars=list(lam01=0.05,lam02=0.05,sigma=0.1,sx=0.2,sy=0.2) #will need to tune these for your dataset
a=Sys.time()
store=mcmc.2side(data,niter=niter,nburn=nburn,nthin=nthin, M = 100,inits=inits,swap=10)
b=Sys.time()
b-a
#plot posteriors
par(mfrow=c(2,2))
plot(store$out[,1],main="lam01",type="l")
plot(store$out[,2],main="lam02",type="l")
plot(store$out[,3],main="sigma",type="l")
plot(store$out[,4],main="N",type="l")
par(mfrow=c(1,1))
## End(Not run)

benaug/SPIM documentation built on April 28, 2024, 7:27 a.m.