lmean: Estimate Mean Projection Matrices

View source: R/RcppExports.R

lmeanR Documentation

Estimate Mean Projection Matrices

Description

Function lmean() estimates mean projection matrices as element-wise arithmetic means. It produces lefkoMat objects if provided with them, or single matrices in a simple one-element list if provided a list of matrices.

Usage

lmean(mats, matsout = NULL, force_sparse = FALSE)

Arguments

mats

A lefkoMat object, or a list of square matrices of equal dimension.

matsout

A string identifying which means to estimate. Option "pop" indicates population-level only, "patch" indicates patch-level only, and "all" indicates that both patch- and population-level means should be estimated. Defaults to "all".

force_sparse

A logical value identifying whether to output the mean matrices in sparse format, if input as standard matrices.

Value

Yields a lefkoMat object with the following characteristics:

A

A list of full mean projection matrices in order of sorted populations, patches, and years. These are typically estimated as the sums of the associated mean U and F matrices. All matrices output in either the matrix class, or the dgCMatrix class.

U

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

F

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

hstages

A data frame showing the pairing of ahistorical stages used to create historical stage pairs. Given if the MPM is historical.

ahstages

A data frame detailing the characteristics of associated ahistorical stages.

labels

A data frame detailing the order of population, patch, and year of each mean matrix. If pop, patch, or year2 are NA in the original labels set, then these will be re-labeled as A, 1, or 1, respectively.

matrixqc

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

modelqc

This is the qc portion of the modelsuite input. Only output from lefkoMat objects resulting from function-based estimation.

dataqc

A vector showing the numbers of individuals and rows in the vertical dataset used as input. Only output from lefkoMat objects resulting from raw matrix estimation.

Examples

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)

cypsupp2r <- supplemental(stage3 = c("SD", "P1", "P2", "P3", "SL", "D", 
    "XSm", "Sm", "SD", "P1"),
  stage2 = c("SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "rep",
    "rep"),
  eststage3 = c(NA, NA, NA, NA, NA, "D", "XSm", "Sm", NA, NA),
  eststage2 = c(NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", NA, NA),
  givenrate = c(0.10, 0.20, 0.20, 0.20, 0.25, NA, NA, NA, NA, NA),
  multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5),
  type =c(1, 1, 1, 1, 1, 1, 1, 1, 3, 3),
  stageframe = cypframe_raw, historical = FALSE)

cypmatrix2r <- rlefko2(data = cypraw_v1, stageframe = cypframe_raw, 
  year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"),
  size = c("size3added", "size2added"), supplement = cypsupp2r,
  yearcol = "year2", patchcol = "patchid", indivcol = "individ")

cyp2mean <- lmean(cypmatrix2r)


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