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

nest survival modeling - example script for mallard data

Postby Rotella » Thu Sep 26, 2019 10:43 pm

This script processes the data 1 time and then sets up 9 competing models for daily survival rate (S).

Code: Select all
# scripted analysis of mallard nest-survival data in RMark

# Example of use of RMark for modeling nest survival data
# Mallard nests example                                       
# The example runs the 9 models that are used in the Nest     
# Survival chapter of the Gentle Introduction to MARK and that
# appear in Table 3 (page 198) of 
# Rotella, J.J., S. J. Dinsmore, T.L. Shaffer.  2004.
# Modeling nest-survival data: a comparison of recently
# developed methods that can be implemented in MARK and SAS.
# Animal Biodiversity and Conservation 27:187-204.

library(RMark)

# Retrieve the mallard data set that is with RMark
data(mallard)

# use the indicator variables for the 4 habitat types to yield
# 1 variable with habitat as a factor with 4 levels that
# can be used for a group variable in RMark
mallard$habitat <- as.factor(ifelse(mallard$Native == 1, "Native",
                                                    ifelse(mallard$Planted == 1, "Planted",
                                                             ifelse(mallard$Roadside == 1, "Roadside",
                                                                      "Wetland"))))

# make the new variable 'habitat' a factor
mallard$habitat <- as.factor(mallard)

mallard.pr <- process.data(mallard,
                                         nocc=90,
                                         model="Nest",
                                         groups=("habitat"))

# Write a function for evaluating a set of competing models
run.mallard = function()
{
  # 1. A model of constant daily survival rate (DSR)
  S.Dot = list(formula = ~1)
 
  # 2. DSR varies by habitat type - treats habitats as factors
  #  and the output provides S-hats for each habitat type
  S.Hab = list(formula = ~habitat)
 
  # 3. DSR varies with vegetation thickness (Robel reading)
  S.Robel = list(formula = ~Robel)
 
  # 4. DSR varies with the amount of native vegetation in the surrounding area
  S.PpnGr = list(formula = ~PpnGrass)

  # 5. DSR follows a trend through time
  S.TimeTrend = list(formula = ~Time)

  # 6. DSR varies with nest age
  S.Age = list(formula = ~NestAge)

  # 7. DSR varies with nest age & habitat type
  S.AgeHab = list(formula = ~NestAge + habitat)

  # 8. DSR varies with nest age & vegetation thickness
  S.AgeRobel = list(formula = ~NestAge + Robel)

  # 9. DSR varies with nest age & amount of native vegetation in surrounding area
  S.AgePpnGrass = list(formula = ~NestAge + PpnGrass)

  # Return model table and list of models

  mallard.model.list=create.model.list("Nest")
 
  mallard.results=mark.wrapper(mallard.model.list,
                             data=mallard.pr, adjust=FALSE)
}

# The next line runs the 9 models above and takes a minute or 2
mallard.results=run.mallard()

mallard.results
Rotella
 
Posts: 73
Joined: Mon Jun 09, 2003 11:32 am

Re: nest survival modeling - example script for mallard data

Postby jlaake » Sat Sep 28, 2019 7:55 pm

Do not use this one. Use the second post at

http://www.phidot.org/forum/viewtopic.php?f=21&t=3887#p12843

This post and the first one at the above link contain a small error:

mallard$habitat <- as.factor(mallard)

should be

mallard$habitat <- as.factor(mallard$habitat)
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: No registered users and 1 guest

cron