actualstage3: Calculate Actual Stage, Age, Stage-Pair, or Age-Stage...

View source: R/RcppExports.R

actualstage3R Documentation

Calculate Actual Stage, Age, Stage-Pair, or Age-Stage Distributions

Description

Function actualstage3() shows the frequencies and proportions of each stage, stage pair, age-stage, or age in each year.

Usage

actualstage3(
  data,
  check_stage = TRUE,
  check_age = FALSE,
  historical = FALSE,
  year2 = NULL,
  indices = NULL,
  stagecol = NULL,
  agecol = NULL,
  remove_stage = NULL,
  t1_allow = NULL
)

Arguments

data

A demographic dataset in hfv format.

check_stage

A logical value indicating whether to assess frequencies and proportions of stages. Defaults to TRUE.

check_age

A logical value indicating whether to assess frequencies and proportions of ages. Defaults to FALSE.

historical

A logical value indicating whether the stage structure should be ahistorical (FALSE) or historical (TRUE). Defaults to FALSE.

year2

A string value indicating the name of the variable coding for monitoring occasion at time t. Defaults to "year2".

indices

A vector of three strings, indicating the stage indices for times t+1, t, and t-1, respectively, in data. Defaults to c("stage3index", "stage2index", "stage1index").

stagecol

A vector of three strings, indicating the stage name columns for times t+1, t, and t-1, respectively, in data. Defaults to stagecol = c("stage3", "stage2", "stage1").

agecol

A single string indicating the age of individuals in time t. Defaults to "obsage".

remove_stage

A string vector indicating the names of stages to remove from consideration. Defaults to "NotAlive".

t1_allow

A string vector indicating which stages to be removed should be allowed in the stage at time t-1 portion of historical stage pairs, if historical = TRUE. Defaults to "NotAlive". Can also be set to "none".

Value

A data frame with the following variables:

rowid

A string identifier term, equal to the monitoring occasion in time t and the stage index.

stageindex

The stageframe index of the stage. Only output if check_stage = TRUE.

stage

The name of each stage, or NA. Only output if check_stage = TRUE.

stage2

The name of the stage in time t. Only output if check_stage = TRUE.

stage1

The name of the stage in time t-1, or NA. Only output if check_stage = TRUE.

age

The age at time t. Only output if check_age = TRUE.

year2

Monitoring occasion in time t.

frequency

The number of individuals in the respective stage and time.

actual_prop

The proportion of individuals alive in time t in the respective stage.

Notes

This function produces frequencies and proportions of stages in hfv formatted data using stage index variables rather than stage name variables, and so requires the former. The latter is only required if the user wants to know the associated stage names.

Frequencies and proportions will be calculated for all times, including the last time, which is generally found in the stage3 columns of the last year2 entry in object data. The default is to treat the year2 entry for that time as max(year2) + 1.

If check_stage = TRUE and check_age = FALSE, then this function will assess frequencies and proportions of stages or historical stage-pairs. If both check_stage = TRUE and check_age = TRUE, then this function will assess frequencies and proportions of age-stages. If check_stage = FALSE and check_age = TRUE, then the frequencies and proportions of ages only will be assessed.

Note that no stageframe is required for this function to operate. Stage names and their order are inferred directly from the object data.

Examples

sizevector <- c(0, 0, 0, 0, 0, 0, 1, 3, 6, 11, 19.5)
stagevector <- c("SD", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "Md", "Lg",
  "XLg")
repvector <- c(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1)
obsvector <- c(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1)
matvector <- c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1)
immvector <- c(0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0)
propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
indataset <- c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1)
binvec <- c(0, 0, 0, 0, 0, 0.5, 0.5, 1.5, 1.5, 3.5, 5)
comments <- c("Dormant seed", "1st yr protocorm", "2nd yr protocorm",
  "3rd yr protocorm", "Seedling", "Dormant adult",
  "Extra small adult (1 shoot)", "Small adult (2-4 shoots)",
  "Medium adult (5-7 shoots)", "Large adult (8-14 shoots)",
  "Extra large adult (>14 shoots)")
cypframe_raw <- sf_create(sizes = sizevector, stagenames = stagevector, 
  repstatus = repvector, obsstatus = obsvector, matstatus = matvector,
  propstatus = propvector, immstatus = immvector, indataset = indataset, 
  binhalfwidth = binvec, comments = comments)

cypraw_v1 <- verticalize3(data = cypdata, noyears = 6, firstyear = 2004, 
  patchidcol = "patch", individcol = "plantid", blocksize = 4,
  sizeacol = "Inf2.04", sizebcol = "Inf.04", sizeccol = "Veg.04",
  repstracol = "Inf.04", repstrbcol = "Inf2.04", fecacol = "Pod.04",
  stageassign = cypframe_raw, stagesize = "sizeadded", NAas0 = TRUE,
  NRasRep = TRUE, age_offset = 4)

all_stage_props_ah <- actualstage3(cypraw_v1)
all_stage_props_h <- actualstage3(cypraw_v1, historical = TRUE)
all_stage_props_h_NANotAllow <- actualstage3(cypraw_v1, historical = TRUE,
  t1_allow = "none")
all_stage_props_as <- actualstage3(cypraw_v1, check_age = TRUE)
all_age_props <- actualstage3(cypraw_v1, check_stage = FALSE,
  check_age = TRUE)


lefko3 documentation built on May 29, 2024, 6:39 a.m.