Datasets included in the package
The biogrowth package includes three datasets to aid in the understanding of its functions: * example_cardinal
: an example of the results of a set of growth experiments to estimate cardinal parameters. * example_dynamic_growth
and example_env_conditions
: an example of the results of a dynamic growth experiment.
All of them are automatically saved when the package is installed. Each one of them can be loaded with a call to the function data()
passing the name of the dataset as an argument.
The dataset example_cardinal
includes an example of the type of data used for estimating cardinal model parameters. It has three columns: temperature, pH and mu. The two first represent the storage conditions during several static growth experiments, whereas the latter is the specific growth rate estimated in those experiments. This dataset is intended to be used for fit_secondary_growth()
.
data("example_cardinal")
head(example_cardinal)
#> temperature pH mu
#> 1 0.000000 5 9.768505e-04
#> 2 5.714286 5 2.624919e-03
#> 3 11.428571 5 0.000000e+00
#> 4 17.142857 5 1.530706e-04
#> 5 22.857143 5 2.301817e-05
#> 6 28.571429 5 3.895598e-04
The datasets example_dynamic_growth
and example_env_conditions
describe a dynamic growth experiment, which can be used for the fit_dynamic_growth()
function. The dataset example_env_conditions
describes the experimental design; i.e. how the environmental factors vary during the experiment. It has three columns: time (the elapsed time), temperature (the storage temperature) and aw (the water activity).
data("example_env_conditions")
head(example_env_conditions)
#> # A tibble: 3 x 3
#> time temperature aw
#> <dbl> <dbl> <dbl>
#> 1 0 20 0.99
#> 2 5 30 0.95
#> 3 15 35 0.9
The dataset example_dynamic_growth
illustrates the microbial counts observed during the experiment described by example_env_conditions
. It has two columns: time (the elapsed time) and logN (the observed microbial count).
data("example_dynamic_growth")
head(example_dynamic_growth)
#> # A tibble: 6 x 2
#> time logN
#> <deSolve> <deSolve>
#> 1 0.0000000 0.066970558
#> 2 0.5172414 -0.004634428
#> 3 1.0344828 -0.097964735
#> 4 1.5517241 -0.098558778
#> 5 2.0689655 0.110913049
#> 6 2.5862069 -0.046531175
The dataset multiple_experiments
simulates several growth experiments performed for the same microorganism under dynamic conditions that vary between experiments. It is a nested list with two elements, each describing a single experiment.
data("multiple_experiments")
length(multiple_experiments)
#> [1] 2
Each experiment is described using a list with two elements: data
and conditions
. The former is a tibble with two columns: time
(the elapsed time) and logN
the observed microbial count.
head(multiple_experiments[[1]]$data)
#> # A tibble: 6 x 2
#> time logN
#> <dbl> <dbl>
#> 1 0 -0.208
#> 2 1.67 -0.0363
#> 3 3.33 -0.298
#> 4 5 0.350
#> 5 6.67 0.143
#> 6 8.33 -0.404
Then, conditions
is also a tibble with one column named time
(elapsed time), one called temperature
(the storage temperature) and another one called pH
(the pH of the media).
print(multiple_experiments[[1]]$conditions)
#> # A tibble: 3 x 3
#> time temperature pH
#> <dbl> <dbl> <dbl>
#> 1 0 20 6.5
#> 2 15 30 7
#> 3 40 40 6.5
The second experiment is described using the same structure.
head(multiple_experiments[[2]]$data)
#> # A tibble: 6 x 2
#> time logN
#> <dbl> <dbl>
#> 1 0 0.533
#> 2 1.67 -0.336
#> 3 3.33 0.0650
#> 4 5 -0.121
#> 5 6.67 0.165
#> 6 8.33 -0.0198
print(multiple_experiments[[2]]$conditions)
#> # A tibble: 3 x 3
#> time temperature pH
#> <dbl> <dbl> <dbl>
#> 1 0 25 7
#> 2 15 30 6
#> 3 40 25 5
Deterministic modelling
Growth prediction under static conditions
The biogrowth package includes the function predict_isothermal_growth
to make predictions under static conditions. The calculations are based on the primary model, without the need of defining a secondary model. This function has 3 arguments:
model_name
: a character vector indicating the primary model. Admisible values are those returned by primary_model_data
.
times
: a numeric vector of storage times to make the predictions.
model_pars
: a named list defining the values of the model parameters.
For instance, to make predictions using the modified Gompertz model we would define
my_model <- "modGompertz"
This model has 3 model parameters: mu
, lambda
and C
(retrieved using primary_model_data
). Additional, for making the calculations, we need to define an initial microbial count (logN0
). All this information must be defined in a single list:
my_pars <- list(logN0 = 2, C = 6, mu = .2, lambda = 25)
Finally, we have to define the storage times for which the prediction is calculated. For instance, we can define
my_time <- seq(0, 100, length = 1000)
Once we have defined the arguments, we can call the function predict_isothermal_growth
to get the model predictions. This function automatically checks that the number of model parameters and their names and raises a warning or error if there are mismatches between the arguments and the model definition.
static_prediction <- predict_isothermal_growth(my_model, my_time, my_pars)
This function returns a list of class IsothermalGrowth
with the results of the simulation. It has three items:
simulation
: A tibble with the results of the simulation.
model
: The name of the model used for making the calculations.
pars
: Vector of model parameters used for the calculations.
Hence, we can retrieve the results of the simulation by accessing the simulation
item
static_prediction$simulation
#> # A tibble: 1,000 x 2
#> time logN
#> <dbl> <dbl>
#> 1 0 2.
#> 2 0.100 2.
#> 3 0.200 2.
#> 4 0.300 2.
#> 5 0.400 2.
#> 6 0.501 2.
#> 7 0.601 2.
#> 8 0.701 2.
#> 9 0.801 2.
#> 10 0.901 2.
#> # ... with 990 more rows
Alternatively, this class implements an S3 method for plot that illustrates the survivor curve:

The plot is generated as a gpplot object, with theme_cowplot() as default. Therefore, it can be edited using layers as usual in the ggplot2 package. For instance,
plot(static_prediction) +
xlab("Storage time (h)") +
ylab("Microbial count (log CFU/ml)") +
theme_gray()

See the vignette #ADD LINK HERE for pretty graphics
Growth prediction under dynamic conditions
The biogrowth package can also be used for simulating growth under dynamic conditions using the predict_dynamic_growth()
function. This function has 5 arguments:
times
: Numeric vector of storage times to make the calculations.
env_conditions
: A tibble describing the variation of the environmental conditions through storage.
primary_pars
: A list describing the model parameters of the primary model.
secondary_models
: A nested list defining the secondary model(s).
...
: Additional arguments passed to the numeric solver of the differential equation.
The varying environmental conditions are defined using a tibble. This object must have a column named time
and as many additional columns as needed for each environmental factor. For the simulations, the value of the environmental conditions at time points not included in env_conditions
is calculated by linear interpolation.
For instance, we can define the temperature and pH variation through storage using the following tibble:
my_conditions <- tibble(time = c(0, 5, 40),
temperature = c(20, 30, 35),
pH = c(7, 6.5, 5)
)
Then, the simulations would consider this temperature profile
ggplot(my_conditions) +
geom_line(aes(x = time, y = temperature))

And this pH profile
ggplot(my_conditions) +
geom_line(aes(x = time, y = pH))

Therefore, in order to get smoother profiles, one has to define additional rows in the tibble.
For dynamic conditions, biogrowth can only use the Baranyi growth model as primary model. This model requires the definition of two model parameters: the specific growth rate at optimum conditions (mu_opt
) and the maximum microbial count (Nmax
). Moreover, the initial values of the microbial count (N0
) and the theoretical substance \(Q\) (Q0
) must be defined. Note that \(Q_0\) is related to the duration of the lag phase under isothermal conditions by the identity \(\lambda = \ln \left( 1 + 1/q_0 \right)/\mu_{max}\). For the predict_dynamic_growth()
function, they all must be defined in a single list:
my_primary <- list(mu_opt = 2,
Nmax = 1e8,
N0 = 1e0,
Q0 = 1e-3)
The next step is the definition of the secondary models. As already described above, biogrowth describes the variation of \(\mu\) with temperature based on the gamma concept. Therefore, we need to define one secondary model per environmental condition. This must be done using a list. We define a list per environmental condition and this list defines the type of gamma model as well as the model parameters. The function secondary_model_data()
can aid in the definition of the secondary models.
For instance, we will define a gamma-type model for temperature as defined by Zwietering et al. This is done by including an item called model
in the list and assigning it the value "Zwietering"
. Then, we define the values of the model parameters. In this case, we need the minimum (xmin
) and optimum (xopt
) cardinal values, as well as the order of the model (n
) (this information can be retrieved using secondary_model_data
). We define them using individual entries in the list:
sec_temperature <- list(model = "Zwietering",
xmin = 25,
xopt = 35,
n = 1)
Next, we will define a CPM model for the effect of pH. Note that the model selection is for illustration purposes, not based on predictive power. The definition is very similar as for the Zwietering-type model. First of all, we need to set the item model
to "CPM"
instead of "Zwietering"
. Then, we need to give one additional parameter value (xmax
):
sec_pH = list(model = "CPM",
xmin = 5.5,
xopt = 6.5,
xmax = 7.5,
n = 2)
The final step for the definition of the gamma-type secondary model is putting all the individual models together in a single list. Be mindful, though, that every element on the list must be named using the same column names as in env_conditions
. Before, we had used the column names temperature
and pH
. Therefore, we must repeat the exact same names in the definition of the secondary model.
my_secondary <- list(
temperature = sec_temperature,
pH = sec_pH
)
The final argument is the time points where to make the calculations. We can use a numeric vector between 0 and 50 for this:
my_times <- seq(0, 50, length = 1000)
Once we have defined every argument, we can call the predict_dynamic_growth()
function:
dynamic_prediction <- predict_dynamic_growth(my_times,
my_conditions, my_primary,
my_secondary)
This function returns a list of class DynamicGrowth
with several items:
simulation
: A tibble with the results of the simulation.
gammas
: A tibble describing the variation of each gamma factor through the simulation.
env_conditions
: Environmental conditions used for the simulations.
primary_pars
: Primary model parameters used for the simulations.
sec_models
: Secondary model parameters used for the simulations.
Therefore, the results of the simulation can be retrieved from the simulation
item:
dynamic_prediction$simulation
#> # A tibble: 1,000 x 4
#> time Q N logN
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0 0.001 1 0
#> 2 0.0501 0.001 1 0
#> 3 0.100 0.001 1 0
#> 4 0.150 0.001 1 0
#> 5 0.200 0.001 1 0
#> 6 0.250 0.001 1 0
#> 7 0.300 0.001 1 0
#> 8 0.350 0.001 1 0
#> 9 0.400 0.001 1 0
#> 10 0.450 0.001 1 0
#> # ... with 990 more rows
Alternatively, this class implements an S3 method for plot that can be used to visualize the growth curve:

The argument add_factor
of the plot method can be used to plot the variation of a single environmental factor through storage. For that, one has to pass the name of the desired factor to the function. Note that this name must be identical to the one used for the columns in env_conditions
. For instance, we can add the plot of temperature
plot(dynamic_prediction, add_factor = "temperature")

The arguments ylims
, label_y1
and label_y2
enable to further edit the plot by changing the limits of the y-axis and the names of the primary and secondary axes:
plot(dynamic_prediction, add_factor = "temperature", ylims= c(0, 8),
label_y1 = "Microbial count (log CFU/ml)", label_y2 = "Storage temperature (ºC)")

Time to reach a given microbial count
For shelf-life estimation and food safety, it is usually of interest to calculate the storage time required to reach a given microbial count. The biogrowth package includes the function time_to_logcount()
can be used for this purpose. This function has 2 arguments:
model
: A model returned by predict_dynamic_growth()
or predict_isothermal_growth()
.
log_count
: target microbial count.
For instance, we can use this function to estimate the time required to reach a microbial count of 2.5 log CFU/ml for the static prediction we did earlier:
time_to_logcount(static_prediction, 2.5)
#> [1] 25.99053
Or the time required to reach 5 log CFU/ml in the dynamic prediction:
time_to_logcount(dynamic_prediction, 5)
#> [1] 11.36447
If the value of log_count
was outside the range of the simulations, the function returns an NA
:
time_to_logcount(dynamic_prediction, 10)
#> [1] NA
Note that the calculations are based on linear interpolation of the simulated growth curve. Therefore, its accuracy is strongly dependent on the number of time points used for the simulation.
Fitting of primary models
The function fit_isothermal_growth()
can be used to estimate the values of primary growth models from data obtained under static conditions. This function has 4 arguments:
fit_data
defines the data used for model fitting.
model_name
defines the primary model to use (according to primary_model_data()
).
starting_point
defines the initial values of the model parameters (according to primary_model_data()
).
known_pars
defines parameters that are considered known and are not fitted to the data.
...
can be used to pass additional arguments to the modFit()
function from the FME package (e.g. lower and upper bounds for the model parameters).
The data used for model fitting is defined through the fit_data
argument. It must be a tibble with two columns named time
(the elapsed time) and logN
(the microbial count).
my_data <- tibble(time = c(0, 25, 50, 75, 100),
logN = c(2, 2.5, 7, 8, 8))
The primary model is defined using model_name
. For instance, we can use the Baranyi model in this example:
This function uses non-linear regression (through the modFit()
function of the FME package), so it requires initial values for every model parameter to fit. In the case of the Baranyi model, the model parameters are: mu
, lambda
and logNmax
. Additional, the initial microbial count must be defined. Nonetheless, the fit_isothermal_growth()
function enables to fix any model parameter before model fit using the known_pars
argument. For instance, we can fix the specific growth rate to 0.2
And fit the remaining model parameters
start = c(logNmax = 8, lambda = 25, logN0 = 2)
Once every model parameter has been defined, we can call the fit_isothermal_growth()
function:
static_fit <- fit_isothermal_growth(my_data, my_model,
start, known
)
This function returns a list of class FitIsoGrowth
with several items:
data
: data used for model fitting
model
: name of the primary model
starting_point
: starting point used for model fitting
known
: fixed model parameters
fit
: object returned by modFit()
best_prediction
: an instance of IsothermalGrowth
corresponding to the fitted model.
The FitIsoGrowth
class includes several S3 methods to visualize the results. The statistical information of the fit can be retrieved using summary()
summary(static_fit)
#>
#> Parameters:
#> Estimate Std. Error t value Pr(>|t|)
#> logNmax 7.99600 0.06980 114.56 7.62e-05 ***
#> lambda 24.64154 0.74220 33.20 0.000906 ***
#> logN0 2.05084 0.09201 22.29 0.002007 **
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 0.09879 on 2 degrees of freedom
#>
#> Parameter correlation:
#> logNmax lambda logN0
#> logNmax 1.00000 0.05788 0.01589
#> lambda 0.05788 1.00000 0.76437
#> logN0 0.01589 0.76437 1.00000
whereas plot()
compares the data and the fitted curve

Fitting of secondary (gamma) models
The function fit_secondary_growth()
can be used to estimate the values of the cardinal parameters from the specific growth rates observed in a series of static growth experiments. This function has 6 arguments:
fit_data
: data used for the fit.
starting_point
: initial value of the model parameters
known_pars
: model parameters fixed (not fitted to the data).
sec_model_names
: type of secondary model for each environmental factor.
transformation
: transformation of the growth rate for the fit (square root by default).
...
: additional arguments passed to modFit()
.
A method to estimate the cardinal parameters is based on realizing various static growth experiments under a variety of experimental conditions. Such dataset is passed using the fit_data
argument. The biogrowth package includes an example dataset with the right format.
data("example_cardinal")
head(example_cardinal)
#> temperature pH mu
#> 1 0.000000 5 9.768505e-04
#> 2 5.714286 5 2.624919e-03
#> 3 11.428571 5 0.000000e+00
#> 4 17.142857 5 1.530706e-04
#> 5 22.857143 5 2.301817e-05
#> 6 28.571429 5 3.895598e-04
This dataset must have one column named mu
with the observed growth rate. Then, it must have as many additional columns as environmental factors included in the experiment. In the example dataset, the series of experiments considered two environmental conditions: temperature and pH. Nonetheless, the fit_secondary_growth()
function is entirely flexible with respect to the number of factors and their names. The only restriction is that the definition of the columns of the dataset and the secondary models is consistent.
The type of secondary model to use for each environmental factor is defined in the sec_model_names
argument. It is a named vector whose names are the environmental factors and whose values define the model to use. The list of available models can be retrieved using secondary_model_data()
. For this example, we will use a CPM for the pH and an Zwietering model for temperature (this decision is not based on any scientific argument, just as demonstration of the functions in the package). Note that the names of the vector are identical to the column names of fit_data
.
sec_model_names <- c(temperature = "Zwietering",
pH = "CPM")
The fit_secondary_growth()
function estimates the values of the cardinal parameters, as well as the specific growth rate under optimal conditions. Also, it enables to fix any model parameter to an arbitrary value before fitting the model. The model parameters to fit are defined using the known_pars
argument. The remaining parameters, because of the use of non-linear regression for parameter estimation, require the definition of initial parameter values.
The specific growth rate under optimal conditions is named mu_opt
. The remaining cardinal parameters are named according to the convention environ_factor
+_
+parameter(lower case)
. For instance, the minimum temperature for growth is temperature_xmin
and the order of the CPM for pH is pH_n
. Note that the environmental factor must be identical to the one used in sec_model_names
.
For this example, we will consider that the maximum specific growth rate is known, as well as most of the the cardinal parameters for pH. For temperature, we will only fix the order of the model.
known_pars <- list(mu_opt = 1.2,
temperature_n = 1,
pH_n = 2, pH_xmax = 6.8, pH_xmin = 5.2
)
The remaining model parameters will be fitted using reasonable initial values.
my_start <- list(temperature_xmin = 5, temperature_xopt = 35,
pH_xopt = 6.5)
Finally, the transformation
argument defines the transformation of the growth rate to use for model fitting. By default, the function applies a square root transformation, which has proved to stabilize the variance of microbial growth. Once the arguments have been defined, we can call the fit_secondary_growth()
function. Note that, because we are using the default value of transformation
, we do not need to define this argument:
fit_cardinal <- fit_secondary_growth(example_cardinal, my_start, known_pars, sec_model_names)
This function returns an instance of FitSecondaryGrowth
with 5 items:
fit_results
the object returned by modFit
.
secondary_model
parameters of the secondary model.
mu_opt_fit
growth rate under optimal storage conditiosn.
data
data used for the fit.
transformation
tranformation applied to the growth rate before fitting.
This class incorporates several S3 method to ease visualization of results. The function summary()
returns the statistical information of the fit.
summary(fit_cardinal)
#>
#> Parameters:
#> Estimate Std. Error t value Pr(>|t|)
#> temperature_xmin 5.31768 0.14965 35.53 <2e-16 ***
#> temperature_xopt 34.29640 0.76253 44.98 <2e-16 ***
#> pH_xopt 6.51109 0.01171 555.90 <2e-16 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 0.04026 on 61 degrees of freedom
#>
#> Parameter correlation:
#> temperature_xmin temperature_xopt pH_xopt
#> temperature_xmin 1.000e+00 -0.1911 -2.376e-09
#> temperature_xopt -1.911e-01 1.0000 -2.173e-01
#> pH_xopt -2.376e-09 -0.2173 1.000e+00
The package includes S3 methods to plot the results. By default, a plot comparing observed and predicted values is shown
plot(fit_cardinal)
#> `geom_smooth()` using formula 'y ~ x'

In this plot, the dashed line is the line with intercept 0 and slope 1 where every point should fall in case of a perfect fit. The solid grey line is the regression line of predictions vs observations.
Alternativelly, by passing the argument which=2
, one can plot the observed and predicted counts as a function of the environmental factors
plot(fit_cardinal, which = 2)

A trend line can be added to this plot using the add_trend=TRUE
argument:
plot(fit_cardinal, which = 2, add_trend = TRUE)
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Note that this line is not the predictions of the gamma model but a trend line based on the observations. Therefore, it can be used to compare the tendency of the model predictions against the one of the observations, but it should not be extrapolated for predictions.
One-step fitting under dynamic conditions
The function fit_dynamic_growth()
can be used to estimate the parameters of both the primary and the secondary model based on a growth experiment obtained under dynamic conditions. This function has 6 arguments:
fit_data
: data used for model fitting.
env_conditions
: variation of the environmental conditions during the experiment.
starting_point
: initial value of the model parameters.
known_pars
: model parameters known (i.e. not fitted).
sec_model_names
: type of secondary model for each environmental factor.
...
: additional arguments passed to modFit
.
The arguments env_conditions
and fit_data
are tibbles that describe, respectively, the experimental design and the observations. To help understanding fit_dynamic_growth()
, biogrowth includes two example datasets that can be used with this function:
data("example_dynamic_growth")
data("example_env_conditions")
The tibble passed to the argument env_conditions
must have a column named time
and as many additional columns as environmental factors. The fit_dynamic_growth()
function is totally flexible with respect to the number of factors or the way they are named. The only requirement is that the definition of every argument is consistent. In the case of example_env_conditions
, this dataset considers two factors: temperature and water activity (aw
).
head(example_env_conditions)
#> # A tibble: 3 x 3
#> time temperature aw
#> <dbl> <dbl> <dbl>
#> 1 0 20 0.99
#> 2 5 30 0.95
#> 3 15 35 0.9
Note that for the calculations this function joins the data points by linear interpolation, as shown in this plot:
ggplot(example_env_conditions, aes(x = time, y = temperature)) +
geom_line() +
geom_point()

In order to have a stepwise profile, one should define additional time points.
The tibble passed to the argument fit_data
must have two columns named time
(elapsed time) and logN
(log microbial count), in the same format as example_dynamic_growth
.
head(example_dynamic_growth)
#> # A tibble: 6 x 2
#> time logN
#> <deSolve> <deSolve>
#> 1 0.0000000 0.066970558
#> 2 0.5172414 -0.004634428
#> 3 1.0344828 -0.097964735
#> 4 1.5517241 -0.098558778
#> 5 2.0689655 0.110913049
#> 6 2.5862069 -0.046531175
The type of secondary model for each environmental factor is defined by the argument sec_model_names
. As in every function in biogrowth, this argument is a named vector where the names refer to the environmental factor and the value the type of model. Supported models can be retrieved using secondary_model_data()
. In this example we will use cardinal models for both environmental factors. Note that the names of this vector must be identical to the columns in env_conditions
.
sec_model_names <- c(temperature = "CPM",
aw= "CPM")
The fit_dynamic_growth()
function enables to fit or fix any model parameter. This distinction is made using the arguments known_pars
(fixed parameters) and starting_point
(fitted parameters). Note that these arguments must contain every parameter of the primary and secondary models.
Regarding the primary model, this function only enables the use of the Baranyi model. This primary model has two variables that need initial values (N0
and Q0
) and one primary model parameter (Nmax
). The specific growth rate is described using the gamma concept. This requires the definition of its value under optimal conditions (mu_opt
) as well as the cardinal parameters for each environmental factor. As well as for other functions, these must be defined as factor
+_
+parameter name
. For instance, the minimum water activity for growth must be written as aw_min
.
In this example we will consider the model parameters of the primary model as known. For the secondary model for water activity, we will only consider the optimum value for growth as unknown. Finally, for the effect of temperature, the only parameter we consider known is the order of the model:
known_pars <- list(Nmax = 1e4, # Nmax for 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
)
Then, the remaining model parameters must be defined in starting_points
. Due to the use of non-linear regression for model fitting, it is required to define initial values for these parameters. They can be defined based on previous esperience or preliminary numerical simulations.
my_start <- list(temperature_xmin = 25, temperature_xopt = 35,
temperature_xmax = 40,
aw_xopt = .95)
Once every model parameter has been defined, we can call the fit_dynamic_growth()
function.
my_dyna_fit <- fit_dynamic_growth(example_dynamic_growth, example_env_conditions,
my_start,
known_pars,
sec_model_names)
This function returns an instance of FitDynamicGrowth
with 6 items:
fit_results
: object returned by modFit()
.
best_prediction
: an instance of DynamicGrowth
with the prediction corresponding to the fitted model.
data
: data used to fit the model.
starting
: starting values used for parameter estimation.
known
: model parameters considered known.
sec_models
: type of secondary model for each environmental factor.
The FitDynamicGrowth
includes several S3 methods that ease the visualization of the results. The summary function returns the statistical information of the fit.
summary(my_dyna_fit)
#>
#> Parameters:
#> Estimate Std. Error t value Pr(>|t|)
#> temperature_xmin 2.667e+01 5.172e+01 0.516 0.610
#> temperature_xopt 3.888e+01 3.200e+03 0.012 0.990
#> temperature_xmax 7.044e+01 2.416e+04 0.003 0.998
#> aw_xopt 9.852e-01 2.771e+00 0.356 0.725
#>
#> Residual standard error: 0.1506 on 26 degrees of freedom
#>
#> Parameter correlation:
#> temperature_xmin temperature_xopt temperature_xmax aw_xopt
#> temperature_xmin 1.0000 0.9963 0.9970 -0.9945
#> temperature_xopt 0.9963 1.0000 1.0000 -0.9998
#> temperature_xmax 0.9970 1.0000 1.0000 -0.9996
#> aw_xopt -0.9945 -0.9998 -0.9996 1.0000
The plot()
method compares the model predictions against the data used for the fit:

The variation of the environmental factor can be plotted alongside the previous plot. For that, the name of the environmental factor must be passed to add_factor
. Note that the value passed must be identical to the one defined in the previous arguments. Then, the label of the primary or secondary axes can be changed using label_y1
or label_y2
plot(my_dyna_fit, add_factor = "aw",
label_y1 = "Log count (log CFU/ml)",
label_y2 = "Water activity")

Global fitting of various (dynamic) experiments
The function fit_multiple_growth()
can be used to fit one growth model to data gathered in various experiments performed under dynamic conditions. It has several arguments:
starting_point
starting values of the model parameters to fit.
experiment_data
a nested list describing the experimental data and conditions.
known_pars
vector of parameters that are fixed (i.e. not fitted).
sec_model_names
definition of the secondary models for each condition.
...
additional arguments passed to FME::modFit
.
The data to use for the fit is described using the experiment_data
argument. It is a nested list with as many elements as experiments. The dataset multiple_experiments
serves as an example with the format required by this function.
data("multiple_experiments")
Each experiemnt is described using a list with two elements: data
and conditions
. The element data
is a tibble with two columns, time
and logN
, that describe the observed log-microbial count.
ggplot(multiple_experiments[[1]]$data) +
geom_point(aes(x = time, y = logN))

The element conditions
describes the (dynamic) environmental conditions during storage. It must have one column named time
and as many additional columns as environmental conditions considered in the model. Note that, for every simulation, the values of environmental conditions at times not included in the data frame are calculated by linear interpolation.
multiple_experiments[[1]]$conditions %>%
pivot_longer(-time, names_to = "condition", values_to = "value") %>%
ggplot() +
geom_line(aes(x = time, y = value)) +
facet_wrap("condition", scales = "free")

The secondary models to use to describe the influence of the environmental conditions on the growth rate is defined using sec_model_names
. This argument is a named vector whose names are identical to those in the experimental data and whose values corresponds to valid identifiers according to seccondary_model_data()
. For this example, we will use a CPM model for both pH and temperature (for no particular scientific reason).
sec_names <- c(temperature = "CPM", pH = "CPM")
The next step is the definition of what model parameters to estimate from the data and which ones to keep fixed. This is done using the starting_point
and known_pars
arguments, which are lists. Every parameter of both the primary and secondary models must be included in either of these arguments. The format for parameter definition is identical to the one of fit_dynamic_inactivation
.
For this example, we will only fit the maximum specific growth rate and the optimum temperature for growth (for no particular scientific reason).
known <- list(Nmax = 1e8, N0 = 1e0, Q0 = 1e-3,
temperature_n = 2, temperature_xmin = 20, temperature_xmax = 35,
pH_n = 2, pH_xmin = 5.5, pH_xmax = 7.5, pH_xopt = 6.5)
start <- list(mu_opt = .8, temperature_xopt = 30)
Once every argument has been defined, we can call the fit_multiple_growth()
function.
global_fit <- fit_multiple_growth(start, multiple_experiments, known, sec_names)
This function returns a list of class FitMultipleDynamicGrowth
with several elements. The parameter estimates can be accessed using the S3 method for summary.
summary(global_fit)
#>
#> Parameters:
#> Estimate Std. Error t value Pr(>|t|)
#> mu_opt 0.54196 0.01222 44.35 <2e-16 ***
#> temperature_xopt 30.62395 0.18727 163.53 <2e-16 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 0.4282 on 48 degrees of freedom
#>
#> Parameter correlation:
#> mu_opt temperature_xopt
#> mu_opt 1.0000 0.8837
#> temperature_xopt 0.8837 1.0000
Moreover, the predictions of the fitted model can be compared against the data using the S3 method for plot.

This function generates an individual plot for each experiment. Any environmental factor can be included in the plot by passing the name of the factor to the add_factor
argument. Note that the name must be identical to the one used for model definition.
plot(global_fit, add_factor = "temperature")

Stochastic modelling
Stochastic prediction under static conditions
Due to the relevance of uncertainty and variability Quantitative Microbial Risk Assessment usually requires the calculation of stochastic simulations. The function predict_stochastic_growth
enables to constract credible intervals of the microbial growth for a normal distribution of: * the square root of \(\mu\) * the square root of \(\lambda\) * the logarithm of the initial microbial count * the logarithm of the maximum microbial count
For that, this function includes two arguments per growth parameter (expected value and standard deviation) and 4 additional arguments:
model_name
defines the primary growth model
times
defines the time points where to make the calculations
n_sims
defines the number of Monte Carlo simulations.
corr_matrix
correlation matrix between the model parameters. By default, this argument is set to a diagonal matrix (i.e. no correlation between parameters).
The calculations are done by taking a sample of size n_sims
of the model parameters according to a multi-variate normal distribution. For simulation, the microbial growth is predicted and the quantiles of the predicted microbial count is used as an estimate of the credible interval.
For this example, we will use the tri-linear growth model
For the time points, we will take 100 points uniformly distributed between 0 and 30:
my_times <- seq(0, 30, length = 100)
For the example, we will set the number of simulations to 1000. Nevertheless, it is advisable to repeat the calculations for various number of simulations to ensure that the relevant variables converged.
Once the arguments have been defined, we can call the predict_stochastic_growth()
function.
stoc_growth <- predict_stochastic_growth(my_model, my_times, n_sims,
mean_logN0 = 0, sd_logN0 = .2,
mean_sqmu = 2,sd_sqmu = .3,
mean_sqlambda = 4, sd_sqlambda = .4,
mean_logNmax = 6, sd_logNmax = .5)
This function returns an instance of StochasticGrowth
with several items:
sample
: sample of model parameters used for the simulations
simulations
: results of the individual simulations
quantiles
: quantiles of the microbial count predicted in the simulatinos
model
: model used for the simulations
mus
: expected values of the model parameters used for the simulations.
sigma
: parameter variance-covariance matrix used for the simulations
This class implements an S3 method for plot that can be used to visualize the credible intervals

In this plot, the solid line represents the mean of the simulations. Then, the two shaded areas represent, respectively, the space between the 10th and 90th, and the 5th and 95th quantiles.
By default, the function considers that there is no correlation between the model parameters. This can be varied by defining a correlation matrix. Note that the rows and columns of this matrix are defined in the order [logN0, sqrt(mu), sqrt(lambda), logNmax]. For instance, we can define a correlation of 0.7 between the square root of \(\mu\) and the square root of \(\lambda\):
my_cor <- matrix(c(1, 0, 0, 0,
0, 1, 0.7, 0,
0, 0.7, 1, 0,
0, 0, 0, 1),
nrow = 4)
Then, we can include it in the call to the function
stoc_growth2 <- predict_stochastic_growth(my_model, my_times, n_sims,
mean_logN0 = 0, sd_logN0 = .2,
mean_sqmu = 2,sd_sqmu = .3,
mean_sqlambda = 4, sd_sqlambda = .4,
mean_logNmax = 6, sd_logNmax = .5,
my_cor)
plot(stoc_growth2)

Note that, in order to omit the variability/uncertainty of any model parameter, one just has to set its corresponding standard error to zero.
One-step fitting using MCMC algorithms
Numerical algorithms based on Markov Chains have been suggested as an alternative to non-linear regression for dynamic models. For that reason, biogrowth includes the function fit_MCMC_growth()
that uses the interface included in the FME package to the Adaptive Monte Carlo algorithm by Haario et al. (2006). The arguments and the requirements of this function are identical to those of fit_dynamic_growth()
. The only difference is that this function has the additional argument niter
, which defines the number of samples from the Markov Chain. Hence, we will repeat the previous code to define the model parameters and the data.
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)
Then, we can call the fit_MCMC_growth()
using these arguments plus the argument niter
that we will set to 500.
my_MCMC_fit <- fit_MCMC_growth(example_dynamic_growth, example_env_conditions,
my_start,
known_pars,
sec_model_names,
niter = 500,
updatecov = 10)
#> number of accepted runs: 142 out of 500 (28.4%)
This function returns an instance of FitDynamicGrowthMCMC
with 6 entries:
fit_results
: object returned by modMCMC()
.
best_prediction
: an instance of DynamicGrowth
with the prediction corresponding to the fitted model.
data
: data used to fit the model.
starting
: starting values used for parameter estimation.
known
: model parameters considered known.
sec_models
: type of secondary model for each environmental factor.
This class implements several S3 methods to aid in the the visualization of the results. A call to summary()
returns the statistics of the Markov Chain.
summary(my_MCMC_fit)
#> temperature_xmin temperature_xopt temperature_xmax aw_xopt
#> mean 21.634182 108.89778 488.72908 0.93576107
#> sd 5.216537 103.27422 622.08071 0.03013679
#> min 3.633527 28.64327 40.00000 0.86398247
#> max 28.820248 415.48202 2855.42504 1.00145804
#> q025 19.694013 44.07705 80.71768 0.91499366
#> q050 22.996927 57.89964 178.86958 0.93382135
#> q075 25.047293 128.95375 830.97710 0.95857218
And a call to plot()
compares the data against the model fitted.

As well as for fit_dynamic_growth()
, the environmental conditions can be added to the plot using the add_factor
argument.
plot(my_MCMC_fit, add_factor = "temperature")

Global fitting using MCMC algorithms
Following the same logic as with the fit_MCMC_growth()
function, fit_multiple_growth_MCMC()
serves as an alternative to fit_multiple_growth()
that uses an MCMC fitting algorithm instead of non-linear regression. The arguments of this function are identical to those of fit_multiple_growth()
with the addition of niter
, which defines the number of iterations from the MCMC sample.
Therefore, the definition of the data to use for the fit is identical.
data("multiple_experiments")
As well as the model definition.
## For each environmental factor, we need to defined a model
sec_names <- c(temperature = "CPM", pH = "CPM")
## Any model parameter can be fixed
known <- list(Nmax = 1e8, N0 = 1e0, Q0 = 1e-3,
temperature_n = 2, temperature_xmin = 20, temperature_xmax = 35,
pH_n = 2, pH_xmin = 5.5, pH_xmax = 7.5, pH_xopt = 6.5)
## The rest require starting values for model fitting
start <- list(mu_opt = .8, temperature_xopt = 30)
Then, the function can be called. Note that the MCMC algorithm is stochastic, so we will set the seed before fitting to grant reproducibility. Additionally, we will define upper and lower bounds for this function by passing the arguments lower
and upper
to modMCMC
. For further ways to edit the fitting, please check the help page of modMCMC()
.
set.seed(12412)
global_MCMC <- fit_multiple_growth_MCMC(start, multiple_experiments, known, sec_names, niter = 1000,
lower = c(.2, 29), # lower limits of the model parameters
upper = c(.8, 34)) # upper limits of the model parameters
#> number of accepted runs: 59 out of 1000 (5.9%)
This function returns a list of class FitMultipleDynamicGrowthMCMC
with the same entries as FitMultipleDynamicGrowth
. It also implements S3 methods to inspect the parameter estimates
summary(global_MCMC)
#> mu_opt temperature_xopt
#> mean 0.53775356 30.4587639
#> sd 0.03978701 0.5917605
#> min 0.45669053 29.0981761
#> max 0.80000000 33.4447884
#> q025 0.50786427 30.1298758
#> q050 0.53381851 30.4569710
#> q075 0.55284038 30.7688826
Or to plot the predictions of the fitted model against the data.

Any environmental factor can be included in the plot using the add_factor
argument.
plot(global_MCMC, add_factor = "temperature")

Stochastic prediction based on an MCMC fit
The function predict_MCMC_growth()
provides an interface to make stochastic predictions based on parameter distributions estimated using fit_MCMC_growth()
or fit_multiple_growth_MCMC()
. This function has 4 arguments:
MCMCfit
an instance of FitDynamicGrowthMCMC
returned by fit_MCMC_growth()
, or an instance of FitMultipleGrowthMCMC
returned by fit_multiple_growth_MCMC()
.
times
vector of time points for the calculations.
env_conditions
tibble describing the (dynamic) environmental conditions.
niter
number of samples for the Monte Carlo calculations.
For this first example, we will use the same data we used previously to illustrate the use of the fit_MCMC_growth()
function. The environmental conditions were defined by example_env_conditions
example_env_conditions
#> # A tibble: 3 x 3
#> time temperature aw
#> <dbl> <dbl> <dbl>
#> 1 0 20 0.99
#> 2 5 30 0.95
#> 3 15 35 0.9
This function estimates the credible intervals based on the quantiles of the predicted microbial count at each time point. Hence, their precision depends on the number of time points and the number of simulations. If the number of time points is too low, the prediction interval would not be “smooth”. On the other hand, if the number of simulations is too low, the crecible interval would vary between repetitions of the same calculation.
As an example, we wil use 5 time points uniformly distributed between 0 and 15
my_times <- seq(0, 15, length = 5)
and 100 iterations.
Once we have defined every argument, we can call the predict_MCMC_growth()
function.
my_MCMC_prediction <- predict_MCMC_growth(my_MCMC_fit,
my_times,
example_env_conditions,
niter)
This function returns an instance of MCMCgrowth
with 4 entries:
sample
a tibble with the sample of model parameters used for the simulations.
simulations
a tibble with the results of every individual simulation used.
quantiles
a tibble providing the calculated quantiles (5th, 10th, 50th, 90th, 95th) of the microbial count for each time point.
model
the instance of FitDynamicGrowthMCMC
used for the predictions.
Hence, the individual quantiles can be retrieved from quantiles
my_MCMC_prediction$quantiles
#> # A tibble: 5 x 7
#> time q50 q10 q90 q05 q95 m_logN
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0 0 0 0 0 0 0
#> 2 3.75 0.00289 0.0000579 0.0406 0 0.0747 0.0201
#> 3 7.5 2.73 1.88 3.58 1.62 3.65 2.67
#> 4 11.2 4.00 3.96 4.00 3.80 4.00 3.98
#> 5 15 4.00 4.00 4 3.94 4 3.99
This class implements an S3 method for plot
to visualize the prediction interval.

In this plot, the solid line represents the median of the simulations, whereas the two shaded areas represent the space between the 10th and 90th, and 5th and 95th quantiles. As shown in this plot, the prediction interval is far from smooth. The reason for that is the low number of time points used for the calculations. Consequently, we will repeat them using 100 time points instead of 5:
better_prediction <- predict_MCMC_growth(my_MCMC_fit,
seq(0, 15, length = 100),
example_env_conditions,
niter)
If we visualize the new prediction interval

it is now smoother. However, the prediction interval is still odd. Even if it is smooth, there are several inflection points that are hard to justify based on the model equations. They are the result of the low number of Monte Carlo samples used for the simulations. Hence, this number should be increased to obtain reliable intervals (not done in this vignette due to excessive compilation time).
Distributions of times to reach a certain count
For shelf-life estimation and risk assessment, the storage time required to reach a critical microbial count is usually of interest. For stochastic simulations, this time is not defined by a single value but by a probability distribution that can be estimated using the distribution_to_logcount()
function. This function has two arguments:
model
: an object returned by predict_stochastic_growth()
or fit_MCMC_growth()
.
log_count
: target microbial count.
For instance, we can use this function to get the distribution of times required to reach a microbial count of 4 log cFU/g based on the simulations we did before and saved in stoc_growth
time_distrib <- distribution_to_logcount(stoc_growth, 4)
This function returns an instance of TimeDistribution
with 2 items:
distribution
includes a numeric vector with the distribution of times to reach log_count
. summary
includes summary statistics of distribution
.
Hence, we can observe the summary
time_distrib$summary
#> # A tibble: 1 x 5
#> m_time sd_time med_time q10 q90
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 17.3 3.23 17.0 13.3 21.5
Alternatively, this class implements an S3 method to visualize the distribution of times:

In this plot, the vertical red line illustrates the median of the distribution and the grey lines the 10th and 90th quantile.
References
Baranyi, J., & Roberts, T. A. (1994). A dynamic approach to predicting bacterial growth in food. International Journal of Food Microbiology, 23(3–4), 277–294. https://doi.org/10.1016/0168-1605(94)90157-0
Bates, D. M., & Watts, D. G. (2007). Nonlinear Regression Analysis and Its Applications (1 edition). Wiley-Interscience.
Buchanan, R. L., Whiting, R. C., & Damert, W. C. (1997). When is simple good enough: A comparison of the Gompertz, Baranyi, and three-phase linear models for fitting bacterial growth curves. Food Microbiology, 14(4), 313–326. https://doi.org/10.1006/fmic.1997.0125
Chang, W., Cheng, J., Allaire, J. J., Xie, Y., & McPherson, J. (2017). shiny: Web Application Framework for R. https://CRAN.R-project.org/package=shiny
Chang, W., & Ribeiro, B. B. (2017). shinydashboard: Create Dashboards with “Shiny.” https://CRAN.R-project.org/package=shinydashboard
Haario, H., Laine, M., Mira, A., & Saksman, E. (2006). DRAM: Efficient adaptive MCMC. Statistics and Computing, 16(4), 339–354. https://doi.org/10.1007/s11222-006-9438-0
Hindmarsh, A. (1983). ODEPACK, A Systematized Collection of ODE Solvers , R. S. Stepleman et al. (Eds.), North-Holland, Amsterdam, (vol. 1 of ), pp. 55-64. IMACS Transactions on Scientific Computation, 1, 55–64.
Moré, J. J. (1978). The Levenberg-Marquardt algorithm: Implementation and theory. In Numerical Analysis (pp. 105–116). Springer, Berlin, Heidelberg. https://doi.org/10.1007/BFb0067700
Perez-Rodriguez, F., & Valero, A. (2012). Predictive Microbiology in Foods. Springer.
Poschet, F., Geeraerd, A. H., Van Loey, A. M., Hendrickx, M. E., & Van Impe, J. F. (2005). Assessing the optimal experiment setup for first order kinetic studies by Monte Carlo analysis. Food Control, 16(10), 873–882. https://doi.org/10.1016/j.foodcont.2004.07.009
Ratkowsky, D. A., Lowry, R. K., McMeekin, T. A., Stokes, A. N., & Chandler, R. E. (1983). Model for bacterial culture growth rate throughout the entire biokinetic temperature range. Journal of Bacteriology, 154(3), 1222–1226.
Ratkowsky, D. A., Olley, J., McMeekin, T. A., & Ball, A. (1982). Relationship between temperature and growth rate of bacterial cultures. J Bacteriol, 149(1), 1–5.
Rosso, L., Lobry, J. R., Bajard, S., & Flandrois, J. P. (1995). Convenient Model To Describe the Combined Effects of Temperature and pH on Microbial Growth. Applied and Environmental Microbiology, 61(2), 610–616.
Soetaert, K., & Petzoldt, T. (2010). Inverse Modelling, Sensitivity and Monte Carlo Analysis in R Using Package FME. Journal of Statistical Software, 33(3). https://doi.org/10.18637/jss.v033.i03
Soetaert, K., Petzoldt, T., & Setzer, R. W. (2010). Solving Differential Equations in R: Package deSolve. Journal of Statistical Software, 33(9). https://doi.org/10.18637/jss.v033.i09
Tocino, A., & Ardanuy, R. (2002). Runge–Kutta methods for numerical solution of stochastic differential equations. Journal of Computational and Applied Mathematics, 138(2), 219–241. https://doi.org/10.1016/S0377-0427(01)00380-6
Wijtzes, T., Rombouts, F. M., Kant-Muermans, M. L. T., van ’t Riet, K., & Zwietering, M. H. (2001). Development and validation of a combined temperature, water activity, pH model for bacterial growth rate of Lactobacillus curvatus. International Journal of Food Microbiology, 63(1–2), 57–64. https://doi.org/10.1016/S0168-1605(00)00401-3
Zwietering, M. H., Jongenburger, I., Rombouts, F. M., & Riet, K. van ’t. (1990). Modeling of the Bacterial Growth Curve. Applied and Environmental Microbiology, 56(6), 1875–1881.
Zwietering, Marcel H., Wijtzes, T., De Wit, J. C., & Riet, K. V. (1992). A Decision Support System for Prediction of the Microbial Spoilage in Foods. Journal of Food Protection, 55(12), 973–979. https://doi.org/10.4315/0362-028X-55.12.973