Coding a variable nest stage length

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

Coding a variable nest stage length

Postby birdman » Wed Sep 11, 2013 9:28 am

I’m working on a stage specific survival model for some sparrow data, comparing two species across multiple years including additional covariates. I came across Jeff Laake’s very helpful create.stage.var function posted 28 July 2009 (http://www.phidot.org/forum/viewtopic.php?f=21&t=1152) and, not finding much additional information in the help files, Gentle Intro, or on the forum, I find I need a little help.

Jeff provided the following mallard example, which ran perfectly.
data(mallard)
x=create.stage.var(mallard,"AgeDay1","Incubation",rep(1,90),10)

My question is regarding the cutoff value (i.e. the final “10” in the example). This cutoff assumes that time to hatching is invariant which is untrue for our data, and we’ve been able to account for it. Egg stage length (“incub” below) for us is the combination of laying (varies with clutch size) and incubation, expressed as incubation + (#eggs – 1), which I’ve already coded as a covariate, ‘hatchday’ included in the input file. This value ranges from 12 to 16 in our data. I would like to be able to use the variable ‘hatchday’ as the cutoff for each nest. I was able to do this previously in MARK with the GE() function.

Can someone suggest how I might make this work? I tried simply adding ‘hatchday’ as the cutoff value, but that didn’t seem to work. A look at summary(incub) showed that the value always calculated as “1”. I may not have asked correctly for such input:

stg <- create.stage.var(spar,"AgeDay1","Incub",rep(1,115),"Hatchday")

Thanks in advance for your suggestions.
Shane
birdman
 
Posts: 34
Joined: Wed Oct 24, 2007 4:14 pm

Re: Coding a variable nest stage length

Postby jlaake » Wed Sep 11, 2013 10:21 am

Try the following. cutoff can now be specified as a single value or as a vector of values with the vector length matching the number of rows in data. The easiest to do is specify cutoff as a variable in data as shown below with mallard. I created a random variable for hatchday between 10 and 15 in the example.

Code: Select all
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=age.mat<cutoff
stage.mat=t(apply(stage.mat,1,function(x) as.numeric(x)))
stage.mat=data.frame(stage.mat)
names(stage.mat)=paste(stagevar.name,1:(nocc-1),sep="")
return(stage.mat)
}

data(mallard)
mallard$hatchday=10+runif(nrow(mallard))*5
x=create.stage.var(mallard,"AgeDay1","Inc",rep(1,90),mallard$hatchday)
jlaake
 
Posts: 1480
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Coding a variable nest stage length

Postby birdman » Wed Sep 11, 2013 11:15 am

Thanks Jeff. This seems to work just fine. I'll finish the rest of my code for the other models and see how it stacks up.
birdman
 
Posts: 34
Joined: Wed Oct 24, 2007 4:14 pm


Return to RMark

Who is online

Users browsing this forum: Bing [Bot] and 1 guest