Changing individual covariates within nest survival

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

Changing individual covariates within nest survival

Postby djohns » Fri Feb 26, 2016 1:47 am

Hi Team,

I am interested in modeling the survival of ducklings in relation to landscape variables. To collect this data we marked the brood-rearing female and obtained visual counts of brood size at somewhat regular intervals throughout the breeding season. But as sightings were not guaranteed I am using the nest survival model to conduct this analysis as it will help deal with the ragged nature of the data. Ducklings are considered "fledged" at 30 days so I am using a 30 occasions history (1 day = 1 occasion). My main research question is if the composition of the habitat surrounding the brood impact's survival as the brood moves through the landscape. Much like the mallard example I have the proportion of grassland surrounding the brood and use it as an individual covariate.

My question is this: does it make sense to change the value of an individual covariate part way through the occasions (i.e. can I change the value of a individual covariate within a DM column)?.

For example; the brood travels from pond A to pond B in its 1st week of life, then in week 2 travels from pond B to pond C and stays there until 30 days old. The proportion of grass surrounding pond A & B = PpnG1, and the proportion of grass around pond B & C = PpnG2. When using a design matrix to test the model of a linear trend in survival and the amount of grass (i.e. S(time) ~ PpnG) is the following design matrix correct?

AND...If so, is there an easy way to build these design matrices within RMark? I can easily complie them within MARK but am unsure how to specify a changing DM individual covariate in R.

model: S(time) ~ PpnG

Int B1 B2
1 1 PpnG1
1 2 PpnG1
1 3 PpnG1
1 4 PpnG1
1 5 PpnG1
1 6 PpnG1
1 7 PpnG1
1 8 PpnG2
1 9 PpnG2
1 10 PpnG2
1 11 PpnG2
1 12 PpnG2
1 13 PpnG2
1 14 PpnG2
1 15 PpnG2
1 16 PpnG2
1 17 PpnG2
1 18 PpnG2
1 19 PpnG2
1 20 PpnG2
1 21 PpnG2
etc... to 30

Thanks for the help and suggestions
-David
djohns
 
Posts: 5
Joined: Wed Mar 11, 2015 12:52 pm

Re: Changing individual covariates within nest survival

Postby jlaake » Mon Feb 29, 2016 1:39 pm

You are close but what you need to do is to create a covariate for each time rather than just 2 of them because presumably you'll have different breaks in time for different broods. Create PPnG1,PPnG2,PPNG3,...PPnGk in your data where k is last time period. For each "nest" the value is the PPnG value for that brood for that time. Then use ~PPnG as the formula. It will create a DM that looks like

1 PPnG1
1 PPnG2
1 PPnG3
...
1 PPnGk

and the values can vary for each brood. If a brood doesn't change locations then all of the values across time can have the same value.

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

Re: Changing individual covariates within nest survival

Postby djohns » Mon Feb 29, 2016 8:32 pm

Thanks Jeff,

While I think I follow along I don't think a time varying individual covariate is appropriate after I spent some time looking over your answer and thinking about my issue. My apologies as I realized that my example was not the actually what I was finding and in my case the breaks will be the same for each individual.

Currently each individual "enters" the data set on day 1 (hatch) and if survives then exits on day 31 (fledge). I am modeling age (days 1-31) and only using calendar date of hatch as an individual covariate rather than a having a nocc= length of study and AgeDay1 variable. As the movement data was coarse I pooled it into two relevant periods (days 1-7 & days 8-30) and calculated the amount of grassland surrounding all movements for those periods (i.e. PpnG1, PpnG2). So my interest is more if the amount of grassland in the "week one home range" and/or "week two+ home range" influences survival.

Does this change the best method of formatting? As of now all PpnG1 values will be identical as will all PpnG2 values for each individual.

Thinking about this more maybe the better route would be including each as an individual covariate and structuring the DM as the following?

int time var1 var2
1 1 PpnG1 0
1 2 PpnG1 0
1 3 PpnG1 0
1 4 PpnG1 0
1 5 PpnG1 0
1 6 PpnG1 0
1 7 PpnG1 0
1 8 0 PpnG2
1 9 0 PpnG2
1 10 0 PpnG2
1 11 0 PpnG2
1 12 0 PpnG2
1 13 0 PpnG2
1 14 0 PpnG2
1 1 PpnG1 0
1 2 PpnG1 0
etc....


If this is correct can you confirm if this is the right way to setup such a ddl in RMark? The model appears to run but comparing between MARK and RMark seem to provide different estimates..... :shock:

Code: Select all
NSM.proc=process.data(NSM,model="Nest",nocc=31,groups=c("SAR")) #grouped by site

NSM.ddl=make.design.data(NSM.proc) #make sure order matches original NSM order

NSM.ddl$S$PpnG1=0  #creates null column in ddl
NSM.ddl$S$PpnG1<-factor(c(rep(c(rep(1,7),rep(0,23)),11)))  #fills in PpnG1 into first 7 rows for each site
levels(NSM.ddl$S$PpnG1)=c("0","PpnG1")

NSM.ddl$S$PpnG2=0  #creates null column in ddl
NSM.ddl$S$PpnG2<-factor(c(rep(c(rep(0,7),rep(1,23)),11)))  #fills in PpnG2 into first 7 rows for each site
levels(NSM.ddl$S$PpnG2)=c("0","PpnG2")

NSM.ddl$S
Last edited by djohns on Tue Mar 01, 2016 2:22 am, edited 1 time in total.
djohns
 
Posts: 5
Joined: Wed Mar 11, 2015 12:52 pm

Re: Changing individual covariates within nest survival

Postby jlaake » Mon Feb 29, 2016 10:10 pm

The code you created for PpnG1 and PpnG2 makes no sense to me. They should be numeric values. From what you said, the values of PpnG1 and PpnG2 are constant for all individuals and for the 2 time periods. Is that correct? If that is the case, you should create a single column in ddl$S called say PpnG and then for times 1-7 it would have the first value and for times 8-31 it would have the second value. Am I understanding what you are saying? Regardless, it should not be a 0/1 factor variable which is what you have created.

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

Re: Changing individual covariates within nest survival

Postby djohns » Tue Mar 01, 2016 3:32 am

Well it looks like I only added to the confusion....I will try to clear some of this up. Thanks for sticking in there.
jlaake wrote:From what you said, the values of PpnG1 and PpnG2 are constant for all individuals and for the 2 time periods. Is that correct?
Yes...Individual i will have two values, one for PpnG1 and another for PpnG2 but individual i+1....k will each have their own unique sets of values.

The code I supplied above was trying to replicate the two column DM in that same post. One column for PpnG1 and the other for PpnG2. When I run a model without specifying the process data or ddl and included PpnG1 + PpnG2 as indv. covariates I noticed that the resulting DM had "PpnG1" and "PpnG2" so I wrongly assumed that when using the make.design.data function I needed to create a column of factors. Ooops.

That leaves me with two questions:
1) Is my initial approach correct in having just a single column switching after day 7 or two columns each representing the appropriate time period (occ 1-7 or occ 8-30)

1 2 PpnG1
1 3 PpnG1
1 4 PpnG1
1 5 PpnG1
1 6 PpnG1
1 7 PpnG1
1 8 PpnG2
1 9 PpnG2
1 10 PpnG2
1 11 PpnG2
1 12 PpnG2
etc...

OR

1 1 PpnG1 0
1 2 PpnG1 0
1 3 PpnG1 0
1 4 PpnG1 0
1 5 PpnG1 0
1 6 PpnG1 0
1 7 PpnG1 0
1 8 0 PpnG2
1 9 0 PpnG2
1 10 0 PpnG2
1 11 0 PpnG2
1 12 0 PpnG2
etc...

2) How do you code a individual covariate using make.design.data? I can add a column(s) to the ddl but can't seem to get the modeling call to reference my individual covariates using the new ddl. Doing something/most things wrong I presume


#using the mallard data example and its nocc of 90
Code: Select all
mall.proc=process.data(mallard,model="Nest",nocc=90)
mall.ddl=make.design.data(mall.proc)

mall.ddl$S$PpnG=0
mall.ddl$S$PpnG<-c(rep(c(rep("PpnG1",7),rep("PpnG2",82))))

##  OR ####

mall.ddl$S$PpnG1=0
mall.ddl$S$PpnG1<-c(rep(c(rep("PpnG1",7),rep(0,82))))
mall.ddl$S$PpnG2=0
mall.ddl$S$PpnG2<-c(rep(c(rep(0,7),rep("PpnG2",82))))


Thanks for the help!
djohns
 
Posts: 5
Joined: Wed Mar 11, 2015 12:52 pm

Re: Changing individual covariates within nest survival

Postby jlaake » Tue Mar 01, 2016 11:07 am

My prior post describes what you need to do. Have you read the workshop notes from May 2015 in the documentation zip on phidot? It describes the differences between design covariates whose values are the same for each individual or group of individuals versus individual covariates which can vary for each individual. Design covariates go in the design data. Individual covariates go in the encounter history data (nest data here) because they have to be linked to each individual (brood in this case).

I now understand what you were trying to do but it will not work. RMark uses the R function model.matrix to create the DM from a formula and that will not work with text strings like "PpnG1" which was what you were trying to force it to do. To make that work, RMark has specific code to handle individual covariates and it plugs in the text string after creating the base DM with model.matrix. That is explained in Appendix C and in the workshop notes.

Thus you need to create individual covariate values PpnG1,PpnG2,...PpnG31 in the data - a covariate for each time. In your case PpnG1 to PpnG7 will have the same value for an individual record as will PpnG8 to PpnG31 but those values will differ across broods. Then when you use ~PpnG it will create a DM that looks like

1 PpnG1
1 PpnG2
.....
1 PpnG30
1 PpnG31

It will be equivalent to your approach because the first 7 will have the same value as will the last 24. This is slightly cumbersome in this example but it will work.

The suffix on the individual covariate name depends on the value in time. I have not done it but you may be able to change the value of time in the design data so it is 1 for 1 to 7 and 2 for 8 to 31 and then use PpnG1 and PpnG2 in the nest data. If you do that you'll want to save time in another design data variable (e.g., occasion) and then create a new factor variable time as described above. Like I said, I've not done it so not sure it will work.
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Changing individual covariates within nest survival

Postby djohns » Tue Mar 01, 2016 3:29 pm

Thanks so much for your help Jeff. Your responses have been very clear and I now understand why I could not force the design data. I have read the workshop notes but will go over them once or twice more.

Much appreciated
djohns
 
Posts: 5
Joined: Wed Mar 11, 2015 12:52 pm


Return to RMark

Who is online

Users browsing this forum: No registered users and 1 guest