bins in add.design.data() for time-since-marking and age

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

bins in add.design.data() for time-since-marking and age

Postby B.K. Sandercock » Fri Aug 23, 2013 1:41 pm

Time-since-marking (or age) models are a useful global model for CJS data but are not yet available as one of the canned models in Program Mark. They can be quickly added as a candidate model in RMark. I was trying to learn the syntax for the bins argument for the add.design.data() function. In case anybody else had a similar question, here is an example with the dipper data. First bit of code brings in the data.
Code: Select all
# load package
library(RMark)
# get dipper data
data(dipper)
# process data
dipper.process = process.data(dipper, model="CJS", begin.time=1980, groups="sex")
# indexing of all parameters
ddl = make.design.data(dipper.process)

Here is one quick way to add a time-since-marking or 2-age class effect. It adds a tsm field to the ddl object, all transitions are coded as one, and then the first transitions after capture are recoded as zero.
Code: Select all
# add time-since-marking
ddl$Phi$tsm = 1
ddl$Phi$tsm[ddl$Phi$age==0] = 0
[run the script]

> ddl$Phi
   par.index model.index  group cohort age time occ.cohort Cohort Age Time    sex tsm
1          1           1 Female   1980   0 1980          1      0   0    0 Female   0
2          2           2 Female   1980   1 1981          1      0   1    1 Female   1
3          3           3 Female   1980   2 1982          1      0   2    2 Female   1
4          4           4 Female   1980   3 1983          1      0   3    3 Female   1
5          5           5 Female   1980   4 1984          1      0   4    4 Female   1
6          6           6 Female   1980   5 1985          1      0   5    5 Female   1
[stuff deleted]

However the bins argument in the add.design.data() function should be more flexible
Code: Select all
ddl = add.design.data(dipper.process, ddl, parameter="Phi", type="age",
bins=c(0,1,5),name="agebin")

I was a little puzzled by the syntax of the bins argument. The dipper example has seven years of data and six transitions. In the ddl object, the six age-classes are coded 0 through 5. To collapse six categories to two, the bins argument needs three values to specify the two range of values. The input values above with c(0,1,5) would be inclusive across the first two transitions and both get a [0,1] in the ddl. This would be incorrect if you wanted to separate the first transition after capture from later intervals.
Code: Select all
> ddl$Phi
   par.index model.index  group cohort age time occ.cohort Cohort Age Time    sex agebin
1          1           1 Female   1980   0 1980          1      0   0    0 Female  [0,1]
2          2           2 Female   1980   1 1981          1      0   1    1 Female  [0,1]
3          3           3 Female   1980   2 1982          1      0   2    2 Female  (1,5]
4          4           4 Female   1980   3 1983          1      0   3    3 Female  (1,5]
5          5           5 Female   1980   4 1984          1      0   4    4 Female  (1,5]
6          6           6 Female   1980   5 1985          1      0   5    5 Female  (1,5]
[stuff deleted]

To separate the first transition after capture from later intervals, the threshold for the second value in the bins argument has to be set lower than the index value for the second interval, which is one. Setting the value to 0.5 gives the following ddl where only the interval after first capture gets a [0,0.5] and all other intervals get a (0.5,5].
Code: Select all
ddl = add.design.data(dipper.process, ddl, parameter="Phi", type="age",
bins=c(0,0.5,5),name="agebin")
[rerun the script]

> ddl$Phi
   par.index model.index  group cohort age time occ.cohort Cohort Age Time    sex  agebin
1          1           1 Female   1980   0 1980          1      0   0    0 Female [0,0.5]
2          2           2 Female   1980   1 1981          1      0   1    1 Female (0.5,5]
3          3           3 Female   1980   2 1982          1      0   2    2 Female (0.5,5]
4          4           4 Female   1980   3 1983          1      0   3    3 Female (0.5,5]
5          5           5 Female   1980   4 1984          1      0   4    4 Female (0.5,5]
6          6           6 Female   1980   5 1985          1      0   5    5 Female (0.5,5]
[stuff deleted]

Both the tsm and agebin models give the same results if you then go on to run the models based on the modified ddl.
Code: Select all
# models
dipper.models = function(){
  Phi.agebin = list(formula = ~agebin)
  Phi.tsm = list(formula = ~tsm)
  p.dot = list(formula = ~1)
  cml = create.model.list("CJS")
  results = mark.wrapper(cml, data = dipper.process, ddl = ddl)
  return(results)
}
# model output
(dipper.results = dipper.models())
[results not shown]

To use the bins argument, n occasions gives n-1 intervals which will be numbered from zero to n-2. For g groups, need g+1 values in the bins arguments, where g1=0 and will be inclusive with the next value. I had not seen the format with the mixture of round and square brackets and initially wondered if it was an error. In the case of [0,0.5], there is only one possible index value, or zero for the first interval after capture. It looks like (0.5,5] in the ddl for agebin is effectively binning the indices for age across the range of 1-5, or the second to sixth intervals after first capture.
Code: Select all
(0.5,5]

Hope this example is helpful.
B.K. Sandercock
 
Posts: 48
Joined: Mon Jun 02, 2003 4:18 pm
Location: Norwegian Institute of Nature Research

Re: bins in add.design.data() for time-since-marking and age

Postby jlaake » Fri Aug 23, 2013 1:45 pm

Thanks for the example Brett. add.design.data is limited but you aren't restricted to using it. You can use any R function to modify the design data (just don't sort the records and expect it to work). To create bins, add.design.data uses the R function cut. You can use it directly or create bins however you want.

--jeff
jlaake
 
Posts: 1479
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 1 guest