I've successfully fitted trap dependence (td) in CJS models in the past by means of a time-varying covariate, as explained in section C16 of MARK book. I am now wanting to fit td in a robust design modelling framework. I have modified the code (see below) to add a sequence of covariates that contain the capture history entry for each secondary occasion, so that when p is estimated it can be done as a function of this covariate td, and account for trap-dependence. The data consists of 21 primary sampling occasions with 17 to 28 secondary occasions within each.

The function is written as described in Appendix C:

- Code: Select all
`create.td=function(ch,varname="td",begin.time=1)`

#

# Arguments:

# ch - capture history vector (0/1 values only)

# varname - prefix for variable name

# begin.time - time for first occasion

#

# Value:

# returns a datframe with trap-dependent variables

# named varnamet+1,...,varnamet+nocc-1

# where t is begin.time and nocc is the

# number of occasions

#

{

# turn vector of capture history strings into a vector of characters

char.vec=unlist(strsplit(ch,""))

# test to make sure they only contain 0 or 1

if(!all(char.vec %in% c(0,1)))

stop("Function only valid for CJS model without missing values")

else

{

# get number of occasions (nocc) and change it into a matrix of numbers

nocc=nchar(ch[1])

tdmat=matrix(as.numeric(char.vec),ncol=nocc,byrow=TRUE)

# remove the last column which is not used

tdmat=tdmat[,1:(nocc-1)]

# turn it into a dataframe and assign the field (column) names

tdmat=as.data.frame(tdmat)

names(tdmat)=paste(varname,(begin.time+1):(begin.time+nocc-1),sep="")

return(tdmat)

}

}

And then the data are processed, design data added and models specified as follows (for the purpose of this exercise I am only running no movement, no heterogeneity models):

- Code: Select all
`#Process data specifying primary and secondary capture occasions (trip sec occ)`

time.intervals.SAC_trip=c(rep(0,27),1,rep(0,23),1,rep(0,22),1,rep(0,20),1,rep(0,18),1,rep(0,27),1,rep(0,25),1,rep(0,23),1,rep(0,28),1,rep(0,23),1,rep(0,19),1,rep(0,17),1,rep(0,21),1,rep(0,20),1,rep(0,19),1,rep(0,20),1,rep(0,22),1,rep(0,20),1,rep(0,18),1,rep(0,19),1,rep(0,17))

do.SAC.td=function()

{

# get data and add the td time-varying covariate, process the data

df=cbind(trip_markdata,create.td(trip_markdata$ch,begin.time=1))

dp2=process.data(df,begin.time=2001,model="RDFullHet",time.intervals=time.intervals.SAC_trip)

# and create the design data to constrain gammas

ad.ddl=make.design.data(dp2)

ad.ddl=add.design.data(dp2,ad.ddl,parameter="GammaPrime",type="time",bins=c(2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2021),right=FALSE, name="constrain",replace=TRUE) ad.ddl=add.design.data(dp2,ad.ddl,parameter="GammaDoublePrime",type="time",bins=c(2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2021),right=FALSE, name="constrain",replace=TRUE)

# define parameters

S.dot=list(formula=~1)

p.td=list(formula=~td) #trap dependance

pi.null=list(formula=~1,fixed=1)

GammaDoublePrime.0=list(formula=~1,fixed=0)

GammaPrime.0=list(formula=~1,fixed=1)

# create model list

cml=create.model.list("RDFullHet")

# run and return models

return(mark.wrapper(cml,data=dp2,ddl=ad.ddl))

}

td.results.nomov=do.SAC.td()

td.results.nomov

When I run this, I can see that the covariate has been added to the data frame of capture histories, named as td2, td3, td4 etc, but I get the following error:

td.results.nomov=do.SAC.td()

Using default formula for c

Using default formula for f0

S.dot.GammaDoublePrime.0.GammaPrime.0.pi.null.p.td

Error in make.mark.model(data.proc, title = title, parameters = model.parameters, :

Error: Variable td used in formula is not defined in data

Error in mark(model.parameters = model.parameters, initial = initial, :

Misspecification of model or internal error in code

No mark models found

I could not find an example using RD. I wonder if the issue is in the naming of the covariate, given that in the CJS example is says they need to match the times for the capture probabilities? Or is it that the covariate should be for each session instead of each occasion within session? (I don't completely see the logic there though). Any guidance would be appreciated.

Many thanks,

Monica