Description Usage Arguments Value Notes Examples
View source: R/matrixcreation.R
Function flefko3()
returns functionbased historical MPMs
corresponding to the patches and years given, including the associated
component transition and fecundity matrices, data frames detailing the
characteristics of the ahistorical stages used and historical stage pairs
created, and a data frame characterizing the patch and year combinations
corresponding to these matrices. Unlike rlefko3()
, this
function currently does not distinguish populations within the same dataset.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42  flefko3(
year = "all",
patch = "all",
stageframe,
supplement = NA,
repmatrix = NA,
overwrite = NA,
data = NA,
modelsuite = NA,
surv_model = NA,
obs_model = NA,
size_model = NA,
repst_model = NA,
fec_model = NA,
jsurv_model = NA,
jobs_model = NA,
jsize_model = NA,
jrepst_model = NA,
paramnames = NA,
inda = 0,
indb = 0,
indc = 0,
surv_dev = 0,
obs_dev = 0,
size_dev = 0,
repst_dev = 0,
fec_dev = 0,
jsurv_dev = 0,
jobs_dev = 0,
jsize_dev = 0,
jrepst_dev = 0,
repmod = 1,
yearcol = NA,
patchcol = NA,
year.as.random = FALSE,
patch.as.random = FALSE,
randomseed = NA,
negfec = FALSE,
format = "ehrlen",
reduce = FALSE,
err_check = FALSE
)

year 
A variable corresponding to the observation occasion, or a set
of such values, given in values associated with the year term used in linear
model development. Can also equal 
patch 
A variable designating which patches or subpopulations will have
matrices estimated. Should be set to specific patch names, or to 
stageframe 
A stageframe object that includes information on the size, observation status, propagule status, immaturity status, and maturity status of each ahistorical stage. Should also incorporate bin widths if size is continuous. 
supplement 
An optional data frame of class 
repmatrix 
A reproduction matrix, which is an optional matrix composed
mostly of 0s, with nonzero values for each potentially new individual (row)
born to each reproductive stage (column). Entries act as multipliers on
fecundity, with 1 equaling full fecundity. Fecundity multipliers provided
this way supplement rather than replace those provided in 
overwrite 
An optional data frame developed with the

data 
The historical vertical demographic data frame used to estimate
vital rates (class 
modelsuite 
An optional 
surv_model 
A linear model predicting survival probability. This can
be a model of class 
obs_model 
A linear model predicting sprouting or observation
probability. This can be a model of class 
size_model 
A linear model predicting size. This can be a model 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 of
class 
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 observation
probability. This can be a model of class 
jsize_model 
A linear model predicting juvenile size. This can be a
model of class 
jrepst_model 
A linear model predicting reproduction probability of a
mature individual that was immature in the previous year. This can be a model
of class 
paramnames 
A dataframe with two columns, the first showing the general
model terms that will be used in matrix creation, and the second showing the
equivalent terms used in modeling. Only required if 
inda 
A numeric value to use for individual covariate a. Defaults to 0. 
indb 
A numeric value to use for individual covariate b. Defaults to 0. 
indc 
A numeric value to use for individual covariate c. Defaults to 0. 
surv_dev 
A numeric value to be added to the yintercept in the linear model for survival probability. 
obs_dev 
A numeric value to be added to the yintercept in the linear model for observation probability. 
size_dev 
A numeric value to be added to the yintercept in the linear model for size. 
repst_dev 
A numeric value to be added to the yintercept in the linear model for probability of reproduction. 
fec_dev 
A numeric value to be added to the yintercept in the linear model for fecundity. 
jsurv_dev 
A numeric value to be added to the yintercept in the linear model for juvenile survival probability. 
jobs_dev 
A numeric value to be added to the yintercept in the linear model for juvenile observation probability. 
jsize_dev 
A numeric value to be added to the yintercept in the linear model for juvenile size. 
jrepst_dev 
A numeric value to be added to the yintercept in the linear model for juvenile reproduction probability. 
repmod 
A scalar multiplier of fecundity. Defaults to 1. 
yearcol 
The variable name or column number corresponding to year
in occasion t in the dataset. Not needed if 
patchcol 
The variable name or column number corresponding to patch in
the dataset. Not needed if 
year.as.random 
A logical term indicating whether coefficients for missing patches within vital rate models should be estimated as random intercepts. Defaults to FALSE, in which case missing coefficients corresponding to observation occasions are set to 0. 
patch.as.random 
A logical term indicating whether coefficients for missing patches within vital rate models should be estimated as random intercepts. Defaults to FALSE, in which case missing patch coefficients are set to 0. 
randomseed 
A numeric value used as a seed to generate random estimates
for missing occasion and patch coefficients, if either 
negfec 
A logical value denoting whether fecundity values estimated to be negative should be reset to 0. Defaults to FALSE. 
format 
A string indicating whether to estimate matrices in

reduce 
A logical value denoting whether to remove historical stages associated solely with 0 transitions. These are only removed in cases where the associated row and column sums in ALL matrices estimated equal 0. Defaults to FALSE. 
err_check 
A logical value indicating whether to append matrices of vital rate probabilities associated with each matrix. These matrices are developed internally and can be used for erroc checking. Defaults to FALSE. 
If all inputs are properly formatted, then this function will return
an object of class lefkoMat
, which is a list that holds the matrix
projection model and all of its metadata. Its structure is a list with the
following elements:
A 
A list of full projection matrices in order of sorted patches and
years. 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 stages used to create historical stage pairs. 
agestages 
A data frame showing agestage pairs. In this function, it
is set to NA. Only used in output to function 
ahstages 
A data frame detailing the characteristics of associated ahistorical stages, in the form of a modified stageframe that includes status as an entry stage through reproduction. 
labels 
A data frame showing the patch and year of each matrix in
order. In 
matrixqc 
A short vector describing the number of nonzero elements in

modelqc 
This is the 
prob_out 
An optional element only added if 
The default behavior of this function is to estimate fecundity with regards
to transitions specified via associated fecundity multipliers in either
supplement
or repmatrix
. If both of these fields are left
empty, then fecundity will be estimated at full for all transitions leading
from reproductive stages to immature and propagule stages. However, if a
supplement
is provided and a repmatrix
is not, or if
repmatrix
is set to 0, then only fecundity transitions noted in the
supplement will be set to nonzero values. To use the default behavior of
setting all reproductive stages to reproduce at full fecundity into immature
and propagule stages but incorporate given or proxy survival transitions,
input those given and proxy transitions through the overwrite
option.
The reproduction matrix (field repmatrix
) may be supplied as either
historical or ahistorical. If provided as ahistorical, then flefko3()
will assume that all historical transitions involving stages noted for
occasions t and t+1 should be set to the respective fecundity
multipliers noted.
Users may at times wish to estimate MPMs using a dataset incorporating
multiple patches or subpopulations. Should the aim of analysis be a general
MPM that does not distinguish these patches or subpopulations, the
patchcol
variable should be left to NA, which is the default.
Input options including multiple variable names must be entered in the order of variables in occasion t+1, t, and t1. Rearranging the order WILL lead to erroneous calculations, and will probably also lead to fatal errors.
Using the err_check
option will produce a matrix of 4 columns, each
characterizing a different vital rate. The product of each row yields an
element in the associated $U
matrix. The number and order of elements
in each column of this matrix matches the associated matrix in column vector
format. Use of this option is generally for the purposes of debugging code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58  # Lathyrus example
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 = TRUE)
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)
lathmat3ln < flefko3(year = "all", patch = "all", stageframe = lathframeln,
modelsuite = lathmodelsln3, data = lathvertln, supplement = lathsupp3,
patchcol = "patchid", yearcol = "year2", year.as.random = FALSE,
patch.as.random = FALSE, reduce = FALSE)
summary(lathmat3ln)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.