by 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