nest survival modeling - example script for mallard data

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

Re: nest survival modeling - example script for mallard data

Postby Rotella » Tue Feb 02, 2021 12:13 pm

The answer depends on how you treated "Year" in your models (e.g., was it a grouping variable or entered as an individual covariate). You can access the estimated beta's for your model along with their variance-covariance values and use the delta method or bootstrapping to obtain the values you seek using R code and help on those procedures presented in the Gentle Introduction to MARK online book.
Rotella
 
Posts: 72
Joined: Mon Jun 09, 2003 11:32 am

Re: nest survival modeling - example script for mallard data

Postby Chen-Yang Liu » Wed Feb 03, 2021 10:28 am

Hi Rotella,

Thanks for replying. I treated "Year" as group variable. My model seted as below. I do not really understand your meaning. Could you please have a look my R code below.

Thank you so much.

Best
Chenyang Liu

R code:

RWB.year <- process.data(RWB,nocc=198,model="Nest",groups=("Year"))

RWB.weather=make.design.data(RWB.year)

RWB.weather$S=merge_design.covariates(RWB.weather$S,climate,bygroup=TRUE)

run.RWB=function()
{

Dot=mark(RWB,nocc=198,model="Nest",model.parameters=list(S=list(formula=~1)))

TimeTrend=mark(RWB,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Time)))

Age=mark(RWB,nocc=198,model="Nest",model.parameters=list(S=list(formula=~NestAge)))

TimeAge=mark(RWB,nocc=198,model="Nest",model.parameters=list(S=list(formula=~NestAge+Time)))

Year=mark(RWB,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Year)),groups=c("Year"))

TimeYear=mark(RWB,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Time+Year)),groups = c("Year"))

AgeYear=mark(RWB.year,RWB.weather,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Year+NestAge)),groups = c("Year"))

#AgeYearTime=mark(RWB,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Time+NestAge+Year)),
#groups = c("Year"))
Rain=mark(RWB.year,RWB.weather,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Rain)))

Tepmt=mark(RWB.year,RWB.weather,nocc=198,model="Nest",model.parameters=list(S=list(formula=~MeanT)))

RTepmt=mark(RWB.year,RWB.weather,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Rain+MeanT)))

RainYearAge=mark(RWB.year,RWB.weather,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Year+NestAge+Rain)),
groups = c("Year"))

TemptYearAge=mark(RWB.year,RWB.weather,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Year+NestAge+MeanT)),
groups = c("Year"))
RTYearAge <- mark(RWB.year,RWB.weather,nocc=198,model="Nest",model.parameters=list(S=list(formula=~Year+NestAge+MeanT+Rain)),
groups = c("Year"))

return(collect.models() )
}
Chen-Yang Liu
 
Posts: 2
Joined: Wed Jan 27, 2021 11:14 pm

Re: nest survival modeling - example script for mallard data

Postby Rotella » Wed Feb 03, 2021 7:57 pm

It is helpful to understand the Delta method and how the estimated beta's and their variance-covariances are used in making predictions. There is a great deal of useful information about the Delta method in Appendix B of the Gentle Introduction to MARK: http://www.phidot.org/software/mark/docs/book/pdf/app_2.pdf.

You can use the RMark function 'covariate.predictions' to make predictions. I have added some code below for a new model for the mallard dataset that includes a continuous covariate and a covariate used to group the data. The code runs the model and then generates predictions for a variety of values for the continuious covariate for individuals in each group: I hope it is helpful.

Code: Select all
# Run single model with grouping variable for habitat
# to show how to obtain predictions for different values
# of a continuous covariate (PpnGrass) by group (habitat)

# Make design data
mallard.ddl <- make.design.data(mallard.pr)

# run 1 model with proportion grass and habitat
ppn.gr.hab = mark(mallard.pr,
                  mallard.ddl,
                  nocc=90,
                  model="Nest",
                  model.parameters=list(S=list(formula = ~PpnGrass + habitat)))

# generate range of values of PpnGrass to use for predictions
min.PpnGrass = min(mallard$PpnGrass)
max.PpnGrass = max(mallard$PpnGrass)
PpnGrass.values = seq(from = min.PpnGrass, to = max.PpnGrass, length = 100)

# Find 1st index value for each group
first.row.for.group = c(
  min(which(mallard.ddl$S$habitat == "Native")),
  min(which(mallard.ddl$S$habitat == "Planted")),
  min(which(mallard.ddl$S$habitat == "Roadside")),
  min(which(mallard.ddl$S$habitat == "Wetland")))

# make covariate predictions for various values of PpnGrass
# in each habitat type
pred.PpnGrass.hab <- covariate.predictions(ppn.gr.hab,
                                           data=data.frame(PpnGrass=PpnGrass.values),
                                           indices = first.row.for.group)

head(pred.PpnGrass.hab$estimates)
# Note 'covdata' represents "PpnGrass", and par.index relates to 'habitat',
# but it's helpful to do more work to label columns

library(dplyr)
# rename 'covdata' as 'PpnGrass'
preds <- pred.PpnGrass.hab$estimates %>%
  rename(PpnGrass = covdata)

head(preds)

# merge 'habitat' values in from mallard.ddl based on 'par.index'
preds2 <- left_join(preds,
                    mallard.ddl$S %>%
                      dplyr::select(par.index, habitat))
head(preds2)
Rotella
 
Posts: 72
Joined: Mon Jun 09, 2003 11:32 am

Previous

Return to RMark

Who is online

Users browsing this forum: No registered users and 7 guests