Stage specific nest survival in RMark

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

Stage specific nest survival in RMark

Postby dhegg » Mon Jul 27, 2009 6:52 pm

I've been trying to create a stage specific nest survival model in RMark. Quite simply, a model with a parameter NestAge > X, where X is the duration of the incubation phase.
I know how to do this in MARK (using the GE() function on the age of the nest in the design matrix), and I have had no problems coding nest survival models in RMark that account for continuous covariates, fixed factors, time, or nest age. I just can't figure out how to define a function of any of the above (a step function of nest age in this case) as a model parameter.
I have searched the forums but found nothing on this topic. Many thanks to anyone who can help!
dhegg
 
Posts: 2
Joined: Fri Jul 24, 2009 12:10 am
Location: Dunedin, New Zealand

Postby jlaake » Tue Jul 28, 2009 2:24 pm

RMark does have the capability to add a column to any design matrix, so you could use that but I would recommend against it because it depends on the dimensions of the DM which can change.

This is one area where RMark is a little more clumsy than MARK but it is quite doable. I presume you have looked at the killdeer example that describes inclusion of AgeDay1 in you dataframe so it will create NestAge which is a time dependent individual covariate which means there is a variable named NestAge1,...NestAgek where k is the number of occasions. If you haven't seen that then I suggest you read through that example.

The NestAge variable is not created until it makes the mark model so there is no way for you to manipulate it. I could and will likely change that for a future version. If it created the NestAge variable for you then you would only need to create another time dependent variable with values 0/1 to indicate the stage. So what I've done is extract the function that creates the NestAge variable and modified it to create a function that wil create the stage variable for you. The code is as follows.


create.stage.var=function(data,agevar.name,stagevar.name,time.intervals,cutoff)
{
nocc=length(time.intervals)
age.mat=matrix(data[,agevar.name],nrow=dim(data)[1],ncol=nocc-1)
age.mat=t(t(age.mat)+cumsum(c(0,time.intervals[1:(nocc-2)])))
stage.mat=t(apply(age.mat,1,function(x) as.numeric(x<cutoff)))
stage.mat=data.frame(stage.mat)
names(stage.mat)=paste(stagevar.name,1:(nocc-1),sep="")
return(stage.mat)
}


Copy and paste the above into any script or workspace that will use it. I'll add it to the package in a future version.

Below is an example with the mallard data. It has a variable named AgeDay1 which is the age of the nest on the first occasion. I've told it I want to create a variable named Incubation which is 1 if NestAge is < 10 and 0 otherwise. You can eaily modify the code in the function create.stage.var if you want something different or if you'll have multiple stages. Below is an example with the mallard data with a stage cutoff of 10.

data(mallard)
x=create.stage.var(mallard,"AgeDay1","Incubation",rep(1,90),10)
mallard=cbind(mallard,x)
mark(mallard,model="Nest",model.parameters=list(S=list(formula=~Incubation)),nocc=90)

Let me know how this works out for you and if you can think of any other similar ideas that I can add to the package for nest survival.

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

Postby dhegg » Sun Aug 02, 2009 7:12 pm

Thanks a lot!

The script you have supplied works just fine.

Of course it would be nice to have stage specific nest survival built in a future version of RMark, but we can definitely work easily enough with this.
dhegg
 
Posts: 2
Joined: Fri Jul 24, 2009 12:10 am
Location: Dunedin, New Zealand

Re: Stage specific nest survival in RMark

Postby murray.efford » Sat Apr 14, 2012 5:21 am

Is Jeff's code here still the recommended approach for stage-specific nest survival in RMark? I'm asking on behalf of an off-list colleague for whom it doesn't seem to be working (he says it merely fits the first column Incubation1 as a predictor).
Murray
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Stage specific nest survival in RMark

Postby jlaake » Sat Apr 14, 2012 9:46 am

Murray-

Have your colleague contact me off-list. I assume the code you are referring to is the little R function I wrote to create a time-dependent covariate. It is only a single column in the DM but its value varies across time for each individual. Without knowing more I can't help much more. My guess is that they are confused because the output will only list one set of real parameter values. You have to use covariate.predictions to get individual real values.

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

Re: Stage specific nest survival in RMark

Postby murray.efford » Wed Apr 18, 2012 4:31 pm

Just noting the result of off-list discussion with Jeff and Gary, as I understand it.

Using 'Incubation' as the time-varying covariate name in RMark resulted in MARK silently fitting the wrong model. This was because covariate names passed to MARK are truncated if they exceed 10 characters, as do Incubation1, Incubation2, ..., Incubation90. A shorter name ('Incub') appears to work. The recommended mechanism for specifying stage effects using MARK's own interface is rather different (Gary says "use the GT or GE function and the ADD(Age,x) function: GT(ADD(Age,x),y) does the trick, where x is the incrementing age from the base age covariate, and y is the age where you want the function to kick in"). The time-varying covariate approach should do the same thing (my interpretation), but it would be good for someone to check.

Murray
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Stage specific nest survival in RMark

Postby jlaake » Wed Apr 18, 2012 4:36 pm

Thanks Murray. The next release of RMark to CRAN will contain a check to make sure individual covariate names do not exceed the MARK limit of 10. I was previously unaware of that limitation in MARK and thank Murray and colleague for finding and reporting the problem. I have always used very short names and have never encountered the problem before.

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

Re: Stage specific nest survival in RMark

Postby bacollier » Wed Apr 25, 2012 10:32 am

Just had this issue this AM so I am posting it here.

I don' think that this error Murray found is globally true for MARK. I was running some single season occupancy models in MARK this morning and I have multiple covariates with names that are >10 characters which ran just fine this morning under RMark 2.1.0 using the most recent updated version of MARK on one of my laptops (R 2.14.1 if it matters). But, since I upgraded yesterday to RMark 2.1.1 (R 2.15.0) on my main machine to test Jeff and Gary's tweaks for multi-strata models, I get the below error and all my previous occupancy models that worked on 2.1.0 now bomb out.

> + Error in make.mark.model(data.proc, title = title, parameters = model.parameters, :

Following covariates longer than 10 characters canhtmean100

Is there a way to check and see if this is just a limitation for the nest survival module that Murray noted, as it does not seem to be a global limitation in MARK as my models do work with the variable canhtmean100 in the previous RMark version and the new RMark error means I have to go back and re-structure a bunch of datasets and previous analysis I did if I want to be able to recreate them again.

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

Re: Stage specific nest survival in RMark

Postby jlaake » Wed Apr 25, 2012 10:39 am

Well that is the insidious part of this issue. The model will run but is probably wrong. I think MARK truncates the variable to 10 characters and then I'm not exactly sure what happens internally but it will run. Truncate your variables so they will be less than 10 characters with the time prefix appended and compare to the results you got previously. If you want variables longer than 10 characters you'll have to lobby with Gary. Sorry about this. I had no idea there was a limit much less one that was so short.

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

Re: Stage specific nest survival in RMark

Postby bacollier » Wed Apr 25, 2012 11:29 am

jlaake wrote:Well that is the insidious part of this issue. The model will run but is probably wrong. I think MARK truncates the variable to 10 characters and then I'm not exactly sure what happens internally but it will run. Truncate your variables so they will be less than 10 characters with the time prefix appended and compare to the results you got previously. If you want variables longer than 10 characters you'll have to lobby with Gary. Sorry about this. I had no idea there was a limit much less one that was so short.

--jeff


OK I (as I am sure have others) have imported and run models with longer covariate names previously before RMark. In the one I am messing with here, the MARK output for that covariate name (canhtmean100) is not truncated in the marknnn.out file on my system except in the beta estimate "Parameter" name column and in the Unstandardized Covariates values section. The name canhtmean100, where used in the inp file looks fine, as do the values in the output from the estimation procedure and the predicted results match up pretty cleanly with my expectation for the data (althought this was not a known dataset).

Gary: What are the implications here we should be looking for?

I did notice (just tested) that you cannot type into MARK a covariate name >10 characters.
bacollier
 
Posts: 230
Joined: Fri Nov 26, 2004 10:33 am
Location: Louisiana State University

Next

Return to RMark

Who is online

Users browsing this forum: No registered users and 16 guests