Page 1 of 1

assigning initial.ages

PostPosted: Wed Sep 04, 2019 12:25 pm
by SoConfused
Hello,

I'm working on a CJS model where animal ages are continuous and can be anything from 0.5 to 15 at first capture. I managed to write a model where ages are given as a time-varying covariate, but am finding it a bit cumbersome. However, I can't figure out how to assign initial.ages correctly in my setup, so that they only depend on the year of birth. Any help would be appreciated.

Here's a toy dataset:

Code: Select all
df <- structure(list(ch = c("010000000", "001000000", "000100000", "000010000", "000010000", "000001000", "000001000", "000000100", "100000000", "100000000", "000000010", "010000000", "000000010",
"000000010", "000000001", "000100000", "000000001", "000100000", "000100000", "000001000", "000001000", "000001000", "000001000", "000001000", "000000100", "110000000", "000000010", "001000000", "000000001", "000000001"), BirthYear = c("2009", "2009", "2009", "2009", "2009", "2009", "2009", "2009", "2005", "2005", "2009", "2005", "2009", "2009", "2009", "2005", "2009", "2005", "2005", "2005", "2005", "2005", "2005", "2005", "2005", "2001", "2005", "2001", "2005", "2001"), Age.Occ1 = c(3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 7.6, 7.6, 3.6, 7.6, 3.6, 3.6, 3.6, 7.6, 3.6, 7.6, 7.6, 7.6, 7.6, 7.6, 7.6, 7.6, 7.6, 11.6, 7.6, 11.6, 7.6, 11.6), Age.firstcap = c(4.1, 4.7, 5.1, 5.7, 5.7, 6.1, 6.1, 7.1, 7.7, 7.7, 8.1, 8.1, 8.1, 8.1, 9.1, 9.1, 9.1, 9.1, 9.1, 10.1, 10.1, 10.1, 10.1, 10.1, 11.1, 11.7, 12.1, 12.7, 13.1, 17.1)), row.names = c(NA, -30L), class = "data.frame")


## data processing
Code: Select all
library(RMark)
library(ggplot2)

data1.proc <- process.data(df, model="CJS", groups = c("BirthYear", "Age.firstcap"), age.var = 2, initial.ages = unique(df$Age.firstcap))
data1.ddl <- make.design.data(data1.proc)

# this shows the issue - the ages should form a single line per panel...
ggplot(data1.ddl$p) +
   geom_line(aes(x = time, y = Age, colour = BirthYear, group = group)) +
   facet_wrap(~ BirthYear)

Re: assigning initial.ages

PostPosted: Wed Sep 04, 2019 12:39 pm
by SoConfused
I suppose that I could directly edit data1.ddl$p to create a numeric Age.calc variable that would essentially be the difference between birth year and sampling time. Is there a problem with this approach??

Re: assigning initial.ages

PostPosted: Wed Sep 04, 2019 1:13 pm
by jlaake
If you are using a time varying individual covariate for age, then you don't use initial.ages which is for age groups. Not sure why you think you need continuous ages (and they aren't truly continuous) for something that lives to 15 but that is up to you. If you are using a time varying covariate you assign the age for each individual at each time to a covariate that matches the time value on the prefix. For example, I'll use cage for continuous age. If the begin.time is 0 and each time.interval is 0.5 then I would have variables cage.0,cage.0.5,cage.1.0, etc. If animal 1 was released at time 0 at an age of 9.1 then cage.0 would be 9.1, cage.0.5 would be 9.6 etc. If animal 2 was released at time 1.0 at age 1.4 then values of cage.0 and cage.0.5 could be anything because they aren't used but using 0 might make it easier to read. cage.1.0 would be 1.4 and cage.1.5 would be 1.9 etc. You have to have a complete set of covariate values for each animal and then you can use cage in the formula.

That said, this can get rather messy if your time.intervals are not unit values like 1996, 1997 etc. The prefix of the covariate (eg. cage.xxx) must match the time values exactly. If they don't, it will tell you that a covariate is missing. Also, if you are using for survival and for capture probability, then you have to have an extra value for p at the last occasion. Remember, survival time is at the beginning of the interval and p is at the occasion (end of the interval).

If you have a relatively small number of discrete ages at time of capture(say less than 30) then you might want to use the initial age at capture as a group variable and use initial.ages which is the vector of initial age values - one for each group. Then RMark handles all the messy aging of the animals over time by adding the time.interval value to the initial.age for each group of animals.

I believe all of this is explained in the documentation. --jeff

Re: assigning initial.ages

PostPosted: Wed Sep 04, 2019 1:17 pm
by SoConfused
My apologies - the initial question was not worded well. I managed to write it as a time-varying covariate, but I would prefer to use the initial.ages approach instead, which is where I get stuck. It is indeed explained in the documentation, but I seem to not be able to replicate the approach with my data... The toy data and code show the issue I'm having.

On a side note - is there an issue with the approach I mention in the comment (=directly calculate ages in the ddl data)?

Re: assigning initial.ages

PostPosted: Wed Sep 04, 2019 5:28 pm
by jlaake
That makes more sense. You only need Age.firstcap for group variable. There is design.data for each release cohort (row). So there is an age 4.1 for first occasion, second occasion etc. Not all will be used if there are no releases of age 4.1 for an occasion.

Code: Select all
data1.proc <- process.data(df, model="CJS", groups = c("Age.firstcap"), age.var = 1, initial.ages = unique(df$Age.firstcap))

Re: assigning initial.ages

PostPosted: Wed Sep 04, 2019 6:51 pm
by jlaake
Final question. Yes you can calculate the ages from initial age plus time since release. That is what RMark does. But you need to have a group for each different initial age.

Re: assigning initial.ages

PostPosted: Thu Sep 05, 2019 8:57 am
by SoConfused
Sorry, still being slow here... Two follow-up questions:
1) Following your code snippet - why is it that each group still has multiple ages associated with it based on cohort? For example, group 17.1 (birth year 2001) can only be a single age at any given time, but there's a spread of ages...
Code: Select all
ggplot(data1.ddl$p) +
         geom_line(aes(x = time, y = Age,group = Cohort)) + facet_wrap(~ group)


2) If my interest is in both age and BirthYear (age affects recap, birth affects survival), but you indicate that BirthYear should not be in the grouping vars - do I then need to add BirthYear to the design data manually?

3) I don't quite follow the option where I calculate the ages directly in the ddl data based on occasion and birthyear, but also provide initial ages as a grouping variable. Doesn't the grouping variable create the same issue with different cohorts having different ages (per #1 above), but then the manual calculation would override that?

Re: assigning initial.ages

PostPosted: Fri Sep 06, 2019 9:10 pm
by jlaake
Each group (initial age in this case) has a triangular pim. There is a row for each release cohort. Keeping this simple if at time 0 you release animals of age 1 then they will be 2 at time 1, etc. Animals of age 1 released at time 1 are 2 at time 2. Thus at any time the animals in age group 1 will be different ages depending on when they were released.

Birthyear is simply time of release minus age at release. For example, if first release time is 1990 for an animal of age 4 is 1986. An animal from same birthyear initially released in 1991 would be in the initial age group of 5. So I'm not sure how that gains you anything over cohort which is the row in the pim.

You can always override the default design data. Just make sure you understand what you are doing. I wasn't suggesting that you needed to override the design data.