Skip to contents

Bayesian population model for boreal caribou

Usage

bayesianTrajectoryWorkflow(
  surv_data = bboudata::bbousurv_a,
  recruit_data = bboudata::bbourecruit_a,
  disturbance = NULL,
  priors = "default",
  startYear = NULL,
  endYear = NULL,
  N0 = NA,
  returnSamples = F,
  inputList = list(),
  niters = formals(bboutools::bb_fit_survival)$niters,
  nthin = formals(bboutools::bb_fit_survival)$nthin,
  ...
)

Arguments

surv_data

either a path to a csv file or a survival data table in bboutools format.

recruit_data

either a path to a csv file or a recruitment data table in bboutools format.

disturbance

either a path to a csv file or a dataframe containing the columns "Anthro","Fire_excl_anthro", and "Year".

priors

list. Optional. If disturbance is NA, this should be list(priors_survival=c(...),priors_recruitment=c(...)); see bboutools::bb_priors_survival and bboutools::bb_priors_recruitment for details. If disturbance is not NA, see betaNationalPriors for details.

startYear, endYear

year defining the beginning of the observation period and the end of the projection period.

N0

number or dataframe. Optional. Initial population size(s). If NA (default) then population growth rate is $_t=S_t*(1+cR_t)/s$. If a data frame N0 column is required, and PopulationName column is required if there is more than one row. Additional (optional) variation columns will be used by addN0Variation().

returnSamples

logical. If FALSE returns only summaries. If TRUE returns example trajectories.

inputList

an optional list of inputs with names matching the above. If an argument is included in this list it will override the named argument.

niters

integer. The number of iterations per chain after thinning and burn-in.

nthin

integer. The number of the thinning rate.

...

Other parameters passed on to bboutools::bb_fit_survival and bboutools::bb_fit_recruitment.

Value

a list with elements:

  • result: a list of model results:

    • summary: a data.frame

    • samples: a tibble providing the full range of MCMC trajectories from the model. It is in a long format where "Amount" gives the value for each metric in Anthro, Fire_excl_anthro, c, survival, recruitment, X, N, lambda, Sbar, Rbar, Xbar, Nbar, and lambda_bar, with a row for each combination of "MetricTypeID", "Replicate", "Year" and "LambdaPercentile"

    • surv_data: a data.frame

    • recruit_data: a tibble

    • popInfo: a data.frame

  • inData: a list of data that is used as input to the jags model:

    • survDataIn: survival data

    • disturbanceIn: disturbance data

    • recruitDataIn: composition data

Examples

# \donttest{
  # Note these examples take a long time to run!
  
  # Using observed survival, recruitment and disturbance data
  mod <- bayesianTrajectoryWorkflow(
    surv_data = bboudata::bbousurv_a,
    recruit_data = bboudata::bbourecruit_a,
    disturbance = NULL
  )
#> Warning: missing years of recruitment data: 1985, 1986, 1987, 1988
  str(mod, max.level = 2)
#> List of 4
#>  $ result :List of 4
#>   ..$ summary     :'data.frame':	320 obs. of  8 variables:
#>   ..$ surv_data   :'data.frame':	384 obs. of  9 variables:
#>   ..$ recruit_data:'data.frame':	32 obs. of  9 variables:
#>   ..$ popInfo     :'data.frame':	3000 obs. of  4 variables:
#>  $ inData :List of 1
#>   ..$ disturbanceIn: NULL
#>  $ parTab :'data.frame':	1 obs. of  18 variables:
#>   ..$ PopulationName: chr "A"
#>   ..$ R_bar         : num 0.198
#>   ..$ R_sd          : num 0.0888
#>   ..$ R_iv_mean     : num 0.322
#>   ..$ R_iv_shape    : num 13.6
#>   ..$ R_bar_lower   : num 0.171
#>   ..$ R_bar_upper   : num 0.227
#>   ..$ S_bar         : num 0.874
#>   ..$ S_sd          : num 0.171
#>   ..$ S_iv_mean     : num 0.363
#>   ..$ S_iv_shape    : num 4.4
#>   ..$ S_bar_lower   : num 0.836
#>   ..$ S_bar_upper   : num 0.907
#>   ..$ N0            : logi NA
#>   ..$ nCollarYears  : num NA
#>   ..$ nSurvYears    : int 32
#>   ..$ nCowsAllYears : int NA
#>   ..$ nRecruitYears : int 31
#>  $ parList:List of 5
#>   ..$ Rbar:'data.frame':	32 obs. of  7 variables:
#>   ..$ Sbar:'data.frame':	32 obs. of  7 variables:
#>   ..$ Siv :'data.frame':	1 obs. of  2 variables:
#>   ..$ Riv :'data.frame':	1 obs. of  2 variables:
#>   ..$ type: chr "bbou"
  
  # Using simulated observation data
  scns <- getScenarioDefaults(projYears = 10, obsYears = 10,
                              obsAnthroSlope = 1, projAnthroSlope = 5,
                              collarCount = 20, cowMult = 5)
  
  simO <- simulateObservations(scns)
  
  out <- bayesianTrajectoryWorkflow(surv_data = simO$simSurvObs, recruit_data = simO$simRecruitObs,
                           disturbance = simO$simDisturbance,
                           startYear = 2014)
#> Compiling model graph
#>    Resolving undeclared variables
#>    Allocating nodes
#> Graph information:
#>    Observed stochastic nodes: 10
#>    Unobserved stochastic nodes: 33
#>    Total graph size: 665
#> 
#> Initializing model
#> 
#> Compiling model graph
#>    Resolving undeclared variables
#>    Allocating nodes
#> Graph information:
#>    Observed stochastic nodes: 20
#>    Unobserved stochastic nodes: 84
#>    Total graph size: 729
#> 
#> Initializing model
#> 
# }