Learn R Programming

biogrowth (version 0.2.0)

predict_MCMC_growth: Stochastic growth of MCMC fit

Description

Makes a stochastic prediction of microbial growth based on a growth model fitted using fit_MCMC_growth or fit_multiple_growth_MCMC. This function predicts growth curves for niter samples (with replacement) of the samples of the MCMC algorithm. Then, credible intervals are calculated based on the quantiles of the model predictions at each time point.

Usage

predict_MCMC_growth(MCMCfit, times, env_conditions, niter, newpars = NULL)

Arguments

MCMCfit

An instance of FitDynamicGrowthMCMC or FitMultipleGrowthMCMC.

times

Numeric vector of storage times for the predictions.

env_conditions

Tibble with the (dynamic) environmental conditions during the experiment. It must have one column named 'time' with the storage time and as many columns as required with the environmental conditions.

niter

Number of iterations.

newpars

A named list defining new values for the some model parameters. The name must be the identifier of a model already included in the model. These parameters do not include variation, so defining a new value for a fitted parameters "fixes" it. NULL by default (no new parameters).

Value

An instance of MCMCgrowth.

Examples

Run this code
# NOT RUN {
## We need a FitDynamicGrowthMCMC object

data("example_dynamic_growth")
data("example_env_conditions")

sec_model_names <- c(temperature = "CPM", aw= "CPM")

known_pars <- list(Nmax = 1e4,  # Primary model
    N0 = 1e0, Q0 = 1e-3,  # Initial values of the primary model
    mu_opt = 4, # mu_opt of the gamma model
    temperature_n = 1,  # Secondary model for temperature
    aw_xmax = 1, aw_xmin = .9, aw_n = 1  # Secondary model for water activity
    )

my_start <- list(temperature_xmin = 25, temperature_xopt = 35,
    temperature_xmax = 40,
    aw_xopt = .95)

set.seed(12124) # Setting seed for repeatability

my_MCMC_fit <- fit_MCMC_growth(example_dynamic_growth, example_env_conditions,
    my_start, known_pars, sec_model_names, niter = 3000)

## Define the conditions for the simulation

my_times <- seq(0, 15, length = 50)
niter <- 2000

newpars <- list(N0 = 1e-1,  # A parameter that was fixed
                temperature_xmax = 120  # A parameter that was fitted
                )


## Make the simulations

my_MCMC_prediction <- predict_MCMC_growth(my_MCMC_fit,
    my_times,
    example_env_conditions, # It could be different from the one used for fitting
    niter,
    newpars)
    
## We can plot the prediction interval

plot(my_MCMC_prediction)

## We can also get the quantiles at each time point

print(my_MCMC_prediction$quantiles)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab