R/demographicRates.R
, R/sampleRates.R
demographicRates.Rd
Apply sampled coefficients to disturbance covariates to
calculate expected recruitment and survival.demographicRates
is a wrapper
around sampleRates
to sample both survival and recruitment rates based on
the result of demographicCoefficients()
and using recommended defaults.
demographicRates(
covTable,
popGrowthPars,
ignorePrecision = FALSE,
returnSample = FALSE,
useQuantiles = TRUE,
predInterval = list(PI_R = c(0.025, 0.975), PI_S = c(0.025, 0.975)),
transformFns = list(S_transform = function(y) {
(y * 46 - 0.5)/45
}, R_transform
= function(y) {
y
})
)
sampleRates(
covTable,
coefSamples,
coefValues,
modelVersion,
resVar,
ignorePrecision,
returnSample,
quantilesToUse = NULL,
predInterval = c(0.025, 0.975),
transformFn = function(y) {
y
}
)
data.frame. A table of covariate values to be used. Column names must match the coefficient names in popGrowthTableJohnsonECCC. Each row is a different scenario.
list. Coefficient values and (optionally) quantiles
returned by demographicCoefficients
.
logical. Should the precision of the model be used if it is available? When precision is used variation among populations around the National mean responses is considered in addition to the uncertainty about the coefficient estimates.
logical. If TRUE the returned data.frame has replicates * scenarios rows. If FALSE the returned data.frame has one row per scenario and additional columns summarizing the variation among replicates. See Value for details.
logical or numeric. If it is a numeric vector it must be
length 2 and give the low and high limits of the quantiles to use. Only
relevant when ignorePrecision = FALSE
. If useQuantiles != FALSE
, each
replicate population is assigned to a quantile of the distribution of
variation around the expected values, and remains in that quantile as
covariates change. If useQuantiles != FALSE
and popGrowthPars contains
quantiles, those quantiles will be used. If useQuantiles = TRUE
and
popGrowthPars does not contain quantiles, replicate populations will be
assigned to quantiles in the default range of 0.025 and 0.975. If
useQuantiles = FALSE
, sampling is done independently for each combination
of scenario and replicate, so the value for a particular replicate
population in one scenario is unrelated to the values for that replicate in
other scenarios. Useful for projecting impacts of changing disturbance on
the trajectories of replicate populations.
numeric vector with length 2. The default 95% interval
is (c(0.025,0.975)
). Only relevant when returnSample = TRUE
and
quantilesToUse = NULL
.
list of functions used to transform demographic rates.
The default is list(S_transform = function(y){(y*46-0.5)/45},R_transform = function(y){y})
. The back transformation is applied to survival rates as
in Johnson et al. 2020.
matrix. Bootstrapped coefficients with one row per replicate and one column per coefficient
data.table. One row table with expected values for each coefficient
character. Which model version to use. Currently the only option is "Johnson" for the model used in Johnson et. al. (2020), but additional options may be added in the future.
character. Response variable, typically "femaleSurvival" or "recruitment"
numeric vector of length coefSamples
. See useQuantiles
.
function used to transform demographic rates.
A data.frame of predictions. The data.frame includes all columns in
covTable
with additional columns depending on returnSample
.
If returnSample = FALSE
the number of rows is the same as the number of
rows in covTable
, additional columns are:
"S_bar" and "R_bar": The mean estimated values of survival and recruitment (calves per cow)
"S_stdErr" and "R_stdErr": Standard error of the estimated values
"S_PIlow"/"S_PIhigh" and "R_PIlow"/"R_PIhigh": If not using quantiles, 95\ minimum values are returned.
If returnSample = TRUE
the number of rows is nrow(covTable) * replicates
additional columns are:
"scnID": A unique identifier for scenarios provided in
covTable
"replicate": A replicate identifier, unique within each scenario
"S_bar" and "R_bar": The expected values of survival and recruitment (calves per cow)
For sampleRates
a similar data frame for one response variable
First the mean recruitment (\(\mu^R_t\)) and survival (\(\mu^S_t\)) are calculated from the sampled coefficients and provided disturbance covariates according to the beta regression models estimated by Johnson et al. (2020): $$log(\mu^R_t)=\dot{\beta^R_0}+\dot{\beta^R_a}A_t+\dot{\beta}^R_fF_t$$
$$log(\mu^S_t)=\dot{\beta^S_0}+\dot{\beta^S_a}A_t$$
Then each replicate population is assigned to a quantile (if useQuantiles = TRUE
) of the Beta distributed expected recruitment \(\bar{R}_t\) and
survival \(\bar{S}_t\) where \(\phi^R\) and \(\phi^S\) are the
precisions of the Beta distributed errors:
$$\bar{R}_t \sim \text{Beta}(\mu^R_t,\phi^R)$$
$$\bar{S}_t \sim (46\times \text{Beta}(\mu^S_t,\phi^S)-0.5)/45)$$
Using quantiles means that the population will stay in these quantiles as disturbance changes over time, so there is persistent variation in recruitment and survival among example populations. A transformation function is also applied to survival to avoid survival probabilities of 1.
Caribou demography functions:
caribouBayesianPM()
,
caribouPopGrowth()
,
compositionBiasCorrection()
,
demographicCoefficients()
,
demographicProjectionApp()
,
getOutputTables()
,
getPriors()
,
getScenarioDefaults()
,
getSimsNational()
,
plotRes()
,
popGrowthTableJohnsonECCC
,
runScnSet()
,
simulateObservations()
# get coefficient samples
coefs <- demographicCoefficients(10)
# table of different scenarios to test
covTableSim <- expand.grid(Anthro = seq(0, 90, by = 20),
fire_excl_anthro = seq(0, 70, by = 20))
covTableSim$Total_dist = covTableSim$Anthro + covTableSim$fire_excl_anthro
demographicRates(covTableSim, coefs)
#> popGrowthPars contains quantiles so they are used instead of the defaults
#> popGrowthPars contains quantiles so they are used instead of the defaults
#> Anthro fire_excl_anthro Total_dist S_bar S_stdErr S_PIlow S_PIhigh
#> 1 0 0 0 0.8757906 0.05144116 0.7742470 0.9461327
#> 2 0 20 20 0.8757906 0.05144116 0.7742470 0.9461327
#> 3 0 40 40 0.8757906 0.05144116 0.7742470 0.9461327
#> 4 0 60 60 0.8757906 0.05144116 0.7742470 0.9461327
#> 5 20 0 20 0.8617131 0.05249148 0.7600169 0.9349891
#> 6 20 20 40 0.8617131 0.05249148 0.7600169 0.9349891
#> 7 20 40 60 0.8617131 0.05249148 0.7600169 0.9349891
#> 8 20 60 80 0.8617131 0.05249148 0.7600169 0.9349891
#> 9 40 0 40 0.8478591 0.05346178 0.7461747 0.9236675
#> 10 40 20 60 0.8478591 0.05346178 0.7461747 0.9236675
#> 11 40 40 80 0.8478591 0.05346178 0.7461747 0.9236675
#> 12 40 60 100 0.8478591 0.05346178 0.7461747 0.9236675
#> 13 60 0 60 0.8342249 0.05436676 0.7326912 0.9122309
#> 14 60 20 80 0.8342249 0.05436676 0.7326912 0.9122309
#> 15 60 40 100 0.8342249 0.05436676 0.7326912 0.9122309
#> 16 60 60 120 0.8342249 0.05436676 0.7326912 0.9122309
#> 17 80 0 80 0.8208071 0.05521723 0.7195422 0.9007266
#> 18 80 20 100 0.8208071 0.05521723 0.7195422 0.9007266
#> 19 80 40 120 0.8208071 0.05521723 0.7195422 0.9007266
#> 20 80 60 140 0.8208071 0.05521723 0.7195422 0.9007266
#> R_bar R_stdErr R_PIlow R_PIhigh
#> 1 0.35951478 0.10851724 0.179082645 0.5556043
#> 2 0.30574618 0.10328036 0.135114514 0.4834488
#> 3 0.26001915 0.09776378 0.100843238 0.4212997
#> 4 0.22113100 0.09208391 0.074259518 0.3679433
#> 5 0.25589195 0.10062059 0.106309806 0.4352440
#> 6 0.21762106 0.09398087 0.078488082 0.3799060
#> 7 0.18507391 0.08757339 0.057034481 0.3324470
#> 8 0.15739448 0.08139631 0.040651426 0.2917479
#> 9 0.18213629 0.09055572 0.060436272 0.3430861
#> 10 0.15489621 0.08364207 0.043236151 0.3008740
#> 11 0.13173012 0.07716521 0.030236951 0.2646475
#> 12 0.11202872 0.07108257 0.020569879 0.2334999
#> 13 0.12963921 0.07984924 0.032276924 0.2727746
#> 14 0.11025053 0.07321763 0.022074475 0.2404942
#> 15 0.09376159 0.06708509 0.014613757 0.2126830
#> 16 0.07973872 0.06139701 0.009297291 0.1886397
#> 17 0.09227334 0.06935266 0.015764994 0.2189341
#> 18 0.07847305 0.06325836 0.010106806 0.1940522
#> 19 0.06673672 0.05765799 0.006181654 0.1724727
#> 20 0.05675565 0.05249671 0.003568697 0.1536647
cfs <- getCoefs(popGrowthTableJohnsonECCC, "recruitment", "Johnson", "M3")
cfSamps <- sampleCoefs(cfs[[1]], 10)
# disturbance scenarios
distScen <- data.frame(Total_dist = 1:10/10)
# return summary across replicates
sampleRates(distScen, cfSamps$coefSamples, cfSamps$coefValues,
"Johnson", "recruitment", ignorePrecision = TRUE,
returnSample = FALSE)
#> Total_dist average stdErr PIlow PIhigh
#> 1 0.1 0.3838513 0.02006103 0.3570003 0.4106380
#> 2 0.2 0.3832760 0.02002569 0.3564191 0.4099922
#> 3 0.3 0.3827015 0.01999050 0.3558388 0.4093474
#> 4 0.4 0.3821279 0.01995546 0.3552595 0.4087036
#> 5 0.5 0.3815551 0.01992056 0.3546812 0.4080608
#> 6 0.6 0.3809832 0.01988581 0.3541038 0.4074190
#> 7 0.7 0.3804122 0.01985120 0.3535273 0.4067783
#> 8 0.8 0.3798420 0.01981674 0.3529517 0.4061386
#> 9 0.9 0.3792726 0.01978242 0.3523771 0.4054998
#> 10 1.0 0.3787041 0.01974824 0.3518035 0.4048621
# return one row per replicate * scenario
sampleRates(distScen, cfSamps$coefSamples, cfSamps$coefValues,
"Johnson", "recruitment", ignorePrecision = TRUE,
returnSample = TRUE)
#> scnID Total_dist replicate value
#> 1 1 0.1 V1 0.3642969
#> 2 1 0.1 V5 0.3583532
#> 3 1 0.1 V9 0.3915873
#> 4 1 0.1 V3 0.3984518
#> 5 1 0.1 V4 0.3566075
#> 6 1 0.1 V8 0.3749438
#> 7 1 0.1 V2 0.3679183
#> 8 1 0.1 V6 0.3923606
#> 9 1 0.1 V7 0.4129336
#> 10 1 0.1 V10 0.4027309
#> 11 2 0.2 V7 0.4122729
#> 12 2 0.2 V8 0.3743541
#> 13 2 0.2 V9 0.3909808
#> 14 2 0.2 V10 0.4021362
#> 15 2 0.2 V1 0.3638272
#> 16 2 0.2 V5 0.3578169
#> 17 2 0.2 V2 0.3673812
#> 18 2 0.2 V3 0.3978951
#> 19 2 0.2 V4 0.3560133
#> 20 2 0.2 V6 0.3917268
#> 21 3 0.3 V4 0.3554200
#> 22 3 0.3 V5 0.3572814
#> 23 3 0.3 V3 0.3973392
#> 24 3 0.3 V7 0.4116133
#> 25 3 0.3 V8 0.3737653
#> 26 3 0.3 V9 0.3903752
#> 27 3 0.3 V6 0.3910941
#> 28 3 0.3 V10 0.4015423
#> 29 3 0.3 V1 0.3633582
#> 30 3 0.3 V2 0.3668449
#> 31 4 0.4 V1 0.3628897
#> 32 4 0.4 V9 0.3897706
#> 33 4 0.4 V3 0.3967840
#> 34 4 0.4 V4 0.3548278
#> 35 4 0.4 V5 0.3567467
#> 36 4 0.4 V2 0.3663093
#> 37 4 0.4 V6 0.3904624
#> 38 4 0.4 V7 0.4109548
#> 39 4 0.4 V8 0.3731775
#> 40 4 0.4 V10 0.4009494
#> 41 5 0.5 V8 0.3725905
#> 42 5 0.5 V9 0.3891669
#> 43 5 0.5 V10 0.4003573
#> 44 5 0.5 V1 0.3624218
#> 45 5 0.5 V5 0.3562127
#> 46 5 0.5 V2 0.3657746
#> 47 5 0.5 V3 0.3962297
#> 48 5 0.5 V4 0.3542365
#> 49 5 0.5 V6 0.3898318
#> 50 5 0.5 V7 0.4102973
#> 51 6 0.6 V4 0.3536462
#> 52 6 0.6 V5 0.3556796
#> 53 6 0.6 V7 0.4096409
#> 54 6 0.6 V8 0.3720045
#> 55 6 0.6 V9 0.3885641
#> 56 6 0.6 V6 0.3892021
#> 57 6 0.6 V10 0.3997661
#> 58 6 0.6 V1 0.3619546
#> 59 6 0.6 V2 0.3652406
#> 60 6 0.6 V3 0.3956761
#> 61 7 0.7 V1 0.3614879
#> 62 7 0.7 V3 0.3951233
#> 63 7 0.7 V4 0.3530569
#> 64 7 0.7 V5 0.3551473
#> 65 7 0.7 V9 0.3879623
#> 66 7 0.7 V6 0.3885735
#> 67 7 0.7 V7 0.4089855
#> 68 7 0.7 V8 0.3714194
#> 69 7 0.7 V2 0.3647074
#> 70 7 0.7 V10 0.3991758
#> 71 8 0.8 V9 0.3873614
#> 72 8 0.8 V10 0.3985863
#> 73 8 0.8 V1 0.3610219
#> 74 8 0.8 V5 0.3546158
#> 75 8 0.8 V2 0.3641750
#> 76 8 0.8 V3 0.3945712
#> 77 8 0.8 V4 0.3524686
#> 78 8 0.8 V8 0.3708353
#> 79 8 0.8 V6 0.3879458
#> 80 8 0.8 V7 0.4083311
#> 81 9 0.9 V5 0.3540851
#> 82 9 0.9 V7 0.4076778
#> 83 9 0.9 V8 0.3702520
#> 84 9 0.9 V9 0.3867614
#> 85 9 0.9 V6 0.3873192
#> 86 9 0.9 V10 0.3979977
#> 87 9 0.9 V1 0.3605564
#> 88 9 0.9 V2 0.3636433
#> 89 9 0.9 V3 0.3940199
#> 90 9 0.9 V4 0.3518813
#> 91 10 1.0 V1 0.3600916
#> 92 10 1.0 V4 0.3512949
#> 93 10 1.0 V5 0.3535551
#> 94 10 1.0 V9 0.3861624
#> 95 10 1.0 V3 0.3934694
#> 96 10 1.0 V7 0.4070256
#> 97 10 1.0 V8 0.3696697
#> 98 10 1.0 V2 0.3631124
#> 99 10 1.0 V6 0.3866936
#> 100 10 1.0 V10 0.3974100
# return one row per replicate * scenario with replicates assigned to a quantile
sampleRates(distScen, cfSamps$coefSamples, cfSamps$coefValues,
"Johnson", "recruitment", ignorePrecision = TRUE,
returnSample = TRUE,
quantilesToUse = quantile(x = c(0, 1),
probs = seq(0.025, 0.975, length.out = 10)))
#> scnID Total_dist replicate value
#> 1 1 0.1 V1 0.3642969
#> 2 1 0.1 V5 0.3583532
#> 3 1 0.1 V9 0.3915873
#> 4 1 0.1 V3 0.3984518
#> 5 1 0.1 V4 0.3566075
#> 6 1 0.1 V8 0.3749438
#> 7 1 0.1 V2 0.3679183
#> 8 1 0.1 V6 0.3923606
#> 9 1 0.1 V7 0.4129336
#> 10 1 0.1 V10 0.4027309
#> 11 2 0.2 V7 0.4122729
#> 12 2 0.2 V8 0.3743541
#> 13 2 0.2 V9 0.3909808
#> 14 2 0.2 V10 0.4021362
#> 15 2 0.2 V1 0.3638272
#> 16 2 0.2 V5 0.3578169
#> 17 2 0.2 V2 0.3673812
#> 18 2 0.2 V3 0.3978951
#> 19 2 0.2 V4 0.3560133
#> 20 2 0.2 V6 0.3917268
#> 21 3 0.3 V4 0.3554200
#> 22 3 0.3 V5 0.3572814
#> 23 3 0.3 V3 0.3973392
#> 24 3 0.3 V7 0.4116133
#> 25 3 0.3 V8 0.3737653
#> 26 3 0.3 V9 0.3903752
#> 27 3 0.3 V6 0.3910941
#> 28 3 0.3 V10 0.4015423
#> 29 3 0.3 V1 0.3633582
#> 30 3 0.3 V2 0.3668449
#> 31 4 0.4 V1 0.3628897
#> 32 4 0.4 V9 0.3897706
#> 33 4 0.4 V3 0.3967840
#> 34 4 0.4 V4 0.3548278
#> 35 4 0.4 V5 0.3567467
#> 36 4 0.4 V2 0.3663093
#> 37 4 0.4 V6 0.3904624
#> 38 4 0.4 V7 0.4109548
#> 39 4 0.4 V8 0.3731775
#> 40 4 0.4 V10 0.4009494
#> 41 5 0.5 V8 0.3725905
#> 42 5 0.5 V9 0.3891669
#> 43 5 0.5 V10 0.4003573
#> 44 5 0.5 V1 0.3624218
#> 45 5 0.5 V5 0.3562127
#> 46 5 0.5 V2 0.3657746
#> 47 5 0.5 V3 0.3962297
#> 48 5 0.5 V4 0.3542365
#> 49 5 0.5 V6 0.3898318
#> 50 5 0.5 V7 0.4102973
#> 51 6 0.6 V4 0.3536462
#> 52 6 0.6 V5 0.3556796
#> 53 6 0.6 V7 0.4096409
#> 54 6 0.6 V8 0.3720045
#> 55 6 0.6 V9 0.3885641
#> 56 6 0.6 V6 0.3892021
#> 57 6 0.6 V10 0.3997661
#> 58 6 0.6 V1 0.3619546
#> 59 6 0.6 V2 0.3652406
#> 60 6 0.6 V3 0.3956761
#> 61 7 0.7 V1 0.3614879
#> 62 7 0.7 V3 0.3951233
#> 63 7 0.7 V4 0.3530569
#> 64 7 0.7 V5 0.3551473
#> 65 7 0.7 V9 0.3879623
#> 66 7 0.7 V6 0.3885735
#> 67 7 0.7 V7 0.4089855
#> 68 7 0.7 V8 0.3714194
#> 69 7 0.7 V2 0.3647074
#> 70 7 0.7 V10 0.3991758
#> 71 8 0.8 V9 0.3873614
#> 72 8 0.8 V10 0.3985863
#> 73 8 0.8 V1 0.3610219
#> 74 8 0.8 V5 0.3546158
#> 75 8 0.8 V2 0.3641750
#> 76 8 0.8 V3 0.3945712
#> 77 8 0.8 V4 0.3524686
#> 78 8 0.8 V8 0.3708353
#> 79 8 0.8 V6 0.3879458
#> 80 8 0.8 V7 0.4083311
#> 81 9 0.9 V5 0.3540851
#> 82 9 0.9 V7 0.4076778
#> 83 9 0.9 V8 0.3702520
#> 84 9 0.9 V9 0.3867614
#> 85 9 0.9 V6 0.3873192
#> 86 9 0.9 V10 0.3979977
#> 87 9 0.9 V1 0.3605564
#> 88 9 0.9 V2 0.3636433
#> 89 9 0.9 V3 0.3940199
#> 90 9 0.9 V4 0.3518813
#> 91 10 1.0 V1 0.3600916
#> 92 10 1.0 V4 0.3512949
#> 93 10 1.0 V5 0.3535551
#> 94 10 1.0 V9 0.3861624
#> 95 10 1.0 V3 0.3934694
#> 96 10 1.0 V7 0.4070256
#> 97 10 1.0 V8 0.3696697
#> 98 10 1.0 V2 0.3631124
#> 99 10 1.0 V6 0.3866936
#> 100 10 1.0 V10 0.3974100