Format trajectory tables
Source:R/internal_demog_fns.R, R/simulateTrajectoriesFromPosterior.R
simulateTrajectoriesFromPosterior.RdThis function is used inside trajectoriesFromBayesian() to simulate
trajectories from Bayesian model results.
Assumes that rec_pred and surv_pred each include the same years and
populations.
Usage
convertTrajectories(trajectories)
summarizeTrajectories(trajectories, returnSamples = T)
simulateTrajectoriesFromPosterior(
popInfo = NA,
rec_pred,
surv_pred,
initYear = NULL,
correlateRates = FALSE,
returnExpected = FALSE,
c = formals(caribouPopGrowth)$c,
K = FALSE,
...
)Arguments
- trajectories
data.frame containing trajectories created by
simulateTrajectoriesFromPosterior- returnSamples
logical. Should samples table be returned as well as summary?
- popInfo
If NA (default) predictions are made without populations size, density dependence, or demographic stochasticity. See
caribouPopGrowth()for details.- rec_pred
results returned by
bb_fit_recruitment()orbb_predict_calf_cow_ratio()functions of bboutools R package, or recruit_fit returned byestimateBayesianRates().- surv_pred
bboufit object return by
bb_fit_survival()orbb_predict_survival()functions of bboutools R package, or surv_fit returned byestimateBayesianRates().- initYear
numeric. Initial year.
- correlateRates
logical. Set TRUE to force correlation between recruitment and survival. Ignored
- returnExpected
logical. Default FALSE. Set TRUE to return expected values of R, S, and lambda (without interannual variation). Ignored if rec_pred/surv_pred are
bb_predict_calf_cow_ratio()/bb_predict_survival()results.- c
Number. Bias correction term.
- K
Number. Carrying capacity.
- ...
Other parameters passed to
caribouPopGrowth()
Value
convertTrajectories: formatted tables
summarizeTrajectories: a list containing "summary" with a summary
table of trajectories and, if returnSamples = TRUE, "samples" with the
sample table
simulateTrajectoriesFromPosterior: a data frame with results from caribouPopGrowth() for each set of survival/recruitment predictions.
Interpretation of Years
Throughout the package a year is treated as the calendar year only if it is in a table that also contains a month column. In all other contexts year is treated as the caribou year which is the annual demographic cycle of caribou, measured from one calving season to the next. By default, April is set as the start of the caribou year.
See also
Caribou demography functions:
addMissingYears(),
addN0Variation(),
bayesianScenariosWorkflow(),
bayesianTrajectoryWorkflow(),
betaNationalPriors(),
caribouPopGrowth(),
compareTrajectories(),
compositionBiasCorrection(),
dataFromSheets(),
demographicProjectionApp(),
estimateBayesianRates(),
estimateNationalRate(),
getCaribouYear(),
getNationalCoefficients(),
getScenarioDefaults(),
plotCompareTrajectories(),
plotSurvivalSeries(),
plotTrajectories(),
popGrowthTableJohnsonECCC,
simulateObservations(),
trajectoriesFromBayesian(),
trajectoriesFromNational(),
trajectoriesFromSummary(),
trajectoriesFromSummaryForApp()
Examples
# \donttest{
# Note these examples take a long time to run!
mod <- estimateBayesianRates(
surv_data = bboudata::bbousurv_a,
recruit_data = bboudata::bbourecruit_a,
N0 = NA, return_mcmc = TRUE
)
outmcmc = simulateTrajectoriesFromPosterior(popInfo=NA,mod$recruit_fit,mod$surv_fit)
names(outmcmc)
#> [1] "N0" "lambda" "lambdaE"
#> [4] "N" "R_t" "X_t"
#> [7] "S_t" "n_recruits" "surviving_adFemales"
#> [10] "lab" "Year" "PopulationName"
#> [13] "id"
#get 95% prediction intervals from demographic trajectories
PImcmc <- summarizeTrajectories(convertTrajectories(outmcmc))
str(PImcmc, max.level = 3, give.attr = FALSE)
#> List of 2
#> $ summary:'data.frame': 189 obs. of 8 variables:
#> ..$ MetricTypeID : chr [1:189] "N" "N" "N" "N" ...
#> ..$ Year : num [1:189] 1989 2012 1995 1997 2001 ...
#> ..$ PopulationName: chr [1:189] "A" "A" "A" "A" ...
#> ..$ Mean : num [1:189] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
#> ..$ lower : Named num [1:189] NA NA NA NA NA NA NA NA NA NA ...
#> ..$ upper : Named num [1:189] NA NA NA NA NA NA NA NA NA NA ...
#> ..$ probViable : num [1:189] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
#> ..$ Metric : chr [1:189] "Female population size" "Female population size" "Female population size" "Female population size" ...
#> $ samples:'data.frame': 567000 obs. of 8 variables:
#> ..$ MetricTypeID : chr [1:567000] "N" "N" "N" "N" ...
#> ..$ Replicate : chr [1:567000] "x2565" "x2567" "x2569" "x2568" ...
#> ..$ LambdaPercentile: logi [1:567000] NA NA NA NA NA NA ...
#> ..$ Year : num [1:567000] 2003 2003 2003 2003 2003 ...
#> ..$ PopulationName : chr [1:567000] "A" "A" "A" "A" ...
#> ..$ Timestep : num [1:567000] 2003 2003 2003 2003 2003 ...
#> ..$ Amount : num [1:567000] NA NA NA NA NA NA NA NA NA NA ...
#> ..$ Metric : chr [1:567000] "Female population size" "Female population size" "Female population size" "Female population size" ...
# }