Learn R Programming

lefko3 (version 3.1.0)

rlefko3: Create Raw Historical Population Projection Matrices

Description

rlefko3() returns raw historical MPMs, including the associated component transition and fecundity matrices, data frames describing the ahistorical stages used and the historical paired stages, and a data frame describing the population, patch, and year associated with each matrix.

Usage

rlefko3(
  data,
  stageframe,
  year = "all",
  pop = NA,
  patch = NA,
  censor = FALSE,
  stages = NA,
  alive = c("alive3", "alive2", "alive1"),
  size = c("sizea3", "sizea2", "sizea1"),
  repst = c("repstatus3", "repstatus2", "repstatus1"),
  matst = c("matstatus3", "matstatus2", "matstatus1"),
  fec = c("feca3", "feca2", "feca1"),
  repmatrix = NA,
  overwrite = NA,
  yearcol = NA,
  popcol = NA,
  patchcol = NA,
  indivcol = NA,
  censorcol = NA,
  reduce = FALSE
)

Arguments

data

A vertical demographic data frame, with variables corresponding to the naming conventions in verticalize3().

stageframe

A stageframe object that includes information on the size, observation status, propagule status, immaturity status, and maturity status of each ahistorical stage. Should also incorporate bin widths if size is continuous.

year

A variable corresponding to year or observation time, or a set of such values, given in values associated with the year term used in linear model development. Can also equal all, in which case matrices will be estimated for all years. Defaults to all.

pop

A variable designating which populations will have matrices estimated. Should be set to specific population names, or to all if all populations should have matrices estimated.

patch

A variable designating which patches or subpopulations will have matrices estimated. Should be set to specific patch names, or to all if matrices should be estimated for all patches. Defaults to all.

censor

If TRUE, then data will be removed according to the variable set in censorcol, such that only data with censor values equal to 1 will remain. Defaults to FALSE.

stages

An optional vector denoting the names of the variables within the main vertical dataset coding for the stages of each individual in times t+1, t, and t-1. The names of stages in these variables should match those used in the stageframe exactly. If left blank, then rlefko3() will attempt to infer stages by matching values of alive, size, repst, and matst to characteristics noted in the associated stageframe.

alive

A vector of names of binomial variables corresponding to status as alive (1) or dead (0) in times t+1, t, and t-1, respectively.

size

A vector of names of variables coding size in times t+1, t, and t-1, respectively. Defaults to c("sizea3", "sizea2", "sizea1").

repst

A vector of names of variables coding reproductive status in times t+1, t, and t-1, respectively. Defaults to c("repstatus3", "repstatus2", "repstatus1").

matst

A vector of names of variables coding maturity status in times t+1, t, and t-1, respectively. Defaults to c("matstatus3", "matstatus2", "matstatus1"). Must be supplied if stages is not provided.

fec

A vector of names of variables coding fecundity in times t+1, t, and t-1, respectively. Defaults to c("feca3", "feca2", "feca1").

repmatrix

A matrix composed mostly of 0s, with non-zero values for each potentially new individual (row) born to each reproductive stage (column). Entries act as multipliers on fecundity, with 1 equaling full fecundity.

overwrite

A data frame developed with the overwrite() function describing transitions to be overwritten either with given values or with other estimated transitions.

yearcol

The variable name or column number corresponding to time in time t in the dataset.

popcol

The variable name or column number corresponding to the identity of the population.

patchcol

The variable name or column number corresponding to patch in the dataset.

indivcol

The variable name or column number coding individual identity.

censorcol

The variable name or column number denoting the censor status. Only needed if censor = TRUE.

reduce

A logical value denoting whether to remove historical stages associated exclusively with zero transitions. These are removed only if all row and column sums in ALL matrices estimated equal 0. Defaults to FALSE.

Value

If all inputs are properly formatted, then this function will return either an object of class lefkoMat. Output includes:

A

A list of full projection matrices in order of sorted populations, patches, and years. All matrices output in the matrix class.

U

A list of survival-transition matrices sorted as in A. All matrices output in the matrix class.

F

A list of fecundity matrices sorted as in A. All matrices output in the matrix class.

hstages

A data frame matrix showing the pairing of ahistorical stages used to create historical stage pairs.

ahstages

A data frame detailing the characteristics of associated ahistorical stages.

labels

A data frame giving the population, patch, and year of each matrix in order.

matrixqc

A short vector describing the number of non-zero elements in U and F matrices, and the number of annual matrices.

dataqc

A vector showing the numbers of individuals and rows in the vertical dataset used as input.

Examples

Run this code
# NOT RUN {
data(cypdata)

sizevector <- c(0, 0, 0, 0, 0, 0, 1, 2.5, 4.5, 8, 17.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, 1, 2.5, 7)

cypframe_raw <- sf_create(sizes = sizevector, stagenames = stagevector,
                          repstatus = repvector, obsstatus = obsvector,
                          matstatus = matvector, propstatus = propvector,
                          immstatus = immvector, indataset = indataset,
                          binhalfwidth = binvec)

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)

rep_cyp_raw <- matrix(0, 11, 11)
rep_cyp_raw[1:2,7:11] <- 0.5

cypover3r <- overwrite(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", 
                       "SL", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm"), 
                       stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", 
                       "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL"),
                       stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", 
                       "P3", "SL", "P3", "P3", "P3", "SL", "SL", "SL"),
                       eststage3 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, "D", 
                       "XSm", "Sm", "D", "XSm", "Sm"), eststage2 = c(NA, NA, NA, 
                       NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm",
                       "XSm"), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
                       "XSm", "XSm", "XSm", "XSm", "XSm", "XSm"), 
                       givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, 0.4,
                       0.4, NA, NA, NA, NA, NA, NA), type = c("S", "S", "S", 
                       "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", 
                       "S"))

cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all",
                       patch = "all", stages = c("stage3", "stage2", "stage1"),
                       size = c("size3added", "size2added", "size1added"),
                       repmatrix = rep_cyp_raw, overwrite = cypover3r,
                       yearcol = "year2", patchcol = "patchid", indivcol = "individ")

summary(cypmatrix3r)

# }

Run the code above in your browser using DataLab