knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "Vitals-",
  cache = TRUE
)

options(dplyr.width = Inf)

Back to Respository

Functions for calculating vital rates

Prepare workspace and read biography and fertility data

  Sys.setenv(TZ = 'UTC')

  library(plhdbR)
  load_plhdb_packages()

  lh <- read_bio_table("../data/biography_2015_05_20.csv")
  fert <- read_fert_table("../data/fertility_2015_05_20.csv")

It's a good idea to error-check the data extensively before running the fuctions below.

Median age at first reproduction

The function age_first_rep uses the biography data to calculate the minimum, maximum, and median age at first reproduction for each study species.

  age_first_rep(lh)

Stage-specific fertility between censuses

The function stage_specific_fertility uses the biography and fertility tables to calculate stage-specific fertility separately for each study species. The function uses pseudo-census dates on January 1 of each year of the study. The life-history stages include (following Morris et al. 2011):

The optional logical argument annual determines whether fertilities are calculated for each year separately (the default is TRUE).

Warning: this function takes ~5 minutes to run.

  ssf <- stage_specific_fertility(lh, fert, annual = TRUE)
  ssf

Stage-specific survival

The function stage_specific_survival uses the biography table to calculate stage-specific probability of survival separately for each study species for each year of the study. The function uses pseudo-census dates on January 1 of each year of the study. The life-history stages include (following Morris et al. 2011):

Warning: this function takes ~1 minute to run.

  sss <- stage_specific_survival(lh)
  sss

  # Visualize changes over time (not adjusted for sampling effort!!!)
  library(ggplot2)

  ggplot(sss, aes(x = year_of, y = s)) +
  geom_line() +
  facet_grid(Study.Id ~ age_class) +
  labs(x = "Year", y = "Probability of Survival") + 
  theme_bw()

  # Convert to trials / successes
  surv_trials <- make_survivorship_trials(sss)
  surv_trials


camposfa/plhdbR documentation built on May 13, 2019, 11:02 a.m.