trap dendancy covariate

posts related to the RMark library, which may not be of general interest to users of 'classic' MARK

trap dendancy covariate

Postby RSAWhite » Wed Jun 19, 2013 6:27 pm

Hello,

I would like to include a trap dependancy individual covariate to my data using RMark as presented from page c-77 in the RMark appendix of the MARK introductory book.

I am having trouble modifying the code on pages c-77-c-78 to incorporate uneven time intervals between capture occasions. My data includes 8 capture occasions with monthly intervals of 0.53, 3.21, 2.47, 4.61, 0.25, 5.98 and 1.12 between capture occasions. I think my issue lies with column names given my varying time intervals, however, I am unsure how to correctly modify the code to incorporate my time intervals.

Thanks for your help.
Richard.
RSAWhite
 
Posts: 10
Joined: Fri May 24, 2013 10:47 pm

Re: trap dendancy covariate

Postby bacollier » Fri Jun 21, 2013 2:15 pm

RSAWhite wrote:Hello,

I would like to include a trap dependancy individual covariate to my data using RMark as presented from page c-77 in the RMark appendix of the MARK introductory book.

I am having trouble modifying the code on pages c-77-c-78 to incorporate uneven time intervals between capture occasions. My data includes 8 capture occasions with monthly intervals of 0.53, 3.21, 2.47, 4.61, 0.25, 5.98 and 1.12 between capture occasions. I think my issue lies with column names given my varying time intervals, however, I am unsure how to correctly modify the code to incorporate my time intervals.

Thanks for your help.
Richard.


Richard

Can you post your code/example, that would help with figuring out an answer to your question.

\bret
bacollier
 
Posts: 230
Joined: Fri Nov 26, 2004 10:33 am
Location: Louisiana State University

Re: trap dendancy covariate

Postby jlaake » Fri Jun 21, 2013 3:01 pm

Richard-

Look at the values of time in your design data. The suffix of the covariates has to match that. In retrospect, I should have used the occasion # rather than the time value and this is something I still might add because it does become problematic with non-integer time values.

Let me know if you still are having a problem and I can look into it further for you. Rather than use your data, try it with the dipper data and assign unequal decimal time values. That will make it easier to help you with it.

--jeff
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: trap dendancy covariate

Postby tiffanygoh » Thu Mar 18, 2021 1:46 pm

Hello,

Hope it's okay for me to piggyback onto this post.
I'm attempting to model trap dependency for recapture probability (the dataset spans from 1988-2019 but with a 4 year gap from 2009-2012).

I'm following Appendix C page 74-75 and it mentions "It was written as a function because it is general and could be used elsewhere; although it would have to be changed if the time intervals between occasions were not 1." Apologise in advance if I missed it, but I'm wondering how should I change the function to account for the 4 year gap? I've tried to include time.intervals after begin.time, but it still creates td1989-td2016.

Many thanks in advance to anyone who can assist :)

Code: Select all
## including the effect of trap-dependence
create.td=function(ch,varname="td",begin.time=1988, time.intervals=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,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)
  }
}

# get data and add the td time-varying covariate
winter.year=cbind(winter.year,create.td(winter.year$ch,begin.time=1988, time.intervals=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,1)))

#process data - year intervals are 1 except 21st when there was a 4-year interval gap
winter.process=process.data(winter.year,model="CJS", begin.time=1988, time.intervals=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,1))
tiffanygoh
 
Posts: 8
Joined: Mon Aug 10, 2020 10:45 am

Re: trap dendancy covariate

Postby jlaake » Fri Mar 19, 2021 1:25 pm

When you post code like that it is much easier for me or anyone else to help if you provide reproducible code. That doesn't mean you need to include the data. For example, I just did the following.

Code: Select all
time.intervals=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,1)
ch=rep(paste(c("1",rep(c(0,1),14)) ,collapse=""),2)
# get data and add the td time-varying covariate
create.td(ch,begin.time=1988,time.intervals=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,1))


That allows me to understand the problem and what you are saying.

Simple solution here is to remove the following line and then assign the names you want.

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


You could do that manually or create the code that should replace that line.

Code: Select all
tdmat=create.td(ch,begin.time=1988,time.intervals=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,1))
names(tdmat)
 [1] "V1"  "V2"  "V3"  "V4"  "V5"  "V6"  "V7"  "V8"  "V9"  "V10" "V11" "V12" "V13" "V14" "V15" "V16" "V17" "V18"
[19] "V19" "V20" "V21" "V22" "V23" "V24" "V25" "V26" "V27" "V28"



Something like the following or you could spell them out.
Code: Select all
names(tdmat)=c(paste("td",1988:2008,sep=""),"td2009-2012",...)


Now the issue here is that those will not match the labels for time (as described earlier in posts) unless you change them because it will use intervals like [1989,1990) etc. You can change the labels in the design data. See ?factor in R. But here is a bigger issue to think about. You are using td here to suggest that the probability in year t+1 is affected by capture history in year t. Do you really think that will be the same for year t+4 given year t?

One way around this pickle and it solves your earlier problem is to not have unequal intervals and simply fix p=0 for the years you did not sample. The only tweak you have is to make sure you don't fit time dependent survival without using time intervals such that you assume constant survival during the years in the gap.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: No registered users and 12 guests