Description Usage Arguments Value Notes Examples
View source: R/matrixcreation.R
Function aflefko2()
returns ahistorical age x stage MPMs corresponding
to the patches and years given, including the associated component transition
and fecundity matrices, data frame detailing the characteristics of
ahistorical stages and the exact agestage combinations corresponding to rows
and columns in estimated matrices, and a data frame characterizing the patch
and year combinations corresponding to these matrices. Unlike
rlefko2()
and rlefko3()
, this function does not
currently distinguish populations.
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  aflefko2(
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 = "year2",
patchcol = "patchid",
year.as.random = FALSE,
patch.as.random = FALSE,
final_age = 10,
continue = TRUE,
randomseed = NA,
negfec = FALSE,
reduce = FALSE,
err_check = FALSE
)

year 
A variable corresponding to year or observation time, or a set
of such values, given in values associated with the year term used in linear
model development. Can also equal 
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 original historical 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
time t in the dataset. Not needed if a 
patchcol 
The variable name or column number corresponding to patch in
the dataset. Not needed if a 
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 time step coefficients 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. 
final_age 
The final age to model in the matrix, where the first age will be age 0. 
continue 
A logical value designating whether to allow continued survival of individuals going past the final age, using the demographic characteristics of the final age. 
randomseed 
A numeric value used as a seed to generate random estimates
for missing time step 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. 
reduce 
A logical value denoting whether to remove ahistorical 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 add matrices of vital rate probabilities associated with each matrix. Defaults to FALSE. 
If all inputs are properly formatted, then this function will return
an object of class lefkoMat
. Output includes:
A 
A list of full projection matrices in order of sorted patches and years. 
U 
A list of survival transition matrices sorted as in 
F 
A list of fecundity matrices sorted as in 
hstages 
Null for ahistorical matrices. 
agestages 
A data frame showing the stage number and stage name
corresponding to 
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 giving 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 
This function will yield incorrect estimates if the models utilized incorporate state in time t1. Only use models developed testing for ahistorical effects.
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 also incorporate given or proxy
survival transitions, input those given and proxy transitions through the
overwrite
option.
The reproduction matrix (field repmatrix
) may only be supplied as
ahistorical. If provided as historical, then flefko2()
will fail and
produce an error.
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 time 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 59  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(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
maxima < c(NA, 1, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA)
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, maxage = maxima)
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", age = "obsage",
year.as.random = TRUE, patch.as.random = TRUE, show.model.tables = TRUE,
quiet = TRUE)
# Here we use supplemental() to provide overwrite and reproductive info
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)
lathmat2age < aflefko2(year = "all", patch = "all",
stageframe = lathframeln, modelsuite = lathmodelsln2, data = lathvertln,
supplement = lathsupp2, patchcol = "patchid",
yearcol = "year2", year.as.random = FALSE, patch.as.random = FALSE,
final_age = 2, continue = TRUE, reduce = FALSE)
summary(lathmat2age)

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