Staggered known fate model in RMark

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

Staggered known fate model in RMark

Postby cwbeirne » Mon Jul 11, 2011 8:16 am

Hi All,
I am performing a known-fate analysis on the “survival” of volunteers in a mink eradication project, where their survival is analogous to a volunteer staying within the project for a given time step or leaving (I’m am sure some of you will be thinking this is madness!).

Before I get onto that, I have been trying to recreate the MARK 16.5.1. Staggered entry – worked example in RMark to check my understanding. Although I have managed to recreate it, I have done it only with substantial manual editing of the design matrix.

I added a “Cohort” column to the data frame and assigned a value to each individual which I used to group the data:
    ch freq Cohort
    1 1100000000 865 1
    2 1011000000 126 1
    3 1010110000 113 1
    4 1010101100 71 1
    5 1010101011 71 1
    6 1010101010 254 1
    7 0011000000 921 2
    8 0010110000 116 2
    9 0010101100 102 2
    10 0010101011 75 2
    11 0010101010 286 2
    12 0000110000 876 3
    13 0000101100 121 3
    14 0000101011 97 3
    15 0000101010 406 3
    16 0000001100 909 4
    17 0000001011 119 4
    18 0000001010 472 4
    19 0000000011 916 5
    20 0000000010 584 5

Code: Select all
 staggered.process <- process.data(staggered, model="Known", groups="Cohort", begin.time=2000,initial.age=0)

staggered.ddl <- make.design.data(staggered.process)


However my issues start with the .ddl

> staggered.ddl

group age time Age Time Cohort
1 1 1 2001 1 0 1
2 1 2 2002 2 1 1
3 1 3 2003 3 2 1
4 1 4 2004 4 3 1
5 1 5 2005 5 4 1
6 2 1 2001 1 0 2
7 2 2 2002 2 1 2
8 2 3 2003 3 2 2
9 2 4 2004 4 3 2
10 2 5 2005 5 4 2
11 3 1 2001 1 0 3
12 3 2 2002 2 1 3
13 3 3 2003 3 2 3
14 3 4 2004 4 3 3
15 3 5 2005 5 4 3
16 4 1 2001 1 0 4
17 4 2 2002 2 1 4
18 4 3 2003 3 2 4
19 4 4 2004 4 3 4
20 4 5 2005 5 4 4
21 5 1 2001 1 0 5
22 5 2 2002 2 1 5
23 5 3 2003 3 2 5
24 5 4 2004 4 3 5
25 5 5 2005 5 4 5

The make.design.data step generates a row for every cohort for every year. This is an issue because, for example, cohort 5 individuals are only added in 2005 where they should be aged 1 - not 5! I can address this issue by deleting the pointless rows (structural lack of data), then editing the age class manually.

Am I missing a clever trick in the import process where cohort can be recognised and and appropriate .ddl's generated? - (more akin to the age_ya example in "C.15. More complex examples" - where I would only have one entry for my 2005 cohort with an age of 1)?

Manually editing the .ddl will get very tiresome - especially as my actual data has 9 cohorts (each with 5 sub classifications) and I just cant think of a cunning fix!

Thanks in advance for any help!

(Sorry I cant find a better way to show those lists)

Chris
cwbeirne
 
Posts: 2
Joined: Fri Jul 08, 2011 1:26 pm

Re: Staggered known fate model in RMark

Postby jlaake » Mon Jul 11, 2011 2:11 pm

I assume you meant "manually editing design data" as you cannot easily edit design matrix with RMark. What you missed is initial.ages which you can assign to any grouping variable identified as an age variable. Use

staggered.process <- process.data(staggered, model="Known", groups="Cohort", begin.time=2000,initial.age=0, age.var=1,initial.ages=c(0,-1,-2,-3...))

but fill in the appropriate initial.ages which I don't know. You want to use as the initial age the value in 2000 such that when they are incremented they are 0 at the time they entered. Then you can easily use an R command to remove all design data with a negative value for age. But age is a factor variable and you can't do something like age<0 so you'll want as.numeric(as.character(age))<0. If x is a factor variable then as.character turns it into a character string using the level names and as.numeric turns it to a number. Here is a little R example to show that.

Code: Select all
> x=factor(-5:5)
> x
 [1] -5 -4 -3 -2 -1 0  1  2  3  4  5
Levels: -5 -4 -3 -2 -1 0 1 2 3 4 5
> x<0
 [1] NA NA NA NA NA NA NA NA NA NA NA
Warning message:
In Ops.factor(x, 0) : < not meaningful for factors
> as.character(x)
 [1] "-5" "-4" "-3" "-2" "-1" "0"  "1"  "2"  "3"  "4"  "5"
> as.numeric(as.character(x))<0
 [1]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
>



Your intuition was correct. You don't want to be fiddling with the desgign data by hand. Largely defeats the purpose of using RMark to automate/script the analysis. Let me know if you run into anymore problems.

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

Re: Staggered known fate model in RMark

Postby cwbeirne » Mon Jul 11, 2011 4:33 pm

That is awesome - I thanks Jeff! (I am so annoyed I didnt see that!)

Chris
cwbeirne
 
Posts: 2
Joined: Fri Jul 08, 2011 1:26 pm

Re: Staggered known fate model in RMark

Postby wijw » Wed Sep 21, 2022 11:47 am

I tried using the same code structure for my analysis.
Code: Select all
#Import data and set columns as numeric or factor
kfm = import.chdata("file path",
                          header = FALSE,
                          field.names = c("ch", "freq", "release.type", "Cohort"),
                          field.types = c("n", "f", "n"))

#Process data
kfm.process = process.data(kfm, model = "Known",
                           groups = c("release.type", "Cohort"),
                           begin.time = 2015,
                           initial.age = 2,
                           age.var = 1,
                           initial.ages = c(2,1,0,-1,-2))


But I receive the following error message:
Error in process.data(kfm, model = "Known", groups = c("release.type", :
unused argument (initial.age = 2)

I am not sure what I am doing wrong. I recently started using RMARK. Any advice?
wijw
 
Posts: 23
Joined: Mon Oct 26, 2020 2:27 pm

Re: Staggered known fate model in RMark

Postby jlaake » Wed Sep 21, 2022 5:23 pm

The initial.age argument in my post was an error. It is possible that R used to ignore and now it doesn't. The correct argument is initial.ages. Remove initial.age in your call and it should work. Check your design data to make sure that you got the proper order for your initial.ages.

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


Return to RMark

Who is online

Users browsing this forum: Google [Bot] and 10 guests

cron