| Type: | Package |
| Title: | Historical and Ahistorical Population Projection Matrix Analysis |
| Version: | 6.6.0 |
| Date: | 2025-10-28 |
| Description: | Complete analytical environment for the construction and analysis of matrix population models and integral projection models. Includes the ability to construct historical matrices, which are 2d matrices comprising 3 consecutive times of demographic information. Estimates both raw and function-based forms of historical and standard ahistorical matrices. It also estimates function-based age-by-stage matrices and raw and function-based Leslie matrices. |
| Encoding: | UTF-8 |
| License: | GPL-2 |GPL-3 [expanded from: GPL (≥ 2)] |
| URL: | https://github.com/dormancy1/lefko3 |
| Imports: | Rcpp (≥ 1.0.5), glmmTMB, lme4, MASS, Matrix, methods, MuMIn,pscl, rlang, stats, VGAM, grDevices |
| LinkingTo: | Rcpp, RcppArmadillo, BH |
| LazyData: | true |
| BugReports: | https://github.com/dormancy1/lefko3/issues |
| RoxygenNote: | 7.3.3 |
| Suggests: | knitr, popbio, rmarkdown, Rcompadre |
| VignetteBuilder: | knitr |
| NeedsCompilation: | yes |
| Packaged: | 2025-10-27 21:07:52 UTC; richpshefferson |
| Author: | Richard P. Shefferson |
| Maintainer: | Richard P. Shefferson <cdorm@g.ecc.u-tokyo.ac.jp> |
| Depends: | R (≥ 3.5.0) |
| Repository: | CRAN |
| Date/Publication: | 2025-10-28 06:10:32 UTC |
Historical and Ahistorical Population Projection Matrix Analysis
Description
This package creates population matrix projection models (MPMs)for use in population ecological analyses. It presents a complete workingenvironment for the construction and analysis of ALL kinds of MPMs and IPMs,including age, stage, and age-by-stage versions. Its specialty is theestimation of historical MPMs, which are 2d matrices comprising 3 monitoringoccasions (2 time steps or periods) of demographic information. The packageconstructs both function-based and raw MPMs for both standard ahistorical(i.e. 2 occasions, 1 time step) and historical analyses, has functions forcomplex density-dependent and independent, and stochastic and cyclical,projections, and also includes the automatic calculation of quality controlmetrics throughout every step of analysis. It also includes powerfulfunctions to standardize demographic datasets.
Details
The lefko3 package provides seven categories of functions:
1. Data transformation and handling functions
2. Functions determining population characteristics from vertical data
3. Model building and selection
4. Matrix / integral projection model creation functions
5. Population dynamics analysis and projection functions
6. Functions describing, summarizing, or visualizing MPMs and derivedstructures
7. Extra functions used to illustrate core theory and ideas.
lefko3 also includes example datasets complete with sample code.
Author(s)
Maintainer: Richard P. Sheffersoncdorm@g.ecc.u-tokyo.ac.jp (ORCID)
Authors:
Johan Ehrlen (ORCID)
Richard P. Shefferson <cdorm@g.ecc.u-tokyo.ac.jp>
Johan Ehrlén
References
Shefferson, R.P., J. Ehrlen, and S. Kurokawa. 2021.lefko3: analyzing individual history through size-classified matrix population models.Methods in Ecology and Evolution 12(2): 378-382.
See Also
Useful links:
Calculate Actual Stage, Age, Stage-Pair, or Age-Stage Distributions
Description
Functionactualstage3() shows the frequencies and proportions ofeach 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 frequenciesand proportions of stages. Defaults to |
check_age | A logical value indicating whether to assess frequencies andproportions of ages. Defaults to |
historical | A logical value indicating whether the stage structureshould be ahistorical ( |
year2 | A string value indicating the name of the variable coding formonitoring occasion at timet. Defaults to |
indices | A vector of three strings, indicating the stage indices fortimest+1,t, andt-1, respectively, in |
stagecol | A vector of three strings, indicating the stage name columnsfor timest+1,t, andt-1, respectively, in |
agecol | A single string indicating the age of individuals in timet. Defaults to |
remove_stage | A string vector indicating the names of stages to removefrom consideration. Defaults to |
t1_allow | A string vector indicating which stages to be removed shouldbe allowed in the stage at timet-1 portion of historical stagepairs, if |
Value
A data frame with the following variables:
rowid | A string identifier term, equal to the monitoring occasion intimet and the stage index. |
stageindex | The stageframe index of the stage. Only output if |
stage | The name of each stage, or |
stage2 | The name of the stage in timet. Only output if |
stage1 | The name of the stage in timet-1, or |
age | The age at timet. Only output if |
year2 | Monitoring occasion in timet. |
frequency | The number of individuals in the respective stage and time. |
actual_prop | The proportion of individuals alive in timet inthe respective stage. |
Notes
This function produces frequencies and proportions of stages in hfv formatteddata using stage index variables rather than stage name variables, and sorequires the former. The latter is only required if the user wants to knowthe associated stage names.
Frequencies and proportions will be calculated for all times, including thelast time, which is generally found in thestage3 columns of the lastyear2 entry in objectdata. The default is to treat theyear2 entry for that time asmax(year2) + 1.
Ifcheck_stage = TRUE andcheck_age = FALSE, then this functionwill assess frequencies and proportions of stages or historical stage-pairs.If bothcheck_stage = TRUE andcheck_age = TRUE, then thisfunction will assess frequencies and proportions of age-stages. Ifcheck_stage = FALSE andcheck_age = TRUE, then the frequenciesand proportions of ages only will be assessed.
Note that no stageframe is required for this function to operate. Stagenames and their order are inferred directly from the objectdata.
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)Add Matrices to a lefkoMat or lefkoMatList Object
Description
Functionadd_lM() adds matrices tolefkoMat andlefkoMatList objects.
Usage
add_lM( lM, Amats = NA, Umats = NA, Fmats = NA, UFdecomp = FALSE, entrystage = 1, pop = NA, patch = NA, year = NA)Arguments
lM | The |
Amats | Either a single |
Umats | Either a single |
Fmats | Either a single |
UFdecomp | A logical value indicating whether U and F matrices should beinferred from A matrices and the given |
entrystage | The stage or stages produced by reproductive individuals.Used to determine which transitions are reproductive for U-F decomposition.Defaults to |
pop | The population designation for each matrix. If object |
patch | The patch designation for each matrix. If object |
year | The designation for occasion at timet corresponding toeach matrix. Cannot be left empty. |
Value
AlefkoMat orlefkoMatList object incorporating the newmatrices within the object input inlM. Note that if alefkoMatList object is used as input, then ALL compositelefkoMat objects will have the same matrices added in exactly the sameway.
Notes
This function will not allow matrices of different dimension from those inputin objectlM to be added to that object.
Two ofAmats,Umats, andFmats must be provided for thisfunction to proceed. Also, ifAmats,Umats, andFmatsare all provided, then this function will default to replacingAmatswith the sum of the respectiveUmats andFmats.
See Also
Examples
# These matrices are of 9 populations of the plant species Anthyllis# vulneraria, and were originally published in Davison et al. (2010) Journal# of Ecology 98:255-267 (doi: 10.1111/j.1365-2745.2009.01611.x).sizevector <- c(1, 1, 2, 3) # These sizes are not from the original paperstagevector <- c("Sdl", "Veg", "SmFlo", "LFlo")repvector <- c(0, 0, 1, 1)obsvector <- c(1, 1, 1, 1)matvector <- c(0, 1, 1, 1)immvector <- c(1, 0, 0, 0)propvector <- c(0, 0, 0, 0)indataset <- c(1, 1, 1, 1)binvec <- c(0.5, 0.5, 0.5, 0.5)anthframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)# POPN C 2003-2004XC3 <- matrix(c(0, 0, 1.74, 1.74,0.208333333, 0, 0, 0.057142857,0.041666667, 0.076923077, 0, 0,0.083333333, 0.076923077, 0.066666667, 0.028571429), 4, 4, byrow = TRUE)# 2004-2005XC4 <- matrix(c(0, 0, 0.3, 0.6,0.32183908, 0.142857143, 0, 0,0.16091954, 0.285714286, 0, 0,0.252873563, 0.285714286, 0.5, 0.6), 4, 4, byrow = TRUE)# 2005-2006XC5 <- matrix(c(0, 0, 0.50625, 0.675,0, 0, 0, 0.035714286,0.1, 0.068965517, 0.0625, 0.107142857,0.3, 0.137931034, 0, 0.071428571), 4, 4, byrow = TRUE)# POPN E 2003-2004XE3 <- matrix(c(0, 0, 2.44, 6.569230769,0.196428571, 0, 0, 0,0.125, 0.5, 0, 0,0.160714286, 0.5, 0.133333333, 0.076923077), 4, 4, byrow = TRUE)XE4 <- matrix(c(0, 0, 0.45, 0.646153846,0.06557377, 0.090909091, 0.125, 0,0.032786885, 0, 0.125, 0.076923077,0.049180328, 0, 0.125, 0.230769231), 4, 4, byrow = TRUE)XE5 <- matrix(c(0, 0, 2.85, 3.99,0.083333333, 0, 0, 0,0, 0, 0, 0,0.416666667, 0.1, 0, 0.1), 4, 4, byrow = TRUE)mats_list <- list(XC3, XC4, XC5, XE3, XE4, XE5)yr_ord <- c(1, 2, 3, 1, 2, 3)pch_ord <- c(1, 1, 1, 2, 2, 2)anth_lefkoMat <- create_lM(mats_list, anthframe, hstages = NA, historical = FALSE, poporder = 1, patchorder = pch_ord, yearorder = yr_ord) XH3 <- matrix(c(0, 0, 0.1125, 1.05,0.2, 0, 0, 0,0, 0.5, 0, 0,0.2, 0.5, 0, 0), 4, 4, byrow = TRUE)XH3u <- matrix(c(0, 0, 0, 0,0.2, 0, 0, 0,0, 0.5, 0, 0,0.2, 0.5, 0, 0), 4, 4, byrow = TRUE)XH4 <- matrix(c(0, 0, 0, 0,0, 0, 0.5, 0,0.8, 0.5, 0.25, 0.25,0.2, 0, 0, 0.75), 4, 4, byrow = TRUE)XH4u <- matrix(c(0, 0, 0, 0,0, 0, 0.5, 0,0.8, 0.5, 0.25, 0.25,0.2, 0, 0, 0.75), 4, 4, byrow = TRUE)XH5 <- matrix(c(0, 0, 0.2, 1.05,0, 0, 0, 0,0.001, 0.001, 0.333333333, 0,0.001, 0, 0, 0), 4, 4, byrow = TRUE)XH5u <- matrix(c(0, 0, 0, 0,0, 0, 0, 0,0.001, 0.001, 0.333333333, 0,0.001, 0, 0, 0), 4, 4, byrow = TRUE)anth_lefkoMat <- add_lM(anth_lefkoMat, Amats = list(XH3, XH4, XH5), Umats = list(XH3u, XH4u, XH5u), patch = c(3, 3, 3), year = c(1, 2, 3))Add a New Stage to an Existing lefkoMat or lefkoMatList Object
Description
Functionadd_stage() adds a new stage to an existinglefkoMatorlefkoMatList object. In addition to altering theahstagesobject within the MPM, it alters thehstages andagestagesobjects and adds the appropriate number of new rows and columns depending onthe kind of MPM input. Note that, if entering alefkoMatList object,then a stage will be added to alllefkoMat objects contained therein.
Usage
add_stage(mpm, add_before = 0L, add_after = 0L, stage_name = NULL)Arguments
mpm | The |
add_before | The index of the stage to insert a new stage before. Thisindex should be derived from the |
add_after | The index of the stage to insert a new stage after. Thisindex should be derived from the |
stage_name | The name of the new stage to add. Defaults to |
Value
A new copy of the original MPM edited to include new rows andcolumns in the associated matrices, and withahstages,agestages, andhstages objects edited to include the newstage.
See Also
edit_lM()
Examples
data(cypdata)cyp_lesl_data <- 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", stagesize = "sizeadded", NAas0 = TRUE, age_offset = 2)cyp_survival <- glm(alive3 ~ obsage + as.factor(year2), data = cyp_lesl_data, family = "binomial")cyp_fecundity <- glm(feca2 ~ 1 + obsage + as.factor(year2), data = cyp_lesl_data, family = "poisson")mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[22] <- "obsage"germination <- 0.08protocorm_to_seedling <- 0.10seeding_to_adult <- 0.20seeds_per_fruit <- 8000cyp_lesl_supp <- supplemental(historical = FALSE, stagebased = FALSE, agebased = TRUE, age2 = c(1, 2), type = c(1, 1), givenrate = c(protocorm_to_seedling, seeding_to_adult))cyp_lesl_fb_mpm <- fleslie(data = cyp_lesl_data, surv_model = cyp_survival, fec_model = cyp_fecundity, paramnames = mod_params, last_age = 7, fecage_min = 3, fecmod = (germination * seeds_per_fruit), supplement = cyp_lesl_supp)altered1 <- add_stage(cyp_lesl_fb_mpm, add_before = 1, stage_name = "DS")Create Function-based Ahistorical Age x Stage Matrix Projection Model
Description
Functionaflefko2() returns ahistorical age x stage MPMs correspondingto the patches and occasions given, including the associated componenttransition and fecundity matrices, data frames detailing the characteristicsof ahistorical stages and the exact age-stage combinations corresponding torows and columns in estimated matrices, and a data frame characterizing thepatch and occasion combinations corresponding to these matrices.
Usage
aflefko2( year = "all", patch = "all", stageframe, supplement = NULL, repmatrix = NULL, overwrite = NULL, data = NULL, modelsuite = NULL, surv_model = NULL, obs_model = NULL, size_model = NULL, sizeb_model = NULL, sizec_model = NULL, repst_model = NULL, fec_model = NULL, jsurv_model = NULL, jobs_model = NULL, jsize_model = NULL, jsizeb_model = NULL, jsizec_model = NULL, jrepst_model = NULL, jmatst_model = NULL, paramnames = NULL, inda = NULL, indb = NULL, indc = NULL, annua = NULL, annub = NULL, annuc = NULL, surv_dev = 0, obs_dev = 0, size_dev = 0, sizeb_dev = 0, sizec_dev = 0, repst_dev = 0, fec_dev = 0, jsurv_dev = 0, jobs_dev = 0, jsize_dev = 0, jsizeb_dev = 0, jsizec_dev = 0, jrepst_dev = 0, jmatst_dev = 0, density = NA, fecmod = 1, random.inda = FALSE, random.indb = FALSE, random.indc = FALSE, final_age = NA, continue = TRUE, prebreeding = TRUE, negfec = FALSE, ipm_method = "CDF", reduce = FALSE, simple = FALSE, err_check = FALSE, exp_tol = 700, theta_tol = 1e+08, sparse_output = FALSE)Arguments
year | A variable corresponding to the observation occasion, or a setof such values, given in values associated with the year term used in linear model development. Defaults to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Defaults to |
stageframe | An object of class |
supplement | An optional data frame of class |
repmatrix | An optional reproduction matrix. This matrix is composedmostly of |
overwrite | An optional data frame developed with the |
data | The historical vertical demographic data frame used to estimatevital rates (class |
modelsuite | One of three kinds of lists. The first is a |
surv_model | A linear model predicting survival probability. This can be a model of class |
obs_model | A linear model predicting sprouting or observationprobability. This can be a model of class |
size_model | A linear model predicting primary size. This can be a modelof class |
sizeb_model | A linear model predicting secondary size. This can be amodel of class |
sizec_model | A linear model predicting tertiary size. This can be amodel of class |
repst_model | A linear model predicting reproduction probability. This can be a model of class |
fec_model | A linear model predicting fecundity. This can be a model ofclass |
jsurv_model | A linear model predicting juvenile survival probability.This can be a model of class |
jobs_model | A linear model predicting juvenile sprouting or observationprobability. This can be a model of class |
jsize_model | A linear model predicting juvenile primary size. Thiscan be a model of class |
jsizeb_model | A linear model predicting juvenile secondary size. Thiscan be a model of class |
jsizec_model | A linear model predicting juvenile tertiary size. Thiscan be a model of class |
jrepst_model | A linear model predicting reproduction probability of a mature individual that was immature in timet. This can be a modelof class |
jmatst_model | A linear model predicting maturity probability of an individual that was immature in timet. This can be a model of class |
paramnames | A data frame with three columns, the first describing allterms used in linear modeling, the second (must be called |
inda | Can be a single value to use for individual covariate |
indb | Can be a single value to use for individual covariate |
indc | Can be a single value to use for individual covariate |
annua | Can be a single value to use for annual covariate |
annub | Can be a single value to use for annual covariate |
annuc | Can be a single value to use for annual covariate |
surv_dev | A numeric value to be added to the y-intercept in the linearmodel for survival probability. Defaults to |
obs_dev | A numeric value to be added to the y-intercept in the linearmodel for observation probability. Defaults to |
size_dev | A numeric value to be added to the y-intercept in the linearmodel for primary size. Defaults to |
sizeb_dev | A numeric value to be added to the y-intercept in the linearmodel for secondary size. Defaults to |
sizec_dev | A numeric value to be added to the y-intercept in the linearmodel for tertiary size. Defaults to |
repst_dev | A numeric value to be added to the y-intercept in the linearmodel for probability of reproduction. Defaults to |
fec_dev | A numeric value to be added to the y-intercept in the linearmodel for fecundity. Defaults to |
jsurv_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile survival probability. Defaults to |
jobs_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile observation probability. Defaults to |
jsize_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile primary size. Defaults to |
jsizeb_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile secondary size. Defaults to |
jsizec_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile tertiary size. Defaults to |
jrepst_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile reproduction probability. Defaults to |
jmatst_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile maturity probability. Defaults to |
density | A numeric value indicating density value to use to propagatematrices. Only needed if density is an explanatory term used in one or morevital rate models. Defaults to |
fecmod | A scalar multiplier of fecundity. Defaults to |
random.inda | A logical value denoting whether to treat individualcovariate |
random.indb | A logical value denoting whether to treat individualcovariate |
random.indc | A logical value denoting whether to treat individualcovariate |
final_age | The final age to model in the matrix, where the first agewill be age 0. Defaults to the maximum age in the dataset. |
continue | A logical value designating whether to allow continuedsurvival of individuals past the final age noted in the stageframe, using the demographic characteristics of the final age. Defaults to |
prebreeding | A logical value indicating whether the life history modelis a pre-breeding model. Defaults to |
negfec | A logical value denoting whether fecundity values estimated tobe negative should be reset to |
ipm_method | A string indicating what method to use to estimate sizetransition probabilities, if size is treated as continuous. Options include: |
reduce | A logical value denoting whether to remove age-stagesassociated solely with |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
exp_tol | A numeric value used to indicate a maximum value to setexponents to in the core kernel to prevent numerical overflow. Defaults to |
theta_tol | A numeric value used to indicate a maximum value to theta asused in the negative binomial probability density kernel. Defaults to |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
If the user inputs a standardlefkoMod orvrm_inputobject in argumentmodelsuite, or individual vital rate models areinput separately,then this function will return an object of classlefkoMat. If the user inputs an object of classlefkoModListin argumentmodelsuite, then the output will be an object of classlefkoMatList, in which each element is an object of classlefkoMat.
AlefkoMat object is a list that holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted patches andoccasions. All matrices output in R's |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. Set to |
agestages | A data frame showing the stage number and stage namecorresponding to |
ahstages | A data frame detailing the characteristics of associatedahistorical stages, in the form of a modified stageframe that includesstatus as an entry stage through reproduction. |
labels | A data frame giving the patch and year of each matrix in order.In |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
prob_out | An optional element only added if |
allstages | An optional element only added if |
Notes
Unlikerlefko2(),rlefko3(),arlefko2(), andrleslie(), this function does notcurrently distinguish populations. Users wishing to use the same vital ratemodels across populations should label them as patches (though we do notadvise this approach, as populations should typically be treated asstatistically independent).
This function will yield incorrect estimates if the models utilizedincorporate state in occasiont-1. Only use models developed testingfor ahistorical effects.
The default behavior of this function is to estimate fecundity with regardsto transitions specified via associated fecundity multipliers in thesupplement. If this field is left empty, then fecundity will beestimated at full for all transitions leading from reproductive stages toimmature and propagule stages.
Stageframes used in this function should include ages for minimum and maximumage for each stage.NAs are treated as0s in minimum age, andasfinal_age for maximum age.
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations, but without discriminating between thosepatches or subpopulations. Should the aim of analysis be a general MPM thatdoes not distinguish these patches or subpopulations, themodelsearch() run should not include patch terms.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1 andt. Rearranging the order willlead to erroneous calculations, and may lead to fatal errors.
Care should be taken to match the random status of year and patch to thestates of those variables within themodelsuite. If they do not match,then they will be treated as zeroes in vital rate estimation.
Theipm_method function gives the option of using two different meansof estimating the probability of size transition. The midpoint method("midpoint") refers to the method in which the probability isestimated by first estimating the probability associated with transition fromthe exact size at the midpoint of the size class using the correspondingprobability density function, and then multiplying that value by the binwidth of the size class. Doak et al. 2021 (Ecological Monographs) noted thatthis method can produce biased results, with total size transitionsassociated with a specific size not totaling to 1.0 and even specific sizetransition probabilities capable of being estimated at values greater than1.0. The alternative and default method,"CDF", uses the correspondingcumulative density function to estimate the probability of size transition asthe cumulative probability of size transition at the greater limit of thesize class minus the cumulative probability of size transition at the lowerlimit of the size class. The latter method avoids this bias. Note, however,that both methods are exact and unbiased for the Poisson and negativebinomial distributions.
Under the Gaussian and gamma size distributions, the number of estimatedparameters may differ between the twoipm_method settings. Becausethe midpoint method has a tendency to incorporate upward bias in theestimation of size transition probabilities, it is more likely to yield non-zero values when the true probability is extremely close to 0. This willresult in thesummary.lefkoMat function yielding higher numbers ofestimated parameters than theipm_method = "CDF" yields in some cases.
Using theerr_check option will produce a matrix of 7 columns, eachcharacterizing a different vital rate. The product of each row yields anelement in the associatedU matrix. The number and order of elementsin each column of this matrix matches the associated matrix in column vectorformat. Use of this option is generally for the purposes of debugging code.
Individual covariates are treated as categorical only if they are set asrandom terms. Fixed categorical individual covariates are currently notallowed. However, such terms may be supplied if themodelsuite optionis set to avrm_input object. In that case, the user should also setthe logical random switch for the individual covariate to be used toTRUE (e.g.,random.inda = TRUE).
See Also
flefko3()
flefko2()
fleslie()
arlefko2()
rlefko3()
rlefko2()
rleslie()
Examples
data(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)minima <- c(1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector, minage = minima)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathvertln_adults <- subset(lathvertln, stage2index > 2)surv_model <- glm(alive3 ~ obsage + sizea2 + as.factor(patchid) + as.factor(year2), data = lathvertln_adults, family = "binomial")obs_data <- subset(lathvertln_adults, alive3 == 1)obs_model <- glm(obsstatus3 ~ obsage + as.factor(patchid) + as.factor(year2), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)siz_model <- lm(sizea3 ~ sizea2 + repstatus2 + obsage + as.factor(patchid) + as.factor(year2), data = size_data)reps_model <- glm(repstatus3 ~ sizea2 + as.factor(patchid) + as.factor(year2), data = size_data, family = "binomial")fec_data <- subset(lathvertln_adults, repstatus2 == 1)fec_model <- glm(feca2 ~ sizea2 + obsage + as.factor(patchid) + as.factor(year2), data = fec_data, family = "poisson")lathvertln_juvs <- subset(lathvertln, stage2index < 3)jsurv_model <- glm(alive3 ~ as.factor(patchid), data = lathvertln_juvs, family = "binomial")jobs_data <- subset(lathvertln_juvs, alive3 == 1)jobs_model <- glm(obsstatus3 ~ 1, family = "binomial", data = jobs_data)jsize_data <- subset(jobs_data, obsstatus3 == 1)jsiz_model <- lm(sizea3 ~ as.factor(year2), data = jsize_data)jrepst_model <- 0jmatst_model <- 1lathsupp2 <- supplemental(stage3 = c("Sd", "Sdl", "mat", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sdl", "rep", "rep"), eststage3 = c(NA, NA, "mat", NA, NA), eststage2 = c(NA, NA, "Dorm", NA, NA), givenrate = c(0.345, 0.054, NA, NA, NA), multiplier = c(NA, NA, 0.8, 0.345, 0.054), type = c(1, 1, 1, 3, 3), stageframe = lathframeln, historical = FALSE, agebased = TRUE)mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[3] <- "patchid"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "feca2"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[18] <- "repstatus2"mod_params$modelparams[22] <- "obsage"lathmat2age2 <- aflefko2(year = "all", patch = "all", data = lathvertln, stageframe = lathframeln, supplement = lathsupp2, final_age = 3, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, repst_model = reps_model, fec_model = fec_model, jsurv_model = jsurv_model, jobs_model = jobs_model, jsize_model = jsiz_model, jrepst_model = jrepst_model, jmatst_model = jmatst_model, paramnames = mod_params, continue = TRUE, reduce = FALSE)Matrix Set ofAnthyllis vulneraria Populations in Belgium
Description
AlefkoMat object containing projection matrices developed fromdemographic data gathered on nineAnthyllis vulneraria populationsfrom 2003 to 2006 in southwestern Belgium.
Usage
data(anthyllis)Format
AlefkoMat object holding 27 matrices. The structure of theobject is as below:
- A
The 27 A matrices.
- U
The 27 survival-transition matrices used to develop the Amatrices.
- F
The 27 fecundity matrices used to develop the A matrices.
- hstages
Not used, so set to
NA.- agestages
Not used, so set to
NA.- ahstages
The edited stageframe describing the life history of thestudy organism as interpreted in the original demographic study.
- labels
The order of the matrices, where each population is treatedas a separate patch and each matrix corresponds to a different combinationof population and year in timet.
- matrixqc
A vector of integers used in the quality control section of
lefkoMatsummary statements.- dataqc
Currently a vector with two
NAvalues.
Source
Davison, R. et al. 2010. Demographic effects of extreme weatherevents on a short-lived calcareous grassland species: stochastic life tableresponse experiments.Journal of Ecology 98(2):255-267.
Examples
data(anthyllis)lambda3(anthyllis)Append Projections To Create New lefkoProj Object
Description
Functionappend_lP() combines two population projections. It takestwolefkoProj objects and appends them into a newlefkoProjobject.
Usage
append_lP(proj1 = NULL, proj2 = NULL)Arguments
proj1 | A |
proj2 | A second |
Value
A list of classlefkoProj, which always includes the firstthree elements of the following, and also includes the remaining elementsbelow when alefkoMat object is used as input:
projection | A list of lists of matrices showing the total number ofindividuals per stage per occasion. The first list corresponds to eachpop-patch followed by each population (this top-level list is a singleelement in |
stage_dist | A list of lists of the actual stage distribution in eachoccasion in each replicate in each pop-patch or population. |
rep_value | A list of lists of the actual reproductive value in eachoccasion in each replicate in each pop-patch or population. |
pop_size | A list of matrices showing the total population size in eachoccasion per replicate (row within data frame) per pop-patch or population(list element). |
labels | A data frame showing the order of populations and patches initem |
ahstages | The original stageframe used in the study. |
hstages | A data frame showing the order of historical stage pairs. |
agestages | A data frame showing the order of age-stage pairs. |
labels | A short data frame indicating the population (always |
control | A data frame showing the number of replicates and time stepscorresponding to each set of projections, where each set corresponds to apop-patch within the labels object of each input projection. |
density | The data frame input under the density option. Only providedif input by the user for at least one of the two projections. Output as anested list corresponding to each pop-patch - replicate. |
density_vr | The data frame input under the density_vr option. Onlyprovided if input by the user for at least one of the two projections.Output as a nested list corresponding to each pop-patch - replicate. |
Notes
lefkoProj objects resulting from previous appends can also beappended.
See Also
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.1, 0.2, 0.2, 0.2, 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_AB <- rlefko2(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = c("A", "B"), stages = c("stage3", "stage2"), size = c("size3added", "size2added"), supplement = cypsupp2r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix2r_AC <- rlefko2(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = c("A", "C"), stages = c("stage3", "stage2"), size = c("size3added", "size2added"), supplement = cypsupp2r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypproj1 <- projection3(cypmatrix2r_AB, nreps = 5, times = 15, stochastic = TRUE)cypproj2 <- projection3(cypmatrix2r_AC, nreps = 10, times = 20, stochastic = TRUE)cypproj3 <- append_lP(cypproj1, cypproj2)Create Raw Ahistorical Age x Stage Matrix Projection Model
Description
Functionarlefko2() returns raw ahistorical age x stage MPMscorresponding to the patches and occasion times given, including theassociated component transition and fecundity matrices, data frames detailingthe characteristics of ahistorical stages and the exact age-stagecombinations corresponding to rows and columns in estimated matrices, and adata frame characterizing the patch and occasion time combinationscorresponding to these matrices.
Usage
arlefko2( data, stageframe, year = "all", pop = NULL, patch = NULL, censor = FALSE, stages = NULL, alive = c("alive3", "alive2"), obsst = NULL, size = c("sizea3", "sizea2"), sizeb = NULL, sizec = NULL, repst = c("repstatus3", "repstatus2"), matst = c("matstatus3", "matstatus2"), fec = c("feca3", "feca2"), supplement = NULL, repmatrix = NULL, overwrite = NULL, agecol = "obsage", yearcol = NULL, popcol = NULL, patchcol = NULL, indivcol = NULL, censorcol = NULL, censorkeep = 0, final_age = NA, continue = TRUE, prebreeding = TRUE, NRasRep = FALSE, reduce = FALSE, simple = FALSE, err_check = FALSE, sparse_output = FALSE)Arguments
data | A vertical demographic data frame, with variables corresponding to the naming conventions in functions |
stageframe | A stageframe object that includes information on the size,observation status, propagule status, reproduction status, immaturity status,and maturity status of each ahistorical stage. Should also incorporate binwidths if size is continuous. |
year | A variable corresponding to observation occasion, or a setof such values, given in values associated with the year term used in linear model development. Defaults to |
pop | A variable designating which populations will have matricesestimated. Should be set to specific population names, or to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Should be set to specific patch names, or to |
censor | If |
stages | An optional vector denoting the names of the variables withinthe main vertical dataset coding for the stages of each individual inoccasionst+1 andt. The names of stages in these variablesshould match those used in the |
alive | A vector of names of binomial variables corresponding to statusas alive ( |
obsst | A vector of names of binomial variables corresponding toobservation status in occasionst+1,t, andt-1,respectively. Defaults to |
size | A vector of names of variables coding the primary size variablein occasionst+1 andt, respectively. Defaults to |
sizeb | A vector of names of variables coding the secondary sizevariable in occasionst+1 andt, respectively. Defaults to |
sizec | A vector of names of variables coding the tertiary sizevariable in occasionst+1 andt, respectively. Defaults to |
repst | A vector of names of variables coding reproductive status inoccasionst+1 andt, respectively. Defaults to |
matst | A vector of names of variables coding maturity status inoccasionst+1 andt, respectively. Defaults to |
fec | A vector of names of variables coding fecundity in occasionst+1 andt, respectively. Defaults to |
supplement | An optional data frame of class |
repmatrix | An optional reproduction matrix. This matrix is composedmostly of 0s, with non-zero entries acting as element identifiers andmultipliers for fecundity (with 1 equaling full fecundity). If left blank,and no |
overwrite | An optional data frame developed with the |
agecol | The variable name or column number coding for age in timet. |
yearcol | The variable name or column number corresponding to occasiont in the dataset. |
popcol | The variable name or column number corresponding to theidentity of the population. |
patchcol | The variable name or column number corresponding to patch inthe dataset. |
indivcol | The variable name or column number coding individualidentity. |
censorcol | The variable name or column number denoting the censorstatus. Only needed if |
censorkeep | The value of the censor variable denoting data elements tokeep. Defaults to |
final_age | The final age to model in the matrix. Defaults to themaximum age in the dataset. |
continue | A logical value designating whether to allow continuedsurvival of individuals past the final age noted in the stageframe, using the demographic characteristics of the final age. Defaults to |
prebreeding | A logical value indicating whether the life history modelis a pre-breeding model. Defaults to |
NRasRep | If |
reduce | A logical value denoting whether to remove age-stagesassociated with only zero transitions. These are removed only if therespective row and column sums in ALL matrices estimated equal 0. Defaults to |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
If the user inputs a standardhfv_data object in argumentdata, then this function will return an object of classlefkoMat. If the user inputs an object of classhfv_list inargumentdata, then the output will be an object of classlefkoMatList, in which each element is an object of classlefkoMat.
AlefkoMat object is a list that holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted patches andoccasions. All matrices output in R's |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. Set to |
agestages | A data frame showing the stage number and stage namecorresponding to |
ahstages | A data frame detailing the characteristics of associatedahistorical stages, in the form of a modified stageframe that includesstatus as an entry stage through reproduction. |
labels | A data frame giving the patch and year of each matrix in order.In |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
Notes
The default behavior of this function is to estimate fecundity with regardsto transitions specified via associated fecundity multipliers in thesupplement. If this field is left empty, then fecundity will beestimated at full for all transitions leading from reproductive stages toimmature and propagule stages.
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations. Should the aim of analysis be a generalMPM that does not distinguish these patches or subpopulations, thepatchcol variable should be left toNA, which is the default.Otherwise the variable identifying patch needs to be named.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1 andt. Rearranging the order WILLlead to erroneous calculations, and may lead to fatal errors.
Although this function is capable of assigning stages given an inputstageframe, it lacks the power ofverticalize3() andhistoricalize3() in this regard. Users are stronglyencouraged to use the latter two functions for stage assignment.
See Also
flefko3()
flefko2()
aflefko2()
fleslie()
rlefko3()
rlefko2()
rleslie()
Examples
# Cypripedium exampledata(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)minagevec <- c(1, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5)maxagevec <- c(rep(NA, 11))cypframe_raw <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, propstatus = propvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, minage = minagevec, maxage = maxagevec)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)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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, agebased = TRUE)cyp_mats <- arlefko2(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = NA, censor = FALSE, stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added"), fec = c("feca3", "feca2"), supplement = cypsupp2r, agecol = "obsage", yearcol = "year2", patchcol = "patchid", indivcol = "individ", prebreeding = TRUE, final_age = NA, continue = TRUE, reduce = FALSE)Two-Parameter Beverton-Holt Function
Description
Functionbeverton3() creates a vector of values produced by the two-parameter Beverton-Holt function as applied with a user-specified time lag.The two-parameter Beverton-Holt function is given as\phi_{t+1} = \phi_t \alpha / (1 + \beta n_t). Here, if noseparate_N vector is provided, thenn_t = \phi_t.
Usage
beverton3( start_value, alpha, beta, time_steps = 100L, time_lag = 1L, pre0_subs = FALSE, pre0_value = 0, substoch = 0L, separate_N = NULL)Arguments
start_value | A positive number to start the return vector in time 0. |
alpha | The alpha parameter in the two-parameter Beverton-Holtfunction. Must be non-negative. |
beta | The beta parameter in the two-parameter Beverton-Holt function.Must be non-negative. |
time_steps | The number of time steps to run the projection. Must be apositive integer. |
time_lag | A positive integer denoting the number of time steps backfor the value of phi in the two-parameter Beverton-Holt function. |
pre0_subs | A logical value indicating whether to use a number otherthan that given in |
pre0_value | A positive number to use for phi lagged from times priorto time 0. Only used if |
substoch | An integer value indicating the kind of substochasticity touse. Values include: |
separate_N | An optional numeric vector with values of N in each time,if phi is to be treated as different from N in the two-parameter model. |
Value
A numeric vector of values showing values projected under the two-parameter Beverton-Holt function.
Examples
trial_run1 <- beverton3(1, alpha = 0.5, beta = 0.009)plot(trial_run1)trial_run2 <- beverton3(1, alpha = 0.5, beta = 0.9)plot(trial_run2)trial_run3 <- beverton3(1, alpha = 1, beta = 0.009)plot(trial_run3)trial_run4 <- beverton3(1, alpha = 1, beta = 0.9)plot(trial_run4)trial_run5 <- beverton3(1, alpha = 5, beta = 0.009)plot(trial_run5)trial_run6 <- beverton3(1, alpha = 5, beta = 0.9)plot(trial_run6)used_Ns <- c(10, 15, 12, 14, 14, 150, 15, 1, 5, 7, 9, 14, 13, 16, 17, 19, 25, 26)trial_run7 <- beverton3(1, alpha = 1, beta = 0.009, separate_N = used_Ns)plot(trial_run7)Bootstrap Standardized hfv_data Datasets
Description
Functionbootstrap3() takes already standardizedhfvdatadatasets and bootstraps them by individual identity, or by row.
Usage
bootstrap3( data, by_pop = NULL, by_patch = NULL, by_indiv = NULL, prop_size = NULL, max_limit = NULL, reps = NULL, popcol = NULL, patchcol = NULL, indivcol = NULL)Arguments
data | A data frame of class |
by_pop | A logical value indicating whether to sample the data frameby population. If |
by_patch | A logical value indicating whether to sample the data frameby patch. If |
by_indiv | A logical value indicating whether to sample the data frameby individual identity, or by row. If |
prop_size | A logical value indicating whether to keep the proportionsof individuals (if |
max_limit | Sets the sample size to pull from the original data frame,if |
reps | The number of bootstrap replicates to produce. Defaults to |
popcol | A string denoting the variable name coding for populationidentity in the data frame. Defaults to |
patchcol | A string denoting the variable name coding for patchidentity in the data frame. Defaults to |
indivcol | A string denoting the variable name coding for individualidentity in the data frame. Defaults to |
Value
A list of classhfvlist, which is composed of data frames ofclasshfvdata.
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathboot <- bootstrap3(lathvert, reps = 3)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "all", "all"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3_boot <- rlefko3(data = lathboot, stageframe = lathframe, year = c(1989, 1990), stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")Extract Conditional Ahistorical Difference Matrices
Description
Functioncond_diff() takes a set of historical difference matricesresulting from functiondiff_lM() and decomposes them into ahistorical difference matrices conditional upon stage in timet-1.
Usage
cond_diff(lDiff, ref = 1L, matchoice = NULL, err_check = NULL)Arguments
lDiff | An object of class |
ref | Choice of mpm to use as reference. Defaults to |
matchoice | A character denoting whether to use A, U, or F matrices.Defaults to |
err_check | A logical value denoting whether to include a data frameof element equivalence from the conditional matrices to the originalmatrices. Used only for debugging purposes. Defaults to |
Value
AlefkoCondDiff object, with the following elements:
Mcond | A multi-level list holding the conditional matrices derivedfrom the input |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. |
ahstages | A data frame detailing the characteristics of associatedahistorical stages. |
labels | A data frame showing the patch and year of each input full A matrix in order. |
err_check | An optional data frame showing the order of used elementindices to create conditional matrices. |
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)seeds_per_pod <- 5000cypsupp2_raw <- supplemental(stage3 = c("SD", "P1", "P2", "P3", "SL", "SL", "D", "XSm", "SD", "P1"), stage2 = c("SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "rep", "rep"), eststage3 = c(NA, NA, NA, NA, NA, NA, "D", "XSm", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, "XSm", "XSm", NA, NA), givenrate = c(0.03, 0.15, 0.1, 0.1, 0.1, 0.05, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, (0.5 * seeds_per_pod), (0.5 * seeds_per_pod)), type =c(1, 1, 1, 1, 1, 1, 1, 1, 3, 3), stageframe = cypframe_raw, historical = FALSE)cypsupp3_raw <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "D", "XSm", "Sm", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "D", "XSm", "Sm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", NA, NA), givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix2rp <- rlefko2(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2"), size = c("size3added", "size2added"), supplement = cypsupp2_raw, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix2r <- rlefko2(data = cypraw_v1, stageframe = cypframe_raw, year = "all", stages = c("stage3", "stage2"), size = c("size3added", "size2added"), supplement = cypsupp2_raw, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix3rp <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3_raw, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3_raw, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix2r_3 <- hist_null(cypmatrix2r)cypmatrix2r_3 <- delete_lM(cypmatrix2r_3, year = 2004)diff_r <- diff_lM(cypmatrix3r, cypmatrix2r_3)cypmatrix2rp_3 <- hist_null(cypmatrix2rp)cypmatrix2rp_3 <- delete_lM(cypmatrix2rp_3, year = 2004)diff_rp <- diff_lM(cypmatrix3rp, cypmatrix2rp_3)condr1 <- cond_diff(diff_r, ref = 1)condr2 <- cond_diff(diff_r, ref = 2)condrp1 <- cond_diff(diff_rp, matchoice = "U", ref = 1)condrp2 <- cond_diff(diff_rp, matchoice = "F", ref = 2)Extract Conditional Ahistorical Matrices from Historical MPM
Description
Functioncond_hmpm() takes historical MPMs and decomposes them into ahistorical matrices conditional upon stage in timet-1. In effect,the function takes each historical matrix within a lefkoMat object, andforms one ahistorical matrix for each stage in timet-1.
Usage
cond_hmpm(hmpm, matchoice = NULL, err_check = NULL)Arguments
hmpm | A historical matrix projection model of class |
matchoice | A character denoting whether to use A, U, or F matrices.Defaults to |
err_check | A logical value denoting whether to include a data frameof element equivalence from the conditional matrices to the originalmatrices. Used only for debugging purposes. Defaults to |
Value
AlefkoCondMat object, with the following elements:
Mcond | A multi-level list holding the conditional A matrices derivedfrom the input |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. |
ahstages | A data frame detailing the characteristics of associatedahistorical stages. |
labels | A data frame showing the patch and year of each input full A matrix in order. |
err_check | An optional data frame showing the order of used elementindices to create conditional matrices. |
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)cypsupp3r <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "D", "XSm", "Sm", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "D", "XSm", "Sm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", NA, NA), givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypcondmats <- cond_hmpm(cypmatrix3r)summary(cypcondmats)Create lefkoMat Object from Given Input Matrices or an MPM Database
Description
Functioncreate_lM() creates lefkoMat objects from supplied matricesand extra information, or from a supplied MPM database such as COMPADRE orCOMADRE.
Usage
create_lM( mats, stageframe = NULL, hstages = NA, agestages = NA, historical = FALSE, agebystage = FALSE, UFdecomp = TRUE, entrystage = 1, poporder = 1, patchorder = 1, yearorder = NA, matrix_id = NULL, add_FC = TRUE, sparse_output = FALSE)Arguments
mats | A list of A matrices, or, if importing from a matrix databasesuch as COMPADRE or COMADRE, then the object holding the database. |
stageframe | A stageframe describing all stages utilized. |
hstages | A data frame outlining the order of historical stages, ifmatrices provided in |
agestages | A data frame outlining the order of ahistorical age-stages,if age-by-stage matrices are provided. |
historical | A logical value indicating whether input matrices arehistorical or not. Defaults to FALSE. |
agebystage | A logical value indicating whether input matrices areahistorical age-by-stage matrices. If TRUE, then object |
UFdecomp | A logical value indicating whether U and F matrices should beinferred. Defaults to TRUE. |
entrystage | The stage or stages produced by reproductive individuals.Used to determine which transitions are reproductive for U-F decomposition.Defaults to |
poporder | The order of populations in the list supplied in object |
patchorder | The order of patches in the list supplied in object |
yearorder | The order of monitoring occasions in the list supplied inobject |
matrix_id | The values of |
add_FC | A logical value indicating whether to sum the |
sparse_output | A logical value indicating whether to output matrices insparse format. Defaults to |
Value
AlefkoMat object incorporating the matrices input in objectmats as objectA, their U and F decompositions in objectsU andF (if requested), the provided stageframe as objectahstages, the order of historical stages as objecthstages (ifhistorical = TRUE), the order of matrices as objectlabels, anda short quality control section used by thesummary.lefkoMat()function.
Notes for importing lists of matrices
Lists may be composed of a mix of matrices in standard R format (i.e. createdvia thematrix() function), and indgCMatrix sparse format(i.e. created via theMatrix::Matrix() function withsparse = TRUE.) All matrices will be forced to one or the other,depending on the value given for thesparse_output argument.
U and F decomposition assumes that elements holding fecundity values areto be interpreted solely as fecundity rates. Users wishing to split theseelements between fecundity and survival should do so manually after runningthis function.
Age-by-stage MPMs require anagestages data frame outlining the orderof age-stages. This data frame has 3 variables:stage_id, which is thenumber of the stage as labelled by the equivalently named variable in thestageframe;stage, which is the official name of the stage asgiven in the equivalently named variable in thestageframe; andage, which of course gives the age associated with the stage at thattime. The number of rows must be equal to the number of rows and columns ofeach entered matrix.
Users may edit thedataqc object, setting the firstNA to thenumber of individuals sampled, and the secondNA to the number ofrows in a vertical version of the demographic dataset. This is not required,however.
Notes for importing from COMPADRE or COMADRE
For this function to operate, users must have either the COMPADRE databaseor the COMADRE database loaded into the global environment. Note that thesample databases supplied within packageRcompadre will not work withthis function.
This function does not and cannot replace the wonderful tools offered toexplore the COMPADRE and COMADRE packages. Please see packageRcompadre to use those tools. Note that functionimport_Com()has no relationship to theRcompadre development team.
Functionimport_Com() requires that the dimensions of all matricesimported into a singlelefkoMat object be equal.
The reproductive and maturity status of each stage is determined by patternsassessed within theF matrices. Users should check that these valuesmake sense.
Stage names may be edited manually afterward.
Users may edit thedataqc object, setting the firstNA to thenumber of individuals sampled, and the secondNA to the number ofrows in a vertical version of the demographic dataset. This is not required,however.
See Also
add_lM()
Examples
# These matrices are of 9 populations of the plant species Anthyllis# vulneraria, and were originally published in Davison et al. (2010) Journal# of Ecology 98:255-267 (doi: 10.1111/j.1365-2745.2009.01611.x).sizevector <- c(1, 1, 2, 3) # These sizes are not from the original paperstagevector <- c("Sdl", "Veg", "SmFlo", "LFlo")repvector <- c(0, 0, 1, 1)obsvector <- c(1, 1, 1, 1)matvector <- c(0, 1, 1, 1)immvector <- c(1, 0, 0, 0)propvector <- c(0, 0, 0, 0)indataset <- c(1, 1, 1, 1)binvec <- c(0.5, 0.5, 0.5, 0.5)anthframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)# POPN C 2003-2004XC3 <- matrix(c(0, 0, 1.74, 1.74,0.208333333, 0, 0, 0.057142857,0.041666667, 0.076923077, 0, 0,0.083333333, 0.076923077, 0.066666667, 0.028571429), 4, 4, byrow = TRUE)# 2004-2005XC4 <- matrix(c(0, 0, 0.3, 0.6,0.32183908, 0.142857143, 0, 0,0.16091954, 0.285714286, 0, 0,0.252873563, 0.285714286, 0.5, 0.6), 4, 4, byrow = TRUE)# 2005-2006XC5 <- matrix(c(0, 0, 0.50625, 0.675,0, 0, 0, 0.035714286,0.1, 0.068965517, 0.0625, 0.107142857,0.3, 0.137931034, 0, 0.071428571), 4, 4, byrow = TRUE)# POPN E 2003-2004XE3 <- matrix(c(0, 0, 2.44, 6.569230769,0.196428571, 0, 0, 0,0.125, 0.5, 0, 0,0.160714286, 0.5, 0.133333333, 0.076923077), 4, 4, byrow = TRUE)XE4 <- matrix(c(0, 0, 0.45, 0.646153846,0.06557377, 0.090909091, 0.125, 0,0.032786885, 0, 0.125, 0.076923077,0.049180328, 0, 0.125, 0.230769231), 4, 4, byrow = TRUE)XE5 <- matrix(c(0, 0, 2.85, 3.99,0.083333333, 0, 0, 0,0, 0, 0, 0,0.416666667, 0.1, 0, 0.1), 4, 4, byrow = TRUE)mats_list <- list(XC3, XC4, XC5, XE3, XE4, XE5)yr_ord <- c(1, 2, 3, 1, 2, 3)pch_ord <- c(1, 1, 1, 2, 2, 2)anth_lefkoMat <- create_lM(mats_list, anthframe, hstages = NA, historical = FALSE, poporder = 1, patchorder = pch_ord, yearorder = yr_ord)# A theoretical example showcasing historical matricessizevector <- c(1, 2, 3) # These sizes are not from the original paperstagevector <- c("Sdl", "Veg", "Flo")repvector <- c(0, 0, 1)obsvector <- c(1, 1, 1)matvector <- c(0, 1, 1)immvector <- c(1, 0, 0)propvector <- c(1, 0, 0)indataset <- c(1, 1, 1)binvec <- c(0.5, 0.5, 0.5)exframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)A1 <- matrix(c(0.10, 0, 0, 0.12, 0, 0, 0.15, 0, 0, 0.15, 0, 0, 0.17, 0, 0, 0.20, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0.27, 0, 0, 0.30, 0, 0, 0.30, 0, 0, 0.32, 0, 0, 0.35, 0, 0, 0, 2.00, 0, 0, 3.00, 0, 0, 4.00, 0, 0, 0.35, 0, 0, 0.37, 0, 0, 0.40, 0, 0, 0.40, 0, 0, 0.42, 0, 0, 0.45), 9, 9, byrow = TRUE)A2 <- matrix(c(0.10, 0, 0, 0.12, 0, 0, 0.15, 0, 0, 0.15, 0, 0, 0.17, 0, 0, 0.20, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0.27, 0, 0, 0.30, 0, 0, 0.30, 0, 0, 0.32, 0, 0, 0.35, 0, 0, 0, 5.00, 0, 0, 6.00, 0, 0, 7.00, 0, 0, 0.35, 0, 0, 0.37, 0, 0, 0.40, 0, 0, 0.40, 0, 0, 0.42, 0, 0, 0.45), 9, 9, byrow = TRUE)A3 <- matrix(c(0.10, 0, 0, 0.12, 0, 0, 0.15, 0, 0, 0.15, 0, 0, 0.17, 0, 0, 0.20, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0.27, 0, 0, 0.30, 0, 0, 0.30, 0, 0, 0.32, 0, 0, 0.35, 0, 0, 0, 8.00, 0, 0, 9.00, 0, 0, 10.00, 0, 0, 0.35, 0, 0, 0.37, 0, 0, 0.40, 0, 0, 0.40, 0, 0, 0.42, 0, 0, 0.45), 9, 9, byrow = TRUE)B1 <- matrix(c(0.10, 0, 0, 0.12, 0, 0, 0.15, 0, 0, 0.15, 0, 0, 0.17, 0, 0, 0.20, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0.27, 0, 0, 0.30, 0, 0, 0.30, 0, 0, 0.32, 0, 0, 0.35, 0, 0, 0, 11.00, 0, 0, 12.00, 0, 0, 13.00, 0, 0, 0.35, 0, 0, 0.37, 0, 0, 0.40, 0, 0, 0.40, 0, 0, 0.42, 0, 0, 0.45), 9, 9, byrow = TRUE)B2 <- matrix(c(0.10, 0, 0, 0.12, 0, 0, 0.15, 0, 0, 0.15, 0, 0, 0.17, 0, 0, 0.20, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0.27, 0, 0, 0.30, 0, 0, 0.30, 0, 0, 0.32, 0, 0, 0.35, 0, 0, 0, 14.00, 0, 0, 15.00, 0, 0, 16.00, 0, 0, 0.35, 0, 0, 0.37, 0, 0, 0.40, 0, 0, 0.40, 0, 0, 0.42, 0, 0, 0.45), 9, 9, byrow = TRUE)B3 <- matrix(c(0.10, 0, 0, 0.12, 0, 0, 0.15, 0, 0, 0.15, 0, 0, 0.17, 0, 0, 0.20, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0, 0.20, 0, 0, 0.22, 0, 0, 0.25, 0, 0, 0.25, 0, 0, 0.27, 0, 0, 0.30, 0, 0, 0.30, 0, 0, 0.32, 0, 0, 0.35, 0, 0, 0, 17.00, 0, 0, 18.00, 0, 0, 19.00, 0, 0, 0.35, 0, 0, 0.37, 0, 0, 0.40, 0, 0, 0.40, 0, 0, 0.42, 0, 0, 0.45), 9, 9, byrow = TRUE)histmats <- list(A1, A2, A3, B1, B2, B3)stageframe <- exframepch_ord <- c("A", "A", "A", "B", "B", "B")yr_ord <- c(1, 2, 3, 1, 2, 3)hist_trial <- create_lM(histmats, exframe, historical = TRUE, UFdecomp = TRUE, entrystage = 1, patchorder = pch_ord, yearorder = yr_ord)Creates a Skeleton Paramnames Object for Use in Function-based Modeling
Description
Creates a simple skeletonparamnames object that can be entered asinput in functionsflefko2(),flefko3(), andaflefko2().
Usage
create_pm(name_terms = FALSE)Arguments
name_terms | A logical value indicating whether to start each variablename as |
Value
A three column data frame, of which the first describes theparameters in reasonably plain English, the second gives the name of theparameter within the MPM generating functions, and the third is to beedited with the names of the variables as they appear in the models.
Notes
The third column in the resulting object should be edited with the names onlyof those variables actually used in vital rate modeling. Thisparamnames object should apply to all models used in a single MPMbuilding exercise. So, for example, if the models used include random terms,then they should all have the same random terms. Fixed terms can vary,however.
Examples
our_pm <- create_pm()our_pmCheck Continuity of Life Cycle through Matrices in lefkoMat Objects
Description
Functioncycle_check() tests whether stages, stage-pairs, orage-stages connect in matrices withinlefkoMat objects.
Usage
cycle_check(mpm, quiet = NULL)Arguments
mpm | An object of class lefkoMat, a matrix, or a list of matrices. |
quiet | A logical variable indicating whether to suppress diagnosticmessages. Defaults to |
Value
Returns a list with two elements, both of which are also lists.The first list,no_in, contains as many elements as matrices, witheach element containing an integer vector showing the identification numbersof stages, stage-pairs, or age-stages, in each matrix that do not show anytransitions leading to them. The second list,no_out, is structuredsimilarly to the first, but shows stages, stage-pairs, or age-stages fromwhich there are no transitions leading out.
Notes
This function tests whether stages, stage-pairs, and age-stages areconnected to others in matrices used for projection. Whether stages,stage-pairs, or age-stages are shown depends on whether the MPM isahistorical / age-based, historical stage-based, or age-by-stage,respectively. Checks are performed by testing whether each column in amatrix includes non-zero transitions to other columns, and by testingwhether any columns have no transitions to them from other columns. If anysuch columns are found, then functioncycle_checkwill export an integer vector giving the column numbers with problems.These column numbers may then be checked against thestage_id columnof the associated stageframe in the case of a ahistorical or age-based MPM,against the row number of the associatedhstages data frame in thecase of a historical MPM, or against the row number of the associatedagestages data frame in the case of an age-by-stage MPM.
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")cycle_check(cypmatrix2r)Demographic Dataset ofCypripedium candidum Population, in HorizontalFormat
Description
A dataset containing the states and fates ofCypripedium candidum (white lady's slipper orchids), family Orchidaceae, from a population in Illinois, USA, resulting from monitoring that occurred annually between 2004 and 2009.
Usage
data(cypdata)Format
A data frame with 77 individuals and 29 variables. Each row corresponds to an unique individual, and each variable fromsize.04 on refers to the state of the individual in a particular year.
- plantid
A numeric variable giving a unique number to each individual.
- patch
A variable refering to patch within the population.
- X
An X coordinate for the plant within the population.
- Y
A Y coordinate for the plant within the population.
- censor
A variable coding for whether the data point is valid. Anentry of 1 means that it is so.
- Inf2.04
Number of double inflorescences in 2004.
- Inf.04
Number of inflorescences in 2004.
- Veg.04
Number of stems without inflorescences in 2004.
- Pod.04
Number of fruits in 2004.
- Inf2.05
Number of double inflorescences in 2005.
- Inf.05
Number of inflorescences in 2005.
- Veg.05
Number of stems without inflorescences in 2005.
- Pod.05
Number of fruits in 2005.
- Inf2.06
Number of double inflorescences in 2006.
- Inf.06
Number of inflorescences in 2006.
- Veg.06
Number of stems without inflorescences in 2006.
- Pod.06
Number of fruits in 2006.
- Inf2.07
Number of double inflorescences in 2007.
- Inf.07
Number of inflorescences in 2007.
- Veg.07
Number of stems without inflorescences in 2007.
- Pod.07
Number of fruits in 2007.
- Inf2.08
Number of double inflorescences in 2008.
- Inf.08
Number of inflorescences in 2008.
- Veg.08
Number of stems without inflorescences in 2008.
- Pod.08
Number of fruits in 2008.
- Inf2.09
Number of double inflorescences in 2009.
- Inf.09
Number of inflorescences in 2009.
- Veg.09
Number of stems without inflorescences in 2009.
- Pod.09
Number of fruits in 2009.
Source
Shefferson, R.P., R. Mizuta, and M.J. Hutchings. 2017. Predictingevolution in response to climate change: the example of sprouting probabilityin three dormancy-prone orchid species.Royal Society Open Science 4(1):160647.
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") lambda3(cypmatrix2r)Demographic Dataset ofCypripedium candidum Population, in VerticalFormat
Description
A dataset containing the states and fates ofCypripedium candidum (white lady's slipper orchids), family Orchidaceae, from a population in Illinois, USA, resulting from monitoring that occurred annually between 2004 and 2009. Same dataset ascypdata, but arranged in an ahistoricalvertical format.
Usage
data(cypvert)Format
A data frame with 77 individuals, 322 rows, and 14 variables. Eachrow corresponds to a specific two-year transition for a specific individual.Variable codes are similar to those forcypdata, but use.2 toidentify occasiont and.3 to identify occasiont+1.
- plantid
A numeric variable giving a unique number to each individual.
- patch
A variable refering to patch within the population.
- X
An X coordinate for the plant within the population.
- Y
A Y coordinate for the plant within the population.
- censor
A variable coding for whether the data point is valid. Anentry of 1 means that it is so.
- year2
Year in occasiont.
- Inf2.2
Number of double inflorescences in occasiont.
- Inf.2
Number of inflorescences in occasiont.
- Veg.2
Number of stems without inflorescences in occasiont.
- Pod.2
Number of fruits in occasiont.
- Inf2.3
Number of double inflorescences in occasiont+1.
- Inf.3
Number of inflorescences in occasiont+1.
- Veg.3
Number of stems without inflorescences in occasiont+1.
- Pod.3
Number of fruits in occasiont+1.
Source
Shefferson, R.P., R. Mizuta, and M.J. Hutchings. 2017. Predictingevolution in response to climate change: the example of sprouting probabilityin three dormancy-prone orchid species.Royal Society Open Science 4(1):160647.
Examples
data(cypvert)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_v2 <- historicalize3(data = cypvert, patchidcol = "patch", individcol = "plantid", year2col = "year2", sizea2col = "Inf2.2", sizea3col = "Inf2.3", sizeb2col = "Inf.2", sizeb3col = "Inf.3", sizec2col = "Veg.2", sizec3col = "Veg.3", repstra2col = "Inf2.2", repstra3col = "Inf2.3", repstrb2col = "Inf.2", repstrb3col = "Inf.3", feca2col = "Pod.2", feca3col = "Pod.3", repstrrel = 2, stageassign = cypframe_raw, stagesize = "sizeadded", censorcol = "censor", censor = FALSE, NAas0 = TRUE, NRasRep = TRUE, reduce = 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_v2, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2"), size = c("size3added", "size2added"), supplement = cypsupp2r, yearcol = "year2", patchcol = "patchid", indivcol = "individ") lambda3(cypmatrix2r)Delete Matrices from lefkoMat or lefkoMatList Object
Description
Functiondelete_lM() deletes matrices fromlefkoMat andlefkoMatList objects.
Usage
delete_lM(lM, mat_num = NA, pop = NA, patch = NA, year = NA)Arguments
lM | The |
mat_num | Either a single integer corresponding to the matrix to removewithin the |
pop | The population designation for matrices to remove. Only used if |
patch | The patch designation for matrices to remove. Only used if |
year | The timet designation for matrices to remove. Only usedif |
Value
AlefkoMat orlefkoMatList object in which the matricesspecified inlM have been removed. Note that, if applying to alefkoMatList object, then matrices will be deleted from ALL compositelefkoMat objects.
Notes
Ifmat_num is not provided, then at least one ofpop,patch, oryear must be provided. If at least two ofpop,patch, andyear are provided, then functiondetele_lM()will identify matrices to remove as the intersection of provided inputs.
See Also
add_lM()
Examples
# These matrices are of 9 populations of the plant species Anthyllis# vulneraria, and were originally published in Davison et al. (2010) Journal# of Ecology 98:255-267 (doi: 10.1111/j.1365-2745.2009.01611.x).sizevector <- c(1, 1, 2, 3) # These sizes are not from the original paperstagevector <- c("Sdl", "Veg", "SmFlo", "LFlo")repvector <- c(0, 0, 1, 1)obsvector <- c(1, 1, 1, 1)matvector <- c(0, 1, 1, 1)immvector <- c(1, 0, 0, 0)propvector <- c(0, 0, 0, 0)indataset <- c(1, 1, 1, 1)binvec <- c(0.5, 0.5, 0.5, 0.5)anthframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)# POPN C 2003-2004XC3 <- matrix(c(0, 0, 1.74, 1.74,0.208333333, 0, 0, 0.057142857,0.041666667, 0.076923077, 0, 0,0.083333333, 0.076923077, 0.066666667, 0.028571429), 4, 4, byrow = TRUE)# 2004-2005XC4 <- matrix(c(0, 0, 0.3, 0.6,0.32183908, 0.142857143, 0, 0,0.16091954, 0.285714286, 0, 0,0.252873563, 0.285714286, 0.5, 0.6), 4, 4, byrow = TRUE)# 2005-2006XC5 <- matrix(c(0, 0, 0.50625, 0.675,0, 0, 0, 0.035714286,0.1, 0.068965517, 0.0625, 0.107142857,0.3, 0.137931034, 0, 0.071428571), 4, 4, byrow = TRUE)# POPN E 2003-2004XE3 <- matrix(c(0, 0, 2.44, 6.569230769,0.196428571, 0, 0, 0,0.125, 0.5, 0, 0,0.160714286, 0.5, 0.133333333, 0.076923077), 4, 4, byrow = TRUE)XE4 <- matrix(c(0, 0, 0.45, 0.646153846,0.06557377, 0.090909091, 0.125, 0,0.032786885, 0, 0.125, 0.076923077,0.049180328, 0, 0.125, 0.230769231), 4, 4, byrow = TRUE)XE5 <- matrix(c(0, 0, 2.85, 3.99,0.083333333, 0, 0, 0,0, 0, 0, 0,0.416666667, 0.1, 0, 0.1), 4, 4, byrow = TRUE)mats_list <- list(XC3, XC4, XC5, XE3, XE4, XE5)yr_ord <- c(1, 2, 3, 1, 2, 3)pch_ord <- c(1, 1, 1, 2, 2, 2)anth_lefkoMat <- create_lM(mats_list, anthframe, hstages = NA, historical = FALSE, poporder = 1, patchorder = pch_ord, yearorder = yr_ord) smaller_anth_lM <- delete_lM(anth_lefkoMat, patch = 2)Set Density Dependence Relationships in Matrix Elements
Description
Functiondensity_input() provides all necessary data to incorporatedensity dependence into alefkoMat object, a list of matrices, or asingle matrix. Four forms of density dependence are allowed, including theRicker function, the Beverton-Holt function, the Usher function, and thelogistic function. In each case, density must have an effect with a delay ofat least one time-step (see Notes). The resulting data frame provides aguide for otherlefko3 functions to modify matrix elements bydensity.
Usage
density_input( mpm, stage3 = NULL, stage2 = NULL, stage1 = NULL, age2 = NULL, style = NULL, time_delay = NULL, alpha = NULL, beta = NULL, type = NULL, type_t12 = NULL)Arguments
mpm | The |
stage3 | A vector showing the name or number of the stage in occasiont+1 in the transitions to be affected by density. Abbreviations forgroups of stages are also usable (see Notes). |
stage2 | A vector showing the name or number of the stage in occasiont in the transition to be affected by density. Abbreviations forgroups of stages are also usable (see Notes). |
stage1 | A vector showing the name or number of the stage in occasiont-1 in the transition to be affected by density. Only needed if ahistorical MPM is used. Abbreviations for groups of stages are also usable(see Notes). |
age2 | A vector showing the age of the stage in occasiont in thetransition to be affected by density. Only needed if an age-by-stage MPM isused. |
style | A vector coding for the style of density dependence on eachtransition subject to density dependence. Options include |
time_delay | An integer vector indicating the number of occasions backon which density dependence operates. Defaults to |
alpha | A vector indicating the numeric values to use as thealpha term in the two parameter Ricker, Beverton-Holt, or Usher function, orthe value of the carrying capacityK to use in the logistic equation(see |
beta | A vector indicating the numeric values to use as the beta term inthe two parameter Ricker, Beverton-Holt, or Usher function. Used to indicatewhether to useK as a hard limit in the logistic equation (see section |
type | A vector denoting the kind of transition between occasionst andt+1 to be replaced. This should be entered as |
type_t12 | An optional vector denoting the kind of transition betweenoccasionst-1 andt. Only necessary if a historical MPM indeVries format is desired. This should be entered as |
Value
A data frame of classlefkoDens. This object can be used asinput in functionprojection3().
Variables in this object include the following:
stage3 | Stage at occasiont+1 in the transition to be replaced. |
stage2 | Stage at occasiont in the transition to be replaced. |
stage1 | Stage at occasiont-1 in the transition to be replaced,if applicable. |
age2 | Age at occasiont in the transition to be replaced, ifapplicable. |
style | Style of density dependence, coded as 1, 2, 3, or 4 for theRicker, Beverton-Holt, Usher, or logistic function, respectively. |
time_delay | The time delay on density dependence, in time steps. |
alpha | The value of alpha in the Ricker, Beverton-Holt, or Usherfunction, or the value of carrying capacity,K, in the logisticfunction. |
beta | The value of beta in the Ricker, Beverton-Holt, or Usherfunction. |
type | Designates whether the transition from occasiont tooccasiont+1 is a survival transition probability (1), or a fecundityrate (2). |
type_t12 | Designates whether the transition from occasiont-1 tooccasiont is a survival transition probability (1), a fecundity rate(2). |
Notes
This function provides inputs when density dependence is operationalizeddirectly on matrix elements. It can be used in bothprojection3() andf_projection3(). Users wishing to modify vital rate functions bydensity dependence functions for use in function-based projections withfunctionf_projection3() should use functiondensity_vr() toprovide the correct inputs.
The parametersalpha andbeta are applied according to thetwo-parameter Ricker function, the two-parameter Beverton-Holt function, thetwo-parameter Usher function, or the one-parameter logistic function.Although the default is that a 1 time step delay is assumed, greater timedelays can be set through thetime_delay option.
Entries instage3,stage2, andstage1 can includeabbreviations for groups of stages. Userep if all reproductive stagesare to be used,nrep if all mature but non-reproductive stages are tobe used,mat if all mature stages are to be used,immat if allimmature stages are to be used,prop if all propagule stages are to beused,npr if all non-propagule stages are to be used,obs ifall observable stages are to be used,nobs if all unobservable stagesare to be used, and leave empty or useall if all stages in stageframeare to be used.
When using the logistic function, it is possible that the time delay used indensity dependent simulations will cause matrix elements to become negative.To prevent this behavior, set the associatedbeta term to1.0.Doing so will setK as the hard limit in the logistic equation,essentially setting a minimum limit at0 for all matrix elementsmodified.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)e3d <- density_input(ehrlen3mean, stage3 = c("Sd", "Sdl"), stage2 = c("rep", "rep"), stage1 = c("all", "all"), style = 1, time_delay = 1, alpha = 1, beta = 0, type = c(2, 2), type_t12 = c(1, 1))lathproj <- projection3(ehrlen3, nreps = 5, stochastic = TRUE, substoch = 2, density = e3d)Set Density Dependence Relationships in Vital Rates
Description
Functiondensity_vr() provides all necessary data to incorporatedensity dependence into the vital rate functions used to create matrices infunction-based projections using functionf_projection3(). Four formsof density dependence are allowed, including the Ricker function, theBeverton-Holt function, the Usher function, and the logistic function. Ineach case, density must have an effect with at least a one time-step delay(see Notes).
Usage
density_vr( density_yn = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), style = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), time_delay = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), alpha = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), beta = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))Arguments
density_yn | A 14 element logical vector denoting whether each vitalrate is subject to density dependence. The order of vital rates is: survivalprobability, observation probability, primary size transition, secondary sizetransition, tertiary size transition, reproductive status probability,fecundity rate, juvenile survival probability, juvenile observationprobability, juvenile primary size transition, juvenile secondary sizetransition, juvenile tertiary size transition, juvenile reproductive statusprobability, and juvenile maturity status probability. Defaults to a vectorof 14 |
style | A 14 element vector coding for the style of density dependenceon each vital rate. Options include |
time_delay | A 14 element vector indicating the number of occasions backon which density dependence operates. Defaults to 14 values of |
alpha | A 14 element vector indicating the numeric values to use as thealpha term in the two parameter Ricker, Beverton-Holt, or Usher function, orthe value of the carrying capacityK to use in the logistic equation(see |
beta | A 14 element vector indicating the numeric values to use as thebeta term in the two parameter Ricker, Beverton-Holt, or Usher function. Usedto indicate whether to useK as a hard limit in the logistic equation(see |
Value
A data frame of classlefkoDensVR with 14 rows, one for eachvital rate in the order of: survival probability, observation probability,primary size transition, secondary size transition, tertiary size transition,reproductive status probability, fecundity rate, juvenile survivalprobability, juvenile observation probability, juvenile primary sizetransition, juvenile secondary size transition, juvenile tertiary sizetransition, juvenile reproductive status probability, and juvenile maturitystatus probability. This object can be used as input in functionf_projection3().
Variables in this object include the following:
vital_rate | The vital rate to be modified. |
density_yn | Logical value indicating whether vital rate will be subjectto density dependence. |
style | Style of density dependence, coded as |
time_delay | The time delay on density dependence, in time steps. |
alpha | The value of alpha in the Ricker, Beverton-Holt, or Usherfunction, or the value of carrying capacity,K, in the logisticfunction. |
beta | The value of beta in the Ricker, Beverton-Holt, or Usherfunction. |
Notes
This function provides inputs when density dependence is operationalizeddirectly on vital rates. It can be used only in functionf_projection3(). Users wishing to modify matrix elements directly bydensity dependence functions for use in function-based or raw projectionswith functionsprojection3() andf_projection3() should usefunctiondensity_input() to provide the correct inputs.
The parametersalpha andbeta are applied according to thetwo-parameter Ricker function, the two-parameter Beverton-Holt function, thetwo-parameter Usher function, or the one-parameter logistic function.Although the default is that a 1 time step delay is assumed, greater timedelays can be set through thetime_delay option.
When using the logistic function, it is possible that the time delay used indensity dependent simulations will cause matrix elements to become negative.To prevent this behavior, set the associatedbeta term to1.0.Doing so will setK as the hard limit in the logistic equation,essentially setting a minimum limit at0 for all matrix elementsmodified.
See Also
Examples
data(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathvertln_adults <- subset(lathvertln, stage2index > 2)surv_model <- glm(alive3 ~ sizea2 + sizea1 + as.factor(patchid) + as.factor(year2), data = lathvertln_adults, family = "binomial")obs_data <- subset(lathvertln_adults, alive3 == 1)obs_model <- glm(obsstatus3 ~ as.factor(patchid), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)siz_model <- lm(sizea3 ~ sizea2 + sizea1 + repstatus1 + as.factor(patchid) + as.factor(year2), data = size_data)reps_model <- glm(repstatus3 ~ sizea2 + sizea1 + as.factor(patchid) + as.factor(year2), data = size_data, family = "binomial")fec_data <- subset(lathvertln_adults, repstatus2 == 1)fec_model <- glm(feca2 ~ sizea2 + sizea1 + repstatus1 + as.factor(patchid), data = fec_data, family = "poisson")lathvertln_juvs <- subset(lathvertln, stage2index < 3)jsurv_model <- glm(alive3 ~ as.factor(patchid), data = lathvertln_juvs, family = "binomial")jobs_data <- subset(lathvertln_juvs, alive3 == 1)jobs_model <- glm(obsstatus3 ~ 1, family = "binomial", data = jobs_data)jsize_data <- subset(jobs_data, obsstatus3 == 1)jsiz_model <- lm(sizea3 ~ as.factor(year2), data = jsize_data)jrepst_model <- 0jmatst_model <- 1mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[3] <- "patchid"mod_params$modelparams[4] <- "alive3"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "feca2"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[13] <- "sizea1"mod_params$modelparams[18] <- "repstatus2"mod_params$modelparams[19] <- "repstatus1"lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "mat", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "Sdl", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "Sd", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, "Sdl", NA, NA), eststage1 = c(NA, NA, NA, NA, "Sdl", NA, NA), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframeln, historical = TRUE)# While we do not use MPMs to initialize f_projections3(), we do use MPMs to# initialize functions start_input() and density_input().lathmat3ln <- flefko3(year = "all", patch = "all", data = lathvertln, stageframe = lathframeln, supplement = lathsupp3, paramnames = mod_params, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, repst_model = reps_model, fec_model = fec_model, jsurv_model = jsurv_model, jobs_model = jobs_model, jsize_model = jsiz_model, jrepst_model = jrepst_model, jmatst_model = jmatst_model, reduce = FALSE)e3m_sv <- start_input(lathmat3ln, stage2 = "Sd", stage1 = "Sd", value = 1000)dyn7 <- c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)dst7 <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)dal7 <- c(0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)dbe7 <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)e3d_vr <- density_vr(density_yn = dyn7, style = dst7, alpha = dal7, beta = dbe7)trial7_dvr_1 <- f_projection3(format = 1, data = lathvertln, supplement = lathsupp3, paramnames = mod_params, stageframe = lathframeln, nreps = 2, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, repst_model = reps_model, fec_model = fec_model, jsurv_model = jsurv_model, jobs_model = jobs_model, jsize_model = jsiz_model, jrepst_model = jrepst_model, jmatst_model = jmatst_model, times = 100, stochastic = TRUE, standardize = FALSE, growthonly = TRUE, integeronly = FALSE, substoch = 0, sp_density = 0, start_frame = e3m_sv, density_vr = e3d_vr)Calculate Difference Matrices Between lefkoMat Objects of Equal Dimensions
Description
Functiondiff_lM() takes twolefkoMat objects with completelyequal dimensions, including both the size and number of matrices, andgives the matrix differences between each corresponding set.
Usage
diff_lM(mpm1, mpm2)Arguments
mpm1 | The first |
mpm2 | The second |
Value
An object of classlefkoDiff, which is a set ofA,U, andF matrices corresponding to the differences between eachset of matrices, followed by thehstages,ahstages, andlabels elements from each inputlefkoMat object. Elementslabelled with a1 at the end refer tompm1, while thoselabelled2 at the end refer tompm2.
Notes
The exact difference is calculated as the respective matrix inmpm1minus the corresponding matrix inmpm2.
This function first checks to see if the number of matrices is the same, andthen whether the matrix dimensions are the same. If the two sets differ in atleast one of these characteristics, then the function will yield a fatalerror.
If the lengths and dimensions of the inputlefkoMat objects are thesame, then this will check if thelabels element is essentially thesame. If not, then the function will yield a warning, but will still operate.
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)seeds_per_pod <- 5000cypsupp2_raw <- supplemental(stage3 = c("SD", "P1", "P2", "P3", "SL", "SL", "D", "XSm", "SD", "P1"), stage2 = c("SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "rep", "rep"), eststage3 = c(NA, NA, NA, NA, NA, NA, "D", "XSm", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, "XSm", "XSm", NA, NA), givenrate = c(0.03, 0.15, 0.1, 0.1, 0.1, 0.05, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, (0.5 * seeds_per_pod), (0.5 * seeds_per_pod)), type =c(1, 1, 1, 1, 1, 1, 1, 1, 3, 3), stageframe = cypframe_raw, historical = FALSE)cypsupp3_raw <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "SL", "SL", "D", "D", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "SL", "P3", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, "XSm", "D", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", NA, NA), givenrate = c(0.01, 0.05, 0.10, 0.20, 0.1, 0.1, 0.05, 0.05, 0.05, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, (0.5 * seeds_per_pod), (0.5 * seeds_per_pod)), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix2rp <- rlefko2(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2"), size = c("size3added", "size2added"), supplement = cypsupp2_raw, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix2r <- rlefko2(data = cypraw_v1, stageframe = cypframe_raw, year = "all", stages = c("stage3", "stage2"), size = c("size3added", "size2added"), supplement = cypsupp2_raw, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix3rp <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3_raw, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3_raw, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypmatrix2r_3 <- hist_null(cypmatrix2r)cypmatrix2r_3 <- delete_lM(cypmatrix2r_3, year = 2004)diff_r <- diff_lM(cypmatrix3r, cypmatrix2r_3)cypmatrix2rp_3 <- hist_null(cypmatrix2rp)cypmatrix2rp_3 <- delete_lM(cypmatrix2rp_3, year = 2004)diff_rp <- diff_lM(cypmatrix3rp, cypmatrix2rp_3)Edit lefkoMat or lefkoMatList Object based on Supplemental Data
Description
Functionedit_lM() edits existinglefkoMat andlefkoMatList objects with external data supplied by the user. Theeffects are similar to functionsupplemental(), thoughfunctionedit_lM() allows individuals matrices withinlefkoMatobjects to be edited after creation, whilesupplemental()provides external data that modifies all matrices within alefkoMatobject, or within all thelefkoMat objects within alefkoMatList object.
Usage
edit_lM( mpm, pop = NULL, patch = NULL, year2 = NULL, stage3 = NULL, stage2 = NULL, stage1 = NULL, age2 = NULL, eststage3 = NULL, eststage2 = NULL, eststage1 = NULL, estage2 = NULL, givenrate = NULL, offset = NULL, multiplier = NULL, type = NULL, type_t12 = NULL, target_mpm = NULL)Arguments
mpm | The |
pop | A string vector denoting the populations to be edited. Defaultsto |
patch | A string vector denoting the patches to be edited. Defaultsto |
year2 | A string vector denoting the years to be edited. Defaultsto |
stage3 | The name of the stage in occasiont+1 in the transitionto be replaced. Abbreviations for groups of stages are also usable (see |
stage2 | The name of the stage in occasiont in the transitionto be replaced. Abbreviations for groups of stages are also usable (see |
stage1 | The name of the stage in occasiont-1 in the transitionto be replaced. Only needed if a historical matrix is to be produced.Abbreviations for groups of stages are also usable (see |
age2 | An integer vector of the ages in occasiont to use intransitions to be changed or replaced. Required for all age- andage-by-stage MPMs. |
eststage3 | The name of the stage to replace |
eststage2 | The name of the stage to replace |
eststage1 | The name of the stage to replace |
estage2 | The age at timet to replace |
givenrate | A fixed rate or probability to replace for the transitiondescribed by |
offset | A numeric vector of fixed numeric values to add to thetransitions described by |
multiplier | A vector of numeric multipliers for fecundity or for proxytransitions. Defaults to |
type | A vector denoting the kind of transition between occasionst andt+1 to be replaced. This should be entered as |
type_t12 | An optional vector denoting the kind of transition betweenoccasionst-1 andt. Only necessary if a historical MPM indeVries format is desired. This should be entered as |
target_mpm | If modifying a |
Value
An edited copy of the original MPM is returned, also as alefkoMat object.
Notes
Entries instage3,stage2, andstage1 can includeabbreviations for groups of stages. Userep if all reproductivestages are to be used,nrep if all mature but non-reproductive stagesare to be used,mat if all mature stages are to be used,immatif all immature stages are to be used,prop if all propagule stagesare to be used,npr if all non-propagule stages are to be used,obs if all observable stages are to be used,nobs if allunobservable stages are to be used, and leave empty or useall if allstages in stageframe are to be used. Also usegroupX to denote allstages in group X (e.g.group1 will use all stages in the respectivestageframe's group 1).
See Also
Examples
data(cypdata)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", age_offset = 3, NAas0 = TRUE, NRasRep = TRUE)cyp_rl <- rleslie(data = cypraw_v1, start_age = 0, last_age = 6, continue = TRUE, fecage_min = 3, year = "all", pop = NA, patch = "all", yearcol = "year2", patchcol = "patchid", indivcol = "individ")ddd1 <- edit_lM(cyp_rl, age2 = c(0, 1, 2, 3, 4, 5, 6), givenrate = c(0.25, 0.25, 0.4, 0.4, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 2000, 2000, 2000), type = c(1, 1, 1, 1, 3, 3, 3)) ddd1 <- edit_lM(ddd1, age2 = 6, multiplier = 1.5, type = 3, patch = "B", year2 = "2005")Estimate Elasticity of Population Growth Rate to Matrix Elements
Description
elasticity3() is a generic function that returns the elasticity ofthe population growth rate to the elements of the matrices in a matrixpopulation model. Currently, this function estimates both deterministic andstochastic elasticities, where the growth rate is\lambda in the formercase and the log of the stochastic\lambda in the latter case. Thisfunction is made to handle very large and sparse matrices supplied aslefkoMat objects, as lists of matrices, and as individual matrices.
Usage
elasticity3(mats, ...)Arguments
mats | A lefkoMat object, a population projection matrix, or a list ofpopulation projection matrices for which the stable stage distribution isdesired. |
... | Other parameters. |
Value
The value returned depends on the class of themats argument.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)elasticity3(ehrlen3mean)# Cypripedium exampledata(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")elasticity3(cypmatrix2r)Estimate Elasticity of Population Growth Rate of a Single Sparse Matrix
Description
elasticity3.dgCMatrix() returns the elasticities of lambda to elementsof a single matrix. Because this handles only one matrix, the elasticitiesare inherently deterministic and based on the dominant eigen value as thebest metric of the population growth rate.
Usage
## S3 method for class 'dgCMatrix'elasticity3(mats, sparse = "auto", ...)Arguments
mats | An object of class |
sparse | A text string indicating whether to use sparse matrix encoding( |
... | Other parameters. |
Value
This function returns a single elasticity matrix indgCMatrixformat.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)elasticity3(ehrlen3mean$A[[1]])Estimate Elasticity of Population Growth Rate of a lefkoMat Object
Description
elasticity3.lefkoMat() returns the elasticities of population growthrate to elements of all$A matrices in an object of classlefkoMat. If deterministic, then\lambda is taken as thepopulation growth rate. If stochastic, then stochastic\lambda, orthe stochastic growth rate, is taken as the population growth rate. Thisfunction can handle large and sparse matrices, and so can be used with largehistorical matrices, IPMs, age x stage matrices, as well as smallerahistorical matrices.
Usage
## S3 method for class 'lefkoMat'elasticity3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, sparse = "auto", append_mats = FALSE, ...)Arguments
mats | An object of class |
stochastic | A logical value determining whether to conduct adeterministic (FALSE) or stochastic (TRUE) elasticity analysis. Defaults toFALSE. |
times | The number of occasions to project forward in stochasticsimulation. Defaults to 10,000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed in stochastic projection. |
sparse | A text string indicating whether to use sparse matrix encoding( |
append_mats | A logical value indicating whether to include the originalA, U, and F matrices in the output |
... | Other parameters. |
Value
This function returns an object of classlefkoElas, which is alist with 8 elements. The first,h_elasmats, is a list of historicalelasticity matrices (NULL if an ahMPM is used as input). The second,ah_elasmats, is a list of either ahistorical elasticity matrices if anahMPM is used as input, or, if an hMPM is used as input, then the result is alist of elasticity matrices in which historical elasticities have been summedby the stage in occasionst andt+1 to producehistorically-corrected elasticity matrices, which are equivalent in dimensionto ahistorical elasticity matrices but reflect the effects of stage inoccasiont-1. The third element,hstages, is a data frameshowing historical stage pairs (NULL if ahMPM used as input). The fourthelement,agestages, shows age-stage combinations in the order used inage-by-stage MPMs, if suppled. The fifth element,ahstages, is a dataframe showing the order of ahistorical stages. The last 3 elements are the A,U, and F portions of the input.
Notes
Deterministic elasticities are estimated as eqn. 9.72 in Caswell (2001,Matrix Population Models). Stochastic elasticities are estimated as eqn.14.99 in Caswell (2001). Note that stochastic elasticities are of thestochastic\lambda, while stochastic sensitivities are with regard tothe log of the stochastic\lambda.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
Thetime_weights,steps, andforce_sparse arguments arenow deprecated. Instead, please use thetweights,times, andsparse arguments.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")elasticity3(ehrlen3, stochastic = TRUE)# Cypripedium exampledata(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")elasticity3(cypmatrix2r)Estimate Elasticity of Population Growth Rate of a lefkoMatList Object
Description
elasticity3.lefkoMatList() returns the elasticities of population growthgrowth rate to elements of allA matrices in all bootstrappedlefkoMat objects within an entered object of classlefkoMatList. If deterministic, then\lambda is taken as thepopulation growth rate. If stochastic, then stochastic\lambda, orthe stochastic growth rate, is taken as the population growth rate. Thisfunction can handle large and sparse matrices, and so can be used with largehistorical matrices, IPMs, age x stage matrices, as well as smallerahistorical matrices.
Usage
## S3 method for class 'lefkoMatList'elasticity3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, sparse = "auto", append_mats = FALSE, ...)Arguments
mats | An object of class |
stochastic | A logical value determining whether to conduct adeterministic (FALSE) or stochastic (TRUE) elasticity analysis. Defaults toFALSE. |
times | The number of occasions to project forward in stochasticsimulation. Defaults to 10,000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed in stochastic projection. |
sparse | A text string indicating whether to use sparse matrix encoding( |
append_mats | A logical value indicating whether to include the originalA, U, and F matrices in the output |
... | Other parameters. |
Value
This function returns a list with two elements. The first is anobject of classlefkoElas that contains the mean elasticity matricesof the bootstrapped sensitivity matrices. The second is a list containinglefkoElas objects giving the elasticity matrices of all bootstrappedmatrices.
Within these lists are objects of classlefkoElas, which are comprisedof lists of 8 elements. The first,h_elasmats, is a list of historicalelasticity matrices (NULL if an ahMPM is used as input). The second,ah_elasmats, is a list of either ahistorical elasticity matrices if anahMPM is used as input, or, if an hMPM is used as input, then the result is alist of elasticity matrices in which historical elasticities have been summedby the stage in occasionst andt+1 to producehistorically-corrected elasticity matrices, which are equivalent in dimensionto ahistorical elasticity matrices but reflect the effects of stage inoccasiont-1. The third element,hstages, is a data frameshowing historical stage pairs (NULL if ahMPM used as input). The fourthelement,agestages, shows age-stage combinations in the order used inage-by-stage MPMs, if suppled. The fifth element,ahstages, is a dataframe showing the order of ahistorical stages. The last 3 elements are the A,U, and F portions of the input.
Notes
Deterministic elasticities are estimated as eqn. 9.72 in Caswell (2001,Matrix Population Models). Stochastic elasticities are estimated as eqn.14.99 in Caswell (2001). Note that stochastic elasticities are of thestochastic\lambda, while stochastic sensitivities are with regard tothe log of the stochastic\lambda.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
Thetime_weights,steps, andforce_sparse arguments arenow deprecated. Instead, please use thetweights,times, andsparse arguments.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathvert_boot <- bootstrap3(lathvert, reps = 3)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3_boot <- rlefko3(data = lathvert_boot, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")elasticity3(ehrlen3_boot, stochastic = TRUE)# Cypripedium exampledata(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)cypraw_v1_boot <- bootstrap3(cypraw_v1, reps = 3)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_boot <- rlefko2(data = cypraw_v1_boot, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added"), supplement = cypsupp2r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")elasticity3(cypmatrix2r_boot)Estimate Elasticity of Population Growth Rate of a List of Matrices
Description
elasticity3.list() returns the elasticities of lambda to elementsof a single matrix. This function can handle large and sparse matrices, and so can be used with large historical matrices, IPMs, age x stage matrices,as well as smaller ahistorical matrices.
Usage
## S3 method for class 'list'elasticity3( mats, stochastic = FALSE, times = 10000, tweights = NA, historical = FALSE, seed = NA, sparse = "auto", append_mats = FALSE, ...)Arguments
mats | A list of objects of class |
stochastic | A logical value determining whether to conduct adeterministic (FALSE) or stochastic (TRUE) elasticity analysis. Defaults toFALSE. |
times | The number of occasions to project forward in stochasticsimulation. Defaults to 10,000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
historical | A logical value denoting whether the input matrices arehistorical. Defaults to FALSE. |
seed | A number to use as a random number seed in stochastic projection. |
sparse | A text string indicating whether to use sparse matrix encoding( |
append_mats | A logical value indicating whether to include the originalmatrices input as object |
... | Other parameters. |
Value
This function returns an object of classlefkoElas, which is alist with 8 elements. The first,h_elasmats, is a list of historicalelasticity matrices, though in the standard list case it returns a NULLvalue. The second,ah_elasmats, is a list of ahistorical elasticitymatrices. The third element,hstages, the fourth element,agestages, and the fifth element,ahstages, are set to NULL.The last 3 elements are the original A matrices in element A, followed byNULL values for the U and F elements.
Notes
Deterministic elasticities are estimated as eqn. 9.72 in Caswell (2001,Matrix Population Models). Stochastic elasticities are estimated as eqn.14.99 in Caswell (2001). Note that stochastic elasticities are of stochastic\lambda, while stochastic sensitivities are with regard to the log ofthe stochastic\lambda.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
Thetime_weights,steps, andforce_sparse arguments arenow deprecated. Instead, please use thetweights,times, andsparse arguments.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")elasticity3(ehrlen3$A, stochastic = TRUE)# Cypripedium exampledata(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")elasticity3(cypmatrix2r$A)Estimate Elasticity of Population Growth Rate of a Single Matrix
Description
elasticity3.matrix() returns the elasticities of lambda to elementsof a single matrix. Because this handles only one matrix, the elasticitiesare inherently deterministic and based on the dominant eigen value as thebest metric of the population growth rate. This function can handle large andsparse matrices, and so can be used with large historical matrices, IPMs,age x stage matrices, as well as smaller ahistorical matrices.
Usage
## S3 method for class 'matrix'elasticity3(mats, sparse = "auto", ...)Arguments
mats | An object of class |
sparse | A text string indicating whether to use sparse matrix encoding( |
... | Other parameters. |
Value
This function returns a single elasticity matrix.
Notes
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
Theforce_sparse argument is now deprecated. Please usesparseinstead.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)elasticity3(ehrlen3mean$A[[1]])Project Function-based Matrix Projection Model
Description
Functionf_projection3() develops and projects function-based matrixmodels. Unlikeprojection3(), which uses matrices provided asinput via already createdlefkoMat objects, functionf_projection3() creates matrices at each time step from vital ratemodels and parameter inputs provided. Projections may be stochastic or not,and may be density dependent in either case. Also handles replication.
Usage
f_projection3( format, prebreeding = TRUE, start_age = NA_integer_, last_age = NA_integer_, fecage_min = NA_integer_, fecage_max = NA_integer_, cont = TRUE, stochastic = FALSE, standardize = FALSE, growthonly = TRUE, repvalue = FALSE, integeronly = FALSE, substoch = 0L, ipm_cdf = TRUE, nreps = 1L, times = 10000L, repmod = 1, exp_tol = 700, theta_tol = 1e+08, random_inda = FALSE, random_indb = FALSE, random_indc = FALSE, err_check = FALSE, quiet = FALSE, data = NULL, stageframe = NULL, supplement = NULL, repmatrix = NULL, overwrite = NULL, modelsuite = NULL, paramnames = NULL, year = NULL, patch = NULL, sp_density = NULL, ind_terms = NULL, ann_terms = NULL, dev_terms = NULL, surv_model = NULL, obs_model = NULL, size_model = NULL, sizeb_model = NULL, sizec_model = NULL, repst_model = NULL, fec_model = NULL, jsurv_model = NULL, jobs_model = NULL, jsize_model = NULL, jsizeb_model = NULL, jsizec_model = NULL, jrepst_model = NULL, jmatst_model = NULL, start_vec = NULL, start_frame = NULL, tweights = NULL, density = NULL, density_vr = NULL, stage_weights = NULL, sparse = NULL)Arguments
format | An integer indicating the kind of function-based MPM to create.Possible choices include: |
prebreeding | A logical value indicating whether the life history modelis a pre-breeding model. Only used in Leslie and age-by-stage MPMs. Defaultsto |
start_age | The age from which to start the matrix. Defaults to |
last_age | The final age to use in the matrix. Defaults to |
fecage_min | The minimum age at which reproduction is possible. Defaultsto |
fecage_max | The maximum age at which reproduction is possible. Defaultsto |
cont | A logical value designating whether to allow continued survivalof individuals past the final age noted in the stageframe, using the demographic characteristics of the final age. Defaults to |
stochastic | A logical value denoting whether to conduct a stochasticprojection or a deterministic / cyclical projection. |
standardize | A logical value denoting whether to re-standardize thepopulation size to |
growthonly | A logical value indicating whether to produce only theprojected population size at each occasion ( |
repvalue | A logical value indicating whether to calculate reproductivevalue vectors at each time step. Can only be set to |
integeronly | A logical value indicating whether to round the number ofindividuals projected in each stage at each occasion to the nearestinteger. Defaults to |
substoch | An integer value indicating whether to force survival-transition matrices to be substochastic in density dependent and densityindependent simulations. Defaults to |
ipm_cdf | A logical value indicating whether to estimate sizetransitions using the cumulative density function in cases with continuousdistributions. Defaults to |
nreps | The number of replicate projections. Defaults to |
times | Number of occasions to iterate per replicate. Defaults to |
repmod | A scalar multiplier of fecundity. Defaults to |
exp_tol | A numeric value used to indicate a maximum value to setexponents to in the core kernel to prevent numerical overflow. Defaults to |
theta_tol | A numeric value used to indicate a maximum value to theta asused in the negative binomial probability density kernel. Defaults to |
random_inda | A logical value denoting whether to treat individualcovariate |
random_indb | A logical value denoting whether to treat individualcovariate |
random_indc | A logical value denoting whether to treat individualcovariate |
err_check | A logical value indicating whether to append extra outputfor debugging purposes. Defaults to |
quiet | A logical value indicating whether warning messages should besuppressed. Defaults to |
data | The historical vertical demographic data frame used to estimatevital rates (class |
stageframe | An object of class |
supplement | An optional data frame of class |
repmatrix | An optional reproduction matrix. This matrix is composedmostly of |
overwrite | An optional data frame developed with the |
modelsuite | A |
paramnames | A data frame with three columns, the first describing allterms used in linear modeling, the second (must be called |
year | Either a single integer value corresponding to the year toproject, or a vector of |
patch | A value of |
sp_density | Either a single numeric value of spatial density to use invital rate models in all time steps, or a vector of |
ind_terms | An optional data frame with 3 columns and |
ann_terms | An optional data frame with 3 columns and |
dev_terms | An optional data frame with 14 columns and |
surv_model | A linear model predicting survival probability. This can be a model of class |
obs_model | A linear model predicting sprouting or observationprobability. This can be a model of class |
size_model | A linear model predicting primary size. This can be a modelof class |
sizeb_model | A linear model predicting secondary size. This can be amodel of class |
sizec_model | A linear model predicting tertiary size. This can be amodel of class |
repst_model | A linear model predicting reproduction probability. This can be a model of class |
fec_model | A linear model predicting fecundity. This can be a model ofclass |
jsurv_model | A linear model predicting juvenile survival probability.This can be a model of class |
jobs_model | A linear model predicting juvenile sprouting or observationprobability. This can be a model of class |
jsize_model | A linear model predicting juvenile primary size. Thiscan be a model of class |
jsizeb_model | A linear model predicting juvenile secondary size. Thiscan be a model of class |
jsizec_model | A linear model predicting juvenile tertiary size. Thiscan be a model of class |
jrepst_model | A linear model predicting reproduction probability of a mature individual that was immature in timet. This can be a modelof class |
jmatst_model | A linear model predicting maturity probability of an individual that was immature in timet. This can be a model of class |
start_vec | An optional numeric vector denoting the starting stagedistribution for the projection. Defaults to a single individual of eachstage. |
start_frame | An optional data frame characterizing stages, age-stages,or stage-pairs that should be set to non-zero values in the starting vector,and what those values should be. Can only be used with |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If amatrix is input, then a first-order Markovian environment is assumed, inwhich the probability of choosing a specific annual matrix depends on whichannual matrix is currently chosen. If a vector is input, then the choice ofannual matrix is assumed to be independent of the current matrix. Defaultsto equal weighting among matrices. |
density | An optional data frame describing the matrix elements thatwill be subject to density dependence, and the exact kind of densitydependence that they will be subject to. The data frame used should be anobject of class |
density_vr | An optional data frame describing density dependencerelationships in vital rates, if such relationships are to be assumed. Thedata frame must be of class |
stage_weights | An optional object of class |
sparse | A text string indicating whether to use sparse matrix encoding( |
Value
If running a single (including replicated) projection, then theoutput is a list of classlefkoProj, which always includes the firstthree elements of the following, and also includes the remaining elementsbelow when alefkoMat object is used as input:
projection | A list of lists of matrices showing the total number ofindividuals per stage per occasion. The first list corresponds to eachpop-patch followed by each population (this top-level list is a singleelement in |
stage_dist | A list of lists of the actual stage distribution in eachoccasion in each replicate in each pop-patch or population. The liststructure is the same as in |
rep_value | A list of lists of the actual reproductive value in eachoccasion in each replicate in each pop-patch or population. The liststructure is the same as in |
pop_size | A list of matrices showing the total population size in eachoccasion per replicate (row within matrix) per pop-patch or population(list element). Only a single pop-patch or population is allowed in |
labels | A data frame showing the order of populations and patches initem |
ahstages | The original stageframe used in the study. |
hstages | A data frame showing the order of historical stage pairs. |
agestages | A data frame showing the order of age-stage pairs. |
labels | A short data frame indicating the population (always |
control | A short vector indicating the number of replicates and thenumber of occasions projected per replicate. |
density | The data frame input under the density option. Only providedif input by the user. |
density_vr | The data frame input under the density_vr option. Onlyprovided if input by the user. |
If running bootstrapped projections (i.e. usinghfvlist andlefkoModList input), then will output an object of classlefkoProjList, which is just a simple list oflefkoProjobjects.
Notes
Population projection can be a very time-consuming activity, and it is mosttime-consuming when matrices need to be created at each time step. We havecreated this function to work as quickly as possible, but some options willslow analysis. First, theerr_check option should always be set toFALSE, as the added created output will not only slow the analysisdown but also potentially crash the memory if matrices are large enough.Second, therepvalue option should be set toFALSE unlessreproductive values are genuinely needed, since this step requiresconcurrent backward projection and so in some cases may double total runtime. Next, if the only needed data is the total population size andage/stage structure at each time step, then settinggrowthonly = TRUEwill yield the quickest possible run time. Finally, the default behavior ofthe function is to round down fractional values of individuals, and to stoprunning projections (replicates) when the population drops to 0. Settingintegeronly = FALSE will have the impact of increasing runtime,potentially dramatically, since the population can reach a point in whichthe population size is extremely small but not equal to 0.
Projections with large matrices may take a long time to run. To assess thelikely running time, try using a low number of iterations on a singlereplicate first. For example, setnreps = 1 andtimes = 10 fora trial run. If a full run is set and takes too long, press the STOP buttonin RStudio to cancel the projection run, or clickesc.
This function currently allows three forms of density dependence. The firstmodifies matrix elements on the basis of the input provided in optiondensity, and so alters matrix elements once the matrix has alreadybeen created. The second form alters the vital rates estimated, and soestimates matrix elements using vital rate values already modified bydensity. This second form uses the input provided in optiondensity_vr. These two forms of density dependence utilize theprojected population size at some time to make these alterations. The thirdform of density dependence also alters the vital rates, but using spatialdensity supplied via optionsp_density and only in vital rates inwhich spatial density is included as a fixed factor in the associatedvital rate model.
When running density dependent simulations involving user-set exponents,such as the beta term in the Ricker function and both the alpha and betaterms in the Usher function, values above or below the computer limits maycause unpredictable behavior. Noted odd behavior includes sudden shifts inpopulation size to negative values. This function produces warnings whensuch values are used, and the values used for warnings may be reset with theexp_tol term. In addition, this function resets beta values for theRicker function automatically to positive or negativeexp_tol, givinga warning when doing so.
Consistently positive population growth can quickly lead to population sizenumbers larger than can be handled computationally. In that circumstance, acontinuously rising population size will suddenly becomeNaN for theremainder of the projection.
This function does not reduce the dimensionality of matrices developed forprojection.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
Some issues may arise in first-order Markovian stochastic projections iftheyear argument is used. Use the matrix input in thetweights argument to eliminate any years from consideration that arenot needed.
See Also
flefko3()
flefko2()
aflefko2()
fleslie()
Examples
data(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathvertln_adults <- subset(lathvertln, stage2index > 2)surv_model <- glm(alive3 ~ sizea2 + sizea1 + as.factor(patchid) + as.factor(year2), data = lathvertln_adults, family = "binomial")obs_data <- subset(lathvertln_adults, alive3 == 1)obs_model <- glm(obsstatus3 ~ as.factor(patchid), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)siz_model <- lm(sizea3 ~ sizea2 + sizea1 + repstatus1 + as.factor(patchid) + as.factor(year2), data = size_data)reps_model <- glm(repstatus3 ~ sizea2 + sizea1 + as.factor(patchid) + as.factor(year2), data = size_data, family = "binomial")fec_data <- subset(lathvertln_adults, repstatus2 == 1)fec_model <- glm(feca2 ~ sizea2 + sizea1 + repstatus1 + as.factor(patchid), data = fec_data, family = "poisson")lathvertln_juvs <- subset(lathvertln, stage2index < 3)jsurv_model <- glm(alive3 ~ as.factor(patchid), data = lathvertln_juvs, family = "binomial")jobs_data <- subset(lathvertln_juvs, alive3 == 1)jobs_model <- glm(obsstatus3 ~ 1, family = "binomial", data = jobs_data)jsize_data <- subset(jobs_data, obsstatus3 == 1)jsiz_model <- lm(sizea3 ~ as.factor(year2), data = jsize_data)jrepst_model <- 0jmatst_model <- 1mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[3] <- "patchid"mod_params$modelparams[4] <- "alive3"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "feca2"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[13] <- "sizea1"mod_params$modelparams[18] <- "repstatus2"mod_params$modelparams[19] <- "repstatus1"lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "mat", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "Sdl", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "Sd", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, "Sdl", NA, NA), eststage1 = c(NA, NA, NA, NA, "Sdl", NA, NA), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframeln, historical = TRUE)# While we do not use MPMs to initialize f_projections3(), we do use MPMs to# initialize functions start_input() and density_input().lathmat3ln <- flefko3(year = "all", patch = "all", data = lathvertln, stageframe = lathframeln, supplement = lathsupp3, paramnames = mod_params, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, repst_model = reps_model, fec_model = fec_model, jsurv_model = jsurv_model, jobs_model = jobs_model, jsize_model = jsiz_model, jrepst_model = jrepst_model, jmatst_model = jmatst_model, reduce = FALSE)e3m_sv <- start_input(lathmat3ln, stage2 = "Sd", stage1 = "Sd", value = 1000)dyn7 <- c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)dst7 <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)dal7 <- c(0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)dbe7 <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)e3d_vr <- density_vr(density_yn = dyn7, style = dst7, alpha = dal7, beta = dbe7)trial7_dvr_1 <- f_projection3(format = 1, data = lathvertln, supplement = lathsupp3, paramnames = mod_params, stageframe = lathframeln, nreps = 2, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, repst_model = reps_model, fec_model = fec_model, jsurv_model = jsurv_model, jobs_model = jobs_model, jsize_model = jsiz_model, jrepst_model = jrepst_model, jmatst_model = jmatst_model, times = 100, stochastic = TRUE, standardize = FALSE, growthonly = TRUE, substoch = 0, sp_density = 0, start_frame = e3m_sv, density_vr = e3d_vr)Create Function-based Ahistorical Matrix Projection Model
Description
Functionflefko2() returns ahistorical MPMs corresponding to thepatches and occasions given, including the associated component transitionand fecundity matrices, a data frame detailing the characteristics of theahistorical stages used, and a data frame characterizing the patch andoccasion combinations corresponding to these matrices.
Usage
flefko2( year = "all", patch = "all", stageframe, supplement = NULL, repmatrix = NULL, overwrite = NULL, data = NULL, modelsuite = NULL, surv_model = NULL, obs_model = NULL, size_model = NULL, sizeb_model = NULL, sizec_model = NULL, repst_model = NULL, fec_model = NULL, jsurv_model = NULL, jobs_model = NULL, jsize_model = NULL, jsizeb_model = NULL, jsizec_model = NULL, jrepst_model = NULL, jmatst_model = NULL, paramnames = NULL, inda = NULL, indb = NULL, indc = NULL, annua = NULL, annub = NULL, annuc = NULL, surv_dev = 0, obs_dev = 0, size_dev = 0, sizeb_dev = 0, sizec_dev = 0, repst_dev = 0, fec_dev = 0, jsurv_dev = 0, jobs_dev = 0, jsize_dev = 0, jsizeb_dev = 0, jsizec_dev = 0, jrepst_dev = 0, jmatst_dev = 0, density = NA, fecmod = 1, random.inda = FALSE, random.indb = FALSE, random.indc = FALSE, negfec = FALSE, ipm_method = "CDF", reduce = FALSE, simple = FALSE, err_check = FALSE, exp_tol = 700, theta_tol = 1e+08, sparse_output = FALSE)Arguments
year | A variable corresponding to the observation occasion, or a setof such values, given in values associated with the year term used in linear model development. Defaults to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Defaults to |
stageframe | An object of class |
supplement | An optional data frame of class |
repmatrix | An optional reproduction matrix. This matrix is composedmostly of |
overwrite | An optional data frame developed with the |
data | The historical vertical demographic data frame used to estimatevital rates (class |
modelsuite | One of three kinds of lists. The first is a |
surv_model | A linear model predicting survival probability. This can be a model of class |
obs_model | A linear model predicting sprouting or observationprobability. This can be a model of class |
size_model | A linear model predicting primary size. This can be a modelof class |
sizeb_model | A linear model predicting secondary size. This can be amodel of class |
sizec_model | A linear model predicting tertiary size. This can be amodel of class |
repst_model | A linear model predicting reproduction probability. This can be a model of class |
fec_model | A linear model predicting fecundity. This can be a model ofclass |
jsurv_model | A linear model predicting juvenile survival probability.This can be a model of class |
jobs_model | A linear model predicting juvenile sprouting or observationprobability. This can be a model of class |
jsize_model | A linear model predicting juvenile primary size. Thiscan be a model of class |
jsizeb_model | A linear model predicting juvenile secondary size. Thiscan be a model of class |
jsizec_model | A linear model predicting juvenile tertiary size. Thiscan be a model of class |
jrepst_model | A linear model predicting reproduction probability of a mature individual that was immature in timet. This can be a modelof class |
jmatst_model | A linear model predicting maturity probability of an individual that was immature in timet. This can be a model of class |
paramnames | A data frame with three columns, the first describing allterms used in linear modeling, the second (must be called |
inda | Can be a single value to use for individual covariate |
indb | Can be a single value to use for individual covariate |
indc | Can be a single value to use for individual covariate |
annua | Can be a single value to use for annual covariate |
annub | Can be a single value to use for annual covariate |
annuc | Can be a single value to use for annual covariate |
surv_dev | A numeric value to be added to the y-intercept in the linearmodel for survival probability. Defaults to |
obs_dev | A numeric value to be added to the y-intercept in the linearmodel for observation probability. Defaults to |
size_dev | A numeric value to be added to the y-intercept in the linearmodel for primary size. Defaults to |
sizeb_dev | A numeric value to be added to the y-intercept in the linearmodel for secondary size. Defaults to |
sizec_dev | A numeric value to be added to the y-intercept in the linearmodel for tertiary size. Defaults to |
repst_dev | A numeric value to be added to the y-intercept in the linearmodel for probability of reproduction. Defaults to |
fec_dev | A numeric value to be added to the y-intercept in the linearmodel for fecundity. Defaults to |
jsurv_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile survival probability. Defaults to |
jobs_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile observation probability. Defaults to |
jsize_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile primary size. Defaults to |
jsizeb_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile secondary size. Defaults to |
jsizec_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile tertiary size. Defaults to |
jrepst_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile reproduction probability. Defaults to |
jmatst_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile maturity probability. Defaults to |
density | A numeric value indicating density value to use to propagatematrices. Only needed if density is an explanatory term used in one or morevital rate models. Defaults to |
fecmod | A scalar multiplier of fecundity. Defaults to |
random.inda | A logical value denoting whether to treat individualcovariate |
random.indb | A logical value denoting whether to treat individualcovariate |
random.indc | A logical value denoting whether to treat individualcovariate |
negfec | A logical value denoting whether fecundity values estimated tobe negative should be reset to |
ipm_method | A string indicating what method to use to estimate sizetransition probabilities, if size is treated as continuous. Options include: |
reduce | A logical value denoting whether to remove ahistorical stagesassociated solely with |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
exp_tol | A numeric value used to indicate a maximum value to setexponents to in the core kernel to prevent numerical overflow. Defaults to |
theta_tol | A numeric value used to indicate a maximum value to theta asused in the negative binomial probability density kernel. Defaults to |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
If the user inputs a standardlefkoMod orvrm_inputobject in argumentmodelsuite, or individual vital rate models areinput separately,then this function will return an object of classlefkoMat. If the user inputs an object of classlefkoModListin argumentmodelsuite, then the output will be an object of classlefkoMatList, in which each element is an object of classlefkoMat.
AlefkoMat object is a list that holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted patches andoccasion times. All matrices output in R's |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. Set to |
agestages | A data frame showing age-stage pairs. In this function, itis set to |
ahstages | A data frame detailing the characteristics of associatedahistorical stages, in the form of a modified stageframe that includesstatus as an entry stage through reproduction. |
labels | A data frame giving the population, patch, and year of eachmatrix in order. In |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
prob_out | An optional element only added if |
allstages | An optional element only added if |
Notes
Unlikerlefko2(),rlefko3(),arlefko2(), andrleslie(), this function does notcurrently distinguish populations. Users wishing to use the same vital ratemodels across populations should label them as patches (though we do notadvise this approach, as populations should typically be treated asstatistically independent).
This function will yield incorrect estimates if the models utilizedincorporate state in occasiont-1. Only use models developed testingfor ahistorical effects.
The default behavior of this function is to estimate fecundity with regardsto transitions specified via associated fecundity multipliers in thesupplement. If this field is left empty, then fecundity will beestimated at full for all transitions leading from reproductive stages toimmature and propagule stages.
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations, but without discriminating between thosepatches or subpopulations. Should the aim of analysis be a general MPM thatdoes not distinguish these patches or subpopulations, themodelsearch() run should not include patch terms.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1 andt. Rearranging the order willlead to erroneous calculations, and may lead to fatal errors.
Care should be taken to match the random status of year and patch to thestates of those variables within themodelsuite. If they do not match,then they will be treated as zeroes in vital rate estimation.
Theipm_method function gives the option of using two different meansof estimating the probability of size transition. The midpoint method("midpoint") refers to the method in which the probability isestimated by first estimating the probability associated with transition fromthe exact size at the midpoint of the size class using the correspondingprobability density function, and then multiplying that value by the binwidth of the size class. Doak et al. 2021 (Ecological Monographs) noted thatthis method can produce biased results, with total size transitionsassociated with a specific size not totaling to 1.0 and even specific sizetransition probabilities capable of being estimated at values greater than1.0. The alternative and default method,"CDF", uses the correspondingcumulative density function to estimate the probability of size transition asthe cumulative probability of size transition at the greater limit of thesize class minus the cumulative probability of size transition at the lowerlimit of the size class. The latter method avoids this bias. Note, however,that both methods are exact and unbiased for negative binomial and Poissondistributions.
Under the Gaussian and gamma size distributions, the number of estimatedparameters may differ between the twoipm_method settings. Becausethe midpoint method has a tendency to incorporate upward bias in theestimation of size transition probabilities, it is more likely to yield non-zero values when the true probability is extremely close to 0. This willresult in thesummary.lefkoMat function yielding higher numbers ofestimated parameters than theipm_method = "CDF" yields in some cases.
Using theerr_check option will produce a matrix of 7 columns, eachcharacterizing a different vital rate. The product of each row yields anelement in the associatedU matrix. The number and order of elementsin each column of this matrix matches the associated matrix in column vectorformat. Use of this option is generally for the purposes of debugging code.
Individual covariates are treated as categorical only if they are set asrandom terms. Fixed categorical individual covariates are currently notallowed. However, such terms may be supplied if themodelsuite optionis set to avrm_input object. In that case, the user should also setthe logical random switch for the individual covariate to be used toTRUE (e.g.,random.inda = TRUE).
See Also
flefko3()
aflefko2()
arlefko2()
fleslie()
rlefko3()
rlefko2()
rleslie()
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathvertln_adults <- subset(lathvertln, stage2index > 2)surv_model <- glm(alive3 ~ sizea2 + as.factor(patchid), data = lathvertln_adults, family = "binomial")obs_data <- subset(lathvertln_adults, alive3 == 1)obs_model <- glm(obsstatus3 ~ as.factor(patchid), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)siz_model <- lm(sizea3 ~ sizea2 + repstatus2 + as.factor(patchid) + as.factor(year2), data = size_data)reps_model <- glm(repstatus3 ~ sizea2 + as.factor(patchid) + as.factor(year2), data = size_data, family = "binomial")fec_data <- subset(lathvertln_adults, repstatus2 == 1)fec_model <- glm(feca2 ~ sizea2 + as.factor(patchid) + as.factor(year2), data = fec_data, family = "poisson")lathvertln_juvs <- subset(lathvertln, stage2index < 3)jsurv_model <- glm(alive3 ~ as.factor(patchid), data = lathvertln_juvs, family = "binomial")jobs_data <- subset(lathvertln_juvs, alive3 == 1)jobs_model <- glm(obsstatus3 ~ 1, family = "binomial", data = jobs_data)jsize_data <- subset(jobs_data, obsstatus3 == 1)jsiz_model <- lm(sizea3 ~ as.factor(year2), data = jsize_data)jrepst_model <- 0jmatst_model <- 1mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[3] <- "patchid"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "feca2"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[18] <- "repstatus2"lathsupp2 <- supplemental(stage3 = c("Sd", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "rep", "rep"), givenrate = c(0.345, 0.054, NA, NA), multiplier = c(NA, NA, 0.345, 0.054), type = c(1, 1, 3, 3), stageframe = lathframeln, historical = FALSE)lathmat2ln <- flefko2(year = "all", patch = "all", data = lathvertln, stageframe = lathframeln, supplement = lathsupp2, paramnames = mod_params, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, repst_model = reps_model, fec_model = fec_model, jsurv_model = jsurv_model, jobs_model = jobs_model, jsize_model = jsiz_model, jrepst_model = jrepst_model, jmatst_model = jmatst_model, reduce = FALSE)# Cypripedium example using three size metrics for classificationdata(cypdata)sizevector_f <- c(0, 0, 0, 0, 0, 0, seq(1, 12, by = 1), seq(0, 9, by = 1), seq(0, 8, by = 1), seq(0, 7, by = 1), seq(0, 6, by = 1), seq(0, 5, by = 1), seq(0, 4, by = 1), seq(0, 3, by = 1), 0, 1, 2, 0, 1, 0, 0, 0, 1, 0)sizebvector_f <- c(0, 0, 0, 0, 0, 0, rep(0, 12), rep(1, 10), rep(2, 9), rep(3, 8), rep(4, 7), rep(5, 6), rep(6, 5), rep(7, 4), rep(8, 3), 9, 9, 10, 0, 1, 1, 2)sizecvector_f <- c(0, 0, 0, 0, 0, 0, rep(0, 12), rep(0, 10), rep(0, 9), rep(0, 8), rep(0, 7), rep(0, 6), rep(0, 5), rep(0, 4), 0, 0, 0, 0, 0, 0, 1, 1, 1, 1)stagevector_f <- c("DS", "P1", "P2", "P3", "Sdl", "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", "V4 I0 D0", "V5 I0 D0", "V6 I0 D0", "V7 I0 D0", "V8 I0 D0", "V9 I0 D0", "V10 I0 D0", "V11 I0 D0", "V12 I0 D0", "V0 I1 D0", "V1 I1 D0", "V2 I1 D0", "V3 I1 D0", "V4 I1 D0", "V5 I1 D0", "V6 I1 D0", "V7 I1 D0", "V8 I1 D0", "V9 I1 D0", "V0 I2 D0", "V1 I2 D0", "V2 I2 D0", "V3 I2 D0", "V4 I2 D0", "V5 I2 D0", "V6 I2 D0", "V7 I2 D0", "V8 I2 D0", "V0 I3 D0", "V1 I3 D0", "V2 I3 D0", "V3 I3 D0", "V4 I3 D0", "V5 I3 D0", "V6 I3 D0", "V7 I3 D0", "V0 I4 D0", "V1 I4 D0", "V2 I4 D0", "V3 I4 D0", "V4 I4 D0", "V5 I4 D0", "V6 I4 D0", "V0 I5 D0", "V1 I5 D0", "V2 I5 D0", "V3 I5 D0", "V4 I5 D0", "V5 I5 D0", "V0 I6 D0", "V1 I6 D0", "V2 I6 D0", "V3 I6 D0", "V4 I6 D0", "V0 I7 D0", "V1 I7 D0", "V2 I7 D0", "V3 I7 D0", "V0 I8 D0", "V1 I8 D0", "V2 I8 D0", "V0 I9 D0", "V1 I9 D0", "V0 I10 D0", "V0 I0 D1", "V0 I1 D1", "V1 I1 D1", "V0 I2 D1")repvector_f <- c(0, 0, 0, 0, 0, rep(0, 13), rep(1, 59))obsvector_f <- c(0, 0, 0, 0, 0, 0, rep(1, 71))matvector_f <- c(0, 0, 0, 0, 0, rep(1, 72))immvector_f <- c(0, 1, 1, 1, 1, rep(0, 72))propvector_f <- c(1, rep(0, 76))indataset_f <- c(0, 0, 0, 0, 0, rep(1, 72))binvec_f <- c(0, 0, 0, 0, 0, rep(0.5, 72))binbvec_f <- c(0, 0, 0, 0, 0, rep(0.5, 72))bincvec_f <- c(0, 0, 0, 0, 0, rep(0.5, 72))vertframe_f <- sf_create(sizes = sizevector_f, sizesb = sizebvector_f, sizesc = sizecvector_f, stagenames = stagevector_f, repstatus = repvector_f, obsstatus = obsvector_f, propstatus = propvector_f, immstatus = immvector_f, matstatus = matvector_f, indataset = indataset_f, binhalfwidth = binvec_f, binhalfwidthb = binbvec_f, binhalfwidthc = bincvec_f)vert_data_f <- verticalize3(cypdata, noyears = 6, firstyear = 2004, individcol = "plantid", blocksize = 4, sizeacol = "Veg.04", sizebcol = "Inf.04", sizeccol = "Inf2.04", repstracol = "Inf.04", repstrbcol = "Inf2.04", fecacol = "Pod.04", censorcol = "censor", censorkeep = 1, censorRepeat = FALSE, stageassign = vertframe_f, stagesize = "sizeabc", NAas0 = TRUE, censor = FALSE)surv_model <- glm(alive3 ~ sizea2 + sizeb2, data = vert_data_f, family = "binomial")obs_data <- subset(vert_data_f, alive3 == 1)obs_model <- glm(obsstatus3 ~ sizeb2 + as.factor(year2), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)siz_model <- MASS::glm.nb(sizea3 ~ sizea2 + sizeb2 + as.factor(year2), data = size_data)sizb_model <- glm(sizeb3 ~ sizea2 + sizeb2 + repstatus2 + as.factor(year2), data = size_data, family = "poisson")sizc_model <- glm(sizec3 ~ repstatus2, data = size_data, family = "poisson")reps_model <- glm(repstatus3 ~ sizea2 + sizeb2 + repstatus2 + as.factor(year2), data = size_data, family = "binomial")fec_data <- subset(vert_data_f, repstatus2 == 1)fec_model <- glm(feca2 ~ sizeb2 + as.factor(year2), data = fec_data, family = "poisson")mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[3] <- "patchid"mod_params$modelparams[4] <- "alive3"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "feca2"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[18] <- "repstatus2"vertsupp2f <- supplemental(stage3 = c("DS", "P1", "P2", "P3", "Sdl", "Sdl", "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", "DS", "P1"), stage2 = c("DS", "DS", "P1", "P2", "P3", "Sdl", "Sdl", "Sdl", "Sdl", "Sdl", "rep", "rep"), eststage3 = c(NA, NA, NA, NA, NA, NA, "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", NA, NA), givenrate = c(0.10, 0.20, 0.20, 0.20, 0.25, 0.40, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5 * 5000, 0.5 * 5000), type =c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), stageframe = vertframe_f, historical = FALSE)vert_mats_f2 <- flefko2(stageframe = vertframe_f, supplement = vertsupp2f, data = vert_data_f, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, sizeb_model = sizb_model, sizec_model = sizc_model, repst_model = reps_model, fec_model = fec_model, paramnames = mod_params)Create Function-based Historical Matrix Projection Model
Description
Functionflefko3() returns function-based historical MPMscorresponding to the patches and occasions given, including the associatedcomponent transition and fecundity matrices, data frames detailing thecharacteristics of the ahistorical stages used and historical stage pairscreated, and a data frame characterizing the patch and occasion combinationscorresponding to these matrices.
Usage
flefko3( year = "all", patch = "all", stageframe, supplement = NULL, repmatrix = NULL, overwrite = NULL, data = NULL, modelsuite = NULL, surv_model = NULL, obs_model = NULL, size_model = NULL, sizeb_model = NULL, sizec_model = NULL, repst_model = NULL, fec_model = NULL, jsurv_model = NULL, jobs_model = NULL, jsize_model = NULL, jsizeb_model = NULL, jsizec_model = NULL, jrepst_model = NULL, jmatst_model = NULL, paramnames = NULL, inda = NULL, indb = NULL, indc = NULL, annua = NULL, annub = NULL, annuc = NULL, surv_dev = 0, obs_dev = 0, size_dev = 0, sizeb_dev = 0, sizec_dev = 0, repst_dev = 0, fec_dev = 0, jsurv_dev = 0, jobs_dev = 0, jsize_dev = 0, jsizeb_dev = 0, jsizec_dev = 0, jrepst_dev = 0, jmatst_dev = 0, density = NA, fecmod = 1, random.inda = FALSE, random.indb = FALSE, random.indc = FALSE, negfec = FALSE, format = "ehrlen", ipm_method = "CDF", reduce = FALSE, simple = FALSE, err_check = FALSE, exp_tol = 700, theta_tol = 1e+08, sparse_output = FALSE)Arguments
year | A variable corresponding to the observation occasion, or a setof such values, given in values associated with the year term used in linear model development. Defaults to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Defaults to |
stageframe | An object of class |
supplement | An optional data frame of class |
repmatrix | An optional reproduction matrix. This matrix is composedmostly of |
overwrite | An optional data frame developed with the |
data | The historical vertical demographic data frame used to estimatevital rates (class |
modelsuite | One of three kinds of lists. The first is a |
surv_model | A linear model predicting survival probability. This can be a model of class |
obs_model | A linear model predicting sprouting or observationprobability. This can be a model of class |
size_model | A linear model predicting primary size. This can be a modelof class |
sizeb_model | A linear model predicting secondary size. This can be amodel of class |
sizec_model | A linear model predicting tertiary size. This can be amodel of class |
repst_model | A linear model predicting reproduction probability. This can be a model of class |
fec_model | A linear model predicting fecundity. This can be a model ofclass |
jsurv_model | A linear model predicting juvenile survival probability.This can be a model of class |
jobs_model | A linear model predicting juvenile sprouting or observationprobability. This can be a model of class |
jsize_model | A linear model predicting juvenile primary size. Thiscan be a model of class |
jsizeb_model | A linear model predicting juvenile secondary size. Thiscan be a model of class |
jsizec_model | A linear model predicting juvenile tertiary size. Thiscan be a model of class |
jrepst_model | A linear model predicting reproduction probability of a mature individual that was immature in timet. This can be a modelof class |
jmatst_model | A linear model predicting maturity probability of an individual that was immature in timet. This can be a model of class |
paramnames | A data frame with three columns, the first describing allterms used in linear modeling, the second (must be called |
inda | Can be a single value to use for individual covariate |
indb | Can be a single value to use for individual covariate |
indc | Can be a single value to use for individual covariate |
annua | Can be a single value to use for annual covariate |
annub | Can be a single value to use for annual covariate |
annuc | Can be a single value to use for annual covariate |
surv_dev | A numeric value to be added to the y-intercept in the linearmodel for survival probability. Defaults to |
obs_dev | A numeric value to be added to the y-intercept in the linearmodel for observation probability. Defaults to |
size_dev | A numeric value to be added to the y-intercept in the linearmodel for primary size. Defaults to |
sizeb_dev | A numeric value to be added to the y-intercept in the linearmodel for secondary size. Defaults to |
sizec_dev | A numeric value to be added to the y-intercept in the linearmodel for tertiary size. Defaults to |
repst_dev | A numeric value to be added to the y-intercept in the linearmodel for probability of reproduction. Defaults to |
fec_dev | A numeric value to be added to the y-intercept in the linearmodel for fecundity. Defaults to |
jsurv_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile survival probability. Defaults to |
jobs_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile observation probability. Defaults to |
jsize_dev | A numeric value to be added to the y-intercept in the linearmodel for juvenile primary size. Defaults to |
jsizeb_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile secondary size. Defaults to |
jsizec_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile tertiary size. Defaults to |
jrepst_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile reproduction probability. Defaults to |
jmatst_dev | A numeric value to be added to the y-intercept in thelinear model for juvenile maturity probability. Defaults to |
density | A numeric value indicating density value to use to propagatematrices. Only needed if density is an explanatory term used in one or morevital rate models. Defaults to |
fecmod | A scalar multiplier of fecundity. Defaults to |
random.inda | A logical value denoting whether to treat individualcovariate |
random.indb | A logical value denoting whether to treat individualcovariate |
random.indc | A logical value denoting whether to treat individualcovariate |
negfec | A logical value denoting whether fecundity values estimated tobe negative should be reset to |
format | A string indicating whether to estimate matrices in |
ipm_method | A string indicating what method to use to estimate sizetransition probabilities, if size is treated as continuous. Options include: |
reduce | A logical value denoting whether to remove historical stagesassociated solely with |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
exp_tol | A numeric value used to indicate a maximum value to setexponents to in the core kernel to prevent numerical overflow. Defaults to |
theta_tol | A numeric value used to indicate a maximum value to theta asused in the negative binomial probability density kernel. Defaults to |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
If the user inputs a standardlefkoMod orvrm_inputobject in argumentmodelsuite, or individual vital rate models areinput separately,then this function will return an object of classlefkoMat. If the user inputs an object of classlefkoModListin argumentmodelsuite, then the output will be an object of classlefkoMatList, in which each element is an object of classlefkoMat.
AlefkoMat object is a list that holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted patches andoccasion times. All matrices output in R's |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. |
agestages | A data frame showing age-stage pairs. In this function, itis set to |
ahstages | A data frame detailing the characteristics of associatedahistorical stages, in the form of a modified stageframe that includesstatus as an entry stage through reproduction. |
labels | A data frame giving the population, patch, and year of eachmatrix in order. In |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
prob_out | An optional element only added if |
allstages | An optional element only added if |
Notes
Unlikerlefko2(),rlefko3(),arlefko2(), andrleslie(), this function does notcurrently distinguish populations. Users wishing to use the same vital ratemodels across populations should label them as patches (though we do notadvise this approach, as populations should typically be treated asstatistically independent).
The default behavior of this function is to estimate fecundity with regardsto transitions specified via associated fecundity multipliers in thesupplement. If this field is left empty, then fecundity will beestimated at full for all transitions leading from reproductive stages toimmature and propagule stages.
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations, but without discriminating between thosepatches or subpopulations. Should the aim of analysis be a general MPM thatdoes not distinguish these patches or subpopulations, themodelsearch() run should not include patch terms.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1,t, andt-1. Rearrangingthe order will lead to erroneous calculations, and will may lead to fatalerrors.
Theipm_method function gives the option of using two different meansof estimating the probability of size transition. The midpoint method("midpoint") refers to the method in which the probability isestimated by first estimating the probability associated with transition fromthe exact size at the midpoint of the size class using the correspondingprobability density function, and then multiplying that value by the binwidth of the size class. Doak et al. 2021 (Ecological Monographs) noted thatthis method can produce biased results, with total size transitionsassociated with a specific size not totaling to 1.0 and even specific sizetransition probabilities capable of being estimated at values greater than1.0. The alternative and default method,"CDF", uses the correspondingcumulative density function to estimate the probability of size transition asthe cumulative probability of size transition at the greater limit of thesize class minus the cumulative probability of size transition at the lowerlimit of the size class. This latter method avoids this bias. Note, however,that both methods are exact and unbiased for negative binomial and Poissondistributions.
Under the Gaussian and gamma size distributions, the number of estimatedparameters may differ between the twoipm_method settings. Becausethe midpoint method has a tendency to incorporate upward bias in theestimation of size transition probabilities, it is more likely to yield non-zero values when the true probability is extremely close to 0. This willresult in thesummary.lefkoMat function yielding higher numbers ofestimated parameters than theipm_method = "CDF" yields in some cases.
Using theerr_check option will produce a matrix of 7 columns, eachcharacterizing a different vital rate. The product of each row yields anelement in the associatedU matrix. The number and order of elementsin each column of this matrix matches the associated matrix in column vectorformat. Use of this option is generally for the purposes of debugging code.'Individual covariates are treated as categorical only if they are set asrandom terms. Fixed categorical individual covariates are currently notallowed. However, such terms may be supplied if themodelsuite optionis set to avrm_input object. In that case, the user should also setthe logical random switch for the individual covariate to be used toTRUE (e.g.,random.inda = TRUE).
See Also
flefko2()
aflefko2()
arlefko2()
fleslie()
rlefko3()
rlefko2()
rleslie()
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "mat", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "Sdl", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "Sd", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, "Sdl", NA, NA), eststage1 = c(NA, NA, NA, NA, "Sdl", NA, NA), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframeln, historical = TRUE)lathvertln_adults <- subset(lathvertln, stage2index > 2)surv_model <- glm(alive3 ~ sizea2 + sizea1 + as.factor(patchid) + as.factor(year2), data = lathvertln_adults, family = "binomial")obs_data <- subset(lathvertln_adults, alive3 == 1)obs_model <- glm(obsstatus3 ~ as.factor(patchid), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)siz_model <- lm(sizea3 ~ sizea2 + sizea1 + repstatus1 + as.factor(patchid) + as.factor(year2), data = size_data)reps_model <- glm(repstatus3 ~ sizea2 + sizea1 + as.factor(patchid) + as.factor(year2), data = size_data, family = "binomial")fec_data <- subset(lathvertln_adults, repstatus2 == 1)fec_model <- glm(feca2 ~ sizea2 + sizea1 + repstatus1 + as.factor(patchid), data = fec_data, family = "poisson")lathvertln_juvs <- subset(lathvertln, stage2index < 3)jsurv_model <- glm(alive3 ~ as.factor(patchid), data = lathvertln_juvs, family = "binomial")jobs_data <- subset(lathvertln_juvs, alive3 == 1)jobs_model <- glm(obsstatus3 ~ 1, family = "binomial", data = jobs_data)jsize_data <- subset(jobs_data, obsstatus3 == 1)jsiz_model <- lm(sizea3 ~ as.factor(year2), data = jsize_data)jrepst_model <- 0jmatst_model <- 1mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[3] <- "patchid"mod_params$modelparams[4] <- "alive3"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "feca2"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[13] <- "sizea1"mod_params$modelparams[18] <- "repstatus2"mod_params$modelparams[19] <- "repstatus1"lathmat3ln <- flefko3(year = "all", patch = "all", data = lathvertln, stageframe = lathframeln, supplement = lathsupp3, paramnames = mod_params, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, repst_model = reps_model, fec_model = fec_model, jsurv_model = jsurv_model, jobs_model = jobs_model, jsize_model = jsiz_model, jrepst_model = jrepst_model, jmatst_model = jmatst_model, reduce = FALSE)# Cypripedium example using three size metrics for classificationdata(cypdata)sizevector_f <- c(0, 0, 0, 0, 0, 0, seq(1, 12, by = 1), seq(0, 9, by = 1), seq(0, 8, by = 1), seq(0, 7, by = 1), seq(0, 6, by = 1), seq(0, 5, by = 1), seq(0, 4, by = 1), seq(0, 3, by = 1), 0, 1, 2, 0, 1, 0, 0, 0, 1, 0)sizebvector_f <- c(0, 0, 0, 0, 0, 0, rep(0, 12), rep(1, 10), rep(2, 9), rep(3, 8), rep(4, 7), rep(5, 6), rep(6, 5), rep(7, 4), rep(8, 3), 9, 9, 10, 0, 1, 1, 2)sizecvector_f <- c(0, 0, 0, 0, 0, 0, rep(0, 12), rep(0, 10), rep(0, 9), rep(0, 8), rep(0, 7), rep(0, 6), rep(0, 5), rep(0, 4), 0, 0, 0, 0, 0, 0, 1, 1, 1, 1)stagevector_f <- c("DS", "P1", "P2", "P3", "Sdl", "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", "V4 I0 D0", "V5 I0 D0", "V6 I0 D0", "V7 I0 D0", "V8 I0 D0", "V9 I0 D0", "V10 I0 D0", "V11 I0 D0", "V12 I0 D0", "V0 I1 D0", "V1 I1 D0", "V2 I1 D0", "V3 I1 D0", "V4 I1 D0", "V5 I1 D0", "V6 I1 D0", "V7 I1 D0", "V8 I1 D0", "V9 I1 D0", "V0 I2 D0", "V1 I2 D0", "V2 I2 D0", "V3 I2 D0", "V4 I2 D0", "V5 I2 D0", "V6 I2 D0", "V7 I2 D0", "V8 I2 D0", "V0 I3 D0", "V1 I3 D0", "V2 I3 D0", "V3 I3 D0", "V4 I3 D0", "V5 I3 D0", "V6 I3 D0", "V7 I3 D0", "V0 I4 D0", "V1 I4 D0", "V2 I4 D0", "V3 I4 D0", "V4 I4 D0", "V5 I4 D0", "V6 I4 D0", "V0 I5 D0", "V1 I5 D0", "V2 I5 D0", "V3 I5 D0", "V4 I5 D0", "V5 I5 D0", "V0 I6 D0", "V1 I6 D0", "V2 I6 D0", "V3 I6 D0", "V4 I6 D0", "V0 I7 D0", "V1 I7 D0", "V2 I7 D0", "V3 I7 D0", "V0 I8 D0", "V1 I8 D0", "V2 I8 D0", "V0 I9 D0", "V1 I9 D0", "V0 I10 D0", "V0 I0 D1", "V0 I1 D1", "V1 I1 D1", "V0 I2 D1")repvector_f <- c(0, 0, 0, 0, 0, rep(0, 13), rep(1, 59))obsvector_f <- c(0, 0, 0, 0, 0, 0, rep(1, 71))matvector_f <- c(0, 0, 0, 0, 0, rep(1, 72))immvector_f <- c(0, 1, 1, 1, 1, rep(0, 72))propvector_f <- c(1, rep(0, 76))indataset_f <- c(0, 0, 0, 0, 0, rep(1, 72))binvec_f <- c(0, 0, 0, 0, 0, rep(0.5, 72))binbvec_f <- c(0, 0, 0, 0, 0, rep(0.5, 72))bincvec_f <- c(0, 0, 0, 0, 0, rep(0.5, 72))vertframe_f <- sf_create(sizes = sizevector_f, sizesb = sizebvector_f, sizesc = sizecvector_f, stagenames = stagevector_f, repstatus = repvector_f, obsstatus = obsvector_f, propstatus = propvector_f, immstatus = immvector_f, matstatus = matvector_f, indataset = indataset_f, binhalfwidth = binvec_f, binhalfwidthb = binbvec_f, binhalfwidthc = bincvec_f)vert_data_f <- verticalize3(cypdata, noyears = 6, firstyear = 2004, individcol = "plantid", blocksize = 4, sizeacol = "Veg.04", sizebcol = "Inf.04", sizeccol = "Inf2.04", repstracol = "Inf.04", repstrbcol = "Inf2.04", fecacol = "Pod.04", censorcol = "censor", censorkeep = 1, censorRepeat = FALSE, stageassign = vertframe_f, stagesize = "sizeabc", NAas0 = TRUE, censor = FALSE)vertsupp3f <- supplemental(stage3 = c("DS", "P1", "DS", "P1", "P2", "P2", "P3", "Sdl", "Sdl", "Sdl", "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", "mat", "mat", "mat", "mat", "DS", "P1"), stage2 = c("DS", "DS", "DS", "DS", "P1", "P1", "P2", "P3", "Sdl", "Sdl", "Sdl", "Sdl", "Sdl", "Sdl", "Sdl", "Sdl", "Sdl", "Sdl", "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", "rep", "rep"), stage1 = c("DS", "DS", "rep", "rep", "DS", "rep", "P1", "P2", "P3", "Sdl", "Sdl", "Sdl", "Sdl", "Sdl", "P3", "P3", "P3", "P3", "Sdl", "Sdl", "Sdl", "Sdl", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", "mat", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "Dorm", "V1 I0 D0", "V2 I0 D0", "V3 I0 D0", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", "V1 I0 D0", NA, NA), givenrate = c(0.10, 0.20, 0.10, 0.20, 0.20, 0.20, 0.20, 0.25, 0.40, 0.40, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5 * 5000, 0.5 * 5000), type =c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = vertframe_f, historical = TRUE)surv_model <- glm(alive3 ~ sizea2 + sizeb2, data = vert_data_f, family = "binomial")obs_data <- subset(vert_data_f, alive3 == 1)obs_model <- glm(obsstatus3 ~ sizeb2 + sizec1 + as.factor(year2), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)siz_model <- MASS::glm.nb(sizea3 ~ sizea2 + sizea1 + sizeb1, data = size_data)sizb_model <- glm(sizeb3 ~ sizea2 + sizeb2 + sizec1 + repstatus2 + repstatus1 + as.factor(year2), data = size_data, family = "poisson")sizc_model <- glm(sizec3 ~ sizea1 + repstatus2, data = size_data, family = "poisson")reps_model <- glm(repstatus3 ~ sizea2 + sizeb2 + repstatus2 + as.factor(year2), data = size_data, family = "binomial")fec_data <- subset(vert_data_f, repstatus2 == 1)fec_model <- glm(feca2 ~ sizeb2 + as.factor(year2), data = fec_data, family = "poisson")mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[3] <- "patchid"mod_params$modelparams[4] <- "alive3"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "feca2"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[13] <- "sizea1"mod_params$modelparams[18] <- "repstatus2"mod_params$modelparams[19] <- "repstatus1"vert_mats_f3 <- flefko3(stageframe = vertframe_f, supplement = vertsupp3f, data = vert_data_f, surv_model = surv_model, obs_model = obs_model, size_model = siz_model, sizeb_model = sizb_model, sizec_model = sizc_model, repst_model = reps_model, fec_model = fec_model, paramnames = mod_params, sparse_output = TRUE)Create Function-based Age-based (Leslie) Matrix Projection Model
Description
Functionfleslie() returns age-based (Leslie) MPMs corresponding tothe patches and occasions given, including the associated componenttransition and fecundity matrices, data frames detailing the characteristicsof the exact ages corresponding to rows and columns in estimated matrices,and a data frame characterizing the patch and occasion combinationscorresponding to these matrices.
Usage
fleslie( year = "all", patch = NULL, prebreeding = TRUE, data = NULL, modelsuite = NULL, surv_model = NULL, fec_model = NULL, paramnames = NULL, supplement = NULL, start_age = NA, last_age = NA, fecage_min = NA, fecage_max = NA, continue = TRUE, inda = NULL, indb = NULL, indc = NULL, annua = NULL, annub = NULL, annuc = NULL, surv_dev = 0, fec_dev = 0, density = NA, fecmod = 1, random.inda = FALSE, random.indb = FALSE, random.indc = FALSE, negfec = FALSE, reduce = FALSE, simple = FALSE, err_check = FALSE, exp_tol = 700, theta_tol = 1e+08, sparse_output = FALSE)Arguments
year | A variable corresponding to observation occasion, or a setof such values, given in values associated with the year term used in linear model development. Defaults to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Defaults to |
prebreeding | A logical value indicating whether the life history modelis a pre-breeding model. Defaults to |
data | The historical vertical demographic data frame used to estimatevital rates (class |
modelsuite | One of three kinds of lists. The first is a |
surv_model | A linear model predicting survival probability. This can bea model of class |
fec_model | A linear model predicting fecundity. This can be a model ofclass |
paramnames | A data frame with three columns, the first describing allterms used in linear modeling, the second (must be called |
supplement | An optional data frame of class |
start_age | The age from which to start the matrix. Defaults to |
last_age | The final age to use in the matrix. Defaults to |
fecage_min | The minimum age at which reproduction is possible. Defaultsto |
fecage_max | The maximum age at which reproduction is possible. Defaultsto |
continue | A logical value designating whether to allow continuedsurvival of individuals past the final age noted in the stageframe, using the demographic characteristics of the final age. Defaults to |
inda | Can be a single value to use for individual covariate |
indb | Can be a single value to use for individual covariate |
indc | Can be a single value to use for individual covariate |
annua | Can be a single value to use for annual covariate |
annub | Can be a single value to use for annual covariate |
annuc | Can be a single value to use for annual covariate |
surv_dev | A numeric value to be added to the y-intercept in the linearmodel for survival probability. Defaults to |
fec_dev | A numeric value to be added to the y-intercept in the linearmodel for fecundity. Defaults to |
density | A numeric value indicating density value to use to propagatematrices. Only needed if density is an explanatory term used in linearmodels. Defaults to |
fecmod | A scalar multiplier of fecundity. Defaults to |
random.inda | A logical value denoting whether to treat individualcovariate |
random.indb | A logical value denoting whether to treat individualcovariate |
random.indc | A logical value denoting whether to treat individualcovariate |
negfec | A logical value denoting whether fecundity values estimated tobe negative should be reset to |
reduce | A logical value denoting whether to remove ages associatedsolely with |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
exp_tol | A numeric value used to indicate a maximum value to setexponents to in the core kernel to prevent numerical overflow. Defaults to |
theta_tol | A numeric value used to indicate a maximum value to theta asused in the negative binomial probability density kernel. Defaults to |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
If the user inputs a standardlefkoMod orvrm_inputobject in argumentmodelsuite, or individual vital rate models areinput separately,then this function will return an object of classlefkoMat. If the user inputs an object of classlefkoModListin argumentmodelsuite, then the output will be an object of classlefkoMatList, in which each element is an object of classlefkoMat.
AlefkoMat object is a list that holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted patches andoccasions. All matrices output in R's |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | Set to |
agestages | Set to |
ahstages | A data frame detailing the characteristics of associatedages, in the form of a modified stageframe including reproduction status. |
labels | A data frame giving the patch and year of each matrix in order.In |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
prob_out | An optional element only added if |
Notes
Unlikerlefko2(),rlefko3(),arlefko2(), andrleslie(), this function does notcurrently distinguish populations.
This function will yield incorrect estimates if the models utilizedincorporate state in occasiont-1, or any size or reproductive statusterms.
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations, but without discriminating between thosepatches or subpopulations. Should the aim of analysis be a general MPM thatdoes not distinguish these patches or subpopulations, themodelsearch() run should not include patch terms.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1 andt. Rearranging the order willlead to erroneous calculations, and may lead to fatal errors.
Care should be taken to match the random status of year and patch to thestates of those variables within the modelsuite. If they do not match, thenthey will be treated as zeroes in vital rate estimation.
Individual covariates are treated as categorical only if they are set asrandom terms. Fixed categorical individual covariates are currently notallowed. However, such terms may be supplied if themodelsuite optionis set to avrm_input object. In that case, the user should also setthe logical random switch for the individual covariate to be used toTRUE (e.g.,random.inda = TRUE).
See Also
flefko3()
flefko2()
aflefko2()
arlefko2()
rlefko3()
rlefko2()
rleslie()
Examples
data(lathyrus)lathvert_base <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", censorcol = "Missing1988", censorkeep = NA, censor = TRUE, NAas0 = TRUE, NRasRep = TRUE, NOasObs = TRUE)lathvert_base$feca3 <- round(lathvert_base$feca3)lathvert_base$feca2 <- round(lathvert_base$feca2)lathvert_base$feca1 <- round(lathvert_base$feca1)lathvert_age <- subset(lathvert_base, firstseen > 1988)lath_survival <- glm(alive3 ~ obsage + as.factor(year2), data = lathvert_age, family = "binomial")lath_fecundity <- glm(feca2 ~ obsage + as.factor(year2), data = lathvert_age, family = "poisson")mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[22] <- "obsage"lathmat2fleslie <- fleslie(year = "all", data = lathvert_age, surv_model = lath_survival, fec_model = lath_fecundity, paramnames = mod_params, fecage_min = 1)Assess Quality of hfv Datasets
Description
Functionhfv_qc() tests the overall quality of hfv datasets, and alsoruns a series of tests to assess which statistical distributions match thevariables within these datasets. The input format is equivalent to the inputformat of functionmodelsearch(), allowing users to assessvital rate variable distributions assuming the same internal datasetsubsetting used by the latter function and simply copy and pasting theparameter options from one function to the other.
Usage
hfv_qc( data, stageframe = NULL, historical = TRUE, suite = "size", vitalrates = c("surv", "size", "fec"), surv = c("alive3", "alive2", "alive1"), obs = c("obsstatus3", "obsstatus2", "obsstatus1"), size = c("sizea3", "sizea2", "sizea1"), sizeb = c(NA, NA, NA), sizec = c(NA, NA, NA), repst = c("repstatus3", "repstatus2", "repstatus1"), fec = c("feca3", "feca2", "feca1"), stage = c("stage3", "stage2", "stage1"), matstat = c("matstatus3", "matstatus2", "matstatus1"), indiv = "individ", patch = NA, year = "year2", density = NA, patch.as.random = TRUE, year.as.random = TRUE, juvestimate = NA, juvsize = FALSE, fectime = 2, censor = NA, age = NA, indcova = NA, indcovb = NA, indcovc = NA, random.indcova = FALSE, random.indcovb = FALSE, random.indcovc = FALSE, test.group = FALSE, ...)Arguments
data | The vertical dataset to be used for analysis. This dataset should be of class |
stageframe | The stageframe characterizing the life history model used.Optional unless |
historical | A logical variable denoting whether to assess the effectsof state in occasiont-1, in addition to state in occasiont.Defaults to |
suite | This describes the global model for each vital rate estimation,and has the following possible values: |
vitalrates | A vector describing which vital rates will be estimated vialinear modeling, with the following options: |
surv | A vector indicating the variable names coding for status as aliveor dead in occasionst+1,t, andt-1, respectively.Defaults to |
obs | A vector indicating the variable names coding for observationstatus in occasionst+1,t, andt-1, respectively.Defaults to |
size | A vector indicating the variable names coding for the primarysize variable on occasionst+1,t, andt-1,respectively. Defaults to |
sizeb | A vector indicating the variable names coding for the secondarysize variable on occasionst+1,t, andt-1,respectively. Defaults to |
sizec | A vector indicating the variable names coding for the tertiarysize variable on occasionst+1,t, andt-1,respectively. Defaults to |
repst | A vector indicating the variable names coding for reproductivestatus in occasionst+1,t, andt-1, respectively.Defaults to |
fec | A vector indicating the variable names coding for fecundity inoccasionst+1,t, andt-1, respectively. Defaults to |
stage | A vector indicating the variable names coding for stage inoccasionst+1,t, andt-1. Defaults to |
matstat | A vector indicating the variable names coding for maturitystatus in occasionst+1,t, andt-1. Defaults to |
indiv | A text value indicating the variable name coding individualidentity. Defaults to |
patch | A text value indicating the variable name coding for patch,where patches are defined as permanent subgroups within the study population.Defaults to |
year | A text value indicating the variable coding for observationoccasiont. Defaults to |
density | A text value indicating the name of the variable coding forspatial density, should the user wish to test spatial density as a fixedfactor affecting vital rates. Defaults to |
patch.as.random | If set to |
year.as.random | If set to |
juvestimate | An optional variable denoting the stage name of thejuvenile stage in the vertical dataset. If not |
juvsize | A logical variable denoting whether size should be used as aterm in models involving transition from the juvenile stage. Defaults to |
fectime | A variable indicating which year of fecundity to use as theresponse term in fecundity models. Options include |
censor | A vector denoting the names of censoring variables in thedataset, in order from occasiont+1, followed by occasiont,and lastly followed by occasiont-1. Defaults to |
age | Designates the name of the variable corresponding to age in timet in the vertical dataset. Defaults to |
indcova | Vector designating the names in occasionst+1,t, andt-1 of an individual covariate. Defaults to |
indcovb | Vector designating the names in occasionst+1,t, andt-1 of a second individual covariate. Defaults to |
indcovc | Vector designating the names in occasionst+1,t, andt-1 of a third individual covariate. Defaults to |
random.indcova | A logical value indicating whether |
random.indcovb | A logical value indicating whether |
random.indcovc | A logical value indicating whether |
test.group | A logical value indicating whether to include the |
... | Other parameters. |
Value
This function yields text output describing the subsets to be used inlinear vital rate modeling. No value or object is returned.
Notes
This function is meant to handle input as would be supplied to functionmodelsearch(). To use most easily, users may copy all input parametersfrom a call to functionmodelsearch(), and paste directly within thisfunction. The exact subsets used in themodelsearch() run will also becreated here.
Tests of Gaussian normality are conducted as Shapiro-Wilk tests via base R'sshapiro.test() function. If datasets with more than 5000 rows aresupplied, functionhfv_qc() will sample 5000 rows from the dataset andconduct the Shapiro-Wilk test on the data sample.
Random factor variables are also tested for the presence of singletoncategories, which are factor values that occur only once in the used datasubset. Singleton categories may cause problems with estimation under mixedmodeling.
Examples
data(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)hfv_qc(lathvertln, historical = TRUE, suite = "main", vitalrates = c("surv", "obs", "size", "repst", "fec"), juvestimate = "Sdl", indiv = "individ", patch = "patchid", year = "year2",year.as.random = TRUE, patch.as.random = TRUE)Create Historical MPMs Assuming No Influence of Individual History
Description
Functionhist_null() uses ahistorical MPMs to create the equivalentMPMs in the structure of historical MPMs. These MPMs have the samedimensions and stage structure of hMPMs but assume no influence ofindividual history, and so can be compared to actual hMPMs.
Usage
hist_null(mpm, format = 1L, err_check = FALSE)Arguments
mpm | An ahistorical MPM of class |
format | An integer stipulating whether historical matrices should beproduced in Ehrlen format ( |
err_check | A logical value indicating whether to output the main indexdata frames used to sort elements in the matrices. |
Value
An object of classlefkoMat, with the same list structure asthe input object, but withA,U, andF elementsreplaced with lists of historically-structured matrices, and with elementhstages changed fromNA to an index of stage pairscorresponding to the rows and columns of the new matrices. Iferr_check = TRUE, then a list of three data frames showing the valuesused to determine matrix element index values is also exported.
Notes
This function does not currently identify biologically impossibletransitions. Ahistorical transition values are placed in all theoreticallypossible historical transitions.
Examples
sizevector <- c(1, 1, 2, 3)stagevector <- c("Sdl", "Veg", "SmFlo", "LFlo")repvector <- c(0, 0, 1, 1)obsvector <- c(1, 1, 1, 1)matvector <- c(0, 1, 1, 1)immvector <- c(1, 0, 0, 0)propvector <- c(0, 0, 0, 0)indataset <- c(1, 1, 1, 1)binvec <- c(0.5, 0.5, 0.5, 0.5)anthframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)# POPN C 2003-2004XC3 <- matrix(c(0, 0, 1.74, 1.74,0.208333333, 0, 0, 0.057142857,0.041666667, 0.076923077, 0, 0,0.083333333, 0.076923077, 0.066666667, 0.028571429), 4, 4, byrow = TRUE)# 2004-2005XC4 <- matrix(c(0, 0, 0.3, 0.6,0.32183908, 0.142857143, 0, 0,0.16091954, 0.285714286, 0, 0,0.252873563, 0.285714286, 0.5, 0.6), 4, 4, byrow = TRUE)mats_list <- list(XC3, XC4)yr_ord <- c(1, 2)pch_ord <- c(1, 1)anth_lefkoMat <- create_lM(mats_list, anthframe, hstages = NA, historical = FALSE, poporder = 1, patchorder = pch_ord, yearorder = yr_ord) nullmodel1 <- hist_null(anth_lefkoMat, 1) # Ehrlen formatnullmodel2 <- hist_null(anth_lefkoMat, 2) # deVries formatCreate Historical Vertical Data Frame from Ahistorical Vertical Data Frame
Description
Functionhistoricalize3() returns a vertically formatted demographicdata frame organized to create historical projection matrices, given avertically but ahistorically formatted data frame. This data frame is instandardhfvdata format and can be used in all functions in thepackage.
Usage
historicalize3( data, popidcol = 0, patchidcol = 0, individcol, year2col = 0, year3col = 0, xcol = 0, ycol = 0, sizea2col = 0, sizea3col = 0, sizeb2col = 0, sizeb3col = 0, sizec2col = 0, sizec3col = 0, repstra2col = 0, repstra3col = 0, repstrb2col = 0, repstrb3col = 0, feca2col = 0, feca3col = 0, fecb2col = 0, fecb3col = 0, indcova2col = 0, indcova3col = 0, indcovb2col = 0, indcovb3col = 0, indcovc2col = 0, indcovc3col = 0, alive2col = 0, alive3col = 0, dead2col = 0, dead3col = 0, obs2col = 0, obs3col = 0, nonobs2col = 0, nonobs3col = 0, repstrrel = 1, fecrel = 1, stage2col = 0, stage3col = 0, juv2col = 0, juv3col = 0, stageassign = NA, stagesize = NA, censor = FALSE, censorcol = 0, censorkeep = 0, spacing = NA, NAas0 = FALSE, NRasRep = FALSE, NOasObs = FALSE, prebreeding = TRUE, age_offset = 0, reduce = TRUE, a2check = FALSE, quiet = FALSE)Arguments
data | The horizontal data file. |
popidcol | A variable name or column number corresponding to theidentity of the population for each individual. |
patchidcol | A variable name or column number corresponding to theidentity of the patch or subpopulation for each individual, if patches havebeen designated within populations. |
individcol | A variable name or column number corresponding to theunique identity of each individual. |
year2col | A variable name or column number corresponding to occasiont (year or time). |
year3col | A variable name or column number corresponding to occasiont+1 (year or time). |
xcol | A variable name or column number corresponding to the Xcoordinate of each individual in Cartesian space. |
ycol | A variable name or column number corresponding to the Ycoordinate of each individual in Cartesian space. |
sizea2col | A variable name or column number corresponding to theprimary size entry in occasiont. |
sizea3col | A variable name or column number corresponding to theprimary size entry in occasiont+1. |
sizeb2col | A variable name or column number corresponding to thesecondary size entry in occasiont. |
sizeb3col | A variable name or column number corresponding to thesecondary size entry in occasiont+1. |
sizec2col | A variable name or column number corresponding to thetertiary size entry in occasiont. |
sizec3col | A variable name or column number corresponding to thetertiary size entry in occasiont+1. |
repstra2col | A variable name or column number corresponding to theproduction of reproductive structures, such as flowers, in occasiont.This can be binomial or count data, and is used to in analysis of theprobability of reproduction. |
repstra3col | A variable name or column number corresponding to theproduction of reproductive structures, such as flowers, in occasiont+1. This can be binomial or count data, and is used to in analysisof the probability of reproduction. |
repstrb2col | A second variable name or column number corresponding tothe production of reproductive structures, such as flowers, in occasiont. This can be binomial or count data. |
repstrb3col | A second variable name or column number corresponding tothe production of reproductive structures, such as flowers, in occasiont+1. This can be binomial or count data. |
feca2col | A variable name or column number corresponding to fecundityin occasiont. This may represent egg counts, fruit counts, seed production, etc. |
feca3col | A variable name or column number corresponding to fecundityin occasiont+1. This may represent egg counts, fruit counts, seedproduction, etc. |
fecb2col | A second variable name or column number corresponding to fecundity in occasiont. This may represent egg counts, fruit counts,seed production, etc. |
fecb3col | A second variable name or column number corresponding to fecundity in occasiont+1. This may represent egg counts, fruitcounts, seed production, etc. |
indcova2col | A variable name or column number corresponding to anindividual covariate to be used in analysis, in occasiont. |
indcova3col | A variable name or column number corresponding to anindividual covariate to be used in analysis, in occasiont+1. |
indcovb2col | A variable name or column number corresponding to a secondindividual covariate to be used in analysis, in occasiont. |
indcovb3col | A variable name or column number corresponding to a secondindividual covariate to be used in analysis, in occasiont+1. |
indcovc2col | A variable name or column number corresponding to a thirdindividual covariate to be used in analysis, in occasiont. |
indcovc3col | A variable name or column number corresponding to a thirdindividual covariate to be used in analysis, in occasiont+1. |
alive2col | A variable name or column number that provides informationon whether an individual is alive in occasiont. If used, livingstatus must be designated as binomial (living = |
alive3col | A variable name or column number that provides informationon whether an individual is alive in occasiont+1. If used, livingstatus must be designated as binomial (living = |
dead2col | A variable name or column number that provides information onwhether an individual is dead in occasiont. If used, dead statusmust be designated as binomial (living = |
dead3col | A variable name or column number that provides information onwhether an individual is dead in occasiont+1. If used, dead statusmust be designated as binomial (living = |
obs2col | A variable name or column number providing information onwhether an individual is in an observable stage in occasiont. Ifused, observation status must be designated as binomial (observed = |
obs3col | A variable name or column number providing information onwhether an individual is in an observable stage in occasiont+1. Ifused, observation status must be designated as binomial (observed = |
nonobs2col | A variable name or column number providing information onwhether an individual is in an unobservable stage in occasiont. Ifused, observation status must be designated as binomial (observed = |
nonobs3col | A variable name or column number providing information onwhether an individual is in an unobservable stage in occasiont+1. Ifused, observation status must be designated as binomial (observed = |
repstrrel | This is a scalar multiplier making the variable representedby |
fecrel | This is a scalar multiplier making the variable represented by |
stage2col | Optional variable name or column number corresponding tolife history stage in occasiont. |
stage3col | Optional variable name or column number corresponding tolife history stage in occasiont+1. |
juv2col | A variable name or column number that marks individuals inimmature stages in occasiont. Function |
juv3col | A variable name or column number that marks individuals inimmature stages in occasiont+1. Function |
stageassign | The stageframe object identifying the life history modelbeing operationalized. Note that if |
stagesize | A variable name or column number describing which size variable to use in stage estimation. Defaults to |
censor | A logical variable determining whether the output data shouldbe censored using the variable defined in |
censorcol | A variable name or column number corresponding to a censorvariable within the dataset, used to distinguish between entries to use andthose to discard from analysis, or to designate entries with special issues that require further attention. |
censorkeep | The value of the censoring variable identifying data thatshould be included in analysis. Defaults to |
spacing | The spacing at which density should be estimated, if densityestimation is desired and X and Y coordinates are supplied. Given in the sameunits as those used in the X and Y coordinates given in |
NAas0 | If TRUE, then all |
NRasRep | If set to |
NOasObs | If |
prebreeding | A logical term indicating whether the life history modelis pre-breeding. If so, then |
age_offset | A number to add automatically to all values of age at timet. Defaults to |
reduce | A logical variable determining whether unused variables andsome invariant state variables should be removed from the output dataset.Defaults to |
a2check | A logical variable indicating whether to retain all data withliving status at occasiont. Defaults to |
quiet | A logical variable indicating whether to silence warnings.Defaults to |
Value
If all inputs are properly formatted, then this function will outputa historical vertical data frame (classhfvdata), meaning that theoutput data frame will have three consecutive years of size and reproductivedata per individual per row. This data frame is in standard format for allfunctions used inlefko3, and so can be used without further modification. Note that determination of state in occasionst-1 andt+1 gives preference to condition in occasiont within theinput dataset. Conflicts in condition in input datasets that have bothoccasionst andt+1 listed per row are resolved by usingcondition in occasiont.
Variables in this data frame include the following:
rowid | Unique identifier for the row of the data frame. |
popid | Unique identifier for the population, if given. |
patchid | Unique identifier for patch within population, if given. |
individ | Unique identifier for the individual. |
year2 | Year or time in occasiont. |
firstseen | Occasion of first observation. |
lastseen | Occasion of last observation. |
obsage | Observed age in occasiont, assuming first observationcorresponds to age = 0. |
obslifespan | Observed lifespan, given as |
xpos1,xpos2,xpos3 | X position in Cartesian space in occasionst-1,t, andt+1, respectively, if provided. |
ypos1,ypos2,ypos3 | Y position in Cartesian space in occasionst-1,t, andt+1, respectively, if provided. |
sizea1,sizea2,sizea3 | Main size measurement in occasionst-1,t, andt+1, respectively. |
sizeb1,sizeb2,sizeb3 | Secondary size measurement in occasionst-1,t, andt+1, respectively. |
sizec1,sizec2,sizec3 | Tertiary size measurement in occasionst-1,t, andt+1, respectively. |
size1added,size2added,size3added | Sum of primary, secondary, andtertiary size measurements in occasionst-1,t, andt+1,respectively. |
repstra1,repstra2,repstra3 | Main numbers of reproductive structures inoccasionst-1,t, andt+1, respectively. |
repstrb1,repstrb2,repstrb3 | Secondary numbers of reproductivestructures in occasionst-1,t, andt+1, respectively. |
repstr1added,repstr2added,repstr3added | Sum of primary and secondaryreproductive structures in occasionst-1,t, andt+1,respectively. |
feca1,feca2,feca3 | Main numbers of offspring in occasionst-1,t, andt+1, respectively. |
fecb1,fecb2,fecb3 | Secondary numbers of offspring in occasionst-1,t, andt+1, respectively. |
fec1added,fec2added,fec3added | Sum of primary and secondary fecundityin occasionst-1,t, andt+1, respectively. |
censor1,censor2,censor3 | Censor status values in occasionst-1,t, andt+1, respectively. |
juvgiven1,juvgiven2,juvgiven3 | Binomial variable indicating whetherindividual is juvenile in occasionst-1,t, andt+1.Only given if |
obsstatus1,obsstatus2,obsstatus3 | Binomial observation status inoccasionst-1,t, andt+1, respectively. |
repstatus1,repstatus2,repstatus3 | Binomial reproductive status inoccasionst-1,t, andt+1, respectively. |
fecstatus1,fecstatus2,fecstatus3 | Binomial offspring production statusin occasionst-1,t, andt+1, respectively. |
matstatus1,matstatus2,matstatus3 | Binomial maturity status in occasionst-1,t, andt+1, respectively. |
alive1,alive2,alive3 | Binomial status as alive in occasionst-1,t, andt+1, respectively. |
density | Density of individuals per unit designated in |
Notes
Warnings that some individuals occur in state combinations that do not matchany stages in the stageframe used to assign stages, and that some individualsmatch characteristics of several stages in the stageframe, are common whenfirst working with a dataset. Typically, these situations can be identified asNoMatch entries instage3, although such entries may crop up instage1 andstage2, as well. In some cases, these warnings willarise with no concurrentNoMatch entries. These are important warningsand suggest that there is likely a problem with the stageframe. The mostcommon such problems are: 1) stages have significant overlap incharacteristics, with the most common being overlapping size bins caused byerroneous definitions of size bin halfwidths; and 2) some individuals existin states not defined within the stageframe.
In some datasets with unobservable stages, observation status(obsstatus) might not be inferred properly if a single size variableis used that does not yield sizes greater than 0 in all cases in whichindividuals were observed. Such situations may arise, for example, in plantswhen leaf number is the dominant size variable used, but individualsoccasionally occur with inflorescences but no leaves. In this instances,it helps to mark related variables assizeb andsizec, becauseobservation status will be interpreted in relation to all 3 size variables.Alternatively, observation status may be input viaobs2col andobs3col to force computation with given values (although this requiresall instances of observation and non-observation to be known and coded aheadof time). Further analysis can then utilize only a single size variable, ofthe user's choosing. Similar issues can arise in reproductive status(repstatus).
Juvenile designation should only be used when juveniles fall outside of thesize classification scheme used in determining stages. If juveniles are to besize classified along the size spectrum that adults also fall on, thenit is best to treat juveniles as mature but not reproductive.
Care should be taken to avoid variables with negative values indicating size,fecundity, or reproductive or observation status. Negative values can beinterpreted in different ways, typically reflecting estimation through otheralgorithms rather than actual measured data. Variables holding negativevalues can conflict with data management algorithms in ways that aredifficult to predict.
Unusual errors (e.g."Error in pjf...") may occur in cases where thevariables are improperly passed, or where seemingly numeric variables includetext and so get automatically converted to string variables.
Density estimation is performed as a count of individuals alive and withinthe radius specified inspacing of the respective individual at somepoint in time.
Examples
data(cypvert)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_v2 <- historicalize3(data = cypvert, patchidcol = "patch", individcol = "plantid", year2col = "year2", sizea2col = "Inf2.2", sizea3col = "Inf2.3", sizeb2col = "Inf.2", sizeb3col = "Inf.3", sizec2col = "Veg.2", sizec3col = "Veg.3", repstra2col = "Inf2.2", repstra3col = "Inf2.3", repstrb2col = "Inf.2", repstrb3col = "Inf.3", feca2col = "Pod.2", feca3col = "Pod.3", repstrrel = 2, stageassign = cypframe_raw, stagesize = "sizeadded", censorcol = "censor", censor = FALSE, NAas0 = TRUE, NRasRep = TRUE, reduce = TRUE)Create Matrix Image
Description
Functionimage3() is a generic function that creates matrix plots.
Usage
image3(mats, ...)Arguments
mats | A lefkoMat object, or a single projection matrix, for which thedominant eigenvalue is desired. |
... | Other parameters |
Value
Produces a single matrix image, or a series of images, depending onthe input. Non-zero elements appear as red space, while zero elements appearas white space.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")image3(ehrlen3, used = 1, type = "U")Create a Matrix Image for a Single Sparse Matrix
Description
Functionimage3.dgCMatrix plots a matrix image for a single sparsematrix.
Usage
## S3 method for class 'dgCMatrix'image3(mats, ...)Arguments
mats | A |
... | Other parameters. |
Value
Plots a matrix image, or series of matrix images, denoting non-zeroelements as red space and zero elements as white space.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ", sparse_output = TRUE)image3(ehrlen3$U[[1]])Create Matrix Image(s) for lefkoElas Object
Description
Functionimage3.lefkoElas plots matrix images for elasticity matricessupplied withinlefkoElas objects.
Usage
## S3 method for class 'lefkoElas'image3(mats, used = "all", type = "a", ...)Arguments
mats | A |
used | A numeric value or vector designating the matrices to plot. Canalso take the value |
type | Character value indicating whether to plot |
... | Other parameters. |
Value
Plots a matrix image, or series of matrix images, denoting non-zeroelements as red space and zero elements as white space.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = c(1989, 1990), stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen_elas <- elasticity3(ehrlen3)image3(ehrlen_elas, used = 1, type = "h")Create Matrix Image(s) for lefkoMat Object
Description
Functionimage3.lefkoMat plots matrix images for matrices suppliedwithinlefkoMat objects.
Usage
## S3 method for class 'lefkoMat'image3(mats, used = "all", type = "A", ...)Arguments
mats | A |
used | A numeric value or vector designating the matrices to plot. Canalso take the value |
type | Character value indicating whether to plot |
... | Other parameters. |
Value
Plots a matrix image, or series of matrix images, denoting non-zeroelements as red space and zero elements as white space.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")image3(ehrlen3, used = 1, type = "U")Create Matrix Image(s) for lefkoSens Object
Description
Functionimage3.lefkoSens plots matrix images for sensitivity matricessupplied withinlefkoSens objects.
Usage
## S3 method for class 'lefkoSens'image3(mats, used = "all", type = "a", ...)Arguments
mats | A |
used | A numeric value or vector designating the matrices to plot. Canalso take the value |
type | Character value indicating whether to plot |
... | Other parameters. |
Value
Plots a matrix image, or series of matrix images, denoting non-zeroelements as red space and zero elements as white space.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = c(1989, 1990), stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen_sens <- sensitivity3(ehrlen3)image3(ehrlen_sens, used = 1, type = "h")Create Matrix Images for Matrices in a List
Description
Functionimage3.list plots matrix images for matrices contained in alist of matrices.
Usage
## S3 method for class 'list'image3(mats, used = "all", ...)Arguments
mats | A |
used | A numeric vector of projection matrices within |
... | Other parameters. |
Value
Plots a matrix image, or series of matrix images, denoting non-zeroelements as red space and zero elements as white space.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "all", "all"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")image3(ehrlen3$A, used = 1)Create a Matrix Image for a Single Matrix
Description
Functionimage3.matrix plots a matrix image for a single matrix.
Usage
## S3 method for class 'matrix'image3(mats, ...)Arguments
mats | A |
... | Other parameters. |
Value
Plots a matrix image, or series of matrix images, denoting non-zeroelements as red space and zero elements as white space.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ", sparse_output = FALSE)image3(ehrlen3$U[[1]])Estimate Actual or Deterministic Population Growth Rate
Description
Functionlambda3() is a generic function that returns the dominanteigenvalue of a matrix, set of dominant eigenvalues of a set of matrices,set of dominant eigenvalues for alefkoMat object, or actual\lambda in each year in alefkoProj object. It can handlelarge and sparse matrices supplied aslefkoMat objects or asindividual matrices, and can be used with large historical matrices, IPMs, age x stage matrices, as well as smaller ahistorical matrices, and generalprojetions.
Usage
lambda3(mpm, force_sparse = NULL)Arguments
mpm | A |
force_sparse | A logical value or string detailing whether to forcesparse matrix encoding for simple matrix input. Defaults to |
Value
The value returned depends on the class of thempm argument.If alefkoMat object is provided, then this function will return thelabels data frame with a new column namedlambda showing thedominant eigenvalues for each matrix. If alefkoMatList object isprovided, then a two element list in which the first element is a vectorcomposed of the mean lambda values of eachlefkoMat element withinthe list is provided, and the second element is a list oflefkoMatlambda summaries as previously described. If a list of matrices is provided,then this function will produce a numeric vector with the dominanteigenvalues provided in order of matrix. If a single matrix is provided,then this function will return the dominant eigenvalue of that matrix. Onlythe largest real parts of the eigenvalues are returned.
If alefkoProj object is provided, then the output consists of a listwith three elements. The second and third elements are lists of matriceswith each lower-level list elements corresponding tolabels rows,and matrices within these lists showing the actual\lambda andlog\lambda for each consecutive year or time index (columns)within each replicate (row).
See Also
slambda3()
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)lambda3(ehrlen3mean)# Cypripedium exampledata(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)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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")lambda3(cypmatrix2r)Demographic Dataset ofLathyrus vernus Population
Description
A dataset containing the states and fates ofLathyrus vernus (springvetch), family Fabaceae, from a population in Sweden monitored annuallyfrom 1988 to 1991 in six study plots.
Usage
data(lathyrus)Format
A data frame with 1119 individuals and 34 variables. Each rowcorresponds to a unique individual, and each variable fromVolume88on refers to the state of the individual in a given year.
- SUBPLOT
A variable refering to patch within the population.
- GENET
A numeric variable giving a unique number to each individual.
- Volume88
Aboveground volume in cubic mm in 1988.
- lnVol88
Natural logarithm of
Volume88.- FCODE88
Equals 1 if flowering and 0 if not flowering in 1988.
- Flow88
Number of flowers in 1988.
- Intactseed88
Number of intact mature seeds produced in 1988.Not always an integer, as in some cases seed number was estimated via linear modeling.
- Dead1988
Marked as 1 if known to be dead in 1988.
- Dormant1988
Marked as 1 if known to be alive but vegetatively dormant in 1988.
- Missing1988
Marked as 1 if not found in 1988.
- Seedling1988
Marked as 1, 2, or 3 if observed as a seedling in yeart. Numbers refer to certainty of assignment: 1 = certain that plantis a seedling in 1988, 2 = likely that plant is a seedling in 1988,3 = probable that plant is a seedling in 1988.
- Volume89
Aboveground volume in cubic mm in 1989.
- lnVol89
Natural logarithm of
Volume89.- FCODE89
Equals 1 if flowering and 0 if not flowering in 1989.
- Flow89
Number of flowers in 1989.
- Intactseed89
NZumber of intact mature seeds produced in 1989.Not always an integer, as in some cases seed number was estimated vialinear modeling.
- Dead1989
Marked as 1 if known to be dead in 1989.
- Dormant1989
Marked as 1 if known to be alive but vegetatively dormant in 1989.
- Missing1989
Marked as 1 if not found in 1989.
- Seedling1989
Marked as 1, 2, or 3 if observed as a seedling inyeart. Numbers refer to certainty of assignment: 1 = certain that plant is a seedling in 1989, 2 = likely that plant is a seedling in 1989, 3 = probable that plant is a seedling in 1989.
- Volume90
Aboveground volume in mm<sup>3</sup> in 1990.
- lnVol90
Natural logarithm of
Volume90.- FCODE90
Equals 1 if flowering and 0 if not flowering in 1990.
- Flow90
Number of flowers in 1990.
- Intactseed90
NZumber of intact mature seeds produced in 1990.Not always an integer, as in some cases seed number was estimated via linear modeling.
- Dead1990
Marked as 1 if known to be dead in 1990.
- Dormant1990
Marked as 1 if known to be alive but vegetatively dormant in 1990.
- Missing1990
Marked as 1 if not found in 1990.
- Seedling1990
Marked as 1, 2, or 3 if observed as a seedling inyeart. Numbers refer to certainty of assignment: 1 = certain that plant is a seedling in 1990, 2 = likely that plant is a seedlingin 1990, 3 = probable that plant is a seedling in 1990.
- Volume91
Aboveground volume in mm<sup>3</sup> in 1991.
- lnVol91
Natural logarithm of
Volume91.- FCODE91
Equals 1 if flowering and 0 if not flowering in 1991.
- Flow91
Number of flowers in 1991.
- Intactseed91
NZumber of intact mature seeds produced in 1991.Not always an integer, as in some cases seed number was estimated vialinear modeling.
- Dead1991
Marked as 1 if known to be dead in 1991.
- Dormant1991
Marked as 1 if known to be alive but vegetatively dormant in 1991.
- Missing1991
Marked as 1 if not found in 1991.
- Seedling1991
Marked as 1, 2, or 3 if observed as a seedling in yeart. Numbers refer to certainty of assignment: 1 = certain that plant is a seedling in 1991, 2 = likely that plant is a seedling in 1991, 3 = probable that plant is a seedling in 1991.
Source
Ehrlen, J. 2000. The dynamics of plant populations: does the history of individuals matter?Ecology 81(6):1675-1684.
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", juvcol = c("Seedling1988", "Seedling1989", "Seedling1990", "Seedling1991"), sizeacol = c("Volume88", "Volume89", "Volume90", "Volume91"), repstracol = c("FCODE88", "FCODE89", "FCODE90", "FCODE91"), fecacol = c("Intactseed88", "Intactseed89", "Intactseed90", "Intactseed91"), deadacol = c("Dead1988", "Dead1989", "Dead1990", "Dead1991"), nonobsacol = c("Dormant1988", "Dormant1989", "Dormant1990", "Dormant1991"), censorcol = c("Missing1988", "Missing1989", "Missing1990", "Missing1991"), stageassign = lathframe, stagesize = "sizea", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)ehrlen3mean$A[[1]]lambda3(ehrlen3mean)Estimate Mean Projection Matrices
Description
Functionlmean() estimates mean projection matrices as element-wisearithmetic means. It produceslefkoMat objects if provided with them,or single matrices in a simple one-element list if provided a list ofmatrices. Will produce alefkoMatList object, in which each elementis alefkoMat object, if provided with alefkoMatList object.
Usage
lmean(mats, matsout = NULL, force_sparse = FALSE)Arguments
mats | A |
matsout | A string identifying which means to estimate. Option |
force_sparse | A logical value identifying whether to output the meanmatrices in sparse format, if input as standard matrices. |
Value
Yields alefkoMat object, alefkoMatList object, ora list of matrices. If alefkoMat object. then will have thefollowing characteristics:
A | A list of full mean projection matrices in order of sortedpopulations, patches, and years. These are typically estimated as the sumsof the associated mean |
U | A list of mean survival-transition matrices sorted as in |
F | A list of mean fecundity matrices sorted as in |
hstages | A data frame showing the pairing of ahistorical stages usedto create historical stage pairs. Given if the MPM is historical. |
ahstages | A data frame detailing the characteristics of associatedahistorical stages. |
labels | A data frame detailing the order of population, patch, andyear of each mean matrix. If |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. Only output from |
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)Two-Parameter logistic Function
Description
Functionlogistic3() creates a vector of values produced by thelogistic function as applied with a user-specified time lag. The logisticfunction is given as\phi_{t+1} = \phi_t \lambda (1 - n_t / K). Here,if noseparate_N vector is provided, thenn_t = \phi_t. If\lambda is not provided, then it defaults to1.0.
Usage
logistic3( start_value, alpha, beta = 0, lambda = 1, time_steps = 100L, time_lag = 1L, pre0_subs = FALSE, pre0_value = 0, substoch = 0L, separate_N = NULL)Arguments
start_value | A positive number to start the return vector in time 0. |
alpha | The carrying capacity K. |
beta | If set to some positive number, then this number is the maximumvalue of phi to enforce. Otherwise, equals |
lambda | The value of the discrete population growth rate to use.Equal to the natural logarithm of the instantaneous growth rate, r. |
time_steps | The number of time steps to run the projection. Must be apositive integer. |
time_lag | A positive integer denoting the number of time steps backfor the value of phi in the logistic function. |
pre0_subs | A logical value indicating whether to use a number otherthan that given in |
pre0_value | A positive number to use for phi lagged from times priorto time 0. Only used if |
substoch | An integer value indicating the kind of substochasticity touse. Values include: |
separate_N | An optional numeric vector with values of N in each time,if phi is to be treated as different from N in the logistic model. |
Value
A numeric vector of values showing values projected under the-logistic function.
Examples
trial_run1 <- logistic3(1, alpha = 5)plot(trial_run1)trial_run2 <- logistic3(1, alpha = 5, beta = 5)plot(trial_run2)trial_run3 <- logistic3(1, alpha = 100)plot(trial_run3)trial_run4 <- logistic3(1, alpha = 100, beta = 50)plot(trial_run4)trial_run5 <- logistic3(1, alpha = 500)plot(trial_run5)trial_run6 <- logistic3(1, alpha = 500, beta = 501)plot(trial_run6)used_Ns <- c(10, 15, 12, 14, 14, 150, 15, 1, 5, 7, 9, 14, 13, 16, 17, 19, 25, 26)trial_run7 <- logistic3(1, alpha = 500, beta = 501, separate_N = used_Ns)plot(trial_run7)Conduct a Life Table Response Experiment
Description
ltre3() returns a set of matrices of one-way LTRE (life table responseexperiment), stochastic LTRE (sLTRE) matrices, or small noise approximationLTRE (sna-LTRE) contributions.
Usage
ltre3( mats, refmats = NA, ref = NA, stochastic = FALSE, times = 10000, burnin = 3000, tweights = NA, sparse = "auto", seed = NA, append_mats = FALSE, sna_ltre = FALSE, tol = 1e-30, ...)Arguments
mats | An object of class |
refmats | A reference lefkoMat object, or matrix, for use as thecontrol. Default is |
ref | A numeric value indicating which matrix or matrices in |
stochastic | A logical value determining whether to conduct adeterministic ( |
times | The number of occasions to project forward in stochasticsimulation. Defaults to |
burnin | The number of initial steps to ignore in stochastic projectionwhen calculating stochastic elasticities. Must be smaller than |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. Note that SNA-LTRE analysis cannot take matrixinput. |
sparse | A text string indicating whether to use sparse matrix encoding( |
seed | Optional numeric value corresponding to the random seed forstochastic simulation. |
append_mats | A logical value denoting whether to include the original |
sna_ltre | A logical value indicating whether to treat stochastic LTREvia the sna-LTRE approach from Davison et al. (2019) ( |
tol | A numeric value indicating a lower positive limit to matrixelement values when applied to stochastic and small noise approximation LTREestimation protocols. Matrix element values lower than this will be treatedas |
... | Other parameters. |
Value
This function returns an object of classlefkoLTRE. Thisincludes a list of LTRE matrices as objectcont_mean if adeterministic LTRE is called for, or a list of mean-value LTRE matrices asobjectcont_mean and a list of SD-value LTRE matrices as objectcont_sd if a stochastic LTRE is called for. If a small-noiseapproximation LTRE (SNA-LTRE) is performed, then the output includes sixobjects:cont_mean, which provides the contributions of shifts in meanmatrix elements;cont_elas, which provides the contributions of shiftsin the elasticities of matrix elements;cont_cv, which provides thecontributions of temporal variation in matrix elements;cont_corr,which provides the contributions of temporal correlations in matrix elements;r_values_m, which provides a vector of log deterministic lambda valuesfor treatment populations; andr_values_ref, which provides the logdeterministic lambda of the mean reference matrix.This is followed by thestageframe as objectahstages, the order of historical stages asobjecthstages, the age-by-stage order as objectagestages, theorder of matrices as objectlabels, and, if requested, the original A,U, and F matrices.
Notes
Functionltre3() cannot handlelefkoMatList inputs, althoughindividuallefkoMat elements within these lists can be used.
Deterministic LTRE is one-way, fixed, and based on the sensitivities of thematrix midway between each input matrix and the reference matrix, per Caswell(2001, Matrix Population Models, Sinauer Associates, MA, USA). StochasticLTRE is performed via two methods. The stochastic LTRE approximation issimulated per Davison et al. (2010) Journal of Ecology 98:255-267(doi: 10.1111/j.1365-2745.2009.01611.x). The small noise approximation(sna-LTRE) is analyzed per Davison et al. (2019) Ecological Modelling 408:108760 (doi: 10.1016/j.ecolmodel.2019.108760).
All stochastic and small noise approximation LTREs conducted withoutreference matrices are performed as spatial tests of the population dynamicsamong patches.
Default behavior for stochastic LTRE uses the full population provided inmats as the reference if norefmats andref is provided.If norefmats is provided butref is, then the matrices notedinref are used as the reference matrix set. Year and patch order isutilized from objectmats, but not from objectrefmats, inwhich each matrix is assumed to represent a different year from onepopulation. This function cannot currently handle multiple populations withinthe samemats object (although such analysis is possible if thesepopulations are designated as patches instead).
Ifsparse = "auto", the default, then sparse matrix encodingwill be used if the size of the input matrices is at least 50 columns by 50rows for deterministic and stochastic LTREs and 10 columns by 10 rows forsmall noise approximation LTREs, in all cases as long as 50% of the elementsin the first matrix are non-zero.
Stochastic LTREs do not test for the impact of temporal change in vitalrates. An MPM with a single population, a single patch, and only annualmatrices will produce contributions of 0 to stochastic\lambda.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 10 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
SNA-LTRE analysis cannot test the impact of first-order Markovianenvironments. However, different random weightings of annual matrices areallowed if given in vector format.
Thetime_weights,steps,force_sparse, andrseedarguments are now deprecated. Instead, please use thetweights,times,sparse, andseed arguments.
See Also
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")ltre3(cypmatrix2r, sna_ltre = TRUE)Creates Vector of Times Based on First-Order Markov Transition Matrix
Description
Creates a vector of randomly sampled years / times to be used in projection.Random sampling requires a 1st order Markovian transition matrix, showingthe probability of transitioning to each time from each time. Note that thisfunction is not required if the probability of transitioning to a particulartime does not vary with time.
Usage
markov_run(main_times, mat, times = 10000L, start = NULL)Arguments
main_times | An integer vector giving the years / times to use. |
mat | A matrix giving the transition probabilities from each time toeach time. Must have the same number of columns and rows as there areelements in vector |
times | The number of times to project forward. Defaults to 10000. |
start | The start time to use. Defaults to the first time in vector |
Value
An integer vector giving the order of times / years to use inprojection. This can be used as input in theyear option infunctionsprojection3() andf_projection3().
See Also
Examples
# Cypripedium exampledata(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)cypsupp3r <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "D", "XSm", "Sm", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "D", "XSm", "Sm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", NA, NA), givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3r, yearcol = "year2", indivcol = "individ")used_years <-c(2005, 2006, 2007, 2008)yr_tx_vec <- c(0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4)yr_tx_mat <- matrix(yr_tx_vec, 4, 4)set.seed(1)cyp_markov_vec_1 <- markov_run(main_times = used_years, mat = yr_tx_mat, times = 100)set.seed(2)cyp_markov_vec_2 <- markov_run(main_times = used_years, mat = yr_tx_mat, times = 100)set.seed(3)cyp_markov_vec_3 <- markov_run(main_times = used_years, mat = yr_tx_mat, times = 100)cypstoch_1 <- projection3(cypmatrix3r, nreps = 1, times = 100, year = cyp_markov_vec_1)cypstoch_2 <- projection3(cypmatrix3r, nreps = 1, times = 100, year = cyp_markov_vec_2)cypstoch_3 <- projection3(cypmatrix3r, nreps = 1, times = 100, year = cyp_markov_vec_3)Arranges Matrix Elements in Order of Magnitude for Interpretation
Description
Functionmatrix_interp summarizes matrices fromlefkoMat,lefkoSens,lefkoElas, andlefkoLTRE objects in termsof the magnitudes of their elements. It can also create ordered summaries ofstandard matrices and sparse matrices.
Usage
matrix_interp(object, mat_chosen = 1L, part = 1L, type = 3L)Arguments
object | A list object in one of |
mat_chosen | The number of the matrix to assess, within the appropriatematrix list. See |
part | An integer noting whether to provide assessments of which of themain types of matrices to analyze. In a standard |
type | An integer corresponding to the type of order summary, includingmost to least positive ( |
Value
A data frame arranging all elements in the matrix chosen fromgreatest and smallest. This can be a data frame of only positive elements,of only negative elements, or all elements in order of absolute magnitude.
Notes
Argumentmat_chosen refers to the number of the matrix within thelist that it is held in. For example, if the function is applied to thecont_sd portion of a stochastic LTRE, and there are four LTREmatrices within that list element corresponding to three patch LTRE matricesand one overall population-level LTRE matrix, then setting this value to4 would focus the function on the overall population-level LTREmatrix associated with contributions of the standard deviations of elements.This argument should be left blank if a standard matrix or sparse matrix isinput.
Huge sparse matrices may take more time to process than small, densematrices.
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")aaa <- ltre3(cypmatrix2r, stochastic = TRUE)matrix_interp(aaa, mat_chosen = 1, part = 2, type = 3)Minimize lefkoMod Object by Conversion to vrm_input Object
Description
This function takes alefkoMod object, which consists of vital ratemodels, their associateddredge model tables, and related metadata,and converts them to minimal data frame lists useable in MPM creation andprojection. The main advantage to using this approach is in memory savings.
Usage
miniMod( lMod, hfv_data = NULL, stageframe = NULL, all_years = NULL, all_patches = NULL, all_groups = NULL, all_indcova = NULL, all_indcovb = NULL, all_indcovc = NULL)Arguments
lMod | A |
hfv_data | The |
stageframe | The stageframe used to develop object |
all_years | A vector giving the times / years used to develop object |
all_patches | A vector giving the patch names used to develop object |
all_groups | A vector giving the stage groups used to develop object |
all_indcova | The name of individual covariate a if quantitative andnon-categorical, or of the categories used if the covariate is a factorvariable. Only needed if object |
all_indcovb | The name of individual covariate a if quantitative andnon-categorical, or of the categories used if the cvoariate is a factorvariable. Only needed if object |
all_indcovc | The name of individual covariate a if quantitative andnon-categorical, or of the categories used if the covariate is a factorvariable. Only needed if object |
Value
An object of classvrm_input. See functionvrm_import() for details.
Examples
data(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathmodelsln3 <- modelsearch(lathvertln, historical = TRUE, approach = "mixed", suite = "main", vitalrates = c("surv", "obs", "size", "repst", "fec"), juvestimate = "Sdl", bestfit = "AICc&k", sizedist = "gaussian", fecdist = "poisson", indiv = "individ", patch = "patchid", year = "year2", year.as.random = TRUE, patch.as.random = TRUE, show.model.tables = TRUE, quiet = "partial")lathmodels_mini <- miniMod(lathmodelsln3, hfv_data = lathvertln, stageframe = lathframeln)lathmodels_miniDevelop Best-fit Vital Rate Estimation Models for MPM Development
Description
Functionmodelsearch() runs exhaustive model building and selectionfor each vital rate needed to estimate a function-based MPM or IPM. Itreturns best-fit models for each vital rate, model table showing all modelstested, and model quality control data. The final output can be used as inputin other functions within this package.
Usage
modelsearch( data, stageframe = NULL, historical = TRUE, approach = "mixed", suite = "size", interactions = FALSE, bestfit = "AICc&k", vitalrates = c("surv", "size", "fec"), surv = c("alive3", "alive2", "alive1"), obs = c("obsstatus3", "obsstatus2", "obsstatus1"), size = c("sizea3", "sizea2", "sizea1"), sizeb = c(NA, NA, NA), sizec = c(NA, NA, NA), repst = c("repstatus3", "repstatus2", "repstatus1"), fec = c("feca3", "feca2", "feca1"), stage = c("stage3", "stage2", "stage1"), matstat = c("matstatus3", "matstatus2", "matstatus1"), indiv = "individ", patch = NA, year = "year2", density = NA, test.density = FALSE, sizedist = "gaussian", sizebdist = NA, sizecdist = NA, fecdist = "gaussian", size.zero = FALSE, sizeb.zero = FALSE, sizec.zero = FALSE, size.trunc = FALSE, sizeb.trunc = FALSE, sizec.trunc = FALSE, fec.zero = FALSE, fec.trunc = FALSE, patch.as.random = TRUE, year.as.random = TRUE, juvestimate = NA, juvsize = FALSE, jsize.zero = FALSE, jsizeb.zero = FALSE, jsizec.zero = FALSE, jsize.trunc = FALSE, jsizeb.trunc = FALSE, jsizec.trunc = FALSE, fectime = 2, censor = NA, age = NA, test.age = FALSE, indcova = NA, indcovb = NA, indcovc = NA, random.indcova = FALSE, random.indcovb = FALSE, random.indcovc = FALSE, test.indcova = FALSE, test.indcovb = FALSE, test.indcovc = FALSE, annucova = NA, annucovb = NA, annucovc = NA, test.annucova = FALSE, test.annucovb = FALSE, test.annucovc = FALSE, test.group = FALSE, show.model.tables = TRUE, global.only = FALSE, accuracy = TRUE, data_out = FALSE, quiet = FALSE)Arguments
data | The vertical dataset to be used for analysis. This dataset should be of class |
stageframe | The stageframe characterizing the life history model used.Optional unless |
historical | A logical variable denoting whether to assess the effectsof state in occasiont-1, in addition to state in occasiont.Defaults to |
approach | The statistical approach to be taken for model building. The default is |
suite | Either a single string value or a vector of 14 strings for eachvital rate model. Describes the global model for each vital rate estimation,and has the following possible values: |
interactions | A variable denoting whether to include two-wayinteractions between all fixed factors in the global model. Defaults to |
bestfit | A variable indicating the model selection criterion for thechoice of best-fit model. The default is |
vitalrates | A vector describing which vital rates will be estimated vialinear modeling, with the following options: |
surv | A vector indicating the variable names coding for status as aliveor dead in occasionst+1,t, andt-1, respectively.Defaults to |
obs | A vector indicating the variable names coding for observationstatus in occasionst+1,t, andt-1, respectively.Defaults to |
size | A vector indicating the variable names coding for the primarysize variable on occasionst+1,t, andt-1,respectively. Defaults to |
sizeb | A vector indicating the variable names coding for the secondarysize variable on occasionst+1,t, andt-1,respectively. Defaults to |
sizec | A vector indicating the variable names coding for the tertiarysize variable on occasionst+1,t, andt-1,respectively. Defaults to |
repst | A vector indicating the variable names coding for reproductivestatus in occasionst+1,t, andt-1, respectively.Defaults to |
fec | A vector indicating the variable names coding for fecundity inoccasionst+1,t, andt-1, respectively. Defaults to |
stage | A vector indicating the variable names coding for stage inoccasionst+1,t, andt-1. Defaults to |
matstat | A vector indicating the variable names coding for maturitystatus in occasionst+1,t, andt-1. Defaults to |
indiv | A text value indicating the variable name coding individualidentity. Defaults to |
patch | A text value indicating the variable name coding for patch,where patches are defined as permanent subgroups within the study population.Defaults to |
year | A text value indicating the variable coding for observationoccasiont. Defaults to |
density | A text value indicating the name of the variable coding forspatial density, should the user wish to test spatial density as a fixedfactor affecting vital rates. Defaults to |
test.density | Either a logical value indicating whether to include |
sizedist | The probability distribution used to model primary size.Options include |
sizebdist | The probability distribution used to model secondary size.Options include |
sizecdist | The probability distribution used to model tertiary size.Options include |
fecdist | The probability distribution used to model fecundity. Optionsinclude |
size.zero | A logical variable indicating whether the primary sizedistribution should be zero-inflated. Only applies to Poisson and negativebinomial distributions. Defaults to |
sizeb.zero | A logical variable indicating whether the secondary sizedistribution should be zero-inflated. Only applies to Poisson and negativebinomial distributions. Defaults to |
sizec.zero | A logical variable indicating whether the tertiary sizedistribution should be zero-inflated. Only applies to Poisson and negativebinomial distributions. Defaults to |
size.trunc | A logical variable indicating whether the primary sizedistribution should be zero-truncated. Only applies to Poisson and negativebinomial distributions. Defaults to |
sizeb.trunc | A logical variable indicating whether the secondary sizedistribution should be zero-truncated. Only applies to Poisson and negativebinomial distributions. Defaults to |
sizec.trunc | A logical variable indicating whether the tertiary sizedistribution should be zero-truncated. Only applies to Poisson and negativebinomial distributions. Defaults to |
fec.zero | A logical variable indicating whether the fecunditydistribution should be zero-inflated. Only applies to Poisson and negativebinomial distributions. Defaults to |
fec.trunc | A logical variable indicating whether the fecunditydistribution should be zero-truncated. Only applies to the Poisson andnegative binomial distributions. Defaults to |
patch.as.random | If set to |
year.as.random | If set to |
juvestimate | An optional variable denoting the stage name of thejuvenile stage in the vertical dataset. If not |
juvsize | A logical variable denoting whether size should be used as aterm in models involving transition from the juvenile stage. Defaults to |
jsize.zero | A logical variable indicating whether the primary sizedistribution of juveniles should be zero-inflated. Only applies to Poissonand negative binomial distributions. Defaults to |
jsizeb.zero | A logical variable indicating whether the secondary sizedistribution of juveniles should be zero-inflated. Only applies to Poissonand negative binomial distributions. Defaults to |
jsizec.zero | A logical variable indicating whether the tertiary sizedistribution of juveniles should be zero-inflated. Only applies to Poissonand negative binomial distributions. Defaults to |
jsize.trunc | A logical variable indicating whether the primary sizedistribution in juveniles should be zero-truncated. Defaults to |
jsizeb.trunc | A logical variable indicating whether the secondary sizedistribution in juveniles should be zero-truncated. Defaults to |
jsizec.trunc | A logical variable indicating whether the tertiary sizedistribution in juveniles should be zero-truncated. Defaults to |
fectime | A variable indicating which year of fecundity to use as theresponse term in fecundity models. Options include |
censor | A vector denoting the names of censoring variables in thedataset, in order from occasiont+1, followed by occasiont,and lastly followed by occasiont-1. Defaults to |
age | Designates the name of the variable corresponding to age in timet in the vertical dataset. Defaults to |
test.age | Either a logical value indicating whether to include |
indcova | Vector designating the names in occasionst+1,t, andt-1 of an individual covariate. Defaults to |
indcovb | Vector designating the names in occasionst+1,t, andt-1 of a second individual covariate. Defaults to |
indcovc | Vector designating the names in occasionst+1,t, andt-1 of a third individual covariate. Defaults to |
random.indcova | A logical value indicating whether |
random.indcovb | A logical value indicating whether |
random.indcovc | A logical value indicating whether |
test.indcova | Either a logical value indicating whether to include the |
test.indcovb | Either a logical value indicating whether to include the |
test.indcovc | Either a logical value indicating whether to include the |
annucova | A numeric vector of annual covariates to test within allvital rate models. If |
annucovb | A second numeric vector of annual covariates to test withinall vital rate models. If |
annucovc | A third numeric vector of annual covariates to test withinall vital rate models. If |
test.annucova | A logical value indicating whether to test the variablegiven as |
test.annucovb | A logical value indicating whether to test the variablegiven as |
test.annucovc | A logical value indicating whether to test the variablegiven as |
test.group | Either a logical value indicating whether to include the |
show.model.tables | If set to TRUE, then includes full modeling tablesin the output. Defaults to |
global.only | If set to TRUE, then only global models will be built andevaluated. Defaults to |
accuracy | A logical value indicating whether to test accuracy ofmodels. See |
data_out | A logical value indicating whether to append all subsetteddatasets used in model building and selection to the output. Defaults to |
quiet | May be a logical value, or any one of the strings |
Value
This function yields an object of classlefkoMod, or a list ofclasslefkoModList if the data entered is of classhfvlist.If the latter, then each element is an object of classlefkoMod.ClasslefkoMod objects are themselves lists. The first 14 elements arethe best-fit models for survival, observation status, primary size,secondary size, tertiary size, reproductive status, fecundity,juvenile survival, juvenile observation, juvenile primary size, juvenilesecondary size, juvenile tertiary size, juvenile transition to reproduction,and juvenile transition to maturity, respectively. This is followed by 14elements corresponding to the model tables for each of these vital rates, inorder, followed by a data frame showing the order and names of variables usedin modeling, followed by a single character element denoting the criterionused for model selection, and ending on a data frame with quality controldata:
survival_model | Best-fit model of the binomial probability of survivalfrom occasiont to occasiont+1. Defaults to |
observation_model | Best-fit model of the binomial probability of observation in occasiont+1 given survival to that occasion. Defaultsto |
size_model | Best-fit model of the primary size metric on occasiont+1 given survival to and observation in that occasion. Defaults to |
sizeb_model | Best-fit model of the secondary size metric on occasiont+1 given survival to and observation in that occasion. Defaults to |
sizec_model | Best-fit model of the tertiary size metric on occasiont+1 given survival to and observation in that occasion. Defaults to |
repstatus_model | Best-fit model of the binomial probability ofreproduction in occasiont+1, given survival to and observation inthat occasion. Defaults to |
fecundity_model | Best-fit model of fecundity in occasiont+1given survival to, and observation and reproduction in that occasion.Defaults to |
juv_survival_model | Best-fit model of the binomial probability ofsurvival from occasiont to occasiont+1 of an immatureindividual. Defaults to |
juv_observation_model | Best-fit model of the binomial probability of observation in occasiont+1 given survival to that occasion of animmature individual. Defaults to |
juv_size_model | Best-fit model of the primary size metric on occasiont+1 given survival to and observation in that occasion of an immatureindividual. Defaults to |
juv_sizeb_model | Best-fit model of the secondary size metric onoccasiont+1 given survival to and observation in that occasion of animmature individual. Defaults to |
juv_sizec_model | Best-fit model of the tertiary size metric on occasiont+1 given survival to and observation in that occasion of an immatureindividual. Defaults to |
juv_reproduction_model | Best-fit model of the binomial probability ofreproduction in occasiont+1, given survival to and observation inthat occasion of an individual that was immature in occasiont. Thismodel is technically not a model of reproduction probability for individualsthat are immature, rather reproduction probability here is given forindividuals that are mature in occasiont+1 but immature in occasiont. Defaults to |
juv_maturity_model | Best-fit model of the binomial probability ofbecoming mature in occasiont+1, given survival to that occasion of anindividual that was immature in occasiont. Defaults to |
survival_table | Full dredge model table of survival probability. |
observation_table | Full dredge model table of observation probability. |
size_table | Full dredge model table of the primary size variable. |
sizeb_table | Full dredge model table of the secondary size variable. |
sizec_table | Full dredge model table of the tertiary size variable. |
repstatus_table | Full dredge model table of reproduction probability. |
fecundity_table | Full dredge model table of fecundity. |
juv_survival_table | Full dredge model table of immature survival probability. |
juv_observation_table | Full dredge model table of immature observationprobability. |
juv_size_table | Full dredge model table of primary size in immatureindividuals. |
juv_sizeb_table | Full dredge model table of secondary size in immatureindividuals. |
juv_sizec_table | Full dredge model table of tertiary size in immatureindividuals. |
juv_reproduction_table | Full dredge model table of immaturereproduction probability. |
juv_maturity_table | Full dredge model table of the probability ofan immature individual transitioning to maturity. |
paramnames | A data frame showing the names of variables from the inputdata frame used in modeling, their associated standardized names in linearmodels, and a brief comment describing each variable. |
criterion | Character variable denoting the criterion used to determinethe best-fit model. |
qc | Data frame with five variables: 1) Name of vital rate, 2) numberof individuals used to model that vital rate, 3) number of individualtransitions used to model that vital rate, 4) parameter distribution used tomodel the vital rats, and 5) accuracy of model, given as detailed in Notessection. |
subdata | An optional list of data frames, each of which is the dataframe used to develop each model in the |
Notes
Whenmodelsearch() is called, it first trims the dataset down to justthe variables that will be used (including all response terms and independentvariables). It then subsets the data to only complete cases for thosevariables. Next, it builds global models for all vital rates, and runs them.If a global model fails, then the function proceeds by dropping terms. Ifapproach = "mixed", then it will determine which random factor termcontains the most categories in the respective subset, and drop that term.If this fails, or ifapproach = "glm", then it will drop any two-wayinteractions and run the model. If this fails, then the function will attemptto drop further terms, first patch alone, then year alone, then individualcovariates by themselves, then combinations of these four, and finallyindividual identity. If all of these attempts fail and the approach used ismixed, then the function will try running a glm version of theoriginal failed model. Finally, if all attempts fail, then the functiondisplays a warning and returns1 to allow model building assuming aconstant rate or probability.
Including annual covariates is easy via the argumentsannucova,annucovb, andannucovc together withtest.annucova,test.annucovb, andtest.annucovc. Rather than incorporatea nnual covariates into the dataset, the values corresponding to each yearmay be concatenated into a numeric vector, and then used in one of thesethree arguments. Functionmodelsearch() will then append the valueassociated with each year into the dataset, and proceed with model building.Two-way interactions can be explored with other main effects fixed variablesby settinginteractions = TRUE.
Settingsuite = "cons" prevents the inclusion of size and reproductivestatus as fixed, independent factors in modeling. However, it does notprevent any other terms from being included. Density, age, individualcovariates, individual identity, patch, and year may all be included.
The mechanics governing model building are fairly robust to errors andexceptions. The function attempts to build global models, and simplifiesmodels automatically should model building fail. Model building proceedsthrough the functionslm() (GLM with Gaussian response),glm() (GLM with Poisson, Gamma, or binomial response),glm.nb() (GLM with negative binomial response),zeroinfl() (GLM with zero-inflated Poisson or negativebinomial response),vglm() (GLM with zero-truncatedPoisson or negative binomial response),lmer() (mixedmodel with Gaussian response),glmer() (mixed model withbinomial, Poisson, or Gamma response), andglmmTMB()(mixed model with negative binomial, or zero-truncated or zero-inflatedPoisson or negative binomial response). See documentation related to thesefunctions for further information. Any response term that is invariable inthe dataset will lead to a best-fit model for that response represented by asingle constant value.
Exhaustive model building and selection proceeds via thedredge() function in packageMuMIn. This functionis verbose, so that any errors and warnings developed during model building,model analysis, and model selection can be found and dealt with.Interpretations of errors during global model analysis may be found indocumentation for the functions and packages mentioned. PackageMuMInis used for model dredging (seedredge()), and errors andwarnings during dredging can be interpreted using the documentation for thatpackage. Errors occurring during dredging lead to the adoption of the globalmodel as the best-fit, and the user should view all logged errors andwarnings to determine the best way to proceed. Thequiet = TRUE andquiet = "partial" options can be used to silence dredge warnings, butusers should note that automated model selection can be viewed as a blackbox, and so care should be taken to ensure that the models run makebiological sense, and that model quality is prioritized.
Exhaustive model selection through dredging works best with larger datasetsand fewer tested parameters. Settingsuite = "full" andinteractions = TRUE may initiate a dredge that takes a dramaticallylong time, particularly if the model is historical, individual or annualcovariates are used, or a zero-inflated distribution is assumed. In suchcases, the number of models built and tested will run at least in themillions. Small datasets will also increase the error associated with thesetests, leading to adoption of simpler models overall. Note also thatzero-inflated models are processed as two models, and so include twice theassumed number of parameters. Ifsuite = "full", then this functionwill switch to a main effects global model for the zero-inflated parametermodels if the total number of parameters to test rises above the limitsimposed by thedredge() function in packageMuMIn.
Accuracy of vital rate models is calculated differently depending on vitalrate and assumed distribution. For all vital rates assuming a binomialdistribution, including survival, observation status, reproductive status,and juvenile version of these, accuracy is calculated as the percent ofpredicted responses equal to actual responses. In all other models, accuracyis actually assessed as a simple R-squared in which the observed responsevalues per data subset are compared to the predicted response valuesaccording to each best-fit model. Note that some situations in which factorvariables are used may result in failure to assess accuracy. In these cases,functionmodelsearch() simply yieldsNA values.
Care must be taken to build models that test the impacts of state in occasiont-1 for historical models, and that do not test these impacts forahistorical models. Ahistorical matrix modeling particularly will yieldbiased transition estimates if historical terms from models are ignored. Thiscan be dealt with at the start of modeling by settinghistorical = FALSE for the ahistorical case, andhistorical = TRUE for the historical case.
This function handles generalized linear models (GLMs) under zero-inflateddistributions using thezeroinfl() function, and zero-truncated distributions using thevglm() function. Modeldredging may fail with these functions, leading to the global model beingaccepted as the best-fit model. However, model dredges of mixed models workfor all distributions. We encourage the use of mixed models in all cases.
The negative binomial and truncated negative binomial distributions use thequadratic structure emphasized in Hardin and Hilbe (2018, 4th Edition ofGeneralized Linear Models and Extensions). The truncated negative binomialdistribution may fail to predict size probabilities correctly when dispersionis near that expected of the Poisson distribution. To prevent this problem,we have integrated a cap on the overdispersion parameter. However, when usingthis distribution, please check the matrix column sums to make sure that theydo not predict survival greater than 1.0. If they do, then please use eitherthe negative binomial distribution or the zero-truncated Poissondistribution.
If density dependence is explored through functionmodelsearch(),then the interpretation of density is not the full population size but ratherthe spatial density term included in the dataset.
Users building vital rate models for Leslie matrices must setvitalrates = c("surv", "fec") orvitalrates = "leslie" ratherthan the default, because only survival and fecundity should be estimated inthese cases. Also, thesuite setting can be set to eitherageorcons, as the results will be exactly the same.
Users wishing to test age, density, group, or individual covariates, mustincludetest.age = TRUE,test.density = TRUE,test.group = TRUE, ortest.indcova = TRUE (ortest.indcovb = TRUE ortest.indcovc = TRUE, whichever is mostappropriate), respectively, in addition to stipulating the name of thevariable within the dataset. The default for these options is alwaysFALSE.
lefkoMod objects can be quite large when datasets are large and modelsare complicated. To reduce the amount of memory taken up by models,vrm_input objects can be created to summarize all relevant aspects ofthe vital rate models using functionminiMod().
Examples
data(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathmodelsln3 <- modelsearch(lathvertln, historical = TRUE, approach = "mixed", suite = "main", vitalrates = c("surv", "obs", "size", "repst", "fec"), juvestimate = "Sdl", bestfit = "AICc&k", sizedist = "gaussian", fecdist = "poisson", indiv = "individ", patch = "patchid", year = "year2", year.as.random = TRUE, patch.as.random = TRUE, show.model.tables = TRUE, quiet = "partial")# Here we use supplemental() to provide overwrite and reproductive infolathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "mat", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "Sdl", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "Sd", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, "Sdl", NA, NA), eststage1 = c(NA, NA, NA, NA, "Sdl", NA, NA), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframeln, historical = TRUE)lathmat3ln <- flefko3(year = "all", patch = "all", stageframe = lathframeln, modelsuite = lathmodelsln3, data = lathvertln, supplement = lathsupp3, reduce = FALSE)General Matrix Projection Model and Bootstrapped MPM Creation
Description
Functionmpm_create() is the core workhorse function that createsall flavors of MPM inlefko3. All other MPM creation functions actas wrappers for this function.
Usage
mpm_create( historical = FALSE, stage = TRUE, age = FALSE, devries = FALSE, reduce = FALSE, simple = FALSE, err_check = FALSE, data = NULL, year = NULL, pop = NULL, patch = NULL, stageframe = NULL, supplement = NULL, overwrite = NULL, repmatrix = NULL, alive = NULL, obsst = NULL, size = NULL, sizeb = NULL, sizec = NULL, repst = NULL, matst = NULL, fec = NULL, stages = NULL, yearcol = NULL, popcol = NULL, patchcol = NULL, indivcol = NULL, agecol = NULL, censorcol = NULL, modelsuite = NULL, paramnames = NULL, inda = NULL, indb = NULL, indc = NULL, annua = NULL, annub = NULL, annuc = NULL, dev_terms = NULL, density = NA_real_, CDF = TRUE, random_inda = FALSE, random_indb = FALSE, random_indc = FALSE, negfec = FALSE, exp_tol = 700L, theta_tol = 100000000L, censor = FALSE, censorkeep = NULL, start_age = NA_integer_, last_age = NA_integer_, fecage_min = NA_integer_, fecage_max = NA_integer_, fectime = 2L, fecmod = 1, cont = TRUE, prebreeding = TRUE, stage_NRasRep = FALSE, sparse_output = FALSE)Arguments
historical | A logical value indicating whether to build a historicalMPM. Defaults to |
stage | A logical value indicating whether to build a stage-based MPM.If both |
age | A logical value indicating whether to build an age-based MPM. Ifboth |
devries | A logical value indicating whether to use deVries formatfor historical MPMs. Defaults to |
reduce | A logical value denoting whether to remove ages, ahistoricalstages, or historical stages associated exclusively with zero transitions.These are removed only if the respective row and column sums in ALL matricesestimated equal 0. Defaults to |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
data | A data frame of class |
year | A variable corresponding to observation occasion, or a set ofsuch values, given in values associated with the |
pop | A variable designating which populations will have matricesestimated. Should be set to specific population names, or to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Should be set to specific patch names, or to |
stageframe | An object of class |
supplement | An optional data frame of class |
overwrite | An optional data frame developed with the |
repmatrix | An optional reproduction matrix. This matrix is composedmostly of |
alive | A vector of names of binomial variables corresponding to statusas alive ( |
obsst | A vector of names of binomial variables corresponding toobservation status in occasionst+1,t, andt-1,respectively. Defaults to |
size | A vector of names of variables coding the primary size variablein occasionst+1,t, andt-1, respectively. Defaults to |
sizeb | A vector of names of variables coding the secondary sizevariable in occasionst+1,t, andt-1, respectively.Defaults to an empty set, assuming that secondary size is not used. Onlyneeded for raw, stage-based MPMs. |
sizec | A vector of names of variables coding the tertiary sizevariable in occasionst+1,t, andt-1, respectively.Defaults to an empty set, assuming that tertiary size is not used. Onlyneeded for raw, stage-based MPMs. |
repst | A vector of names of binomial variables corresponding toreproductive status in occasionst+1,t, andt-1,respectively. Defaults to |
matst | A vector of names of binomial variables corresponding tomaturity status in occasionst+1,t, andt-1,respectively. Defaults to |
fec | A vector of names of variables coding for fecundity in occasionst+1,t, andt-1, respectively. Defaults to |
stages | An optional vector denoting the names of the variables withinthe main vertical dataset coding for the stages of each individual inoccasionst+1 andt, andt-1, if historical. The namesof stages in these variables should match those used in the |
yearcol | The variable name or column number corresponding to occasiont in the dataset. Defaults to |
popcol | The variable name or column number corresponding to theidentity of the population. Defaults to |
patchcol | The variable name or column number corresponding to patch in the dataset. Defaults to |
indivcol | The variable name or column number coding individualidentity. Only needed for raw MPMs. |
agecol | The variable name or column corresponding to age in timet. Defaults to |
censorcol | The variable name or column number denoting the censorstatus. Only needed in raw MPMs, and only if |
modelsuite | One of three kinds of lists. The first is a |
paramnames | A data frame with three columns, the first describing allterms used in linear modeling, the second (must be called |
inda | Can be a single value to use for individual covariate |
indb | Can be a single value to use for individual covariate |
indc | Can be a single value to use for individual covariate |
annua | Can be a single value to use for annual covariate |
annub | Can be a single value to use for annual covariate |
annuc | Can be a single value to use for annual covariate |
dev_terms | A numeric vector of 2 elements in the case of a Leslie MPM,and of 14 elements in all other cases. Consists of scalar additions to they-intercepts of vital rate linear models used to estimate vital rates infunction-based MPMs. Defaults to |
density | A numeric value indicating density value to use to propagatematrices. Only needed if density is an explanatory term used in one or morevital rate models. Defaults to |
CDF | A logical value indicating whether to use the cumulativedistribution function to estimate size transition probabilities infunction-based MPMs. Defaults to |
random_inda | A logical value denoting whether to treat individualcovariate |
random_indb | A logical value denoting whether to treat individualcovariate |
random_indc | A logical value denoting whether to treat individualcovariate |
negfec | A logical value denoting whether fecundity values estimated tobe negative should be reset to |
exp_tol | A numeric value used to indicate a maximum value to setexponents to in the core kernel to prevent numerical overflow. Defaults to |
theta_tol | A numeric value used to indicate a maximum value to thetaas used in the negative binomial probability density kernel. Defaults to |
censor | If |
censorkeep | The value of the censor variable denoting data elements tokeep. Defaults to |
start_age | The age from which to start the matrix. Defaults to |
last_age | The final age to use in the matrix. Defaults to |
fecage_min | The minimum age at which reproduction is possible.Defaults to |
fecage_max | The maximum age at which reproduction is possible.Defaults to |
fectime | An integer indicating whether to estimate fecundity usingthe variable given for |
fecmod | A scalar multiplier for fecundity. Only used for purelyage-based MPMs. Defaults to |
cont | A logical value designating whether to allow continued survivalof individuals past the final age noted in age-based and age-by-stage MPMs,using the demographic characteristics of the final age. Defaults to |
prebreeding | A logical value indicating whether the life history modelis a pre-breeding model. Defaults to |
stage_NRasRep | A logical value indicating whether to treatnon-reproductive individuals as reproductive. Used only in raw, stage-basedMPMs in cases where stage assignment must still be handled. Not used infunction-based MPMs, and in stage-based MPMs in which a valid |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
The dominant output is an object of classlefkoMat. Ifdata of classhfv_list for empirical models, or modelsuites of classlefkoModList for function-based models are provided, then a list ofclasslefkoMatList is provided. The latter is a list in which eachelement is a separatelefkoMat object, providing output for abootstrapped MPM analysis.
ClasslefkoMat objects are lists holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted patches andoccasion times. All matrices output in R's |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. Only used in historical MPMs. |
agestages | A data frame showing age-stage pairs. Only used inage-by-stage MPMs. |
ahstages | A data frame detailing the characteristics of associatedahistorical stages, in the form of a modified stageframe that includesstatus as an entry stage through reproduction. Used in all stage-based andage-by-stage MPMs. |
labels | A data frame giving the population, patch, and year of eachmatrix in order. |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
prob_out | An optional element only added if |
allstages | An optional element only added if |
data | An optional element only added if |
General Notes
This function automatically determines whether to create a raw orfunction-based MPM given inputs supplied by the user.
If used, the reproduction matrix (fieldrepmatrix) may be supplied aseither historical or ahistorical. If provided as historical, thena historical MPM must be estimated.
If neither a supplement nor a reproduction matrix are used, and the MPMto create is stage-based, then fecundity will be assumed to occur from allreproductive stages to all propagule and immature stages.
Function-based MPM Notes
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations, but without discriminating between thosepatches or subpopulations. Should the aim of analysis be a general MPM thatdoes not distinguish these patches or subpopulations, themodelsearch() run should not include patch terms.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1,t, andt-1. Rearrangingthe order will lead to erroneous calculations, and will may lead to fatalerrors.
This function provides two different means of estimating the probability ofsize transition. The midpoint method (CDF = FALSE) refers to themethod in which the probability is estimated by first estimating theprobability associated with transition from the exact size at the midpointof the size class using the corresponding probability density function, andthen multiplying that value by the bin width of the size class. Doak et al.2021 (Ecological Monographs) noted that this method can produce biasedresults, with total size transitions associated with a specific size nottotaling to 1.0 and even specific size transition probabilities capable ofbeing estimated at values greater than 1.0. The alternative and defaultmethod (CDF = TRUE) uses the cumulative density function to estimatethe probability of size transition as the cumulative probability of sizetransition at the greater limit of the size class minus the cumulativeprobability of size transition at the lower limit of the size class. Thislatter method avoids this bias. Note, however, that both methods are exactand unbiased for negative binomial and Poisson distributions.
Under the Gaussian and gamma size distributions, the number of estimatedparameters may differ between the twoipm_method settings. Becausethe midpoint method has a tendency to incorporate upward bias in theestimation of size transition probabilities, it is more likely to yield non-zero values when the true probability is extremely close to 0. This willresult in thesummary.lefkoMat() function yielding higher numbers ofestimated parameters than theipm_method = "CDF" yields in some cases.
Examples
data(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathvertln_adults <- subset(lathvertln, stage2index > 2)surv_model <- glm(alive3 ~ sizea2 + sizea1 + as.factor(patchid) + as.factor(year2), data = lathvertln_adults, family = "binomial")obs_data <- subset(lathvertln_adults, alive3 == 1)obs_model <- glm(obsstatus3 ~ as.factor(patchid), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)siz_model <- lm(sizea3 ~ sizea2 + sizea1 + repstatus1 + as.factor(patchid) + as.factor(year2), data = size_data)reps_model <- glm(repstatus3 ~ sizea2 + sizea1 + as.factor(patchid) + as.factor(year2), data = size_data, family = "binomial")fec_data <- subset(lathvertln_adults, repstatus2 == 1)fec_model <- glm(feca2 ~ sizea2 + sizea1 + repstatus1 + as.factor(patchid), data = fec_data, family = "poisson")lathvertln_juvs <- subset(lathvertln, stage2index < 3)jsurv_model <- glm(alive3 ~ as.factor(patchid), data = lathvertln_juvs, family = "binomial")jobs_data <- subset(lathvertln_juvs, alive3 == 1)jobs_model <- glm(obsstatus3 ~ 1, family = "binomial", data = jobs_data)jsize_data <- subset(jobs_data, obsstatus3 == 1)jsiz_model <- lm(sizea3 ~ as.factor(year2), data = jsize_data)jrepst_model <- 0jmatst_model <- 1mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[3] <- "patchid"mod_params$modelparams[4] <- "alive3"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "feca2"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[13] <- "sizea1"mod_params$modelparams[18] <- "repstatus2"mod_params$modelparams[19] <- "repstatus1"used_models <- list(survival_model = surv_model, observation_model = obs_model, size_model = siz_model, sizeb_model = 1, sizec_model = 1, repstatus_model = reps_model, fecundity_model = fec_model, juv_survival_model = jsurv_model, juv_observation_model = jobs_model, juv_size_model = jsiz_model, juv_sizeb_model = 1, juv_sizec_model = 1, juv_reproduction_model = 0, juv_maturity_model = 1, paramnames = mod_params)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "mat", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "Sdl", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "Sd", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, "Sdl", NA, NA), eststage1 = c(NA, NA, NA, NA, "Sdl", NA, NA), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframeln, historical = TRUE)# While we do not use MPMs to initialize f_projections3(), we do use MPMs to# initialize functions start_input() and density_input().lathmat3ln <- mpm_create(historical = TRUE, year = "all", patch = "all", data = lathvertln, stageframe = lathframeln, supplement = lathsupp3, modelsuite = used_models, reduce = FALSE)Create Overwrite Table for MPM Development
Description
overwrite() returns a data frame describing which particulartransitions within an ahistorical or historical projection matrix tooverwrite with either given rates and probabilities, or other estimatedtransitions. This function is now deprecated in favor of functionsupplemental().
Usage
overwrite( stage3, stage2, stage1 = NA, eststage3 = NA, eststage2 = NA, eststage1 = NA, givenrate = NA, type = NA, type_t12 = NA)Arguments
stage3 | The name of the stage in occasiont+1 in the transitionto be replaced. Abbreviations for groups of stages are also allowed(see Notes). |
stage2 | The name of the stage in occasiont in the transition tobe replaced. Abbreviations for groups of stages are also allowed (see Notes). |
stage1 | The name of the stage in occasiont-1 in the transitionto be replaced. Only needed if a historical matrix is to be produced.Abbreviations for groups of stages are also allowed (see Notes). |
eststage3 | The name of the stage to replace |
eststage2 | The name of the stage to replace |
eststage1 | The name of the stage to replace |
givenrate | A fixed rate or probability to replace for the transitiondescribed by |
type | A vector denoting the kind of transition between occasionst andt+1 to be replaced. This should be entered as |
type_t12 | An optional vector denoting the kind of transition betweenoccasionst-1 andt. Only necessary if a historical MPM indeVries format is desired. This should be entered as |
Value
A data frame that puts the above vectors together and can be used asinput inflefko3(),flefko2(),rlefko3(),rlefko2(), andaflefko2().
Variables in this data frame include the following:
stage3 | Stage at occasiont+1 in the transition to be replaced. |
stage2 | Stage at occasiont in the transition to be replaced. |
stage1 | Stage at occasiont-1 in the transition to be replaced. |
eststage3 | Stage at occasiont+1 in the transition to replacethe transition designated by |
eststage2 | Stage at occasiont in the transition to replace thetransition designated by |
eststage1 | Stage at occasiont-1 in the transition to replacethe transition designated by |
givenrate | A constant to be used as the value of the transition. |
convtype | Designates whether the transition from occasiont tooccasiont+1 is a survival-transition probability (1) or a fecundityrate (2). |
convtype_t12 | Designates whether the transition from occasiont-1 to occasiont is a survival transition probability (1), afecundity rate (2). |
Notes
This function is deprecated. Please usesupplemental().
Entries instage3,stage2, andstage1 can includeabbreviations for groups of stages. Userep if all reproductive stagesare to be used,nrep if all mature but non-reproductive stages are tobe used,mat if all mature stages are to be used,immat if allimmature stages are to be used,prop if all propagule stages are to beused,npr if all non-propagule stages are to be used, and leave emptyor useall if all stages in stageframe are to be used.
Examples
cypover2r <- overwrite(stage3 = c("SD", "P1", "P2", "P3", "SL", "D", "XSm", "Sm"), stage2 = c("SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL"), eststage3 = c(NA, NA, NA, NA, NA, "D", "XSm", "Sm"), eststage2 = c(NA, NA, NA, NA, NA, "XSm", "XSm", "XSm"), givenrate = c(0.1, 0.2, 0.2, 0.2, 0.25, NA, NA, NA), type = c("S", "S", "S", "S", "S", "S", "S", "S"))cypover2rcypover3r <- overwrite(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm"), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm"), eststage1 = c(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, NA, NA, NA, NA, NA, NA), type = c("S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S"))cypover3rPlot Projection Simulations
Description
Functionplot.lefkoProj() produces plots oflefkoProj objects.Acts as a convenient wrapper for theplot.default() function.
Usage
## S3 method for class 'lefkoProj'plot( x, variable = "popsize", style = "time", repl = "all", patch = "pop", auto_ylim = TRUE, auto_col = TRUE, auto_lty = TRUE, auto_title = FALSE, ...)Arguments
x | A |
variable | The focus variable of the plot to produce. Defaults to |
style | A string denoting ther kind of plot to produce. Currentlylimited to |
repl | The replicate to plot. Defaults to |
patch | The patch to plot, as labeled in the |
auto_ylim | A logical value indicating whether the maximum of the y axisshould be determined automatically. Defaults to |
auto_col | A logical value indicating whether to shift the color oflines associated with each patch automatically. Defaults to |
auto_lty | A logical value indicating whether to shift the line typeassociated with each replicate automatically. Defaults to |
auto_title | A logical value indicating whether to add a title to eachplot. The plot is composed of the concatenated population and patch names.Defaults to |
... | Other parameters used by functions |
Value
A plot of the results of aprojection3() run.
Notes
Output plots are currently limited to time series and state space plots ofpopulation size.
The default settings will preferentially plot any projections marked as0 in thepatch portion of thelabels element of theinput MPM. This can produce confusing results if a mean MPM resulting fromthelmean() function is used as input and theadd_mean settingis set to the default, which isTRUE.
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathrepm <- matrix(0, 7, 7)lathrepm[1, 6] <- 0.345lathrepm[2, 6] <- 0.054lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "all", "all"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = c(1989, 1990), stages = c("stage3", "stage2", "stage1"), repmatrix = lathrepm, supplement = lathsupp3, yearcol = "year2", indivcol = "individ")lathproj <- projection3(ehrlen3, nreps = 5, stochastic = TRUE)plot(lathproj)Conduct Population Projection Simulations
Description
Functionprojection3() runs projection simulations. It projects thepopulation and patches forward in time by a user-defined number ofoccasions. A given set of matrices is utilized and not recreated, althoughelements may be altered if density dependence is set. Projections may bedeterministic or stochastic, and may be density dependent in either case. Ifdeterministic, then projections will be cyclical if matrices exist coveringmultiple occasions for each population or patch. If stochastic, then annualmatrices will be shuffled within patches and populations. Also producesreplicates if set.
Usage
projection3( mpm, nreps = 1L, times = 10000L, historical = FALSE, stochastic = FALSE, standardize = FALSE, growthonly = TRUE, integeronly = FALSE, substoch = 0L, exp_tol = 700, sub_warnings = TRUE, quiet = FALSE, year = NULL, start_vec = NULL, start_frame = NULL, tweights = NULL, density = NULL, stage_weights = NULL, sparse = NULL)Arguments
mpm | A matrix projection model of class |
nreps | The number of replicate projections. |
times | Number of occasions to iterate per replicate. Defaults to10,000. |
historical | An optional logical value only used if object |
stochastic | A logical value denoting whether to conduct a stochasticprojection or a deterministic / cyclical projection. |
standardize | A logical value denoting whether to re-standardize thepopulation size to 1.0 at each occasion. Defaults to |
growthonly | A logical value indicating whether to produce only theprojected population size at each occasion, or a vector showing the stagedistribution followed by the reproductive value vector followed by the fullpopulation size at each occasion. Defaults to |
integeronly | A logical value indicating whether to round the number ofindividuals projected in each stage at each occasion to the nearestinteger. Defaults to |
substoch | An integer value indicating whether to force survival-transition matrices to be substochastic in density dependent simulations.Defaults to |
exp_tol | A numeric value used to indicate a maximum value to setexponents to in the core kernel to prevent numerical overflow. Defaults to |
sub_warnings | A logical value indicating whether to warn the user ifdensity dependence yields matrix values outside of the realm of possibility.Generally, this means that survival-transition elements altered to valuesoutside of the interval [0, 1], and negative fecundity values, will bothyield warnings. Defaults to |
quiet | A logical value indicating whether to suppress warnings.Defaults to |
year | Either a single integer value corresponding to the year toproject, or a vector of |
start_vec | An optional numeric vector denoting the starting stagedistribution for the projection. Defaults to a single individual of eachstage. |
start_frame | An optional data frame characterizing stages, age-stages,or stage-pairs that should be set to non-zero values in the starting vector,and what those values should be. Can only be used with |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If amatrix is input, then a first-order Markovian environment is assumed, inwhich the probability of choosing a specific annual matrix depends on whichannual matrix is currently chosen. If a vector is input, then the choice ofannual matrix is assumed to be independent of the current matrix. Defaultsto equal weighting among matrices. |
density | An optional data frame describing the matrix elements thatwill be subject to density dependence, and the exact kind of densitydependence that they will be subject to. The data frame used should be anobject of class |
stage_weights | An optional object of class |
sparse | A text string indicating whether to use sparse matrix encoding( |
Value
If alefkoMat object or a simple list of matrices is used asinput, then this function will produce a list of classlefkoProj,which always includes the first three elements of the following, and alsoincludes the remaining elements below when alefkoMat object is usedas input:
projection | A list of lists of matrices showing the total number ofindividuals per stage per occasion. The first list corresponds to eachpop-patch followed by each population. The inner list corresponds toreplicates within each pop-patch or population. |
stage_dist | A list of lists of the actual stage distribution in eachoccasion in each replicate in each pop-patch or population. The list orderis the same as in |
rep_value | A list of lists of the actual reproductive value in eachoccasion in each replicate in each pop-patch or population. The list orderis the same as in |
pop_size | A list of matrices showing the total population size ineach occasion per replicate (row within matrix) per pop-patch orpopulation (list element). |
labels | A data frame showing the order of populations and patches initem |
ahstages | The original stageframe used in the study. |
hstages | A data frame showing the order of historical stage pairs. |
agestages | A data frame showing the order of age-stage pairs. |
control | A short vector indicating the number of replicates and thenumber of occasions projected per replicate. |
density | The data frame input under the density option. Only providedif input by the user. |
If alefkoMatList object is entered, then this function will producea list of classlefkoProjList, in which each element is an object ofclasslefkoProj.
Notes
Density dependent projections requirelefkoMat objects as inputs.Users using simple lists of matrices cannot set density dependence withoutfirst setting a life history model and importing their matrices usingfunctioncreate_lM().
Projections are run both at the patch level and at the population level.Population level estimates will be noted at the end of the data frame with0 entries for patch designation.
Weightings given intweights do not need to sum to 1. Finalweightings used will be based on the proportion per element of the sum ofelements in the user-supplied vector.
Starting vectors can be input in one of two ways: 1) asstart_vecinput, which is a vector of numbers of the numbers of individuals in eachstage, stage pair, or age-stage, with the length of the vector necessarilyas long as there are rows in the matrices of the MPM; or 2) asstart_frame input, which is a data frame showing only those stages,stage pairs, or age-stages that should begin with more than 0 individuals,and the numbers of individuals that those stages should start with (thisobject is created using thestart_input() function). If bothare provided, thenstart_frame takes precedence andstart_vecis ignored. If neither is provided, thenprojection3() automaticallyassumes that each stage, stage pair, or age-stage begins with a singleindividual. Importantly, if alefkoMat object is not used, and a listof matrices is provided instead, thenstart_frame cannot be utilizedand a fullstart_vec must be provided to conduct a simulation withstarting numbers of individuals other than 1 per stage.
The resulting data frames in elementprojection are separated bypop-patch according to the order provided in elementlabels, but thematrices for each element ofprojection have the result of eachreplicate stacked in order on top of one another without any break orindication. Results for each replicate must be separated using theinformation provided in elementscontrol and the 3 stagedescriptor elements.
Density dependent projections are automatically set up if objectdensity is input. If this object is not included, then densityindependent projections will be set up. Note that currently, densitydependent projections can only be performed withlefkoMat objects.
When running density dependent simulations involving user-set exponents,such as the beta term in the Ricker function and both the alpha and betaterms in the Usher function, values above or below the computer limits maycause unpredictable behavior. Noted odd behavior includes sudden shifts inpopulation size to negative values. This function produces warnings whensuch values are used, and the values used for warnings may be reset with theexp_tol term.
The stage distributions and reproductive values produced are not theasymptotic values as would be given by the standardized right and lefteigenvectors associated with the dominant eigenvalue of a matrix, but arevectors describing these values at the specific points in time projected.See equations 14.86 and 14.88 and section 14.4 on Sensitivity and ElasticityAnalysis under Environmental Stochasticity in Caswell (2001, MatrixPopulation Models, Sinauer Associates) for more details.
Consistently positive population growth can quickly lead to population sizenumbers larger than can be handled computationally. In that circumstance, acontinuously rising population size will suddenly becomeNaN for theremainder of the projection.
Users wishing to run a projection of a single patch in alefkoMatobject with multiple patches should subset the MPM first to contain onlythe patch needed. This can be accomplished with thesubset_lM() function.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse. Speed can also be maximized by keeping the default setting,integeronly = TRUE, since the default behavior is to run eachprojection (replicate) until either the end, or the population size dropsto 0. Settingintegeronly = FALSE may increase runtime dramatically,since the population size can reach extremely small levels without droppingto 0.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "all", "all"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = c(1989, 1990), stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")lathproj <- projection3(ehrlen3, nreps = 5, stochastic = TRUE)# Cypripedium exampledata(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)cypsupp3r <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "D", "XSm", "Sm", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "D", "XSm", "Sm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", NA, NA), givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypstoch <- projection3(cypmatrix3r, nreps = 5, stochastic = TRUE)Demographic Dataset ofPyrola japonica andPyrola subaphyllaPopulations, in Horizontal Format
Description
A dataset containing the states and fates ofPyrola japonica andPyrola subaphylla, family Ericaceae, from populations in the vicinityof Mt. Bandai, Fukushima Prefecture, Japan, resulting from monitoring thatoccurred annually between 2015 and 2020.
Usage
data(pyrola)Format
A data frame with 454 individuals and 57 variables. Each row corresponds to an unique individual, and each variable fromsprouted.2015 on refers to the state of the individual in a particularyear.
- species
String denoting which of the two species the individualbelongs to.
- population
Integer denoting whcih population the individual belongsto. Synonymous with species in this dataset.
- id
A numeric variable giving a unique number to each individual within each species. Note that numbers are reused among the twospecies.
- sprouted.2015
A binomial indicating whether the individual hadliving aboveground tissue observable in the 2015 census.
- lvs.num.2015
Number of leaves in 2015.
- lvs.lng.2015
Length of largest leaf in 2015.
- lvs.wdt.2015
Width of largest leaf in 2015.
- inf.num.2015
Number of inflorescences in 2015.
- inf.lng.tot.2015
Summed inflorescence length in 2015.
- flo.tot.2015
Number of flowers in 2015.
- frt.tot.2015
Number of fruits in 2015.
- sprouted.2016
A binomial indicating whether the individual hadliving aboveground tissue observable in the 2016 census.
- lvs.num.2016
Number of leaves in 2016.
- lvs.lng.2016
Length of largest leaf in 2016.
- lvs.wdt.2016
Width of largest leaf in 2016.
- inf.num.2016
Number of inflorescences in 2016.
- inf.lng.tot.2016
Summed inflorescence length in 2016.
- flo.tot.2016
Number of flowers in 2016.
- frt.tot.2016
Number of fruits in 2016.
- sprouted.2017
A binomial indicating whether the individual hadliving aboveground tissue observable in the 2017 census.
- lvs.num.2017
Number of leaves in 2017.
- lvs.lng.2017
Length of largest leaf in 2017.
- lvs.wdt.2017
Width of largest leaf in 2017.
- inf.num.2017
Number of inflorescences in 2017.
- inf.lng.tot.2017
Summed inflorescence length in 2017.
- flo.tot.2017
Number of flowers in 2017.
- frt.tot.2017
Number of fruits in 2017.
- sprouted.2018
A binomial indicating whether the individual hadliving aboveground tissue observable in the 2018 census.
- lvs.num.2018
Number of leaves in 2018.
- lvs.lng.2018
Length of largest leaf in 2018.
- lvs.wdt.2018
Width of largest leaf in 2018.
- inf.num.2018
Number of inflorescences in 2018.
- inf.lng.tot.2018
Summed inflorescence length in 2018.
- flo.tot.2018
Number of flowers in 2018.
- frt.tot.2018
Number of fruits in 2018.
- sprouted.2019
A binomial indicating whether the individual hadliving aboveground tissue observable in the 2019 census.
- lvs.num.2019
Number of leaves in 2019.
- lvs.lng.2019
Length of largest leaf in 2019.
- lvs.wdt.2019
Width of largest leaf in 2019.
- inf.num.2019
Number of inflorescences in 2019.
- inf.lng.tot.2019
Summed inflorescence length in 2019.
- flo.tot.2019
Number of flowers in 2019.
- frt.tot.2019
Number of fruits in 2019.
- sprouted.2020
A binomial indicating whether the individual hadliving aboveground tissue observable in the 2020 census.
- lvs.num.2020
Number of leaves in 2020.
- lvs.lng.2020
Length of largest leaf in 2020.
- lvs.wdt.2020
Width of largest leaf in 2020.
- inf.num.2020
Number of inflorescences in 2020.
- inf.lng.tot.2020
Summed inflorescence length in 2020.
- flo.tot.2020
Number of flowers in 2020.
- frt.tot.2020
Number of fruits in 2020.
Source
Shefferson, R.P., K. Shutoh, and K. Suetsugu.In review.Vegetative dormancy and the evolution of mycoheterotrophy in sisterPyrola species.Journal of Ecology.
Examples
data(pyrola)pyrola$species <- as.factor(pyrola$species)pyrola$population <- as.factor(pyrola$population)jreg <- pyrola[which(pyrola$population == 1),]stagevec_jp <- c("P1", "Sdl", "Dorm", "V0nr", "V1nr", "V2nr", "V3nr", "V4nr", "V0r", "V1r", "V2r", "V3r", "V4r")sizeavec_jp <- c(0, 0, 0, 0, 1, 2, 3, 7, 0, 1, 2, 3, 7)sizeahbin_jp <- c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 3.5, 0.5, 0.5, 0.5, 0.5, 3.5)repvec_jp <- c(0, 0, 0, 0, rep(0, 4), rep(1, 5))propvec_jp <- c(1, rep(0, 12))immvec_jp <- c(1, 1, rep(0, 11))matvec_jp <- c(0, 0, rep(1, 11))obsvec_jp <- c(0, 0, 0, rep(1, 10))indata_jp <- c(0, 0, rep(1, 11))comments_jp <- c("protocorm", "seedling", "dormant adult", "stump", "1lf nr", "2lf nr", "3lf nr", "4+lf nr", "0lf r", "1lf r", "2lf r", "3lf r", "4+lf r")jp_frame <- sf_create(sizes = sizeavec_jp, stagenames = stagevec_jp, binhalfwidth = sizeahbin_jp, repstatus = repvec_jp, obsstatus = obsvec_jp, indataset = indata_jp, propstatus = propvec_jp, immstatus = immvec_jp, matstatus = matvec_jp, comments = comments_jp) jhfv <- verticalize3(data = jreg, noyears = 6, firstyear = 2015, individcol = "id", blocksize = 8, sizeacol = "lvs.num.2015", obsacol = "sprouted.2015", repstracol = "flo.tot.2015", repstrbcol = "frt.tot.2015", fecacol = "flo.tot.2015", fecbcol = "frt.tot.2015", NAas0 = TRUE, stagesize = "sizea", stageassign = jp_frame)surv_model <- glm(alive3 ~ sizea2 + as.factor(year2), data = jhfv, family = "binomial")obs_data <- subset(jhfv, alive3 == 1)obs_model <- glm(obsstatus3 ~ as.factor(year2), data = obs_data, family = "binomial")size_data <- subset(obs_data, obsstatus3 == 1)size_model <- glm(sizea3 ~ sizea2, data = size_data, family = "poisson")reps_model <- glm(repstatus3 ~ sizea2, data = size_data, family = "binomial")fec_data <- subset(jhfv, repstatus2 == 1)fec_model <- MASS::glm.nb(fec2added ~ 1, data = fec_data)mod_params <- create_pm(name_terms = TRUE)mod_params$modelparams[4] <- "alive3"mod_params$modelparams[5] <- "obsstatus3"mod_params$modelparams[6] <- "sizea3"mod_params$modelparams[9] <- "repstatus3"mod_params$modelparams[11] <- "fec2added"mod_params$modelparams[12] <- "sizea2"mod_params$modelparams[18] <- "repstatus2"jp_germ <- 0.90jp_supp2 <- supplemental(stage3 = c("Sdl", "Dorm", "V0nr", "V1nr", "P1", "Sdl"), stage2 = c("P1", "Sdl", "Sdl", "Sdl", "rep", "rep"), eststage3 = c(NA, NA, NA, NA, NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA), givenrate = c(0.25, 0.35, 0.10, 0.10, NA, NA), # 0.345, 0.054 multiplier = c(NA, NA, NA, NA, jp_germ * 0.5, jp_germ * 0.5), type = c(1, 1, 1, 1, 3, 3), stageframe = jp_frame, historical = FALSE)jp_ahmpm <- flefko2(year = "all", stageframe = jp_frame, supplement = jp_supp2, paramnames = mod_params, surv_model = surv_model, obs_model = obs_model, size_model = size_model, repst_model = reps_model, fec_model = fec_model, data = jhfv, err_check = TRUE)lambda3(jp_ahmpm)Estimate Reproductive Value
Description
repvalue3() is a generic function that estimates returns thereproductive values of stages in a population projection matrix or a set ofmatrices. The specifics of estimation vary with the class of input object.This function is made to handle very large and sparse matrices supplied aslefkoMat objects or as individual matrices, and can be used with largehistorical matrices, IPMs, age x stage matrices, as well as ahistoricalmatrices.
Usage
repvalue3(mats, ...)Arguments
mats | A lefkoMat object, a population projection matrix, or a list ofpopulation projection matrices for which the reproductive value vector isdesired. |
... | Other parameters. |
Value
The value returned depends on the class of themats argument.See related functions for details.
See Also
Examples
# Lathyrus deterministic exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)repvalue3(ehrlen3mean)# Cypripedium stochastic exampledata(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)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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")repvalue3(cypmatrix2r, stochastic = TRUE)Estimate Reproductive Value Vector for a Single Population Projection Matrix
Description
repvalue3.dgCMatrix() returns the reproductive values for stages in a sparse population projection matrix. The function makes no assumptions aboutwhether the matrix is ahistorical and simply provides standard reproductivevalues corresponding to each row, meaning that the overall reproductivevalues of basic life history stages in a historical matrix are not provided(therepvalue3.lefkoMat() function estimates these on the basisof stage description information provided in thelefkoMat object usedas input in that function).
Usage
## S3 method for class 'dgCMatrix'repvalue3(mats, ...)Arguments
mats | A population projection matrix. |
... | Other parameters. |
Value
This function returns a vector data frame characterizing the reproductive values for stages of a population projection matrix. This is given as the left eigenvector associated with largest real part of thedominant eigenvalue, divided by the first non-zero element of the left eigenvector.
Notes
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have several hundred rows and columns. Defaultswork best when matrices are very small and dense, or very large and sparse.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ", sparse_output = TRUE)repvalue3(ehrlen3$A[[1]])Estimate Reproductive Value Vectors of Matrices in a lefkoMat Object
Description
repvalue3.lefkoMat() returns the reproductive values for stages in aset of population projection matrices provided as alefkoMat object.This function can handle large and sparse matrices, and so can be used withlarge historical matrices, IPMs, age x stage matrices, as well as ahistoricalmatrices.
Usage
## S3 method for class 'lefkoMat'repvalue3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, force_sparse = "auto", ...)Arguments
mats | An object of class |
stochastic | A logical value indicating whether to use deterministic( |
times | An integer variable indicating number of occasions to project ifusing stochastic analysis. Defaults to 10000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed. |
force_sparse | A text string indicating whether to use sparse matrixencoding ( |
... | Other parameters. |
Value
This function returns the asymptotic reproductive value vectors ifdeterministic analysis is chosen, and long-run mean reproductive valuevectors if stochastic analysis is chosen.
The output depends on whether thelefkoMat object used as input isahistorical or historical, and whether the analysis is deterministic orstochastic. If deterministic and ahistorical, then a single data frame isoutput, which includes the number of the matrix within theA elementof the inputlefkoMat object, followed by the stage id (numeric andassigned throughsf_create()), the stage name, and theestimated proportion of the reproductive value vector (rep_value). Ifstochastic and ahistorical, then a single data frame is output starting withthe number of the population-patch (matrix_set), a stringconcatenating the names of the population and the patch (poppatch),the assigned stage id number (stage_id), and the stage name(stage), and the long-run mean reproductive value vector(rep_value).
If a historical matrix is used as input, then two data frames are outputinto a list object. Thehist element describes the historicalstage-pair reproductive values, while theahist element describes thestage reproductive values. If deterministic, thenhist contains a dataframe including the matrix number (matrix), the numeric stagedesignations for stages in occasionst andt-1,(stage_id_2 andstage_id_1, respectively), followed by therespective stage names (stage_2 andstage_1), and ending withthe estimated reproductive values (rep_value). The associatedahist element is as before. If stochastic, then thehistelement contains a single data frame with the number of the population-patch(matrix_set), a string concatenating the names of the population andthe patch (poppatch), the assigned stage id numbers in timestandt-1 (stage_id_2 andstage_id_2, respectively), andthe associated stage names (stage_2 andstage_1, respectively),and the long-run mean reproductive values (rep_value). The associatedahist element is as before in the ahistorical, stochastic case.
In addition to the data frames noted above, stochastic analysis will resultin the additional output of a list of matrices containing the actualprojected reproductive value vectors across all projected occasions, in theorder of population-patch combinations in thelefkoMat input.
Notes
In stochastic analysis, the projected mean reproductive value vector is thearithmetic mean across the final projected 1000 occasions if the simulationis at least 2000 projected occasions long. If between 500 and 2000 projectedoccasions long, then only the final 200 are used, and if fewer than 500occasions are used, then all are used. Note that because reproductive valuesin stochastic simulations can change greatly in the initial portion of therun, we encourage a minimum 2000 projected occasions per simulation, with10000 preferred.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have several hundred rows and columns. Defaultswork best when matrices are very small and dense, or very large and sparse.
See Also
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)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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")repvalue3(cypmatrix2r, stochastic = TRUE)Estimate Reproductive Value Vectors of Matrices in a lefkoMatList Object
Description
repvalue3.lefkoMatList() returns the reproductive values for stages insets of population projection matrices provided within alefkoMatListobject. This function can handle large and sparse matrices, and so can beused with large historical matrices, IPMs, age x stage matrices, as well asahistorical matrices.
Usage
## S3 method for class 'lefkoMatList'repvalue3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, force_sparse = "auto", ...)Arguments
mats | An object of class |
stochastic | A logical value indicating whether to use deterministic( |
times | An integer variable indicating number of occasions to project ifusing stochastic analysis. Defaults to 10000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed. |
force_sparse | A text string indicating whether to use sparse matrixencoding ( |
... | Other parameters. |
Value
This function returns a list with two elements. The first is the meanreproductive value vector (and long-run mean reproductive value vectors fromstochastic analysis), and the second is a list of reproductive value vectors(and long-run mean reproductive value vectors from stochastic analysis)corresponding to thelefkoMat objects in the originallefkoMatList list input in argumentmats.
The vector format depends on whether thelefkoMat object used as inputis ahistorical or historical, and whether the analysis is deterministic orstochastic. If deterministic and ahistorical, then a single data frame isoutput, which includes the number of the matrix within theA elementof the inputlefkoMat object, followed by the stage id (numeric andassigned throughsf_create()), the stage name, and theestimated proportion of the reproductive value vector (rep_value). Ifstochastic and ahistorical, then a single data frame is output starting withthe number of the population-patch (matrix_set), a stringconcatenating the names of the population and the patch (poppatch),the assigned stage id number (stage_id), and the stage name(stage), and the long-run mean reproductive value vector(rep_value).
If a historical matrix is used as input, then two data frames are outputinto a list object. Thehist element describes the historicalstage-pair reproductive values, while theahist element describes thestage reproductive values. If deterministic, thenhist contains a dataframe including the matrix number (matrix), the numeric stagedesignations for stages in occasionst andt-1,(stage_id_2 andstage_id_1, respectively), followed by therespective stage names (stage_2 andstage_1), and ending withthe estimated reproductive values (rep_value). The associatedahist element is as before. If stochastic, then thehistelement contains a single data frame with the number of the population-patch(matrix_set), a string concatenating the names of the population andthe patch (poppatch), the assigned stage id numbers in timestandt-1 (stage_id_2 andstage_id_2, respectively), andthe associated stage names (stage_2 andstage_1, respectively),and the long-run mean reproductive values (rep_value). The associatedahist element is as before in the ahistorical, stochastic case.
In addition to the data frames noted above, stochastic analysis will resultin the additional output of a list of matrices containing the actualprojected reproductive value vectors across all projected occasions, in theorder of population-patch combinations in thelefkoMat input.
Notes
In stochastic analysis, the projected mean reproductive value vector is thearithmetic mean across the final projected 1000 occasions if the simulationis at least 2000 projected occasions long. If between 500 and 2000 projectedoccasions long, then only the final 200 are used, and if fewer than 500occasions are used, then all are used. Note that because reproductive valuesin stochastic simulations can change greatly in the initial portion of therun, we encourage a minimum 2000 projected occasions per simulation, with10000 preferred.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have several hundred rows and columns. Defaultswork best when matrices are very small and dense, or very large and sparse.
See Also
Examples
# Lathyrus deterministic exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathvert_boot <- bootstrap3(lathvert, reps = 3)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3_boot <- rlefko3(data = lathvert_boot, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3_boot)repvalue3(ehrlen3mean)# Cypripedium stochastic exampledata(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)cypraw_v1_boot <- bootstrap3(cypraw_v1, reps = 3)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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_boot <- rlefko2(data = cypraw_v1_boot, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added"), supplement = cypsupp2r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")repvalue3(cypmatrix2r_boot, stochastic = TRUE)Estimate Reproductive Value Vector for a List of Projection Matrices
Description
repvalue3.list() returns the reproductive values for stages inpopulation projection matrices arranged in a general list. The function makesno assumptions about whether the matrix is ahistorical and simply providesstandard reproductive values corresponding to each row, meaning that theoverall reproductive values of basic life history stages in a historicalmatrix are not provided (therepvalue3.lefkoMat() functionestimates these on the basis of stage description information provided in thelefkoMat object used as input in that function). This function canhandle large and sparse matrices, and so can be used with large historicalmatrices, IPMs, age x stage matrices, as well as smaller ahistoricalmatrices.
Usage
## S3 method for class 'list'repvalue3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, force_sparse = "auto", ...)Arguments
mats | A list of population projection matrices, all in either class |
stochastic | A logical value indicating whether to use deterministic( |
times | An integer variable indicating number of occasions to project ifusing stochastic analysis. Defaults to 10000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed in stochastic projection. |
force_sparse | A text string indicating whether to use sparse matrixencoding ( |
... | Other parameters. |
Value
This function returns a list of vector data frames characterizing the reproductive values for stages of each population projection matrix. This is given as the left eigenvector associated with largest real part of thedominant eigenvalue, divided by the first non-zero element of the left eigenvector.
Notes
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have several hundred rows and columns. Defaultswork best when matrices are very small and dense, or very large and sparse.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")repvalue3(ehrlen3$A)Estimate Reproductive Value Vector for a Single Population Projection Matrix
Description
repvalue3.matrix() returns the reproductive values for stages in a population projection matrix. The function makes no assumptions about whetherthe matrix is ahistorical and simply provides standard reproductive valuescorresponding to each row, meaning that the overall reproductive values ofbasic life history stages in a historical matrix are not provided (therepvalue3.lefkoMat() function estimates these on the basis ofstage description information provided in thelefkoMat object used asinput in that function). This function can handle large and sparse matrices,and so can be used with large historical matrices, IPMs, age x stagematrices, as well as smaller ahistorical matrices.
Usage
## S3 method for class 'matrix'repvalue3(mats, force_sparse = "auto", ...)Arguments
mats | A population projection matrix. |
force_sparse | A text string indicating whether to use sparse matrixencoding ( |
... | Other parameters. |
Value
This function returns a vector data frame characterizing the reproductive values for stages of a population projection matrix. This is given as the left eigenvector associated with largest real part of thedominant eigenvalue, divided by the first non-zero element of the left eigenvector.
Notes
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)repvalue3(ehrlen3mean$A[[1]])Two-Parameter Ricker Function
Description
Functionricker3() creates a vector of values produced by the two-parameter Ricker function as applied with a user-specified time lag. Thetwo-parameter Ricker function is given as\phi_{t+1} = \phi_t \alpha e^{-\beta n_t}. Here, if noseparate_N vector is provided, thenn_t = \phi_t.
Usage
ricker3( start_value, alpha, beta, time_steps = 100L, time_lag = 1L, pre0_subs = FALSE, pre0_value = 0, substoch = 0L, separate_N = NULL)Arguments
start_value | A positive number to start the return vector in time 0. |
alpha | The alpha parameter in the two-parameter Ricker function. Mustbe non-negative. |
beta | The beta parameter in the two-parameter Ricker function. |
time_steps | The number of time steps to run the projection. Must be apositive integer. |
time_lag | A positive integer denoting the number of time steps backfor the value of phi in the two-parameter Ricker function. |
pre0_subs | A logical value indicating whether to use a number otherthan that given in |
pre0_value | A positive number to use for phi lagged from times priorto time 0. Only used if |
substoch | An integer value indicating the kind of substochasticity touse. Values include: |
separate_N | An optional numeric vector with values of N in each time,if phi is to be treated as different from N in the two-parameter model. |
Value
A numeric vector of values showing values projected under the two-parameter Ricker function.
Examples
trial_run1 <- ricker3(1, alpha = 0.5, beta = -0.009)plot(trial_run1)trial_run2 <- ricker3(1, alpha = 0.5, beta = 0.009)plot(trial_run2)trial_run3 <- ricker3(1, alpha = 1, beta = -0.009)plot(trial_run3)trial_run4 <- ricker3(1, alpha = 1, beta = 0.009)plot(trial_run4)trial_run5 <- ricker3(1, alpha = 5, beta = -0.009)plot(trial_run5)trial_run6 <- ricker3(1, alpha = 5, beta = 0.009)plot(trial_run6)used_Ns <- c(10, 15, 12, 14, 14, 150, 15, 1, 5, 7, 9, 14, 13, 16, 17, 19, 25, 26)trial_run7 <- ricker3(1, alpha = 1, beta = -0.009, separate_N = used_Ns)plot(trial_run7)Create Raw Ahistorical Matrix Projection Model
Description
Functionrlefko2() returns raw ahistorical MPMs, including theassociated component transition and fecundity matrices, a data framedescribing the ahistorical stages used, and a data frame describing thepopulation, patch, and occasion time associated with each matrix.
Usage
rlefko2( data, stageframe, year = "all", pop = NULL, patch = NULL, censor = FALSE, stages = NULL, alive = c("alive3", "alive2"), obsst = NULL, size = c("sizea3", "sizea2"), sizeb = NULL, sizec = NULL, repst = c("repstatus3", "repstatus2"), matst = c("matstatus3", "matstatus2"), fec = c("feca3", "feca2"), supplement = NULL, repmatrix = NULL, overwrite = NULL, yearcol = NULL, popcol = NULL, patchcol = NULL, indivcol = NULL, censorcol = NULL, censorkeep = 0, NRasRep = FALSE, reduce = FALSE, simple = FALSE, err_check = FALSE, sparse_output = FALSE)Arguments
data | A vertical demographic data frame, with variables corresponding to the naming conventions in functions |
stageframe | A stageframe object that includes information on the size,observation status, propagule status, reproduction status, immaturity status,and maturity status of each ahistorical stage. |
year | A variable corresponding to observation occasion, or a setof such values, given in values associated with the |
pop | A variable designating which populations will have matricesestimated. Should be set to specific population names, or to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Should be set to specific patch names, or to |
censor | If |
stages | An optional vector denoting the names of the variables withinthe main vertical dataset coding for the stages of each individual inoccasionst+1 andt. The names of stages in these variablesshould match those used in the |
alive | A vector of names of binomial variables corresponding to statusas alive ( |
obsst | A vector of names of binomial variables corresponding toobservation status in occasionst+1,t, andt-1,respectively. Defaults to |
size | A vector of names of variables coding the primary size variablein occasionst+1 andt, respectively. Defaults to |
sizeb | A vector of names of variables coding the secondary sizevariable in occasionst+1 andt, respectively. Defaults to |
sizec | A vector of names of variables coding the tertiary sizevariable in occasionst+1 andt, respectively. Defaults to |
repst | A vector of names of variables coding reproductive status inoccasionst+1 andt, respectively. Defaults to |
matst | A vector of names of variables coding maturity status inoccasionst+1 andt, respectively. Defaults to |
fec | A vector of names of variables coding fecundity in occasionst+1 andt, respectively. Defaults to |
supplement | An optional data frame of class |
repmatrix | An optional reproduction matrix. This matrix is composedmostly of 0s, with non-zero entries acting as element identifiers andmultipliers for fecundity (with 1 equaling full fecundity). If left blank,and no |
overwrite | An optional data frame developed with the |
yearcol | The variable name or column number corresponding to occasiont in the dataset. |
popcol | The variable name or column number corresponding to theidentity of the population. |
patchcol | The variable name or column number corresponding to patch inthe dataset. |
indivcol | The variable name or column number coding individualidentity. |
censorcol | The variable name or column number denoting the censorstatus. Only needed if |
censorkeep | The value of the censor variable denoting data elements tokeep. Defaults to |
NRasRep | If |
reduce | A logical value denoting whether to remove ahistorical stagesassociated with only zero transitions. These are removed only if therespective row and column sums in ALL matrices estimated equal 0. Defaults to |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
If the user inputs a standardhfv_data object in argumentdata, then this function will return an object of classlefkoMat. If the user inputs an object of classhfv_list inargumentdata, then the output will be an object of classlefkoMatList, in which each element is an object of classlefkoMat.
AlefkoMat object is a list that holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted populations,patches, and occasions. All matrices output in the |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. Set to NA for ahistorical matrices. |
agestages | A data frame showing age-stage pairs. In this function, itis set to NA. Only used in output to function |
ahstages | A data frame detailing the characteristics of associatedahistorical stages, in the form of a modified stageframe that includesstatus as an entry stage through reproduction. |
labels | A data frame giving the population, patch, and year of each matrix in order. |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
Notes
The default behavior of this function is to estimate fecundity with regardsto transitions specified via associated fecundity multipliers in thesupplement. If this field is left empty, then fecundity will beestimated at full for all transitions leading from reproductive stages toimmature and propagule stages.
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations. Should the aim of analysis be a generalMPM that does not distinguish these patches or subpopulations, thepatchcol variable should be left toNA, which is the default.Otherwise the variable identifying patch needs to be named.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1 andt. Rearranging the order WILLlead to erroneous calculations, and may lead to fatal errors.
Although this function is capable of assigning stages given an inputstageframe, it lacks the power ofverticalize3() andhistoricalize3() in this regard. Users are stronglyencouraged to use the latter two functions for stage assignment.
See Also
flefko3()
flefko2()
aflefko2()
arlefko2()
fleslie()
rlefko3()
rleslie()
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp2 <- supplemental(stage3 = c("Sd", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "rep", "rep"), givenrate = c(0.345, 0.054, NA, NA), multiplier = c(NA, NA, 0.345, 0.054), type = c(1, 1, 3, 3), stageframe = lathframe, historical = FALSE)ehrlen2 <- rlefko2(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2"), supplement = lathsupp2, yearcol = "year2", indivcol = "individ")# Cypripedium exampledata(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)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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")Create Raw Historical Matrix Projection Model
Description
Functionrlefko3() returns raw historical MPMs, including theassociated component transition and fecundity matrices, data framesdescribing the ahistorical stages used and the historical paired stages, anda data frame describing the population, patch, and occasion time associatedwith each matrix.
Usage
rlefko3( data, stageframe, year = "all", pop = NULL, patch = NULL, censor = FALSE, stages = NULL, alive = c("alive3", "alive2", "alive1"), obsst = NULL, size = c("sizea3", "sizea2", "sizea1"), sizeb = NULL, sizec = NULL, repst = c("repstatus3", "repstatus2", "repstatus1"), matst = c("matstatus3", "matstatus2", "matstatus1"), fec = c("feca3", "feca2", "feca1"), supplement = NULL, repmatrix = NULL, overwrite = NULL, yearcol = NULL, popcol = NULL, patchcol = NULL, indivcol = NULL, censorcol = NULL, censorkeep = 0, NRasRep = FALSE, format = "ehrlen", reduce = FALSE, simple = FALSE, err_check = FALSE, sparse_output = FALSE)Arguments
data | A vertical demographic data frame, with variables corresponding to the naming conventions in functions |
stageframe | A stageframe object that includes information on the size,observation status, propagule status, reproduction status, immaturity status,and maturity status of each ahistorical stage. |
year | A variable corresponding to observation occasion, or a set ofsuch values, given in values associated with the |
pop | A variable designating which populations will have matricesestimated. Should be set to specific population names, or to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Should be set to specific patch names, or to |
censor | If |
stages | An optional vector denoting the names of the variables withinthe main vertical dataset coding for the stages of each individual inoccasionst+1,t, andt-1. The names of stages in thesevariables should match those used in the |
alive | A vector of names of binomial variables corresponding to statusas alive ( |
obsst | A vector of names of binomial variables corresponding toobservation status in occasionst+1,t, andt-1,respectively. Defaults to |
size | A vector of names of variables coding the primary size variablein occasionst+1,t, andt-1, respectively. Defaults to |
sizeb | A vector of names of variables coding the secondary sizevariable in occasionst+1,t, andt-1, respectively.Defaults to |
sizec | A vector of names of variables coding the tertiary sizevariable in occasionst+1,t, andt-1, respectively.Defaults to |
repst | A vector of names of variables coding reproductive status inoccasionst+1,t, andt-1, respectively. Defaults to |
matst | A vector of names of variables coding maturity status inoccasionst+1,t, andt-1, respectively. Defaults to |
fec | A vector of names of variables coding fecundity in occasionst+1,t, andt-1, respectively. Defaults to |
supplement | An optional data frame of class |
repmatrix | An optional reproduction matrix. This matrix is composedmostly of 0s, with non-zero entries acting as element identifiers andmultipliers for fecundity (with 1 equaling full fecundity). If left blank,and no |
overwrite | An optional data frame developed with the |
yearcol | The variable name or column number corresponding to occasiont in the dataset. |
popcol | The variable name or column number corresponding to theidentity of the population. |
patchcol | The variable name or column number corresponding to patch in the dataset. |
indivcol | The variable name or column number coding individualidentity. |
censorcol | The variable name or column number denoting the censorstatus. Only needed if |
censorkeep | The value of the censor variable denoting data elements tokeep. Defaults to |
NRasRep | If |
format | A string indicating whether to estimate matrices in |
reduce | A logical value denoting whether to remove historical stagesassociated exclusively with zero transitions. These are removed only if therespective row and column sums in ALL matrices estimated equal 0. Defaults to |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
If the user inputs a standardhfv_data object in argumentdata, then this function will return an object of classlefkoMat. If the user inputs an object of classhfv_list inargumentdata, then the output will be an object of classlefkoMatList, in which each element is an object of classlefkoMat.
AlefkoMat object is a list that holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted populations,patches, and occasions. All matrices output in the |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. |
agestages | A data frame showing age-stage pairs. In this function, itis set to NA. Only used in output to function |
ahstages | A data frame detailing the characteristics of associatedahistorical stages, in the form of a modified stageframe that includesstatus as an entry stage through reproduction. |
labels | A data frame giving the population, patch, and year of each matrix in order. |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
Notes
The default behavior of this function is to estimate fecundity with regardsto transitions specified via associated fecundity multipliers in thesupplement. If this field is left empty, then fecundity will beestimated at full for all transitions leading from reproductive stages toimmature and propagule stages.
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations. Should the aim of analysis be a generalMPM that does not distinguish these patches or subpopulations, thepatchcol variable should be left toNA, which is the default.Otherwise the variable identifying patch needs to be named.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1,t, andt-1. Rearrangingthe order WILL lead to erroneous calculations, and may lead tofatal errors.
Although this function is capable of assigning stages given an inputstageframe, it lacks the power ofverticalize3() andhistoricalize3() in this regard. Users are stronglyencouraged to use the latter two functions for stage assignment.
See Also
flefko3()
flefko2()
aflefko2()
arlefko2()
fleslie()
rlefko2()
rleslie()
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")# Cypripedium exampledata(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)cypsupp3r <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "D", "XSm", "Sm", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "D", "XSm", "Sm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", NA, NA), givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")Create Raw Leslie (Age-based) Matrix Projection Model
Description
Functionrleslie() returns raw Leslie MPMs, including theassociated component transition and fecundity matrices, a data framedescribing the ages used, and a data frame describing the population, patch,and occasion time associated with each matrix.
Usage
rleslie( data, start_age = NA, last_age = NA, continue = TRUE, fecage_min = NA, fecage_max = NA, alive = c("alive3", "alive2", "alive1"), repst = c("repstatus3", "repstatus2", "repstatus1"), fec = c("feca3", "feca2", "feca1"), agecol = "obsage", year = "all", supplement = NULL, pop = NULL, patch = NULL, yearcol = NULL, popcol = NULL, patchcol = NULL, indivcol = NULL, censor = FALSE, censorcol = NULL, censorkeep = 0, fectime = 2, fecmod = 1, prebreeding = TRUE, reduce = FALSE, simple = FALSE, err_check = FALSE, sparse_output = FALSE)Arguments
data | A vertical demographic data frame, with variables corresponding to the naming conventions in functions |
start_age | The age from which to start the matrix. Defaults to |
last_age | The final age to use in the matrix. Defaults to |
continue | A logical value designating whether to allow continuedsurvival of individuals past the final age noted in the stageframe, using the demographic characteristics of the final age. Defaults to |
fecage_min | The minimum age at which reproduction is possible. Defaultsto |
fecage_max | The maximum age at which reproduction is possible. Defaultsto |
alive | A vector of names of binomial variables corresponding to statusas alive ( |
repst | A vector of names of variables coding reproductive status inoccasionst+1 andt, respectively. Defaults to |
fec | A vector of names of variables coding fecundity in occasionst+1 andt, respectively. Defaults to |
agecol | The name or column number of the variable coding for age in |
year | A variable corresponding to observation occasion, or a setof such values, given in values associated with the |
supplement | An optional data frame of class |
pop | A variable designating which populations will have matricesestimated. Should be set to specific population names, or to |
patch | A variable designating which patches or subpopulations will havematrices estimated. Should be set to specific patch names, or to |
yearcol | The variable name or column number corresponding to occasiont in the dataset. |
popcol | The variable name or column number corresponding to theidentity of the population. |
patchcol | The variable name or column number corresponding to patch inthe dataset. |
indivcol | The variable name or column number coding individualidentity. |
censor | If |
censorcol | The variable name or column number denoting the censorstatus. Only needed if |
censorkeep | The value of the censor variable denoting data elements tokeep. Defaults to |
fectime | An integer indicating whether to estimate fecundity usingthe variable given for |
fecmod | A scalar multiplier for fecundity. Defaults to |
prebreeding | A logical value indicating whether the life history modelis a pre-breeding model. Defaults to |
reduce | A logical value denoting whether to remove ages associated withonly zero transitions. These are removed only if the respective row andcolumn sums in ALL matrices estimated equal 0. Defaults to |
simple | A logical value indicating whether to produce |
err_check | A logical value indicating whether to append extrainformation used in matrix calculation within the output list. Defaults to |
sparse_output | A logical value indicating whether to output matricesin sparse format. Defaults to |
Value
If the user inputs a standardhfv_data object in argumentdata, then this function will return an object of classlefkoMat. If the user inputs an object of classhfv_list inargumentdata, then the output will be an object of classlefkoMatList, in which each element is an object of classlefkoMat.
AlefkoMat object is a list that holds one full matrix projectionmodel and all of its metadata. The structure has the following elements:
A | A list of full projection matrices in order of sorted populations,patches, and occasions. All matrices output in the |
U | A list of survival transition matrices sorted as in |
F | A list of fecundity matrices sorted as in |
hstages | A data frame matrix showing the pairing of ahistorical stagesused to create historical stage pairs. Set to NA for ahistorical matrices. |
agestages | A data frame showing age-stage pairs. In this function, itis set to NA. Only used in output to function |
ahstages | A data frame detailing the characteristics of associatedahistorical stages, in the form of a modified stageframe that includesstatus as an entry stage through reproduction. |
labels | A data frame giving the population, patch, and year of each matrix in order. |
dataqc | A vector showing the numbers of individuals and rows in thevertical dataset used as input. |
matrixqc | A short vector describing the number of non-zero elements in |
modelqc | This is the |
Notes
In order to accomodate survival to timet+1 in the final year of astudy, the maximum age assessed if no inputlast_age is provided isone time step past the final described age.
Users may at times wish to estimate MPMs using a dataset incorporatingmultiple patches or subpopulations. Should the aim of analysis be a generalMPM that does not distinguish these patches or subpopulations, thepatchcol variable should be left toNA, which is the default.Otherwise the variable identifying patch needs to be named.
Input options including multiple variable names must be entered in the orderof variables in occasiont+1 andt. Rearranging the order WILLlead to erroneous calculations, and may lead to fatal errors.
See Also
flefko3()
flefko2()
aflefko2()
arlefko2()
fleslie()
rlefko3()
rlefko2()
Examples
data(cypdata)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", age_offset = 3, NAas0 = TRUE, NRasRep = TRUE)cyp_rl <- rleslie(data = cypraw_v1, start_age = 0, last_age = 4, continue = TRUE, fecage_min = 3, year = "all", pop = NA, patch = "all", yearcol = "year2", patchcol = "patchid", indivcol = "individ")Estimate Sensitivity of Population Growth Rate to Matrix Elements
Description
sensitivity3() is a generic function that returns the sensitivity ofthe population growth rate to the elements of the matrices in a matrixpopulation model. Currently, this function estimates both deterministic andstochastic sensitivities, where the growth rate is\lambda in theformer case and the log of the stochastic\lambda in the latter case.This function is made to handle very large and sparse matrices supplied aslefkoMat objects, as lists of matrices, and as individual matrices.
Usage
sensitivity3(mats, ...)Arguments
mats | A lefkoMat object, or population projection matrix, for whichthe stable stage distribution is desired. |
... | Other parameters |
Value
The value returned depends on the class of themats argument.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")sensitivity3(ehrlen3)Estimate Sensitivity of Population Growth Rate of a Single Matrix
Description
sensitivity3.dgCMatrix() returns the sensitivities of\lambda toelements of a single, sparse matrix. Because this handles only one matrix,sensitivities are inherently deterministic and based on the dominant eigenvalue as the best metric of the population growth rate.
Usage
## S3 method for class 'dgCMatrix'sensitivity3(mats, sparse = "auto", ...)Arguments
mats | An object of class |
sparse | A text string indicating whether to use sparse matrix encoding( |
... | Other parameters. |
Value
This function returns a single deterministic sensitivity matrix.
Notes
All sensitivity matrix outputs from this function are in standard matrixformat.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ", sparse_output = TRUE)sensitivity3(ehrlen3$A[[1]])Estimate Sensitivity of Population Growth Rate of a lefkoMat Object
Description
sensitivity3.lefkoMat() returns the sensitivities of population growthrate to elements of all$A matrices in an object of classlefkoMat. If deterministic, then\lambda is taken as thepopulation growth rate. If stochastic, then the log of stochastic\lambda, or the log stochastic growth rate, is taken as the populationgrowth rate. This function can handle large and sparse matrices, and so canbe used with large historical matrices, IPMs, age x stage matrices, as wellas smaller ahistorical matrices.
Usage
## S3 method for class 'lefkoMat'sensitivity3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, sparse = "auto", append_mats = FALSE, ...)Arguments
mats | An object of class |
stochastic | A logical value determining whether to conduct adeterministic (FALSE) or stochastic (TRUE) sensitivity analysis. Defaults toFALSE. |
times | The number of occasions to project forward in stochasticsimulation. Defaults to |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed in stochastic projection. |
sparse | A text string indicating whether to use sparse matrix encoding( |
append_mats | A logical value indicating whether to include the originalA, U, and F matrices in the output |
... | Other parameters. |
Value
This function returns an object of classlefkoSens, which is alist of 8 elements. The first,h_sensmats, is a list of historicalsensitivity matrices (NULL if an ahMPM is used as input). The second,ah_elasmats, is a list of either ahistorical sensitivity matrices ifan ahMPM is used as input, or, if an hMPM is used as input, then the resultis a list of ahistorical matrices based on the equivalent historicaldependencies assumed in the input historical matrices. The third element,hstages, is a data frame showing historical stage pairs (NULLif an ahMPM used as input). The fourth element,agestages, show theorder of age-stage combinations, if age-by-stage MPMs have been supplied. Thefifth element,ahstages, is a data frame showing the order ofahistorical stages. The last 3 elements are the A, U, and F portions of theinput.
Notes
All sensitivity matrix outputs from this function are in standard matrixformat.
Deterministic sensitivities are estimated as eqn. 9.14 in Caswell (2001,Matrix Population Models). Stochastic sensitivities are estimated as eqn.14.97 in Caswell (2001). Note that stochastic sensitivities are of the log ofthe stochastic\lambda.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
Thetime_weights andsteps arguments are now deprecated.Instead, please use thetweights andtimes arguments.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")sensitivity3(ehrlen3, stochastic = TRUE)Estimate Sensitivity of Population Growth Rate of a lefkoMatList Object
Description
sensitivity3.lefkoMatList() returns the sensitivities of populationgrowth rate to elements of all$A matrices in alllefkoMatobjects in a list of classlefkoMatList. If deterministic, then\lambda is taken as the population growth rate. If stochastic, then thelog of stochastic\lambda, or the log stochastic growth rate, is takenas the population growth rate. This function can handle large and sparsematrices, and so can be used with large historical matrices, IPMs, age xstage matrices, as well as smaller ahistorical matrices.
Usage
## S3 method for class 'lefkoMatList'sensitivity3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, sparse = "auto", append_mats = FALSE, ...)Arguments
mats | An object of class |
stochastic | A logical value determining whether to conduct adeterministic (FALSE) or stochastic (TRUE) sensitivity analysis. Defaults toFALSE. |
times | The number of occasions to project forward in stochasticsimulation. Defaults to |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed in stochastic projection. |
sparse | A text string indicating whether to use sparse matrix encoding( |
append_mats | A logical value indicating whether to include the originalA, U, and F matrices in the output |
... | Other parameters. |
Value
This function returns a list with two elements. The first is anobject of classlefkoSens that contains the mean sensitivity matricesof the bootstrapped sensitivity matrices. The second is a list containinglefkoSens objects giving the sensitivity matrices of all bootstrappedmatrices.
Within these lists are objects of classlefkoSens, which are comprisedof lists of 8 elements. The first,h_sensmats, is a list of historicalsensitivity matrices (NULL if an ahMPM is used as input). The second,ah_elasmats, is a list of either ahistorical sensitivity matrices ifan ahMPM is used as input, or, if an hMPM is used as input, then the resultis a list of ahistorical matrices based on the equivalent historicaldependencies assumed in the input historical matrices. The third element,hstages, is a data frame showing historical stage pairs (NULLif an ahMPM used as input). The fourth element,agestages, show theorder of age-stage combinations, if age-by-stage MPMs have been supplied. Thefifth element,ahstages, is a data frame showing the order ofahistorical stages. The last 3 elements are the A, U, and F portions of theinput.
Notes
All sensitivity matrix outputs from this function are in standard matrixformat.
Deterministic sensitivities are estimated as eqn. 9.14 in Caswell (2001,Matrix Population Models). Stochastic sensitivities are estimated as eqn.14.97 in Caswell (2001). Note that stochastic sensitivities are of the log ofthe stochastic\lambda.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
Thetime_weights andsteps arguments are now deprecated.Instead, please use thetweights andtimes arguments.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathvert_boot <- bootstrap3(lathvert, reps = 3)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3_boot <- rlefko3(data = lathvert_boot, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")sensitivity3(ehrlen3_boot, stochastic = TRUE)Estimate Sensitivity of Population Growth Rate of a List of Matrices
Description
sensitivity3.list() returns the sensitivities of population growthrate to elements of matrices supplied in a list. The sensitivity analysis canbe deterministic or stochastic, but if the latter then at least two Amatrices must be included in the list. This function can handle large andsparse matrices, and so can be used with large historical matrices, IPMs,age x stage matrices, as well as smaller ahistorical matrices.
Usage
## S3 method for class 'list'sensitivity3( mats, stochastic = FALSE, times = 10000, tweights = NA, historical = FALSE, seed = NA, sparse = "auto", append_mats = FALSE, ...)Arguments
mats | An object of class |
stochastic | A logical value determining whether to conduct adeterministic (FALSE) or stochastic (TRUE) sensitivity analysis. Defaults toFALSE. |
times | The number of occasions to project forward in stochasticsimulation. Defaults to 10,000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
historical | A logical value indicating whether matrices are historical.Defaults to |
seed | A number to use as a random number seed in stochastic projection. |
sparse | A text string indicating whether to use sparse matrix encoding( |
append_mats | A logical value indicating whether to include the originalmatrices input as object |
... | Other parameters. |
Value
This function returns an object of classlefkoSens, which is alist of 8 elements. The first,h_sensmats, is a list of historicalsensitivity matrices (NULL if an ahMPM is used as input). The second,ah_elasmats, is a list of ahistorical sensitivity matrices if an ahMPMis used as input (NULL if an hMPM is used as input). The thirdelement,hstages, the fourth element,agestages, and the fifthelement,ahstages, areNULL. The last 3 elements include theoriginal A matrices supplied (as theA element), followed byNULLs for the U and F elements.
Notes
All sensitivity matrix outputs from this function are in standard matrixformat.
Deterministic sensitivities are estimated as eqn. 9.14 in Caswell (2001,Matrix Population Models). Stochastic sensitivities are estimated as eqn.14.97 in Caswell (2001). Note that stochastic sensitivities are with regardto the log of the stochastic\lambda.
Currently, this function does not estimate equivalent ahistorical stochasticsensitivities for input historical matrices, due to the lack of guidanceinput on the order of stages (guidance is provided withinlefkoMatobjects).
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
Thetime_weights andsteps arguments are now deprecated.Instead, please use thetweights andtimes arguments.
See Also
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")sensitivity3(ehrlen3$A)# Cypripedium exampledata(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")sensitivity3(cypmatrix2r$A)Estimate Sensitivity of Population Growth Rate of a Single Matrix
Description
sensitivity3.matrix() returns the sensitivities of\lambda toelements of a single matrix. Because this handles only one matrix, thesensitivities are inherently deterministic and based on the dominant eigenvalue as the best metric of the population growth rate. This function canhandle large and sparse matrices, and so can be used with large historicalmatrices, IPMs, age x stage matrices, as well as smaller ahistoricalmatrices.
Usage
## S3 method for class 'matrix'sensitivity3(mats, sparse = "auto", ...)Arguments
mats | An object of class |
sparse | A text string indicating whether to use sparse matrix encoding( |
... | Other parameters. |
Value
This function returns a single deterministic sensitivity matrix.
Notes
All sensitivity matrix outputs from this function are in standard matrixformat.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)sensitivity3(ehrlen3mean$A[[1]])Create Stageframe for Population Matrix Projection Analysis
Description
Functionsf_create() returns a data frame describing each ahistoricallife history stage in the life history model. This data frame can be used as input into MPM creation functions includingflefko3(),flefko2(),aflefko2(),rlefko3(),rlefko2(), andarlefko2(), in which itdetermines how each stage is treated during matrix estimation.
Usage
sf_create( sizes, stagenames = NULL, sizesb = NULL, sizesc = NULL, repstatus = NULL, obsstatus = NULL, propstatus = NULL, matstatus = NULL, immstatus = NULL, minage = NULL, maxage = NULL, indataset = NULL, sizemin = NULL, sizebmin = NULL, sizecmin = NULL, sizemax = NULL, sizebmax = NULL, sizecmax = NULL, binhalfwidth = NULL, binhalfwidthb = NULL, binhalfwidthc = NULL, group = NULL, comments = NULL, roundsize = 5L, roundsizeb = 5L, roundsizec = 5L, ipmbins = 100L, ipmbinsb = NA_integer_, ipmbinsc = NA_integer_)Arguments
sizes | A numeric vector of the typical or representative size of eachlife history stage. If making function-based MPMs, then this may be avector composed of the midpoints of each size bin, or simply of sizescharacteristic of the size bins. If denoting the boundary of an automatedsize classification group, then should denote the absolute minimum size ofthat group, or the absolute size of that group (see |
stagenames | A vector of stage names, in the same order as elements insizes. Can also be set to |
sizesb | An optional numeric vector for a second size metric for eachlife history stage. Only to be used if stages are defined by at least twosize metrics in all cases. Same issues apply as in |
sizesc | An optional numeric vector for a third size metric for eachlife history stage. Only to be used if stages are defined by at least threesize metrics in all cases. Same issues apply as in |
repstatus | A vector denoting the binomial reproductive status of eachlife history stage. Defaults to |
obsstatus | A vector denoting the binomial observation status of eachlife history stage. Defaults to |
propstatus | A vector denoting whether each life history stage is a propagule. Such stages are generally only used in fecundity estimation. Defaults to |
matstatus | A vector denoting whether each stage is mature. Must becomposed of binomial values if given. Defaults to 1 for all stages defined in |
immstatus | A vector denoting whether each stage is immature. Must becomposed of binomial values if given. Defaults to the complement of vector |
minage | An optional vector denoting the minimum age at which a stagecan occur. Only used in age x stage matrix development. Defaults to |
maxage | An optional vector denoting the maximum age at which a stageshould occur. Only used in age x stage matrix development. Defaults to |
indataset | A vector designating which stages are found within the dataset. While |
sizemin | A vector giving the absolute minimum values corresponding toeach size in the |
sizebmin | A vector giving the absolute minimum values corresponding toeach size in the |
sizecmin | A vector giving the absolute minimum values corresponding toeach size in the |
sizemax | A vector giving the absolute maximum values corresponding toeach size in the |
sizebmax | A vector giving the absolute maximum values corresponding toeach size in the |
sizecmax | A vector giving the absolute maximum values corresponding toeach size in the |
binhalfwidth | A numeric vector giving the half-width of size bins.Required if |
binhalfwidthb | A numeric vector giving the half-width of size binsused for the optional second size metric. Required if |
binhalfwidthc | A numeric vector giving the half-width of size binsused for the optional third size metric. Required if |
group | An integer vector providing information on each respectivestage's size classification group. If used, then function-based MPM creationfunctions |
comments | An optional vector of text entries holding useful textdescriptions of all stages. |
roundsize | This parameter sets the precision of size classification,and equals the number of digits used in rounding sizes. Defaults to |
roundsizeb | This parameter sets the precision of size classificationin the optional second size metric, and equals the number of digits used inrounding sizes. Defaults to |
roundsizec | This parameter sets the precision of size classificationin the optional third size metric, and equals the number of digits used inrounding sizes. Defaults to |
ipmbins | An integer giving the number of size bins to create using theprimary size classification variable. This number is in addition to anystages that are not size classified. Defaults to |
ipmbinsb | An optional integer giving the number of size bins to createusing the secondary size classification variable. This number is in additionto any stages that are not size classified, as well as in addition to anyautomated size classification using the primary and tertiary size variables.Defaults to |
ipmbinsc | An optional integer giving the number of size bins to createusing the tertiary size classification variable. This number is in additionto any stages that are not size classified, as well as in addition to anyautomated size classification using the primary and secondary sizevariables. Defaults to |
Value
A data frame of classstageframe, which includes informationon the stage name, size, reproductive status, observation status, propagule status, immaturity status, maturity status, presence within the core dataset, stage group classification, raw bin half-width, and the minimum, center, and maximum of each size bin, as well as its width. If minimum andmaximum ages were specified, then these are also included. Also includes an empty string variable that can be used to describe stages meaningfully. Thisobject can be used as thestageframe input forflefko3()flefko2(),rlefko3(), andrlefko2().
Variables in this data frame include the following:
stage | The unique names of the stages to be analyzed. |
size | The typical or representative size at which each stage occurs. |
size_b | Size at which each stage occurs in terms of a second sizevariable, if one exists. |
size_c | Size at which each stage occurs in terms of a third sizevariable, if one exists. |
min_age | The minimum age at which the stage may occur. |
max_age | The maximum age at which the stage may occur. |
repstatus | A binomial variable showing whether each stage isreproductive. |
obsstatus | A binomial variable showing whether each stage isobservable. |
propstatus | A binomial variable showing whether each stage is apropagule. |
immstatus | A binomial variable showing whether each stage can occur asimmature. |
matstatus | A binomial variable showing whether each stage occurs inmaturity. |
indataset | A binomial variable describing whether each stage occurs inthe input dataset. |
binhalfwidth_raw | The half-width of the size bin, as input. |
sizebin_min | The minimum size at which the stage may occur. |
sizebin_max | The maximum size at which the stage may occur. |
sizebin_center | The midpoint of the size bin at which the stage mayoccur. |
sizebin_width | The width of the size bin corresponding to the stage. |
binhalfwidthb_raw | The half-width of the size bin of a second sizevariable, as input. |
sizebinb_min | The minimum size at which the stage may occur. |
sizebinb_max | The maximum size at which the stage may occur. |
sizebinb_center | The midpoint of the size bin at which the stage mayoccur, in terms of a second size variable. |
sizebinb_width | The width of the size bin corresponding to the stage,in terms of a second size variable. |
binhalfwidthc_raw | The half-width of the size bin of a third sizevariable, as input. |
sizebinc_min | The minimum size at which the stage may occur, in termsof a third size variable. |
sizebinc_max | The maximum size at which the stage may occur, in termsof a third size variable. |
sizebinc_center | The midpoint of the size bin at which the stage mayoccur, in terms of a third size variable. |
sizebinc_width | The width of the size bin corresponding to the stage,in terms of a third size variable. |
group | An integer denoting the size classification group that thestage falls within. |
comments | A text field for stage descriptions. |
Notes
Vectors used to create a stageframe may not mixNA values withnon-NA values.
If an IPM or function-based matrix with automated size classification isdesired, then two stages that occur within the dataset and represent thelower and upper size limits of the IPM must be marked withipm inthe stagenames vector. These stages should have all characteristics otherthan size equal, and the size input for whichever size will be classifiedautomatically must include the minimum in one stage and the maximum in theother. The actual characteristics of the first stage encountered in theinputs will be used as the template for the creation of these sizes. Notethatipm refers to size classification with the primary sizevariable. To automate size classification with the secondary size variable,useipmb, and to automate size classification with the tertiary sizevariable, useipmc. To nest automated size classifications, useipmab for the primary and secondary size variables,ipmac forthe primary and tertiary size variables,ipmbc for the secondary andtertiary size variables, andipmabc for all three size variables.The primary size variable can also be set withipma.
If two or more groups of stages, each with its own characteristics, are tobe developed for an IPM or function-based MPM, then an even number of stageswith two stages marking the minimum and maximum size of each group should bemarked with the same code as given above, with all other characteristicsequal within each group.
Stage classification groups set with thegroup variable create zoneswithin function-based matrices in which survival transitions are estimated.These groups should not be set if transitions are possible between allstages regardless of group. To denote specific transitions as estimablebetween stage groups, use thesupplemental() function.
If importing an IPM rather than building one withlefko3: Using thevrm_import approach to building function-based MPMs with providedlinear model slope coefficients requires careful attention to thestageframe. Although no hfv data frame needs to be entered in this instance,stages for which vital rates are to be estimated via linear modelsparameterized with coefficients provided via functionvrm_import() should be marked as occurring within the dataset.Stages for which the provided coefficients should not be used should bemarked as not occurring within the dataset.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)# Cypripedium exampledata(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)Test Overdispersion and Zero Inflation in Size and Fecundity Distributions
Description
Functionsf_distrib takes a historically formatted vertical data asinput and tests whether size and fecundity data are dispersed according to aPoisson distribution (where mean = variance), and whether the number of 0sexceeds expectations. This function is now deprecated in favor of functionhfv_qc().
Usage
sf_distrib( data, sizea = NA, sizeb = NA, sizec = NA, obs3 = NA, fec = NA, repst = NA, zisizea = TRUE, zisizeb = TRUE, zisizec = TRUE, zifec = TRUE, fectime = 2, show.size = TRUE, show.fec = TRUE)Arguments
data | A historical vertical data file, which is a data frame of class |
sizea | A vector holding the name or column number of the variablescorresponding to primary size in occasionst+1 andt. Input only if |
sizeb | A vector holding the name or column number of the variablescorresponding to secondary size in occasionst+1 andt. Input only if |
sizec | A vector holding the name or column number of the variablescorresponding to tertiary size in occasionst+1 andt. Input only if |
obs3 | The name or column number of the variable corresponding toobservation status in occasiont+1. This should be used if observationstatus will be used as a vital rate to absorb states of size = 0. |
fec | A vector holding the names or column numbers of the variablescorresponding to in occasionst+1 andt. Input only if |
repst | A vector holding the names or column numbers of the variablescorresponding to reproductive status in occasionst+1 andt.If not provided, then fecundity will be tested without subsetting to onlyreproductive individuals. |
zisizea | A logical value indicating whether to conduct a test of zeroinflation in primary size. Defaults to |
zisizeb | A logical value indicating whether to conduct a test of zeroinflation in secondary size. Defaults to |
zisizec | A logical value indicating whether to conduct a test of zeroinflation in tertiary size. Defaults to |
zifec | A logical value indicating whether to conduct a test of zeroinflation in fecundity. Defaults to TRUE. |
fectime | An integer indicating whether to treat fecundity as occurringin timet ( |
show.size | A logical value indicating whether to show the output fortests of size. Defaults to |
show.fec | A logical value indicating whether to show the output fortests of fecundity. Defaults to |
Value
Produces text describing the degree and significance of differencefrom expected dispersion, and the degree and significance of zero inflation.The tests are chi-squared score tests based on the expectations of mean = variance, and 0s as abundant as predicted by the value of lambdaestimated from the dataset. See van der Broek (1995) for more details.
Notes
This function subsets the data in the same way asmodelsearch()before testing underlying distributions, making the output much moreappropriate than a simple analysis of size and fecundity variables indata.
The specific test used for overdispersion is a chi-squared test of thedispersion parameter estimated using a generalized linear model predictingthe response given size in occasiont, under a quasi-Poissondistribution.
The specific test used for zero-inflation is the chi-squared test presentedin van der Broek (1995).
Examples
data(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)sf_distrib(lathvertln, sizea = c("sizea3", "sizea2"), fec = c("feca3", "feca2"), repst = c("repstatus3", "repstatus2"), zifec = FALSE)Create Skeleton Stageframe
Description
Functionsf_skeleton() creates a skeletonstageframe object.
Usage
sf_skeleton(stages, standard = TRUE)Arguments
stages | The number of stages, as an integer. |
standard | A logical value indicating whether to create a standard |
Value
A data frame of classstageframe.
Estimate Stochastic Population Growth Rate
Description
Functionslambda3() estimates the stochastic population growth rate,a, defined as the long-term arithmetic mean of the log population growth rate estimated per simulated occasion. This function can handlelefkoMat objects, lefkoMatList objects, and lists of full A matrices asinput.
Usage
slambda3( mpm, times = 10000L, historical = FALSE, tweights = NULL, force_sparse = NULL)Arguments
mpm | A matrix projection model of class |
times | Number of occasions to iterate. Defaults to |
historical | An optional logical value only used if object |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If amatrix is input, then a first-order Markovian environment is assumed, inwhich the probability of choosing a specific annual matrix depends on whichannual matrix is currently chosen. If a vector is input, then the choice ofannual matrix is assumed to be independent of the current matrix. Defaultsto equal weighting among matrices. |
force_sparse | A text string indicating whether to force sparse matrix encoding ( |
Value
A data frame with the following variables:
replicate | The bootstrapped replicate. Only provided if a |
pop | The identity of the population. |
patch | The identity of the patch. |
a | Estimate of stochastic growth rate, estimated as the arithmeticmean of the log population growth rate across simulated occasions. |
var | The estimated variance of a. |
sd | The standard deviation of a. |
se | The standard error of a. |
Notes
The log stochastic population growth rate,a, is as given in equation2 of Tuljapurkar, Horvitz, and Pascarella 2003. This term is estimated viaprojection of randomly sampled matrices, similarly to the procedure outlinedin Box 7.4 of Morris and Doak (2002).
Stochastic growth rate is estimated both at the patch level and at thepopulation level. Population level estimates will be noted at the end of thedata frame with 0 entries for patch designation.
Weightings given intweights do not need to sum to 1. Finalweightings used will be based on the proportion per element of the sum ofelements in the user-supplied vector.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
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)cypraw_boot <- bootstrap3(cypraw_v1, reps = 3)cypsupp3r <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "D", "XSm", "Sm", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "D", "XSm", "Sm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", NA, NA), givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypstoch <- slambda3(cypmatrix3r)cypmatrix3r_boot <- rlefko3(data = cypraw_boot, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypstoch_boot <- slambda3(cypmatrix3r_boot)Estimate Stable Stage Distribution
Description
stablestage3() is a generic function that returns the stable stage distribution for a population projection matrix or set of matrices. Thisfunction is made to handle very large and sparse matrices supplied aslefkoMat objects or as individual matrices, and can be used with largehistorical matrices, IPMs, age x stage matrices, as well as ahistoricalmatrices.
Usage
stablestage3(mats, ...)Arguments
mats | A lefkoMat object, a population projection matrix, or a list ofpopulation projection matrices for which the stable stage distribution isdesired. |
... | Other parameters. |
Value
The value returned depends on the class of themats argument.See related functions for details.
See Also
Examples
# Lathyrus deterministic exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)stablestage3(ehrlen3mean)# Cypripedium stochastic exampledata(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)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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")stablestage3(cypmatrix2r, stochastic = TRUE)Estimate Stable Stage Distribution of a Single Population Projection Matrix
Description
stablestage3.dgCMatrix() returns the stable stage distribution for a sparse population projection matrix.
Usage
## S3 method for class 'dgCMatrix'stablestage3(mats, ...)Arguments
mats | A population projection matrix of class |
... | Other parameters. |
Value
This function returns the stable stage distribution corresponding tothe input matrix.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ", sparse_output = TRUE)stablestage3(ehrlen3$A[[1]])Estimate Stable Stage Distribution of Matrices in lefkoMat Object
Description
stablestage3.lefkoMat() returns the deterministic stable stagedistributions of allA matrices in an object of classlefkoMat,as well as the long-run projected mean stage distribution in stochasticanalysis. This function can handle large and sparse matrices, and so can beused with large historical matrices, IPMs, age x stage matrices, as well asahistorical matrices.
Usage
## S3 method for class 'lefkoMat'stablestage3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, force_sparse = "auto", ...)Arguments
mats | An object of class |
stochastic | A logical value indicating whether to use deterministic( |
times | An integer variable indicating number of occasions to project ifusing stochastic analysis. Defaults to 10000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed in stochastic projection. |
force_sparse | A text string indicating whether to use sparse matrixencoding ( |
... | Other parameters. |
Value
This function returns the stable stage distributions (and long-runmean stage distributions in stochastic analysis) corresponding to thematrices in alefkoMat object.
The output depends on whether thelefkoMat object used as input isahistorical or historical, and whether the analysis is deterministic orstochastic. If deterministic and ahistorical, then a single data frame isoutput, which includes the number of the matrix within theA elementof the inputlefkoMat object, followed by the stage id (numeric andassigned throughsf_create()), the stage name, and theestimated proportion of the stable stage distribution (ss_prop). Ifstochastic and ahistorical, then a single data frame is output starting withthe number of the population-patch (matrix_set), a stringconcatenating the names of the population and the patch (poppatch),the assigned stage id number (stage_id), and the stage name(stage), and the long-run average stage distribution (ss_prop).
If a historical matrix is used as input, then two data frames are outputinto a list object. Thehist element describes the historicalstage-pair distribution, while theahist element describes the stagedistribution. If deterministic, thenhist contains a data frameincluding the matrix number (matrix), the numeric stage designations forstages in occasionst andt-1, (stage_id_2 andstage_id_1, respectively), followed by the respective stage names (stage_2 andstage_1), and ending with the estimated stablestage-pair distribution. The associatedahist element is as before. Ifstochastic, then thehist element contains a single data frame withthe number of the population-patch (matrix_set), a stringconcatenating the names of the population and the patch (poppatch),the assigned stage id numbers in timest andt-1 (stage_id_2 andstage_id_2, respectively), and the associatedstage names (stage_2 andstage_1, respectively), and thelong-run average stage distribution (ss_prop). The associatedahist element is as before in the ahistorical, stochastic case.
In addition to the data frames noted above, stochastic analysis will resultin the additional output of a list of matrices containing the actualprojected stage distributions across all projected occasions, in the order ofpopulation-patch combinations in thelefkoMat input.
Notes
In stochastic analysis, the projected mean distribution is the arithmeticmean across the final 1000 projected occasions if the simulation is at least2000 projected occasions long. If between 500 and 2000 projected occasionslong, then only the final 200 are used, and if fewer than 500 occasions areused, then all are used. Note that because stage distributions in stochasticsimulations can change greatly in the initial portion of the run, weencourage a minimum of 2000 projected occasions per simulation, with 10000preferred.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
See Also
Examples
# Lathyrus deterministic exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)stablestage3(ehrlen3mean)# Cypripedium stochastic exampledata(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)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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")stablestage3(cypmatrix2r, stochastic = TRUE)Estimate Stable Stage Distribution of Matrices in lefkoMatList Object
Description
stablestage3.lefkoMatList() returns the deterministic stable stagedistributions of allA matrices in all objects of classlefkoMat stored within the enteredlefkoMatList object, as wellas the long-run projected mean stage distribution in stochastic analysis.This function can handle large and sparse matrices, and so can be used withlarge historical matrices, IPMs, age x stage matrices, as well as ahistoricalmatrices.
Usage
## S3 method for class 'lefkoMatList'stablestage3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, force_sparse = "auto", ...)Arguments
mats | An object of class |
stochastic | A logical value indicating whether to use deterministic( |
times | An integer variable indicating number of occasions to project ifusing stochastic analysis. Defaults to 10000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed in stochastic projection. |
force_sparse | A text string indicating whether to use sparse matrixencoding ( |
... | Other parameters. |
Value
This function returns a list with two elements. The first is the meanstable stage distribution (and long-run mean stage distributions fromstochastic analysis), and the second is a list of stable stage distributions(and long-run mean stage distributions from stochastic analysis)corresponding to thelefkoMat objects in the originalmatslist.
The format of distributions in both cases depends on whether thelefkoMat objects used as input are ahistorical or historical, andwhether the analysis is deterministic or stochastic. If deterministic andahistorical, then a single data frame is output, which includes the number ofthe matrix within theA element of the inputlefkoMat object,followed by the stage id (numeric and assigned throughsf_create()), the stage name, and the estimated proportion ofthe stable stage distribution (ss_prop). If stochastic andahistorical, then a single data frame is output starting with the number ofthe population-patch (matrix_set), a string concatenating the names ofthe population and the patch (poppatch), the assigned stage id number(stage_id), and the stage name (stage), and the long-runaverage stage distribution (ss_prop).
If historical matrices are used as input, then two data frames are outputinto a list object. Thehist element describes the historicalstage-pair distribution, while theahist element describes the stagedistribution. If deterministic, thenhist contains a data frameincluding the matrix number (matrix), the numeric stage designations forstages in occasionst andt-1, (stage_id_2 andstage_id_1, respectively), followed by the respective stage names (stage_2 andstage_1), and ending with the estimated stablestage-pair distribution. The associatedahist element is as before. Ifstochastic, then thehist element contains a single data frame withthe number of the population-patch (matrix_set), a stringconcatenating the names of the population and the patch (poppatch),the assigned stage id numbers in timest andt-1 (stage_id_2 andstage_id_2, respectively), and the associatedstage names (stage_2 andstage_1, respectively), and thelong-run average stage distribution (ss_prop). The associatedahist element is as before in the ahistorical, stochastic case.
In addition to the data frames noted above, stochastic analysis will resultin the additional output of a list of matrices containing the actualprojected stage distributions across all projected occasions, in the order ofpopulation-patch combinations in thelefkoMat input.
Notes
In stochastic analysis, the projected mean distribution is the arithmeticmean across the final 1000 projected occasions if the simulation is at least2000 projected occasions long. If between 500 and 2000 projected occasionslong, then only the final 200 are used, and if fewer than 500 occasions areused, then all are used. Note that because stage distributions in stochasticsimulations can change greatly in the initial portion of the run, weencourage a minimum of 2000 projected occasions per simulation, with 10000preferred.
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
See Also
Examples
# Lathyrus deterministic exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathvert_boot <- bootstrap3(lathvert, reps = 3)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3_boot <- rlefko3(data = lathvert_boot, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3_boot)stablestage3(ehrlen3mean)# Cypripedium stochastic exampledata(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)cypraw_v1_boot <- bootstrap3(cypraw_v1, reps = 3)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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_boot <- rlefko2(data = cypraw_v1_boot, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added"), supplement = cypsupp2r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")stablestage3(cypmatrix2r_boot, stochastic = TRUE)Estimate Stable Stage Distribution of a List of Projection Matrices
Description
stablestage3.list() returns the stable stage distributions for stagesin population projection matrices arranged in a general list. The functionmakes no assumptions about whether the matrix is ahistorical and simplyprovides stable stage distribution values corresponding to each row, meaningthat the overall stable stage distribution of basic life history stages in ahistorical matrix are not provided (thestablestage3.lefkoMat()historical estimates these on the basis of stage description informationprovided in thelefkoMat object used as input in that function). Thisprovided in the handle large and sparse matrices, and so can be used withlarge historical matrices, IPMs, age x stage matrices, as well as smallerahistorical matrices.
Usage
## S3 method for class 'list'stablestage3( mats, stochastic = FALSE, times = 10000, tweights = NA, seed = NA, force_sparse = "auto", ...)Arguments
mats | A list of population projection matrices, all in either class |
stochastic | A logical value indicating whether to use deterministic( |
times | An integer variable indicating number of occasions to project ifusing stochastic analysis. Defaults to 10000. |
tweights | An optional numeric vector or matrix denoting theprobabilities of choosing each matrix in a stochastic projection. If a matrixis input, then a first-order Markovian environment is assumed, in which theprobability of choosing a specific annual matrix depends on which annualmatrix is currently chosen. If a vector is input, then the choice of annualmatrix is assumed to be independent of the current matrix. Defaults to equalweighting among matrices. |
seed | A number to use as a random number seed in stochastic projection. |
force_sparse | A text string indicating whether to use sparse matrixencoding ( |
... | Other parameters. |
Value
This function returns a list of vector data frames characterizing the stable stage distributions for stages of each population projection matrix.
Notes
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)stablestage3(ehrlen3mean$A)Estimate Stable Stage Distribution of a Single Population Projection Matrix
Description
stablestage3.matrix() returns the stable stage distribution for a population projection matrix. This function can handle large and sparsematrices, and so can be used with large historical matrices, IPMs, age x stage matrices, as well as smaller ahistorical matrices.
Usage
## S3 method for class 'matrix'stablestage3(mats, force_sparse = "auto", ...)Arguments
mats | A population projection matrix of class |
force_sparse | A text string indicating whether to use sparse matrixencoding ( |
... | Other parameters. |
Value
This function returns the stable stage distribution corresponding tothe input matrix.
Notes
Speed can sometimes be increased by shifting from automatic sparse matrixdetermination to forced dense or sparse matrix projection. This will mostlikely occur when matrices have between 30 and 300 rows and columns.Defaults work best when matrices are very small and dense, or very large andsparse.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)stablestage3(ehrlen3mean$A[[1]])Create a Vector of Stage Weights for Density Dependence Calculations
Description
Functionstage_weight() creates a data frame summarizing the weightingof individuals of different stages, stage-stage combinations, ages, orage-stages relative to one another in terms of the total population size.Stage weights can be thought of as Lotka-Volterra coefficients applied toindividuals of different stages within a single population.
Usage
stage_weight(mpm, stage2 = NA, stage1 = NA, age2 = NA, value = 1)Arguments
mpm | The lefkoMat object to be used in projection. Can be an exampleMPM if function-based projection is planned. |
stage2 | A vector showing the name or number of a stage in occasiont that should be set to a positive number of individuals in the startvector. Abbreviations for groups of stages are also usable (see Notes).This input is required for all stage-based and age-by-stage MPMs. Defaults to |
stage1 | A vector showing the name or number of a stage in occasiont-1 that should be set to a positive number of individuals in thestart vector. Abbreviations for groups of stages are also usable (see Notes).This is only used for historical MPMs, since the rows of hMPMs correspond tostage-pairs in timest andt-1 together. Only required forhistorical MPMs, and will result in errors if otherwise used. |
age2 | A vector showing the age of each respective stage in occasiont that should be set to a positive number of individuals in the startvector. Only used for Leslie and age-by-stage MPMs. Defaults to |
value | A vector showing the values, in order, of the number ofindividuals set for the stage or stage-pair in question. Defaults to |
Value
A list of classlefkoEq, with four objects, which can beused as input in functionprojection3() andf_projection3(). The last three include theahstages,hstages, andagestages objects from thelefkoMat objectsupplied inmpm. The first element in the list is a data frame withthe following variables:
stage2 | Stage at occasiont. |
stage_id_2 | The stage number associated with |
stage1 | Stage at occasiont-1, if historical. Otherwise NA. |
stage_id_1 | The stage number associated with |
age2 | The age of individuals in |
row_num | A number indicating the respective starting vector element. |
value | Number of individuals in corresponding stage or stage-pair. |
Notes
Users should generally consider which stage to set as the reference, whichshould be designated with a value of1.
In some life histories, certain stages may not count against population sizewith regards to the kind and value of density dependence decided on. Anexample might be the dormant seed stage in some plant species. These stageweight values should be set to0.
Entries instage2, andstage1 can include abbreviations forgroups of stages. Userep if all reproductive stages are to be used,nrep if all mature but non-reproductive stages are to be used,mat if all mature stages are to be used,immat if all immaturestages are to be used,prop if all propagule stages are to be used,npr if all non-propagule stages are to be used,obs if allobservable stages are to be used,nobs if all unobservable stages areto be used, and leave empty or useall if all stages in stageframe areto be used.
Examples
library(lefko3)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)cycaraw_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)cycamatrix2r <- rlefko2(data = cycaraw_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")cyca2_start <- start_input(cycamatrix2r, stage2 = c("SD", "P1", "P2"), value = c(500, 100, 200))cyp2_dv <- density_input(cycamatrix2r, stage3 = c("SD", "P1"), stage2 = c("rep", "rep"), style = c(1, 1), alpha = c(0.5, 1.2), beta = c(1.0, 2.0), type = c(2, 1))cyp_eq <- stage_weight(cycamatrix2r, stage2 = c("SD", "P1", "SL", "D", "XSm", "Sm", "Md", "Lg", "XLg"), value = c(0, 1, 1, 1, 1, 1, 1, 1, 1))cyca_proj <- projection3(mpm = cycamatrix2r, start_frame = cyca2_start, density = cyp2_dv, stage_weights = cyp_eq, times = 10) summary(cyca_proj)Create a Starting Vector for Population Projection
Description
Functionstart_input() creates a data frame summarizing the non-zeroelements of the start vector for use in population projection analysis viafunctionprojection3().
Usage
start_input(mpm, stage2 = NA, stage1 = NA, age2 = NA, value = 1)Arguments
mpm | The lefkoMat object to be used in projection analysis. |
stage2 | A vector showing the name or number of a stage in occasiont that should be set to a positive number of individuals in the startvector. Abbreviations for groups of stages are also usable (see Notes).This input is required for all stage-based and age-by-stage MPMs. Defaults to |
stage1 | A vector showing the name or number of a stage in occasiont-1 that should be set to a positive number of individuals in thestart vector. Abbreviations for groups of stages are also usable (see Notes).This is only used for historical MPMs, since the rows of hMPMs correspond tostage-pairs in timest andt-1 together. Only required forhistorical MPMs, and will result in errors if otherwise used. |
age2 | A vector showing the age of each respective stage in occasiont that should be set to a positive number of individuals in the startvector. Only used for Leslie and age-by-stage MPMs. Defaults to |
value | A vector showing the values, in order, of the number ofindividuals set for the stage or stage-pair in question. Defaults to 1. |
Value
A list of classlefkoSV, with four objects, which can be usedas input in functionprojection3(). The last three include theahstages,hstages, andagestages objects from thelefkoMat object supplied inmpm. The first element in the listis a data frame with the following variables:
stage2 | Stage at occasiont. |
stage_id_2 | The stage number associated with |
stage1 | Stage at occasiont-1, if historical. Otherwise NA. |
stage_id_1 | The stage number associated with |
age2 | The age of individuals in |
row_num | A number indicating the respective starting vector element. |
value | Number of individuals in corresponding stage or stage-pair. |
Notes
Entries instage2, andstage1 can include abbreviations forgroups of stages. Userep if all reproductive stages are to be used,nrep if all mature but non-reproductive stages are to be used,mat if all mature stages are to be used,immat if all immaturestages are to be used,prop if all propagule stages are to be used,npr if all non-propagule stages are to be used,obs if allobservable stages are to be used,nobs if all unobservable stages areto be used, and leave empty or useall if all stages in stageframe areto be used.
See Also
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen3mean <- lmean(ehrlen3)e3m_sv <- start_input(ehrlen3mean, stage2 = "Sd", stage1 = "Sd", value = 1000)lathproj <- projection3(ehrlen3, nreps = 5, times = 100, stochastic = TRUE, start_frame = e3m_sv)Create New lefkoMat or lefkoMatList Object as Subset of Another
Description
Functionsubset_lM() creates a newlefkoMat orlefkoMatList object from a subset of matrices in anotherlefkoMat orlefkoMatList object.
Usage
subset_lM(lM, mat_num = NA, pop = NA, patch = NA, year = NA)Arguments
lM | The |
mat_num | Either a single integer corresponding to the matrix to selectwithin the |
pop | The population designation for matrices to select. Only used if |
patch | The patch designation for matrices to select. Only used if |
year | The timet designation for matrices to select. Only usedif |
Value
AlefkoMat orlefkoMatList object composed of thematrices specified in the options. Note that, when applied to alefkoMatList object, subsetting happens equivalently across allcompositelefkoMat objects.
Notes
Ifmat_num is not provided, then at least one ofpop,patch, oryear must be provided. If at least two ofpop,patch, andyear are provided, then functionsubset_lM()will identify matrices as the intersection of provided inputs.
See Also
add_lM()
Examples
# These matrices are of 9 populations of the plant species Anthyllis# vulneraria, and were originally published in Davison et al. (2010) Journal# of Ecology 98:255-267 (doi: 10.1111/j.1365-2745.2009.01611.x).sizevector <- c(1, 1, 2, 3) # These sizes are not from the original paperstagevector <- c("Sdl", "Veg", "SmFlo", "LFlo")repvector <- c(0, 0, 1, 1)obsvector <- c(1, 1, 1, 1)matvector <- c(0, 1, 1, 1)immvector <- c(1, 0, 0, 0)propvector <- c(0, 0, 0, 0)indataset <- c(1, 1, 1, 1)binvec <- c(0.5, 0.5, 0.5, 0.5)anthframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)# POPN C 2003-2004XC3 <- matrix(c(0, 0, 1.74, 1.74,0.208333333, 0, 0, 0.057142857,0.041666667, 0.076923077, 0, 0,0.083333333, 0.076923077, 0.066666667, 0.028571429), 4, 4, byrow = TRUE)# 2004-2005XC4 <- matrix(c(0, 0, 0.3, 0.6,0.32183908, 0.142857143, 0, 0,0.16091954, 0.285714286, 0, 0,0.252873563, 0.285714286, 0.5, 0.6), 4, 4, byrow = TRUE)# 2005-2006XC5 <- matrix(c(0, 0, 0.50625, 0.675,0, 0, 0, 0.035714286,0.1, 0.068965517, 0.0625, 0.107142857,0.3, 0.137931034, 0, 0.071428571), 4, 4, byrow = TRUE)# POPN E 2003-2004XE3 <- matrix(c(0, 0, 2.44, 6.569230769,0.196428571, 0, 0, 0,0.125, 0.5, 0, 0,0.160714286, 0.5, 0.133333333, 0.076923077), 4, 4, byrow = TRUE)XE4 <- matrix(c(0, 0, 0.45, 0.646153846,0.06557377, 0.090909091, 0.125, 0,0.032786885, 0, 0.125, 0.076923077,0.049180328, 0, 0.125, 0.230769231), 4, 4, byrow = TRUE)XE5 <- matrix(c(0, 0, 2.85, 3.99,0.083333333, 0, 0, 0,0, 0, 0, 0,0.416666667, 0.1, 0, 0.1), 4, 4, byrow = TRUE)# POPN F 2003-2004XF3 <- matrix(c(0, 0, 1.815, 7.058333333,0.075949367, 0, 0.05, 0.083333333,0.139240506, 0, 0, 0.25,0.075949367, 0, 0, 0.083333333), 4, 4, byrow = TRUE)XF4 <- matrix(c(0, 0, 1.233333333, 7.4,0.223880597, 0, 0.111111111, 0.142857143,0.134328358, 0.272727273, 0.166666667, 0.142857143,0.119402985, 0.363636364, 0.055555556, 0.142857143), 4, 4, byrow = TRUE)XF5 <- matrix(c(0, 0, 1.06, 3.372727273,0.073170732, 0.025, 0.033333333, 0,0.036585366, 0.15, 0.1, 0.136363636,0.06097561, 0.225, 0.166666667, 0.272727273), 4, 4, byrow = TRUE)# POPN G 2003-2004XG3 <- matrix(c(0, 0, 0.245454545, 2.1,0, 0, 0.045454545, 0,0.125, 0, 0.090909091, 0,0.125, 0, 0.090909091, 0.333333333), 4, 4, byrow = TRUE)XG4 <- matrix(c(0, 0, 1.1, 1.54,0.111111111, 0, 0, 0,0, 0, 0, 0,0.111111111, 0, 0, 0), 4, 4, byrow = TRUE)XG5 <- matrix(c(0, 0, 0, 1.5,0, 0, 0, 0,0.090909091, 0, 0, 0,0.545454545, 0.5, 0, 0.5), 4, 4, byrow = TRUE)# POPN L 2003-2004XL3 <- matrix(c(0, 0, 1.785365854, 1.856521739,0.128571429, 0, 0, 0.010869565,0.028571429, 0, 0, 0,0.014285714, 0, 0, 0.02173913), 4, 4, byrow = TRUE)XL4 <- matrix(c(0, 0, 14.25, 16.625,0.131443299, 0.057142857, 0, 0.25,0.144329897, 0, 0, 0,0.092783505, 0.2, 0, 0.25), 4, 4, byrow = TRUE)XL5 <- matrix(c(0, 0, 0.594642857, 1.765909091,0, 0, 0.017857143, 0,0.021052632, 0.018518519, 0.035714286, 0.045454545,0.021052632, 0.018518519, 0.035714286, 0.068181818), 4, 4, byrow = TRUE)# POPN O 2003-2004XO3 <- matrix(c(0, 0, 11.5, 2.775862069,0.6, 0.285714286, 0.333333333, 0.24137931,0.04, 0.142857143, 0, 0,0.16, 0.285714286, 0, 0.172413793), 4, 4, byrow = TRUE)XO4 <- matrix(c(0, 0, 3.78, 1.225,0.28358209, 0.171052632, 0, 0.166666667,0.084577114, 0.026315789, 0, 0.055555556,0.139303483, 0.447368421, 0, 0.305555556), 4, 4, byrow = TRUE)XO5 <- matrix(c(0, 0, 1.542857143, 1.035616438,0.126984127, 0.105263158, 0.047619048, 0.054794521,0.095238095, 0.157894737, 0.19047619, 0.082191781,0.111111111, 0.223684211, 0, 0.356164384), 4, 4, byrow = TRUE)# POPN Q 2003-2004XQ3 <- matrix(c(0, 0, 0.15, 0.175,0, 0, 0, 0,0, 0, 0, 0,1, 0, 0, 0), 4, 4, byrow = TRUE)XQ4 <- matrix(c(0, 0, 0, 0.25,0, 0, 0, 0,0, 0, 0, 0,1, 0.666666667, 0, 1), 4, 4, byrow = TRUE)XQ5 <- matrix(c(0, 0, 0, 1.428571429,0, 0, 0, 0.142857143,0.25, 0, 0, 0,0.25, 0, 0, 0.571428571), 4, 4, byrow = TRUE)# POPN R 2003-2004XR3 <- matrix(c(0, 0, 0.7, 0.6125,0.25, 0, 0, 0.125,0, 0, 0, 0,0.25, 0.166666667, 0, 0.25), 4, 4, byrow = TRUE)XR4 <- matrix(c(0, 0, 0, 0.6,0.285714286, 0, 0, 0,0.285714286, 0.333333333, 0, 0,0.285714286, 0.333333333, 0, 1), 4, 4, byrow = TRUE)XR5 <- matrix(c(0, 0, 0.7, 0.6125,0, 0, 0, 0,0, 0, 0, 0,0.333333333, 0, 0.333333333, 0.625), 4, 4, byrow = TRUE)# POPN S 2003-2004XS3 <- matrix(c(0, 0, 2.1, 0.816666667,0.166666667, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0.166666667), 4, 4, byrow = TRUE)XS4 <- matrix(c(0, 0, 0, 7,0.333333333, 0.5, 0, 0,0, 0, 0, 0,0.333333333, 0, 0, 1), 4, 4, byrow = TRUE)XS5 <- matrix(c(0, 0, 0, 1.4,0, 0, 0, 0,0, 0, 0, 0.2,0.111111111, 0.75, 0, 0.2), 4, 4, byrow = TRUE)mats_list <- list(XC3, XC4, XC5, XE3, XE4, XE5, XF3, XF4, XF5, XG3, XG4, XG5, XL3, XL4, XL5, XO3, XO4, XO5, XQ3, XQ4, XQ5, XR3, XR4, XR5, XS3, XS4, XS5)yr_ord <- c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)pch_ord <- c(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9)anth_lefkoMat <- create_lM(mats_list, anthframe, hstages = NA, historical = FALSE, poporder = 1, patchorder = pch_ord, yearorder = yr_ord) smaller_anth_lM <- subset_lM(anth_lefkoMat, patch = c(1, 2, 3), year = c(1, 2))Summary of Class "lefkoCondMat"
Description
This function provides basic information summarizing the characteristics ofconditional matrices derived from alefkoCondMat object.
Usage
## S3 method for class 'lefkoCondMat'summary(object, ...)Arguments
object | An object of class |
... | Other parameters. |
Value
A text summary of the object shown on the console, showing the numberof historical matrices, as well as the number of conditional matrices nestedwithin each historical matrix.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")lathcondmats <- cond_hmpm(ehrlen3)summary(lathcondmats)# Cypripedium exampledata(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)cypsupp3r <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "D", "XSm", "Sm", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "D", "XSm", "Sm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", NA, NA), givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypcondmats <- cond_hmpm(cypmatrix3r)summary(cypcondmats)Summarize lefkoElas Objects
Description
Functionsummary.lefkoElas() summarizeslefkoElas objects.Particularly, it breaks down elasticity values by the kind of ahistoricaland, if applicable, historical transition.
Usage
## S3 method for class 'lefkoElas'summary(object, ...)Arguments
object | A |
... | Other parameters currently not utilized. |
Value
A list composed of 2 data frames. The first,hist, is a dataframe showing the summed elasticities for all 16 kinds of historicaltransition per matrix, with each column corresponding to each elasticitymatrix in order. The second,ahist, is a data frame showing thesummed elasticities for all 4 kinds of ahistorical transition per matrix,with each column corresponding to each elasticity matrix in order.
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)lathsupp2 <- supplemental(stage3 = c("Sd", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "rep", "rep"), givenrate = c(0.345, 0.054, NA, NA), multiplier = c(NA, NA, 0.345, 0.054), type = c(1, 1, 3, 3), stageframe = lathframe, historical = FALSE) ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen2 <- rlefko2(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2"), supplement = lathsupp2, yearcol = "year2", indivcol = "individ")ehrlen3elas <- elasticity3(ehrlen3)ehrlen2elas <- elasticity3(ehrlen2)summary(ehrlen3elas)summary(ehrlen2elas)Summarize lefkoLTRE Objects
Description
Functionsummary.lefkoLTRE() summarizeslefkoLTRE objects.Particularly, it breaks down LTRE contributions by the kind of ahistoricaland, if applicable, historical transition.
Usage
## S3 method for class 'lefkoLTRE'summary(object, ...)Arguments
object | A |
... | Other parameters currently not utilized. |
Value
A list of data frames. In all cases, the first data frame is oneshowing the positive, negative, and total contributions of elements ineach LTRE contribution matrix. If not a SNA-LTRE, then there are anadditional two (if deterministic) or four (if stochastic) data frames. Ifdeterministic, thenhist_det is a data frame showing the summed LTREcontributions for all 16 kinds of historical transition per matrix, with eachcolumn corresponding to each A matrix in order, followed by all summedpositive and all summed negative contributions. Objectahist_det is adata frame showing the summed LTRE contributions for all four kinds ofahistorical transition per matrix, with order as before, followed by summedpositive and summed negative contributions. If stochastic, thenhist_mean andhist_sd are the summed LTRE contributions for themean vital rates and variability in vital rates, respectively, according toall 16 historical transition types, followed by summed positive and negativecontributions, andahist_mean andahist_sd are the equivalentahistorical versions. The output for the SNA-LTRE also includes thelogs of the deterministic lambda estimated through functionltre3().
Examples
data(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)lathsupp2 <- supplemental(stage3 = c("Sd", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "rep", "rep"), givenrate = c(0.345, 0.054, NA, NA), multiplier = c(NA, NA, 0.345, 0.054), type = c(1, 1, 3, 3), stageframe = lathframe, historical = FALSE) ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")ehrlen2 <- rlefko2(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2"), supplement = lathsupp2, yearcol = "year2", indivcol = "individ")ehrlen3ltre <- ltre3(ehrlen3)summary(ehrlen3ltre)Summary of Class "lefkoMat"
Description
A function to simplify the viewing of basic information describing thematrices produced through functionsflefko3(),flefko2(),rlefko3(),rlefko2(),aflefko2(),rleslie(), andfleslie().
Usage
## S3 method for class 'lefkoMat'summary(object, colsums = TRUE, check_cycle = TRUE, ...)Arguments
object | An object of class |
colsums | A logical value indicating whether column sums should be shownfor U matrices, allowing users to check stage survival probabilities.Defaults to |
check_cycle | A logical value indicating whether to test matrices forstage discontinuities in the life cycle. Defaults to |
... | Other parameters. |
Value
A summary of the object, showing the number of each type of matrix,the number of annual matrices, the number of estimated (non-zero) elementsacross all matrices and per matrix, the number of unique transitions in thedataset, the number of individuals, and summaries of the column sums of thesurvival-transition matrices. Stage discontinuities are also checked withfunctioncycle_check. This function will also yield warnings if anysurvival-transition matrices include elements outside of the interval [0,1],if any fecundity matrices contain negative elements, and if any matricesinclude NA values.
Notes
Under the Gaussian and gamma size distributions, the number of estimatedparameters may differ between the twoipm_method settings. Becausethe midpoint method has a tendency to incorporate upward bias in theestimation of size transition probabilities, it is more likely to yield non-zero values when the true probability is extremely close to 0. This willresult in thesummary.lefkoMat function yielding higher numbers ofestimated parameters than theipm_method = "CDF" yields in some cases.
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)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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")summary(cypmatrix2r)Summary of Class "lefkoMatList"
Description
A function to simplify the viewing of basic information describing thebootstrapped matrices produced through functionsflefko3(),flefko2(),rlefko3(),rlefko2(),aflefko2(),rleslie(), andfleslie() when using bootstrapped data input in formathfvlist.
Usage
## S3 method for class 'lefkoMatList'summary( object, elem_summaries = FALSE, colsums = TRUE, check_cycle = TRUE, ...)Arguments
object | An object of class |
elem_summaries | A logical value indicating whether to includesummaries of all |
colsums | If |
check_cycle | If |
... | Other parameters. |
Value
A general summary of thelefkoMatList object, showing thenumber and type oflefkoMat objects included, the mean number ofannual matrices perlefkoMat element, the mean size of each matrix,the mean number of estimated (non-zero) elements across all matrices and permatrix, the mean number of unique transitions in the bootstrapped datasets,the mean number of individuals, and summaries of the column sums of the survival-transitionmatrices across alllefkoMat objects.
ifelem_summaries = TRUE, thensummary.lefkoMat{} outputis also shown for eachlefkoMat object per enteredlefkoMatListobject.
Stage discontinuities may also be also checked across alllefkoMatobjects with functioncycle_check. This function will also yieldwarnings if any survival-transition matrices include elements outside of theinterval [0,1], if any fecundity matrices contain negative elements, and ifany matrices include NA values.
Notes
Under the Gaussian and gamma size distributions, the number of estimatedparameters may differ between the twoipm_method settings. Becausethe midpoint method has a tendency to incorporate upward bias in theestimation of size transition probabilities, it is more likely to yield non-zero values when the true probability is extremely close to 0. This willresult in thesummary.lefkoMat function yielding higher numbers ofestimated parameters than theipm_method = "CDF" yields in some cases.
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)cypraw_v1_boot <- bootstrap3(cypraw_v1, reps = 3)# Here we use supplemental() to provide overwrite and reproductive infocypsupp2r <- 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_boot <- rlefko2(data = cypraw_v1_boot, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added"), supplement = cypsupp2r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")summary(cypmatrix2r_boot)Summary of Class "lefkoMod"
Description
A function to summarize objects of classlefkoMod. This function showsthe best-fit models, summarizes the numbers of models in the model tables,shows the criterion used to determine the best-fit models, and provides somebasic quality control information.
Usage
## S3 method for class 'lefkoMod'summary(object, ...)Arguments
object | An R object of class |
... | Other parameters currently not utilized. |
Value
A summary of the object, showing the best-fit models for all vitalrates, with constants of 0 or 1 used for unestimated models. This is followedby a summary of the number of models tested per vital rate, and a tableshowing the names of the parameters used to model vital rates and representtested factors. At the end is a section describing the numbers of individualsand of individual transitions used to estimate each vital rate best-fitmodel, along with the accuracy of each binomial model.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 4.6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9)stagevector <- c("Sd", "Sdl", "Dorm", "Sz1nr", "Sz2nr", "Sz3nr", "Sz4nr", "Sz5nr", "Sz6nr", "Sz7nr", "Sz8nr", "Sz9nr", "Sz1r", "Sz2r", "Sz3r", "Sz4r", "Sz5r", "Sz6r", "Sz7r", "Sz8r", "Sz9r")repvector <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)obsvector <- c(0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)matvector <- c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)binvec <- c(0, 4.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)lathframeln <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvertln <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "lnVol88", repstracol = "Intactseed88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframeln, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, NAas0 = TRUE, censor = TRUE)lathvertln$feca2 <- round(lathvertln$feca2)lathvertln$feca1 <- round(lathvertln$feca1)lathvertln$feca3 <- round(lathvertln$feca3)lathmodelsln2 <- modelsearch(lathvertln, historical = FALSE, approach = "mixed", suite = "main", vitalrates = c("surv", "obs", "size", "repst", "fec"), juvestimate = "Sdl", bestfit = "AICc&k", sizedist = "gaussian", fecdist = "poisson", indiv = "individ", patch = "patchid", year = "year2", year.as.random = TRUE, patch.as.random = TRUE, show.model.tables = TRUE, quiet = "partial")summary(lathmodelsln2)Summarize lefkoProj Objects
Description
Functionsummary.lefkoProj() summarizeslefkoProj objects.Particularly, it breaks down the data frames provided in theprojection element in ways meaningful for those running simulations.
Usage
## S3 method for class 'lefkoProj'summary( object, threshold = 1, inf_alive = TRUE, milepost = c(0, 0.25, 0.5, 0.75, 1), ext_time = FALSE, ...)Arguments
object | A |
threshold | A threshold population size to be searched for inprojections. Defaults to 1. |
inf_alive | A logical value indicating whether to treat infinitelylarge population size as indicating that the population is still extant.If |
milepost | A numeric vector indicating at which points in the projectionto assess detailed results. Can be input as integer values, in which caseeach number must be between 1 and the total number of occasions projected ineach projection, or decimals between 0 and 1, which would then be translatedinto the corresponding projection steps of the total. Defaults to |
ext_time | A logical value indicating whether to output extinction timesper population-patch. Defaults to |
... | Other parameters currently not utilized. |
Value
Apart from a statement of the results, this function outputs a listwith the following elements:
milepost_sums | A data frame showing the number of replicates at eachof the milepost times that is above the threshold population/patch size. |
extinction_times | A dataframe showing the numbers of replicates goingextinct ( |
Notes
Theinf_alive andext_time options both assess whetherreplicates have reached a value ofNaN orInf. Ifinf_alive = TRUE orext_time = TRUE and one of these values isfound, then the replicate is counted in themilepost_sums object ifthe last numeric value in the replicate is above thethreshold value,and is counted as extant and not extinct if the last numeric value in thereplicate is above the extinction threshold of a single individual.
Extinction time is calculated on the basis of whether the replicate everfalls below a single individual. A replicate with a positive population sizebelow 0.0 that manages to rise above 1.0 individual is still considered tohave gone extinct the first time it crossed below 1.0.
If the inputlefkoProj object is a mixture of two or more otherlefkoProj objects, then mileposts will be given relative to themaximum number of time steps noted.
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathrepm <- matrix(0, 7, 7)lathrepm[1, 6] <- 0.345lathrepm[2, 6] <- 0.054lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep"), stage1 = c("Sd", "rep", "Sd", "rep", "all", "all"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054), type = c(1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = c(1989, 1990), stages = c("stage3", "stage2", "stage1"), repmatrix = lathrepm, supplement = lathsupp3, yearcol = "year2", indivcol = "individ")lathproj <- projection3(ehrlen3, nreps = 5, stochastic = TRUE)summary(lathproj)# Cypripedium exampledata(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)cypsupp3r <- supplemental(stage3 = c("SD", "SD", "P1", "P1", "P2", "P3", "SL", "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", "SD", "P1"), stage2 = c("SD", "SD", "SD", "SD", "P1", "P2", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "D", "XSm", "Sm", "rep", "rep"), stage1 = c("SD", "rep", "SD", "rep", "SD", "P1", "P2", "P3", "P3", "P3", "SL", "SL", "SL", "SL", "SL", "SL", "mat", "mat"), eststage3 = c(NA, NA, NA, NA, NA, NA, NA, "D", "XSm", "Sm", "D", "XSm", "Sm", "mat", "mat", "mat", NA, NA), eststage2 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "D", "XSm", "Sm", NA, NA), eststage1 = c(NA, NA, NA, NA, NA, NA, NA, "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", "XSm", NA, NA), givenrate = c(0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), multiplier = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5), type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3), type_t12 = c(1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), stageframe = cypframe_raw, historical = TRUE)cypmatrix3r <- rlefko3(data = cypraw_v1, stageframe = cypframe_raw, year = "all", patch = "all", stages = c("stage3", "stage2", "stage1"), size = c("size3added", "size2added", "size1added"), supplement = cypsupp3r, yearcol = "year2", patchcol = "patchid", indivcol = "individ")cypstoch <- projection3(cypmatrix3r, nreps = 5, stochastic = TRUE)summary(cypstoch, ext_time = TRUE)Summary of Classes "hfvdata" and "hfvlist
Description
A function to simplify the viewing of basic information describingdemographic data in historical vertical format (data frames of classhfvdata, or bootstrapped data frames in lists of classhfvlist).
Usage
summary_hfv( object, popid = "popid", patchid = "patchid", individ = "individ", year2id = "year2", full = FALSE, err_check = TRUE, ...)Arguments
object | An object of either class |
popid | A string denoting the name of the variable denoting populationidentity. |
patchid | A string denoting the name of the variable denoting patchidentity. |
individ | A string denoting the name of the variable denoting individualidentity. |
year2id | A string denoting the name of the variable denoting the yearin timet. |
full | A logical value indicating whether to include basic data framesummary information in addition to hfvdata-specific summary information.Defaults to |
err_check | A logical value indicating whether to check for errors instage assignment. |
... | Other parameters. |
Value
A summary of the object. If an object of classhfvdata isentered, then the first line of output shows the numbers of populations,patches, individuals, and time steps. Iffull = TRUE, then this isfollowed by a standard data frame summary of the hfv dataset. Iferr_check = TRUE, then a subset of the original data frame input asobject is exported with only rows showing stage assignment issues.
If an object of classhfvlist in entered, then the first line ofoutput shows the number of bootstrapped datasets. This is followed by linesshowing the mean number of rows and variables per data frame, as well as themean numbers of populations, patches, individuals, and years per data frame.This is followed by lines showing the total number of unique populations,patches, individuals, and years sampled across the bootstrapped data frames.Iffull = TRUE, then this is followed by standard data frame summariesof all bootstrapped data frames. Iferr_check = TRUE, then a dataframe is output with all of the problem rows across all bootstrapped dataframes, starting with a new variable giving the bootstrap number of origin.
Notes
Stage assignment issue identified by optionerr_check fall under twocategories. First, all rows showingNoMatch as the identified stageforstage1,stage2, orstage3 are identified. Second,all rows showingstage1 = "NotAlive" andalive1 = 1,stage2 = "NotAlive" andalive2 = 1, orstage3 = "NotAlive" andalive3 = 1 are identified.
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)summary_hfv(cypraw_v1)cypraw_v1_boot <- bootstrap3(cypraw_v1, reps = 3)summary_hfv(cypraw_v1_boot)Create a Data Frame of Supplemental Data for MPM Development
Description
Functionsupplemental() provides all necessary supplemental data formatrix estimation. It allows the establishment of proxy rates, the entry ofdata to overwrite or offset existing rates, the identification of completereproductive transitions, and the entry of rate multipliers. The functionshould be used to incorporate data that affects all matrices to be created.To edit MPMs after creation, useedit_lM() instead.
Usage
supplemental( historical = TRUE, stagebased = TRUE, agebased = FALSE, stageframe = NULL, stage3 = NULL, stage2 = NULL, stage1 = NULL, age2 = NULL, eststage3 = NULL, eststage2 = NULL, eststage1 = NULL, estage2 = NULL, givenrate = NULL, offset = NULL, multiplier = NULL, type = NULL, type_t12 = NULL)Arguments
historical | A single logical value indicating whether the MPMsintended will be historical or ahistorical. Defaults to |
stagebased | A single logical value indicating whether the MPM will bestage-based or age-by-stage. Defaults to |
agebased | A single logical value indicating whether the MPM will beage-based or age-by-stage. Defaults to |
stageframe | The stageframe used to produce the MPM. Required ifproducing any stage-based or age-by-stage MPM. Must be omitted for purelyage-based MPMs. |
stage3 | String vector of stage names in occasiont+1 in thetransition to be affected. Abbreviations for groups of stages are alsousable (see |
stage2 | String vector of stage names in occasiont in thetransition to be affected. Abbreviations for groups of stages are alsousable (see |
stage1 | String vector of stage names in occasiont-1 in thetransition to be affected. Only needed if a historical matrix is to beproduced. Abbreviations for groups of stages are also usable (see |
age2 | An integer vector of the ages in occasiont to use intransitions to be affected. Required for all age- and age-by-stage MPMs. |
eststage3 | String vector of stage names to replace |
eststage2 | String vector of stage names to replace |
eststage1 | String vector of stage names to replace |
estage2 | Integer vector of age at timet to replace |
givenrate | A numeric vector of fixed rates or probabilities to replacefor the transition described by |
offset | A numeric vector of fixed numeric values to add to thetransitions described by |
multiplier | A numeric vector of multipliers for the transitiondescribed by |
type | Integer vector denoting the kind of transition between occasionst andt+1 to be replaced. This should be entered as |
type_t12 | An optional integer vector denoting the kind of transitionbetween occasionst-1 andt. Only necessary if a historicalMPM in deVries format is desired. This should be entered as |
Value
A data frame of classlefkoSD. This object can be used asinput inflefko3(),flefko2(),rlefko3(),rlefko2(), andaflefko2().
Variables in this object include the following:
stage3 | Stage at occasiont+1 in the transition to bereplaced. |
stage2 | Stage at occasiont in the transition to be replaced. |
stage1 | Stage at occasiont-1 in the transition to bereplaced. |
age2 | Age at occasiont in the transition to be replaced. |
eststage3 | Stage at occasiont+1 in the transition to replacethe transition designated by |
eststage2 | Stage at occasiont in the transition to replace thetransition designated by |
eststage1 | Stage at occasiont-1 in the transition to replacethe transition designated by |
estage2 | Age at occasiont in the transition to replace thetransition designated by |
givenrate | A constant to be used as the value of the transition. |
offset | A constant value to be added to the transition or proxytransition. |
multiplier | A multiplier for proxy transitions or for fecundity. |
convtype | Designates whether the transition from occasiont tooccasiont+1 is a survival transition probability (1), a fecundityrate (2), or a fecundity multiplier (3). |
convtype_t12 | Designates whether the transition from occasiont-1 to occasiont is a survival transition probability (1), afecundity rate (2). |
Notes
Negative values are not allowed ingivenrate andmultiplierinput, but are allowed inoffset, if values are to be subtracted fromspecific estimated transitions. Stage entries should not be used for purelyage-based MPMs, and age entries should not be used for purely stage-basedMPMs.
Fecundity multiplier data supplied via thesupplemental() functionacts in the same way as non-zero entries supplied via a reproductive matrix,but gets priority in all matrix creations. Thus, in cases where fecunditymultipliers are provided for the same function via the reproductive matrixand functionsupplemental(), the latter is used.
Entries instage3,stage2, andstage1 can includeabbreviations for groups of stages. Userep if all reproductivestages are to be used,nrep if all mature but non-reproductive stagesare to be used,mat if all mature stages are to be used,immatif all immature stages are to be used,prop if all propagule stagesare to be used,npr if all non-propagule stages are to be used,obs if all observable stages are to be used,nobs if allunobservable stages are to be used, and leave empty or useall if allstages in stageframe are to be used. Also usegroupX to denote allstages in group X (e.g.group1 will use all stages in the respectivestageframe's group 1).
Type 3 conversions are referred to as fecundity set values, or generalfecundity multipliers. These set the transitions to be used as fecunditytransitions. Transitions set here will be interpreted as being generallyreproductive, meaning that the from and to stages will be used to determinethe general fecundity transitions to incorporate into stage-based MPMs,while the age portion of the input will be used to incorporate the actualmultiplier(s) specified. If only stage transitions at certain ages areexpected to be the sole contributors to fecundity, then type 2 conversionsshould also be included in the supplement (Type 1 and 2 conversions can bepurely age-specific, and do not set reproductive transitions in MPMcreation). For example, if all stage 2 to stage 3 transitions above age 2yield fecundity, then stage 2 to stage 3 can be set tomultiplier = 1.0 withconvtype = 3, and the same transitionforage2 = c(1, 2) can be set tomultiplier = c(0, 0).
Several operations may be included per transition. Operations on the samerow of the resulting data frame are generally handled with given ratesubstitutions first, then with proxy transitions, then by additive offsets,and finally by multipliers. This order can be manipulated by orderingoperations across rows, with higher numbered rows in the data frame beingperformed later.
See Also
edit_lM()
Examples
# Lathyrus exampledata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)lathsupp3 <- supplemental(stage3 = c("Sd", "Sd", "Sdl", "Sdl", "Sd", "Sdl", "mat"), stage2 = c("Sd", "Sd", "Sd", "Sd", "rep", "rep", "Sdl"), stage1 = c("Sd", "rep", "Sd", "rep", "npr", "npr", "Sd"), eststage3 = c(NA, NA, NA, NA, NA, NA, "mat"), eststage2 = c(NA, NA, NA, NA, NA, NA, "Sdl"), eststage1 = c(NA, NA, NA, NA, NA, NA, "NotAlive"), givenrate = c(0.345, 0.345, 0.054, 0.054, NA, NA, NA), multiplier = c(NA, NA, NA, NA, 0.345, 0.054, NA), type = c(1, 1, 1, 1, 3, 3, 1), type_t12 = c(1, 2, 1, 2, 1, 1, 1), stageframe = lathframe, historical = TRUE)ehrlen3 <- rlefko3(data = lathvert, stageframe = lathframe, year = "all", stages = c("stage3", "stage2", "stage1"), supplement = lathsupp3, yearcol = "year2", indivcol = "individ")# Cypripedium exampledata(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")Two-Parameter Usher Function
Description
Functionusher3() creates a vector of values produced by the two-parameter Usher function as applied with a user-specified time lag.The Usher function is given as\phi_{t+1} = \phi_t / (1 + e^{\alpha n_t + \beta}). Here,if noseparate_N vector is provided, thenn_t = \phi_t.
Usage
usher3( start_value, alpha, beta, time_steps = 100L, time_lag = 1L, pre0_subs = FALSE, pre0_value = 0, substoch = 0L, separate_N = NULL)Arguments
start_value | A positive number to start the return vector in time 0. |
alpha | The alpha parameter in the two-parameter Usherfunction. |
beta | The beta parameter in the two-parameter Usher function. |
time_steps | The number of time steps to run the projection. Must be apositive integer. |
time_lag | A positive integer denoting the number of time steps backfor the value of phi in the two-parameter Usher function. |
pre0_subs | A logical value indicating whether to use a number otherthan that given in |
pre0_value | A positive number to use for phi lagged from times priorto time 0. Only used if |
substoch | An integer value indicating the kind of substochasticity touse. Values include: |
separate_N | An optional numeric vector with values of N in each time,if phi is to be treated as different from N in the two-parameter model. |
Value
A numeric vector of values showing values projected under the two-parameter Usher function.
Examples
trial_run1 <- usher3(1, alpha = -0.5, beta = 0.005)plot(trial_run1)trial_run2 <- usher3(1, alpha = 0.5, beta = 0.005)plot(trial_run2)trial_run3 <- usher3(1, alpha = -5, beta = 0.005)plot(trial_run3)trial_run4 <- usher3(1, alpha = 5, beta = 0.005)plot(trial_run4)trial_run5 <- usher3(1, alpha = -25, beta = 0.005)plot(trial_run5)trial_run6 <- usher3(1, alpha = 25, beta = 0.005)plot(trial_run6)used_Ns <- c(10, 15, 12, 14, 14, 150, 15, 1, 5, 7, 9, 14, 13, 16, 17, 19, 25, 26)trial_run7 <- usher3(1, alpha = -0.5, beta = 0.005, separate_N = used_Ns)plot(trial_run7)Create Historical Vertical Data Frame from Horizontal Data Frame
Description
Functionverticalize3() returns a vertically formatted demographicdata frame organized to create historical projection matrices, given ahorizontally formatted input data frame. It also handles stage assignmentsif given an appropriate stageframe.
Usage
verticalize3( data, noyears, firstyear = 1, popidcol = 0, patchidcol = 0, individcol = 0, blocksize = NA, xcol = 0, ycol = 0, juvcol = 0, sizeacol, sizebcol = 0, sizeccol = 0, repstracol = 0, repstrbcol = 0, fecacol = 0, fecbcol = 0, indcovacol = 0, indcovbcol = 0, indcovccol = 0, aliveacol = 0, deadacol = 0, obsacol = 0, nonobsacol = 0, censorcol = 0, repstrrel = 1, fecrel = 1, stagecol = 0, stageassign = NA, stagesize = NA, censorkeep = 0, censorRepeat = FALSE, censor = FALSE, coordsRepeat = FALSE, spacing = NA, NAas0 = FALSE, NRasRep = FALSE, NOasObs = FALSE, prebreeding = TRUE, age_offset = 0, reduce = TRUE, a2check = FALSE, quiet = FALSE)Arguments
data | The horizontal data file. A valid data frame is required asinput. |
noyears | The number of years or observation occasions in the dataset. Avalid integer is required as input. |
firstyear | The first year or occasion of observation. Defaults to |
popidcol | A variable name or column number corresponding to the identity of the population for each individual. |
patchidcol | A variable name or column number corresponding to the identity of the patch or subpopulation for each individual, if patches havebeen designated within populations. |
individcol | A variable name or column number corresponding to the identity of each individual. |
blocksize | The number of variables corresponding to each occasion inthe input dataset designated in |
xcol | A variable name(s) or column number(s) corresponding to the X coordinate of each individual, or of each individual at each occasion, inCartesian space. Can refer to the only instance, the first instance, or allinstances of X variables. In the last case, the values should be entered as avector. |
ycol | A variable name(s) or column number(s) corresponding to the Ycoordinate of each individual, or of each individual at each occasion, inCartesian space. Can refer to the only instance, the first instance, or allinstances of Y variables. In the last case, the values should be entered as avector. |
juvcol | A variable name(s) or column number(s) that marks individualsin immature stages within the dataset. This function assumes that immatureindividuals are identified in this variable marked with a number equal to orgreater than |
sizeacol | A variable name(s) or column number(s) corresponding to thesize entry associated with the first year or observation occasion in thedataset. Can refer to the first instance, or all instances of thesevariables. In the latter case, the values should be entered as a vector.This variable should refer to the first size variable in the stageframe,unless |
sizebcol | A second variable name(s) or column number(s) correspondingto the size entry associated with the first year or observation occasion inthe dataset. Can refer to the first instance, or all instances of thesevariables. In the latter case, the values should be entered as a vector.This variable should refer to the second size variable in the stageframe,unless |
sizeccol | A third variable name(s) or column number(s) corresponding tothe size entry associated with the first year or observation occasion in thedataset. Can refer to the first instance, or all instances of these variables.In the latter case, the values should be entered as a vector. This variableshould refer to the third size variable in the stageframe, unless |
repstracol | A variable name(s) or column number(s) corresponding to theproduction of reproductive structures, such as flowers, associated with the first year or observation period in the input dataset. This can be binomial or count data, and is used to analyze the probability of reproduction. Canrefer to the first instance, or all instances of these variables. In thelatter case, the values should be entered as a vector. |
repstrbcol | A second variable name(s) or column number(s) correspondingto the production of reproductive structures, such as flowers, associatedwith the first year or observation period in the input dataset. This can be binomial or count data, and is used to analyze the probability ofreproduction. Can refer to the first instance, or all instances of thesevariables. In the latter case, the values should be entered as a vector. |
fecacol | A variable name(s) or column number(s) denoting fecundityassociated with the first year or observation occasion in the input dataset.This may represent egg counts, fruit counts, seed production, etc. Can referto the first instance, or all instances of these variables. In the lattercase, the values should be entered as a vector. |
fecbcol | A second variable name(s) or column number(s) denotingfecundity associated with the first year or observation occasion in the inputdataset. This may represent egg counts, fruit counts, seed production, etc.Can refer to the first instance, or all instances of these variables. In thelatter case, the values should be entered as a vector. |
indcovacol | A variable name(s) or column number(s) corresponding to anindividual covariate to be used in analysis. Can refer to the only instance,the first instance, or all instances of these variables. In the last case,the values should be entered as a vector. |
indcovbcol | A variable name(s) or column number(s) corresponding to anindividual covariate to be used in analysis. Can refer to the only instance,the first instance, or all instances of these variables. In the last case,the values should be entered as a vector. |
indcovccol | A second variable name(s) or column number(s) correspondingto an individual covariate to be used in analysis. Can refer to the onlyinstance, the first instance, or all instances of these variables. In thelast case, the values should be entered as a vector. |
aliveacol | Variable name(s) or column number(s) providing informationon whether an individual is alive at a given occasion. If used, living statusmust be designated as binomial (living = |
deadacol | Variable name(s) or column number(s) providing information onwhether an individual is alive at a given occasion. If used, dead status mustbe designated as binomial (dead = |
obsacol | A variable name(s) or column number(s) providing informationon whether an individual is in an observable stage at a given occasion. Ifused, observation status must be designated as binomial (observed = |
nonobsacol | A variable name(s) or column number(s) providinginformation on whether an individual is in an unobservable stage at a givenoccasion. If used, observation status must be designated as binomial (notobserved = |
censorcol | A variable name(s) or column number(s) corresponding to thefirst entry of a censor variable, used to distinguish between entries to useand entries not to use, or to designate entries with special issues thatrequire further attention. Can refer to the first instance of a censor statusvariable in the dataset, or a full vector of all censor status variables intemporal order. Can also refer to a single censor status variable used forthe entire individual, if |
repstrrel | This is a scalar multiplier on variable |
fecrel | This is a scalar multiplier on variable |
stagecol | Optional variable name(s) or column number(s) correspondingto life history stage at a given occasion. Can refer to the first instance ofa stage identity variable in the dataset, or a full vector of all stageidentity variables in temporal order. |
stageassign | The stageframe object identifying the life history modelbeing operationalized. Note that if |
stagesize | A variable name or column number describing which size variable to use in stage estimation. Defaults to NA, and can also take |
censorkeep | The value of the censor variable identifying data to beincluded in analysis. Defaults to |
censorRepeat | A logical value indicating whether the censor variableis a single column, or whether it repeats across occasion blocks. Defaults to |
censor | A logical variable determining whether the output data should be censored using the variable defined in |
coordsRepeat | A logical value indicating whether X and Y coordinatescorrespond to single X and Y columns. If |
spacing | The spacing at which density should be estimated, if densityestimation is desired and X and Y coordinates are supplied. Given in the sameunits as those used in the X and Y coordinates given in |
NAas0 | If |
NRasRep | If |
NOasObs | If |
prebreeding | A logical term indicating whether the life history modelis pre-breeding. If so, then |
age_offset | A number to add automatically to all values of age at timet. Defaults to |
reduce | A logical variable determining whether unused variables and some invariant state variables should be removed from the output dataset.Defaults to |
a2check | A logical variable indicating whether to retain all data withliving status at occasiont. Defaults to |
quiet | A logical variable indicating whether to silence warnings.Defaults to |
Value
If all inputs are properly formatted, then this function will outputa historical vertical data frame (classhfvdata), meaning that theoutput data frame will have three consecutive occasions of size andreproductive data per individual per row. This data frame is in standardformat for all functions used inlefko3, and so can be used withoutfurther modification.
Variables in this data frame include the following:
rowid | Unique identifier for the row of the data frame. |
popid | Unique identifier for the population, if given. |
patchid | Unique identifier for patch within population, if given. |
individ | Unique identifier for the individual. |
year2 | Year or time at occasiont. |
firstseen | Occasion of first observation. |
lastseen | Occasion of last observation. |
obsage | Observed age in occasiont, assuming first observationcorresponds to age = 0. |
obslifespan | Observed lifespan, given as |
xpos1,xpos2,xpos3 | X position in Cartesian space in occasionst-1,t, andt+1, respectively, if provided. |
ypos1,ypos2,ypos3 | Y position in Cartesian space in occasionst-1,t, andt+1, respectively, if provided. |
sizea1,sizea2,sizea3 | Main size measurement in occasionst-1,t, andt+1, respectively. |
sizeb1,sizeb2,sizeb3 | Secondary size measurement in occasionst-1,t, andt+1, respectively. |
sizec1,sizec2,sizec3 | Tertiary measurement in occasionst-1,t, andt+1, respectively. |
size1added,size2added,size3added | Sum of primary, secondary, and tertiary size measurements in occasionst-1,t, andt+1, respectively. |
repstra1,repstra2,repstra3 | Main numbers of reproductive structures inoccasionst-1,t, andt+1, respectively. |
repstrb1,repstrb2,repstrb3 | Secondary numbers of reproductive structures in occasionst-1,t, andt+1, respectively. |
repstr1added,repstr2added,repstr3added | Sum of primary and secondaryreproductive structures in occasionst-1,t, andt+1, respectively. |
feca1,feca2,feca3 | Main numbers of offspring in occasionst-1,t, andt+1, respectively. |
fecb1,fecb2,fecb3 | Secondary numbers of offspring in occasionst-1,t, andt+1, respectively. |
fec1added,fec2added,fec3added | Sum of primary and secondary fecundityin occasionst-1,t, andt+1, respectively. |
censor1,censor2,censor3 | Censor state values in occasionst-1,t, andt+1, respectively. |
juvgiven1,juvgiven2,juvgiven3 | Binomial variable indicating whetherindividual is juvenile in occasionst-1,t, andt+1.Only given if |
obsstatus1,obsstatus2,obsstatus3 | Binomial observation state inoccasionst-1,t, andt+1, respectively. |
repstatus1,repstatus2,repstatus3 | Binomial reproductive state inoccasionst-1,t, andt+1, respectively. |
fecstatus1,fecstatus2,fecstatus3 | Binomial offspring production statein occasionst-1,t, andt+1, respectively. |
matstatus1,matstatus2,matstatus3 | Binomial maturity state in occasionst-1,t, andt+1, respectively. |
alive1,alive2,alive3 | Binomial state as alive in occasionst-1,t, andt+1, respectively. |
density | Radial density of individuals per unit designated in |
Notes
In some datasets on species with unobservable stages, observation status(obsstatus) might not be inferred properly if a single size variableis used that does not yield sizes greater than 0 in all cases in whichindividuals were observed. Such situations may arise, for example, in plantswhen leaf number is the dominant size variable used, but individualsoccasionally occur with inflorescences but no leaves. In this instances,it helps to mark related variables assizeb andsizec, becauseobservation status will be interpreted in relation to all 3 size variables.Further analysis can then utilize only a single size variable, of the user'schoosing. Similar issues can arise in reproductive status (repstatus).
Juvenile designation should only be used when juveniles fall outside of thesize classification scheme used in determining stages. If juveniles are to besize classified along the size spectrum that adults also fall on, thenit is best to treat juveniles as mature but not reproductive.
Warnings that some individuals occur in state combinations that do not matchany stages in the stageframe used to assign stages are common when firstworking with a dataset. Typically, these situations can be identified asNoMatch entries instage3, although such entries may crop up instage1 andstage2, as well. In rare cases, these warnings willarise with no concurrentNoMatch entries, which indicates that theinput dataset contained conflicting state data at once suggesting that theindividual is in some stage but is also dead. The latter is removed if theconflict occurs in occasiont ort-1, as only living entriesare allowed in timet and timet-1 may involve living entriesas well as non-living entries immediately prior to birth.
Care should be taken to avoid variables with negative values indicating size,fecundity, or reproductive or observation status. Negative values can beinterpreted in different ways, typically reflecting estimation through otheralgorithms rather than actual measured data. Variables holding negativevalues can conflict with data management algorithms in ways that aredifficult to predict.
Unusual errors (e.g."Error in .pfj...") may occur in cases where thevariables are improperly passed, where seemingly numeric variables includetext, or where theblocksize is improperly set.
Density estimation is performed as a count of individuals alive and withinthe radius specified inspacing of the respective individual at somepoint in time.
If a censor variable is included for each monitoring occasion, and theblocksize option is set, then the user must setcensorRepeat = TRUE in order to censor the correct transitions.Failing this step will likely lead to the loss of a large portion of the dataas all data for entire individuals will be excluded.
Examples
# Lathyrus example using blocksize - when repeated patterns exist in variable# orderdata(lathyrus)sizevector <- c(0, 100, 13, 127, 3730, 3800, 0)stagevector <- c("Sd", "Sdl", "VSm", "Sm", "VLa", "Flo", "Dorm")repvector <- c(0, 0, 0, 0, 0, 1, 0)obsvector <- c(0, 1, 1, 1, 1, 1, 0)matvector <- c(0, 0, 1, 1, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1, 1, 1)binvec <- c(0, 100, 11, 103, 3500, 3800, 0.5)lathframe <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, matstatus = matvector, immstatus = immvector, indataset = indataset, binhalfwidth = binvec, propstatus = propvector)lathvert <- verticalize3(lathyrus, noyears = 4, firstyear = 1988, patchidcol = "SUBPLOT", individcol = "GENET", blocksize = 9, juvcol = "Seedling1988", sizeacol = "Volume88", repstracol = "FCODE88", fecacol = "Intactseed88", deadacol = "Dead1988", nonobsacol = "Dormant1988", stageassign = lathframe, stagesize = "sizea", censorcol = "Missing1988", censorkeep = NA, censor = TRUE)# Cypripedium example using partial repeat patterns with blocksize and part# explicit variable name castdata(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 = c("Inf.04", "Inf.05", "Inf.06", "Inf.07", "Inf.08", "Inf.09"), repstrbcol = c("Inf2.04", "Inf2.05", "Inf2.06", "Inf2.07", "Inf2.08", "Inf2.09"), fecacol = "Pod.04", stageassign = cypframe_raw, stagesize = "sizeadded", NAas0 = TRUE, NRasRep = TRUE)Import Vital Rate Model Factor Values for Function-based MPM Development
Description
Functionvrm_import() builds a skeleton list holding data frames andvectors that can be used to import coefficient values for the factors of thevital rate models used to build function-based MPMs or run function-basedprojections.
Usage
vrm_import( years = NULL, patches = c(1), groups = c(0), interactions = FALSE, zi = FALSE, cat.indcova = NULL, cat.indcovb = NULL, cat.indcovc = NULL, dist.sizea = "gaussian", dist.sizeb = "constant", dist.sizec = "constant", dist.fec = "gaussian", trunc.sizea = FALSE, trunc.sizeb = FALSE, trunc.sizec = FALSE, trunc.fec = FALSE, use.juv = FALSE)Arguments
years | A numeric vector of the years or times at time |
patches | A string or numeric vector of the patch names to be modeled. |
groups | An integer vector of stage groups to be modeled. Defaults to avector with a single element with value |
interactions | A logical value indicating whether to include two-wayinteractions between main effects ( |
zi | A logical value indicating whether to include coefficients for thebinomial components of zero-inflation models. Defaults to |
cat.indcova | If individual covariate a is categorical, then this termshould equal a string vector of the names of the categories. Defaults to |
cat.indcovb | If individual covariate b is categorical, then this termshould equal a string vector of the names of the categories. Defaults to |
cat.indcovc | If individual covariate c is categorical, then this termshould equal a string vector of the names of the categories. Defaults to |
dist.sizea | A string value giving the distribution of the variablecoding primary size. Can equal |
dist.sizeb | A string value giving the distribution of the variablecoding secondary size. Can equal |
dist.sizec | A string value giving the distribution of the variablecoding tertiary size. Can equal |
dist.fec | A string value giving the distribution of the variablecoding fecundity. Can equal |
trunc.sizea | A logical value indicating whether the distribution of theprimary size variable should be zero-truncated. Defaults to |
trunc.sizeb | A logical value indicating whether the distribution of thesecondary size variable should be zero-truncated. Defaults to |
trunc.sizec | A logical value indicating whether the distribution of thetertiary size variable should be zero-truncated. Defaults to |
trunc.fec | A logical value indicating whether the distribution of thefecundity variable should be zero-truncated. Defaults to |
use.juv | A logical value indicating whether to utilize juvenile vitalrates. If |
Value
A list of classvrm_input, with up to 13 elements including:
vrm_frame | A data frame holding the main slope coefficients for thelinear vital rate models. |
year_frame | A data frame holding the main slope coefficients for theyear at time t terms in the linear vital rate models. |
patch_frame | A data frame holding the main slope coefficients for thepatch terms in the linear vital rate models. |
group2_frame | A data frame holding the main slope coefficients for thestage group terms in timet in the linear vital rate models. |
group1_frame | A data frame holding the main slope coefficients for thestage group terms in timet-1 in the linear vital rate models. |
dist_frame | A data frame giving the distributions of all variables,including primary, secondary, and tertiary size, and fecundity. Somevariables begin as |
indcova2_frame | A data frame holding the main slope coefficients forthe categorical individual covariate a terms in timet in the linearvital rate models. |
indcova1_frame | A data frame holding the main slope coefficients forthe categorical individual covariate a terms in timet-1 in the linearvital rate models. |
indcovb2_frame | A data frame holding the main slope coefficients forthe categorical individual covariate b terms in timet in the linearvital rate models. |
indcovb1_frame | A data frame holding the main slope coefficients forthe categorical individual covariate b terms in timet-1 in the linearvital rate models. |
indcovc2_frame | A data frame holding the main slope coefficients forthe categorical individual covariate c terms in timet in the linearvital rate models. |
indcovc1_frame | A data frame holding the main slope coefficients forthe categorical individual covariate c terms in timet-1 in the linearvital rate models. |
st_frame | A data frame holding values of sigma or theta for use inGaussian or negative binomial response terms, respectively. |
The first element, calledvrm_frame, is a data frame with thefollowing 18 variables:
main_effect_1 | The main effect for which coefficients are to beentered. |
main_1_defined | A more natural explanation of |
main_effect_2 | If given, then indicates another effect in a two-wayinteraction with |
main_2_defined | A more natural explanation of |
surv | A vector of coefficients for the factors in the model of adultsurvival. |
obs | A vector of coefficients for the factors in the model of adultobservation status. |
sizea | A vector of coefficients for the factors in the model of adultprimary size. |
sizeb | A vector of coefficients for the factors in the model of adultsecondary size. |
sizec | A vector of coefficients for the factors in the model of adulttertiary size. |
repst | A vector of coefficients for the factors in the model of adultreproductive status. |
fec | A vector of coefficients for the factors in the model of adultfecundity. |
jsurv | A vector of coefficients for the factors in the model ofjuvenile survival. |
jobs | A vector of coefficients for the factors in the model of juvenileobservation status. |
jsize | A vector of coefficients for the factors in the model ofjuvenile primary size. |
jsizeb | A vector of coefficients for the factors in the model ofjuvenile secondary size. |
jsizec | A vector of coefficients for the factors in the model ofjuvenile tertiary size. |
jrepst | A vector of coefficients for the factors in the model ofjuvenile reproductive status, for individuals maturing in the current timestep. |
jmat | A vector of coefficients for the factors in the model of maturitystatus, for individuals capable of maturing at the current time step. |
sizea_zi | A vector of coefficients for the factors in the binomialcomponent of the zero-inflated model of adult primary size, if zero-inflatedmodels are being used. |
sizeb_zi | A vector of coefficients for the factors in the binomialcomponent of the zero-inflated model of adult secondary size, ifzero-inflated models are being used. |
sizec_zi | A vector of coefficients for the factors in the binomialcomponent of the zero-inflated model of adult tertiary size, if zero-inflatedmodels are being used. |
fec_zi | A vector of coefficients for the factors in the binomialcomponent of the zero-inflated model of fecundity, if zero-inflated modelsare being used. |
jsizea_zi | A vector of coefficients for the factors in the binomialcomponent of the zero-inflated model of juvenile primary size, ifzero-inflated models are being used. |
jsizeb_zi | A vector of coefficients for the factors in the binomialcomponent of the zero-inflated model of juvenile secondary size, ifzero-inflated models are being used. |
jsizec_zi | A vector of coefficients for the factors in the binomialcomponent of the zero-inflated model of juvenile tertiary size, ifzero-inflated models are being used. |
Notes
All coefficients across all data frames are initially set to0. Afterusing this function to create the skeleton list, all relevant coefficientvalues should be set to non-zero values equal to the respective slope fromthe appropriate linear model, and any vital rate model to be used shouldhave its distribution set to"binom","gaussian","gamma","poisson", or"negbin". Unused vital ratesshould be set to"constant", and the first element of the correspodingcolumn invrm_frame (corresponding to the y-intercept) should be setto the constant value to utilize (generally1). If no values aremanually edited, then function-based MPM generator functions will not be ableto generate valid MPMs.
Users should never change the labels or the order of terms in the data framesand vectors produced via this function, nor should they ever changes thenames of core list elements in thevrm_input object. Doing so willresult either in fatal errors or erroneous matrix calculations.
Using thevrm_import() approach to building function-based MPMsrequires attention to the stageframe. Although nohfv_data objectneeds to be input, stages for which vital rates are to be estimated viamodels parameterized with coefficients provided via functionvrm_import() should be marked as occurring within the dataset, whilestages for which the provided coefficients should not be used should bemarked as not occurring within the dataset.
Coefficients added to zero-inflation models can only be added to primarysize, secondary size, tertiary size, fecundity, and the juvenile versions ofprimary, secondary, and tertiary size. Care must be taken to include zero-inflated coefficients only for variables without size-truncateddistributions. Adding such terms will result in fatal errors during matrixcreation.
Examples
data(lathyrus)sizevector <- c(0, 100, 0, 1, 7100)stagevector <- c("Sd", "Sdl", "Dorm", "ipm", "ipm")repvector <- c(0, 0, 0, 1, 1)obsvector <- c(0, 1, 0, 1, 1)matvector <- c(0, 0, 1, 1, 1)immvector <- c(1, 1, 0, 0, 0)propvector <- c(1, 0, 0, 0, 0)indataset <- c(0, 1, 1, 1, 1)binvec <- c(0, 100, 0.5, 1, 1)comments <- c("Dormant seed", "Seedling", "Dormant", "ipm adult stage", "ipm adult stage")lathframeipm <- sf_create(sizes = sizevector, stagenames = stagevector, repstatus = repvector, obsstatus = obsvector, propstatus = propvector, immstatus = immvector, matstatus = matvector, comments = comments, indataset = indataset, binhalfwidth = binvec, ipmbins = 100, roundsize = 3)lathsupp2 <- supplemental(stage3 = c("Sd", "Sdl", "Sd", "Sdl"), stage2 = c("Sd", "Sd", "rep", "rep"), givenrate = c(0.345, 0.054, NA, NA), multiplier = c(NA, NA, 0.345, 0.054), type = c(1, 1, 3, 3), stageframe = lathframeipm, historical = FALSE)lath_vrm <- vrm_import(years = c(1988:1990), zi = TRUE, dist.fec = "negbin", use.juv = TRUE)lath_vrm$vrm_frame$surv[1] <- 2.32571lath_vrm$vrm_frame$surv[2] <- 0.00109lath_vrm$vrm_frame$obs[1] <- 2.230lath_vrm$vrm_frame$sizea[1] <- 164.0695lath_vrm$vrm_frame$sizea[2] <- 0.6211lath_vrm$vrm_frame$fec[1] <- 1.517lath_vrm$vrm_frame$fec_zi[1] <- 6.252765lath_vrm$vrm_frame$fec_zi[2] <- -0.007313lath_vrm$vrm_frame$jsurv[1] <- 1.03lath_vrm$vrm_frame$jobs[1] <- 10.390lath_vrm$vrm_frame$jsizea[1] <- 3.0559lath_vrm$vrm_frame$jsizea[2] <- 0.8482lath_vrm$year_frame$fec[c(1:3)] <- c(-0.41749627, 0.51421684, -0.07964038)lath_vrm$year_frame$fec_zi[c(1:3)] <- c(3.741475e-07, -7.804715e-08, -2.533755e-07)lath_vrm$year_frame$sizea[c(1:3)] <- c(96.3244, -240.8036, 144.4792)lath_vrm$year_frame$jobs[c(1:3)] <- c(-0.7459843, 0.6118826, -0.9468618)lath_vrm$year_frame$jsizea[c(1:3)] <- c(0.5937962, 1.4551236, -2.0489198)lath_vrm$dist_frame$dist[2] <- "binom"lath_vrm$dist_frame$dist[9] <- "binom"lath_vrm$st_frame[3] <- 503.6167lath_vrm$st_frame[7] <- 0.2342114lath_vrm$st_frame[10] <- 5.831lath_vrm$vrm_frame$sizeb[1] <- 1lath_vrm$vrm_frame$sizec[1] <- 1lath_vrm$vrm_frame$repst[1] <- 1lath_vrm$vrm_frame$jsizeb[1] <- 1lath_vrm$vrm_frame$jsizec[1] <- 1lath_vrm$vrm_frame$jrepst[1] <- 1lath_vrm$vrm_frame$jmatst[1] <- 1lathmat2_importipm <- flefko2(stageframe = lathframeipm, modelsuite = lath_vrm, supplement = lathsupp2, reduce = FALSE)summary(lathmat2_importipm)