Learn R Programming

fb4package (version 2.0.0)

predict_consumption_bootstrap: Bootstrap method for consumption uncertainty propagation

Description

Propagates p-value uncertainty to consumption predictions using parametric bootstrap. Generates multiple samples from the p-value distribution and runs FB4 simulations for each sample. Provides full uncertainty distribution without linearity assumptions. Supports parallel processing for improved performance.

Usage

predict_consumption_bootstrap(
  p_mean,
  p_sd,
  bio_obj,
  n_sims = 1000,
  first_day = 1,
  last_day = 365,
  parallel = FALSE,
  n_cores = NULL,
  confidence_level = 0.95,
  verbose = FALSE
)

Value

A named list with elements:

method

Character string "bootstrap".

consumption_mean

Mean total consumption across bootstrap samples (g).

consumption_sd

Standard deviation of consumption across samples (g).

consumption_ci

Numeric vector of length 2 with lower and upper quantile-based confidence interval bounds (g).

consumption_samples

Numeric vector of all successful consumption estimates from bootstrap samples.

n_successful

Number of bootstrap iterations that produced valid consumption estimates.

p_mean

The supplied p_mean value.

p_sd

The supplied p_sd value.

Arguments

p_mean

Mean of p-value distribution

p_sd

Standard deviation of p-value distribution

bio_obj

Bioenergetic object with simulation settings and environmental data

n_sims

Number of bootstrap simulations, default 1000

first_day

First simulation day, default 1

last_day

Last simulation day, default 365

parallel

Use parallel processing, default FALSE

n_cores

Number of cores for parallel processing (NULL = auto-detect), default NULL

confidence_level

Confidence level for intervals, default 0.95

verbose

Show progress messages, default FALSE

Details

The bootstrap method: 1. Samples p-values from Normal(p_mean, p_sd) 2. Constrains samples to valid range [0.01, 5.0] 3. Runs FB4 simulation for each p-value sample 4. Summarizes consumption distribution

Parallel processing can significantly reduce computation time for large n_sims. The method handles simulation failures gracefully and reports success rates.

Examples

Run this code
# \donttest{
data(fish4_parameters)
sp   <- fish4_parameters[["Oncorhynchus tshawytscha"]]$life_stages$adult
info <- fish4_parameters[["Oncorhynchus tshawytscha"]]$species_info
bio  <- Bioenergetic(
  species_params     = sp,
  species_info       = info,
  environmental_data = list(
    temperature = data.frame(Day = 1:30, Temperature = rep(12, 30))
  ),
  diet_data = list(
    proportions = data.frame(Day = 1:30, Prey1 = 1.0),
    energies    = data.frame(Day = 1:30, Prey1 = 5000),
    prey_names  = "Prey1"
  ),
  simulation_settings = list(initial_weight = 100, duration = 30)
)
bio$species_params$predator$ED_ini <- 5000
bio$species_params$predator$ED_end <- 5500
uncertainty_result <- predict_consumption_bootstrap(
  p_mean   = 0.5,
  p_sd     = 0.05,
  bio_obj  = bio,
  n_sims   = 20,
  last_day = 30
)
# }

Run the code above in your browser using DataLab