Skip to contents

Bayesian population model for boreal caribou

Usage

caribouBayesianPM(
  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

a list of model priors. 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 getPriors() for details.

startYear, endYear

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

N0

Number or vector of numbers. Initial population size for one or more sample populations. If NA then population growth rate is $_t=S_t*(1+cR_t)/s$.

returnSamples

logical. If F returns only summaries. If T 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

A whole number of the number of iterations per chain after thinning and burn-in.

nthin

integer. The number of the thinning rate.

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 <- caribouBayesianPM(
    surv_data = bboudata::bbousurv_a,
    recruit_data = bboudata::bbourecruit_a,
    disturbance = NULL
  )
#> Warning: requested year range: 1986 - 2016 does not match recruitment data year range:  1990 - 2016
#> Warning: missing years of recruitment data: 1986, 1987, 1988, 1989
#> warning: value of stochastic node FemaleYearlings[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[1]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[2]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[3]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[4]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[1]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[2]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[3]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[4]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[1]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[2]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[3]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[4]: logProb is NA or NaN.
#> warning: value of deterministic node AdultsFemales[1]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[2]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[3]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[4]: value is NA or NaN even after trying to calculate.
#> warning: value of stochastic node Calves[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[1]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[2]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[3]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[4]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[1]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[2]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[3]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[4]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[1]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[2]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[3]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[4]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[1]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[2]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[3]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[4]: logProb is NA or NaN.
#> warning: value of deterministic node AdultsFemales[1]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[2]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[3]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[4]: value is NA or NaN even after trying to calculate.
#> warning: value of stochastic node Calves[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[1]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[2]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[3]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[4]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[1]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[2]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[3]: logProb is NA or NaN.
#> warning: value of stochastic node FemaleYearlings[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node FemaleYearlings[4]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[1]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[2]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[3]: logProb is NA or NaN.
#> warning: value of stochastic node Cows[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Cows[4]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[1]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[2]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[3]: logProb is NA or NaN.
#> warning: value of stochastic node OtherAdultsFemales[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node OtherAdultsFemales[4]: logProb is NA or NaN.
#> warning: value of deterministic node AdultsFemales[1]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[2]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[3]: value is NA or NaN even after trying to calculate.
#> warning: value of deterministic node AdultsFemales[4]: value is NA or NaN even after trying to calculate.
#> warning: value of stochastic node Calves[1]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[1]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[2]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[2]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[3]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[3]: logProb is NA or NaN.
#> warning: value of stochastic node Calves[4]: value is NA or NaN even after trying to simulate.
#> warning: problem initializing stochastic node Calves[4]: logProb is NA or NaN.
  str(mod, max.level = 2)
#> List of 2
#>  $ result:List of 5
#>   ..$ summary     :'data.frame':	310 obs. of  10 variables:
#>   ..$ samples     : tibble [1,209,000 × 9] (S3: tbl_df/tbl/data.frame)
#>   ..$ surv_data   :'data.frame':	372 obs. of  9 variables:
#>   ..$ recruit_data: tibble [31 × 9] (S3: tbl_df/tbl/data.frame)
#>   ..$ popInfo     :'data.frame':	3000 obs. of  5 variables:
#>  $ inData:List of 1
#>   ..$ disturbanceIn: NULL
  
  # Using simulated observation data
  scns <- getScenarioDefaults(projYears = 10, obsYears = 10,
                              obsAnthroSlope = 1, projAnthroSlope = 5,
                              collarCount = 20, cowMult = 5)
  
  simO <- simulateObservations(scns)
  
  out <- caribouBayesianPM(surv_data = simO$simSurvObs, recruit_data = simO$simRecruitObs,
                           disturbance = simO$simDisturbance,
                           startYear = 2014)
#> Registered S3 method overwritten by 'rjags':
#>   method               from 
#>   as.mcmc.list.mcarray mcmcr
#> 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: 29
#>    Unobserved stochastic nodes: 70
#>    Total graph size: 694
#> 
#> Initializing model
#> 
# }