Type: | Package |
Title: | Modelling of Population Growth |
Version: | 1.0.6 |
Description: | Modelling of population growth under static and dynamic environmental conditions. Includes functions for model fitting and making prediction under isothermal and dynamic conditions. The methods (algorithms & models) are based on predictive microbiology (See Perez-Rodriguez and Valero (2012, ISBN:978-1-4614-5519-6)). |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.2.3 |
Imports: | deSolve (≥ 1.28), tibble (≥ 3.0.3), dplyr (≥ 0.8.5), FME (≥ 1.3.6), MASS (≥ 7.3), rlang (≥ 0.4.7), purrr (≥ 0.3.4), ggplot2 (≥ 3.3.2), cowplot (≥ 1.0.0), lamW (≥ 1.3.0), tidyr (≥ 1.0.2), formula.tools (≥ 1.7.1), lifecycle |
Suggests: | knitr, rmarkdown, tidyverse (≥ 1.3.0) |
VignetteBuilder: | knitr |
Depends: | R (≥ 2.10) |
NeedsCompilation: | no |
Packaged: | 2025-03-17 16:28:11 UTC; alber |
Author: | Alberto Garre |
Maintainer: | Alberto Garre <garre.alberto@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-03-17 16:50:02 UTC |
biogrowth: Modelling of Population Growth
Description
Modelling of population growth under static and dynamic environmental conditions. Includes functions for model fitting and making prediction under isothermal and dynamic conditions. The methods (algorithms & models) are based on predictive microbiology (See Perez-Rodriguez and Valero (2012, ISBN:978-1-4614-5519-6)).
Author(s)
Maintainer: Alberto Garre garre.alberto@gmail.com (ORCID)
Authors:
Jeroen Koomen jeroen.koomen@wur.nl
Heidy den Besten heidy.denbesten@wur.nl
Marcel Zwietering marcel.zwietering@wur.nl
Secondary Aryani model
Description
Secondary model as defined by Aryani et al. (2015).
Usage
Aryani_model(x, xmin, xhalf)
Arguments
x |
Value of the environmental factor. |
xmin |
Minimum value for growth. |
xhalf |
Value where gamma = 0.5 |
Value
The corresponding gamma factor.
Secondary Cardinal Parameter (CPM) model
Description
Secondary cardinal parameter model as defined by Rosso et al. (1995).
Usage
CPM_model(x, xmin, xopt, xmax, n)
Arguments
x |
Value of the environmental factor. |
xmin |
Minimum value for growth. |
xopt |
Optimum value for growth. |
xmax |
Maximum value for growth. |
n |
Order of the CPM model. |
Value
The corresponding gamma factor.
DynamicGrowth class
Description
The class DynamicGrowth has been superseded by the top-level class GrowthPrediction, which provides a unified approach for growth modelling.
Still, it is returned if the superseded predict_dynamic_growth()
is called.
A subclass of list with items:
simulation: A tibble with the model prediction
gammas: A tibble with the value of each gamma factor for each value of
times
.env_conditions: A list of functions interpolating the environmental conditions.
primary_pars: A list with the model parameters of the primary model.
sec_models: A nested list defining the secondary models.
Usage
## S3 method for class 'DynamicGrowth'
print(x, ...)
## S3 method for class 'DynamicGrowth'
plot(
x,
y = NULL,
...,
add_factor = NULL,
ylims = NULL,
label_y1 = "logN",
label_y2 = add_factor,
line_col = "black",
line_size = 1,
line_type = "solid",
line_col2 = "black",
line_size2 = 1,
line_type2 = "dashed",
label_x = "time"
)
## S3 method for class 'DynamicGrowth'
coef(object, ...)
Arguments
x |
The object of class |
... |
ignored |
y |
ignored |
add_factor |
whether to plot also one environmental factor.
If |
ylims |
A two dimensional vector with the limits of the primary y-axis. |
label_y1 |
Label of the primary y-axis. |
label_y2 |
Label of the secondary y-axis. |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
line_col2 |
Same as lin_col, but for the environmental factor. |
line_size2 |
Same as line_size, but for the environmental factor. |
line_type2 |
Same as lin_type, but for the environmental factor. |
label_x |
Label of the x-axis. |
object |
an instance of DynamicGrowth |
Methods (by generic)
-
print(DynamicGrowth)
: print of the model -
plot(DynamicGrowth)
: predicted growth curve under dynamic conditions. -
coef(DynamicGrowth)
: coefficients of the model
FitCoupledGrowth class
Description
The FitCoupledGrowth
class contains a Baranyi model fitted to experimental data
considering the coupling between the primary and secondary models.
Its constructor is fit_coupled_growth()
.
It is a subclass of list with the items:
fit: object returned by
FME::modFit()
.mode: fitting approach.
weight: type of weights for the two-steps approach.
logbase_mu: base of the logarithm used for the calculation of mu.
data: data used for the model fitting.
Usage
## S3 method for class 'FitCoupledGrowth'
print(x, ...)
## S3 method for class 'FitCoupledGrowth'
coef(object, ...)
## S3 method for class 'FitCoupledGrowth'
summary(object, ...)
## S3 method for class 'FitCoupledGrowth'
predict(object, newdata = NULL, ...)
## S3 method for class 'FitCoupledGrowth'
residuals(object, ...)
## S3 method for class 'FitCoupledGrowth'
vcov(object, ...)
## S3 method for class 'FitCoupledGrowth'
deviance(object, ...)
## S3 method for class 'FitCoupledGrowth'
fitted(object, ...)
## S3 method for class 'FitCoupledGrowth'
logLik(object, ...)
## S3 method for class 'FitCoupledGrowth'
AIC(object, ..., k = 2)
## S3 method for class 'FitCoupledGrowth'
plot(
x,
y = NULL,
...,
line_col = "black",
line_size = 1,
line_type = 1,
point_col = "black",
point_size = 3,
point_shape = 16,
label_y = NULL,
label_x = NULL
)
Arguments
x |
The object of class FitCoupledGrowth to plot. |
... |
ignored. |
object |
an instance of FitCoupledGrowth |
newdata |
tibble (or data.frame) with the conditions for the prediction.
If |
k |
penalty for the parameters (k=2 by default) |
y |
ignored |
line_col |
colour of the line |
line_size |
size of the line |
line_type |
type of the line |
point_col |
colour of the points |
point_size |
size of the points |
point_shape |
shape of the point |
label_y |
label for the y-axis. By default, |
label_x |
label for the x-axis. By default, |
Methods (by generic)
-
print(FitCoupledGrowth)
: print of the model -
coef(FitCoupledGrowth)
: vector of fitted model parameters. -
summary(FitCoupledGrowth)
: statistical summary of the fit. -
predict(FitCoupledGrowth)
: vector of model predictions. -
residuals(FitCoupledGrowth)
: vector of model residuals. -
vcov(FitCoupledGrowth)
: variance-covariance matrix of the model, estimated as 1/(0.5*Hessian) for regression -
deviance(FitCoupledGrowth)
: deviance of the model. -
fitted(FitCoupledGrowth)
: vector of fitted values. -
logLik(FitCoupledGrowth)
: loglikelihood of the model -
AIC(FitCoupledGrowth)
: Akaike Information Criterion -
plot(FitCoupledGrowth)
: compares the fitted model against the data.
FitDynamicGrowth class
Description
The class FitDynamicGrowth has been superseded by the top-level class GrowthFit, which provides a unified approach for growth modelling.
Still, it is still returned if the superseded fit_dynamic_growth()
is called.
It is a subclass of list with the items:
fit_results: the object returned by
modFit
.best_prediction: the model prediction for the fitted parameters.
env_conditions: environmental conditions for the fit.
data: data used for the fit.
starting: starting values for model fitting
known: parameter values set as known.
sec_models: a named vector with the secondary model for each environmental factor
Usage
## S3 method for class 'FitDynamicGrowth'
print(x, ...)
## S3 method for class 'FitDynamicGrowth'
plot(
x,
y = NULL,
...,
add_factor = NULL,
ylims = NULL,
label_y1 = "logN",
label_y2 = add_factor,
line_col = "black",
line_size = 1,
line_type = 1,
point_col = "black",
point_size = 3,
point_shape = 16,
line_col2 = "black",
line_size2 = 1,
line_type2 = "dashed"
)
## S3 method for class 'FitDynamicGrowth'
summary(object, ...)
## S3 method for class 'FitDynamicGrowth'
residuals(object, ...)
## S3 method for class 'FitDynamicGrowth'
coef(object, ...)
## S3 method for class 'FitDynamicGrowth'
vcov(object, ...)
## S3 method for class 'FitDynamicGrowth'
deviance(object, ...)
## S3 method for class 'FitDynamicGrowth'
fitted(object, ...)
## S3 method for class 'FitDynamicGrowth'
predict(object, times = NULL, newdata = NULL, ...)
## S3 method for class 'FitDynamicGrowth'
logLik(object, ...)
## S3 method for class 'FitDynamicGrowth'
AIC(object, ..., k = 2)
Arguments
x |
The object of class |
... |
ignored |
y |
ignored |
add_factor |
whether to plot also one environmental factor.
If |
ylims |
A two dimensional vector with the limits of the primary y-axis. |
label_y1 |
Label of the primary y-axis. |
label_y2 |
Label of the secondary y-axis. |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
point_col |
Aesthetic parameter to change the colour of the point geom, see: |
point_size |
Aesthetic parameter to change the size of the point geom, see: |
point_shape |
Aesthetic parameter to change the shape of the point geom, see: ggplot2:: |
line_col2 |
Same as lin_col, but for the environmental factor. |
line_size2 |
Same as line_size, but for the environmental factor. |
line_type2 |
Same as lin_type, but for the environmental factor. |
object |
an instance of FitDynamicGrowth |
times |
A numeric vector with the time points for the simulations. |
newdata |
a tibble describing the environmental conditions (as |
k |
penalty for the parameters (k=2 by default) |
Methods (by generic)
-
print(FitDynamicGrowth)
: comparison between the fitted model and the data. -
plot(FitDynamicGrowth)
: comparison between the fitted model and the data. -
summary(FitDynamicGrowth)
: statistical summary of the fit. -
residuals(FitDynamicGrowth)
: residuals of the model. -
coef(FitDynamicGrowth)
: vector of fitted parameters. -
vcov(FitDynamicGrowth)
: (unscaled) variance-covariance matrix of the model, calculated as 1/(0.5*Hessian) -
deviance(FitDynamicGrowth)
: deviance of the model. -
fitted(FitDynamicGrowth)
: fitted values. -
predict(FitDynamicGrowth)
: model predictions. -
logLik(FitDynamicGrowth)
: loglikelihood of the model -
AIC(FitDynamicGrowth)
: Akaike Information Criterion
FitDynamicGrowthMCMC class
Description
The class FitDynamicGrowthMCMC has been superseded by the top-level class GrowthFit, which provides a unified approach for growth modelling.
Still, it is returned if the superseded fit_MCMC_growth()
is called.
It is a subclass of list with the items:
fit_results: the object returned by
modMCMC
.best_prediction: the model prediction for the fitted parameters.
env_conditions: environmental conditions for the fit.
data: data used for the fit.
starting: starting values for model fitting
known: parameter values set as known.
sec_models: a named vector with the secondary model for each environmental factor
Usage
## S3 method for class 'FitDynamicGrowthMCMC'
print(x, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
plot(
x,
y = NULL,
...,
add_factor = NULL,
ylims = NULL,
label_y1 = "logN",
label_y2 = add_factor,
line_col = "black",
line_size = 1,
line_type = 1,
point_col = "black",
point_size = 3,
point_shape = 16,
line_col2 = "black",
line_size2 = 1,
line_type2 = "dashed"
)
## S3 method for class 'FitDynamicGrowthMCMC'
summary(object, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
residuals(object, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
coef(object, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
vcov(object, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
deviance(object, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
fitted(object, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
predict(object, times = NULL, newdata = NULL, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
logLik(object, ...)
## S3 method for class 'FitDynamicGrowthMCMC'
AIC(object, ..., k = 2)
## S3 method for class 'FitDynamicGrowthMCMC'
predictMCMC(
model,
times,
env_conditions,
niter,
newpars = NULL,
formula = . ~ time
)
Arguments
x |
The object of class |
... |
ignored |
y |
ignored |
add_factor |
whether to plot also one environmental factor.
If |
ylims |
A two dimensional vector with the limits of the primary y-axis. |
label_y1 |
Label of the primary y-axis. |
label_y2 |
Label of the secondary y-axis. |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
point_col |
Aesthetic parameter to change the colour of the point geom, see: |
point_size |
Aesthetic parameter to change the size of the point geom, see: |
point_shape |
Aesthetic parameter to change the shape of the point geom, see: |
line_col2 |
Same as lin_col, but for the environmental factor. |
line_size2 |
Same as line_size, but for the environmental factor. |
line_type2 |
Same as lin_type, but for the environmental factor. |
object |
an instance of FitDynamicGrowthMCMC |
times |
Numeric vector of storage times for the predictions. |
newdata |
a tibble describing the environmental conditions (as |
k |
penalty for the parameters (k=2 by default) |
model |
An instance of FitDynamicGrowthMCMC |
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. |
formula |
A formula stating the column named defining the elapsed time in
|
Value
An instance of MCMCgrowth()
.
Methods (by generic)
-
print(FitDynamicGrowthMCMC)
: print of the model -
plot(FitDynamicGrowthMCMC)
: compares the model fitted against the data. -
summary(FitDynamicGrowthMCMC)
: statistical summary of the fit. -
residuals(FitDynamicGrowthMCMC)
: model residuals. -
coef(FitDynamicGrowthMCMC)
: vector of fitted model parameters. -
vcov(FitDynamicGrowthMCMC)
: variance-covariance matrix of the model, estimated as the variance of the samples from the Markov chain. -
deviance(FitDynamicGrowthMCMC)
: deviance of the model, calculated as the sum of squared residuals for the parameter values resulting in the best fit. -
fitted(FitDynamicGrowthMCMC)
: vector of fitted values. -
predict(FitDynamicGrowthMCMC)
: vector of model predictions. -
logLik(FitDynamicGrowthMCMC)
: loglikelihood of the model -
AIC(FitDynamicGrowthMCMC)
: Akaike Information Criterion -
predictMCMC(FitDynamicGrowthMCMC)
: prediction including parameter uncertainty
FitIsoGrowth class
Description
The class FitIsoGrowth has been superseded by the top-level class GrowthFit, which provides a unified approach for growth modelling.
Still, it is still returned if the superseded fit_isothermal_growth()
is called.
It is a subclass of list with the items:
data: data used for model fitting
model: name of the primary inactivation model
starting_point: initial value of the model parameters
known: fixed model parameters
fit: object returned by
FME::modFit()
best_prediction: model prediction for the model fitted.
Usage
## S3 method for class 'FitIsoGrowth'
print(x, ...)
## S3 method for class 'FitIsoGrowth'
plot(
x,
y = NULL,
...,
line_col = "black",
line_size = 1,
line_type = 1,
point_col = "black",
point_size = 3,
point_shape = 16
)
## S3 method for class 'FitIsoGrowth'
summary(object, ...)
## S3 method for class 'FitIsoGrowth'
residuals(object, ...)
## S3 method for class 'FitIsoGrowth'
coef(object, ...)
## S3 method for class 'FitIsoGrowth'
vcov(object, ...)
## S3 method for class 'FitIsoGrowth'
deviance(object, ...)
## S3 method for class 'FitIsoGrowth'
fitted(object, ...)
## S3 method for class 'FitIsoGrowth'
predict(object, times = NULL, ...)
## S3 method for class 'FitIsoGrowth'
logLik(object, ...)
## S3 method for class 'FitIsoGrowth'
AIC(object, ..., k = 2)
Arguments
x |
The object of class |
... |
ignored |
y |
ignored |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
point_col |
Aesthetic parameter to change the colour of the point geom, see: |
point_size |
Aesthetic parameter to change the size of the point geom, see: |
point_shape |
Aesthetic parameter to change the shape of the point geom, see: |
object |
an instance of FitIsoGrowth |
times |
numeric vector describing the time points for the prediction.
If |
k |
penalty for the parameters (k=2 by default) |
Methods (by generic)
-
print(FitIsoGrowth)
: print of the model -
plot(FitIsoGrowth)
: compares the fitted model against the data. -
summary(FitIsoGrowth)
: statistical summary of the fit. -
residuals(FitIsoGrowth)
: vector of model residuals. -
coef(FitIsoGrowth)
: vector of fitted model parameters. -
vcov(FitIsoGrowth)
: variance-covariance matrix of the model, estimated as 1/(0.5*Hessian) -
deviance(FitIsoGrowth)
: deviance of the model. -
fitted(FitIsoGrowth)
: vector of fitted values. -
predict(FitIsoGrowth)
: vector of model predictions. -
logLik(FitIsoGrowth)
: loglikelihood of the model -
AIC(FitIsoGrowth)
: Akaike Information Criterion
FitMultipleDynamicGrowth class
Description
The class FitMultipleDynamicGrowth has been superseded by the top-level class GlobalGrowthFit, which provides a unified approach for growth modelling.
Still, it is still returned if the superseded fit_multiple_growth()
is called.
It is a subclass of list with the items:
fit_results: the object returned by
modFit
.best_prediction: a list with the models predictions for each condition.
data: a list with the data used for the fit.
starting: starting values for model fitting
known: parameter values set as known.
sec_models: a named vector with the secondary model for each environmental factor.
Usage
## S3 method for class 'FitMultipleDynamicGrowth'
print(x, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
plot(
x,
y = NULL,
...,
add_factor = NULL,
ylims = NULL,
label_x = "time",
label_y1 = "logN",
label_y2 = add_factor,
line_col = "black",
line_size = 1,
line_type = "solid",
line_col2 = "black",
line_size2 = 1,
line_type2 = "dashed",
point_size = 3,
point_shape = 16,
subplot_labels = "AUTO"
)
## S3 method for class 'FitMultipleDynamicGrowth'
summary(object, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
residuals(object, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
coef(object, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
vcov(object, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
deviance(object, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
fitted(object, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
predict(object, env_conditions, times = NULL, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
logLik(object, ...)
## S3 method for class 'FitMultipleDynamicGrowth'
AIC(object, ..., k = 2)
Arguments
x |
an instance of FitMultipleDynamicGrowth. |
... |
ignored |
y |
ignored |
add_factor |
whether to plot also one environmental factor.
If |
ylims |
A two dimensional vector with the limits of the primary y-axis. |
label_x |
label of the x-axis |
label_y1 |
Label of the primary y-axis. |
label_y2 |
Label of the secondary y-axis. |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
line_col2 |
Same as lin_col, but for the environmental factor. |
line_size2 |
Same as line_size, but for the environmental factor. |
line_type2 |
Same as lin_type, but for the environmental factor. |
point_size |
Size of the data points |
point_shape |
shape of the data points |
subplot_labels |
labels of the subplots according to |
object |
an instance of FitMultipleDynamicGrowth |
env_conditions |
a tibble describing the environmental conditions (as
in |
times |
A numeric vector with the time points for the simulations. |
k |
penalty for the parameters (k=2 by default) |
Methods (by generic)
-
print(FitMultipleDynamicGrowth)
: print of the model -
plot(FitMultipleDynamicGrowth)
: comparison between the fitted model and the experimental data. -
summary(FitMultipleDynamicGrowth)
: statistical summary of the fit. -
residuals(FitMultipleDynamicGrowth)
: calculates the model residuals. Returns a tibble with 4 columns: time (storage time), logN (observed count), exp (name of the experiment) and res (residual). -
coef(FitMultipleDynamicGrowth)
: vector of fitted parameters. -
vcov(FitMultipleDynamicGrowth)
: (unscaled) variance-covariance matrix, estimated as 1/(0.5*Hessian). -
deviance(FitMultipleDynamicGrowth)
: deviance of the model. -
fitted(FitMultipleDynamicGrowth)
: fitted values. They are returned as a tibble with 3 columns: time (storage time), exp (experiment identifier) and fitted (fitted value). -
predict(FitMultipleDynamicGrowth)
: vector of model predictions -
logLik(FitMultipleDynamicGrowth)
: loglikelihood of the model -
AIC(FitMultipleDynamicGrowth)
: Akaike Information Criterion
FitMultipleGrowthMCMC class
Description
The class FitMultipleGrowthMCMC has been superseded by the top-level class GlobalGrowthFit, which provides a unified approach for growth modelling.
Still, it is still returned if the superseded fit_multiple_growth_MCMC()
is called.
It is a subclass of list with the items:
fit_results: the object returned by
modFit
.best_prediction: a list with the models predictions for each condition.
data: a list with the data used for the fit.
starting: starting values for model fitting
known: parameter values set as known.
sec_models: a named vector with the secondary model for each environmental factor.
Usage
## S3 method for class 'FitMultipleGrowthMCMC'
print(x, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
plot(
x,
y = NULL,
...,
add_factor = NULL,
ylims = NULL,
label_x = "time",
label_y1 = "logN",
label_y2 = add_factor,
line_col = "black",
line_size = 1,
line_type = "solid",
line_col2 = "black",
line_size2 = 1,
line_type2 = "dashed",
point_size = 3,
point_shape = 16,
subplot_labels = "AUTO"
)
## S3 method for class 'FitMultipleGrowthMCMC'
summary(object, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
residuals(object, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
coef(object, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
vcov(object, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
deviance(object, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
fitted(object, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
predict(object, env_conditions, times = NULL, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
logLik(object, ...)
## S3 method for class 'FitMultipleGrowthMCMC'
AIC(object, ..., k = 2)
## S3 method for class 'FitMultipleGrowthMCMC'
predictMCMC(
model,
times,
env_conditions,
niter,
newpars = NULL,
formula = . ~ time
)
Arguments
x |
an instance of FitMultipleGrowthMCMC. |
... |
ignored |
y |
ignored |
add_factor |
whether to plot also one environmental factor.
If |
ylims |
A two dimensional vector with the limits of the primary y-axis. |
label_x |
label of the x-axis |
label_y1 |
Label of the primary y-axis. |
label_y2 |
Label of the secondary y-axis. |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
line_col2 |
Same as lin_col, but for the environmental factor. |
line_size2 |
Same as line_size, but for the environmental factor. |
line_type2 |
Same as lin_type, but for the environmental factor. |
point_size |
Size of the data points |
point_shape |
shape of the data points |
subplot_labels |
labels of the subplots according to |
object |
an instance of FitMultipleGrowthMCMC |
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. |
times |
Numeric vector of storage times for the predictions. |
k |
penalty for the parameters (k=2 by default) |
model |
An instance of FitMultipleGrowthMCMC |
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. |
formula |
A formula stating the column named defining the elapsed time in
|
Value
An instance of MCMCgrowth()
.
Methods (by generic)
-
print(FitMultipleGrowthMCMC)
: print of the model -
plot(FitMultipleGrowthMCMC)
: comparison between the model fitted and the data. -
summary(FitMultipleGrowthMCMC)
: statistical summary of the fit. -
residuals(FitMultipleGrowthMCMC)
: model residuals. They are returned as a tibble with 4 columns: time (storage time), logN (observed count), exp (name of the experiment) and res (residual). -
coef(FitMultipleGrowthMCMC)
: vector of fitted model parameters. -
vcov(FitMultipleGrowthMCMC)
: variance-covariance matrix of the model, estimated as the variance of the samples from the Markov chain. -
deviance(FitMultipleGrowthMCMC)
: deviance of the model, calculated as the sum of squared residuals of the prediction with the lowest standard error. -
fitted(FitMultipleGrowthMCMC)
: fitted values of the model. They are returned as a tibble with 3 columns: time (storage time), exp (experiment identifier) and fitted (fitted value). -
predict(FitMultipleGrowthMCMC)
: model predictions. They are returned as a tibble with 3 columns: time (storage time), logN (observed count), and exp (name of the experiment). -
logLik(FitMultipleGrowthMCMC)
: loglikelihood of the model -
AIC(FitMultipleGrowthMCMC)
: Akaike Information Criterion -
predictMCMC(FitMultipleGrowthMCMC)
: prediction including parameter uncertainty
FitSecondaryGrowth class
Description
The FitSecondaryGrowth
class contains a model fitted to a set of growth rates
gathered under a variety of static conditions.
Its constructor is fit_secondary_growth()
.
It is a subclass of list with the items:
fit_results: object returned by
FME::modFit()
.secondary_model: secondary model fitted to the data.
mu_opt_fit: estimated growth rate under optimum conditions.
data: data used for the fit.
transformation: type of transformation of
mu
for the fit.
Usage
## S3 method for class 'FitSecondaryGrowth'
print(x, ...)
## S3 method for class 'FitSecondaryGrowth'
plot(x, y = NULL, ..., which = 1, add_trend = FALSE, add_segment = FALSE)
## S3 method for class 'FitSecondaryGrowth'
summary(object, ...)
## S3 method for class 'FitSecondaryGrowth'
residuals(object, ...)
## S3 method for class 'FitSecondaryGrowth'
coef(object, ...)
## S3 method for class 'FitSecondaryGrowth'
vcov(object, ...)
## S3 method for class 'FitSecondaryGrowth'
deviance(object, ...)
## S3 method for class 'FitSecondaryGrowth'
fitted(object, ...)
## S3 method for class 'FitSecondaryGrowth'
predict(object, newdata = NULL, ...)
## S3 method for class 'FitSecondaryGrowth'
logLik(object, ...)
## S3 method for class 'FitSecondaryGrowth'
AIC(object, ..., k = 2)
Arguments
x |
An instance of FitSecondaryGrowth. |
... |
ignored |
y |
ignored. |
which |
A numeric with the type of plot. 1 for obs versus predicted (default), 2 for gamma curve |
add_trend |
Whether to add a trend line (only for which=2) |
add_segment |
Whether to join the observed and fitted points (only for which=2) |
object |
an instance of FitSecondaryGrowth |
newdata |
A tibble describing the environmental conditions as in
|
k |
penalty for the parameters (k=2 by default) |
Methods (by generic)
-
print(FitSecondaryGrowth)
: print of the model -
plot(FitSecondaryGrowth)
: plots to evaluate the goodness of the fit. -
summary(FitSecondaryGrowth)
: statistical summary of the fit. -
residuals(FitSecondaryGrowth)
: vector of model residuals. -
coef(FitSecondaryGrowth)
: vector of fitted model parameters. -
vcov(FitSecondaryGrowth)
: variance-covariance matrix of the model, estimated as 1/(0.5*Hessian) -
deviance(FitSecondaryGrowth)
: deviance of the model. -
fitted(FitSecondaryGrowth)
: vector of fitted values.The fitted values are returned in the same scale as the one used for the fitting (sqrt, log or none).
-
predict(FitSecondaryGrowth)
: vector of model predictions. -
logLik(FitSecondaryGrowth)
: loglikelihood of the model -
AIC(FitSecondaryGrowth)
: Akaike Information Criterion
GlobalGrowthComparison class
Description
The GlobalGrowthComparison
class contains several functions for model comparison
and model selection of growth models. It should not be instanced directly. Instead,
it should be constructed using compare_growth_fits()
. It is similar to
GrowthComparison, although with specific tools to deal with several experiments.
It includes two type of tools for model selection and comparison: statistical indexes and visual analyses. Please check the sections below for details.
Note that all these tools use the names defined in compare_growth_fits()
, so
we recommend passing a named list to that function.
Usage
## S3 method for class 'GlobalGrowthComparison'
coef(object, ...)
## S3 method for class 'GlobalGrowthComparison'
summary(object, ...)
## S3 method for class 'GlobalGrowthComparison'
print(x, ...)
## S3 method for class 'GlobalGrowthComparison'
plot(x, y, ..., type = 1, add_trend = TRUE)
Arguments
object |
an instance of GlobalGrowthComparison |
... |
ignored |
x |
an instance of GlobalGrowthComparison |
y |
ignored |
type |
if type==1, the plot compares the model predictions. If type ==2, the plot compares the parameter estimates. If type==3, the plot shows the residuals |
add_trend |
should a trend line of the residuals be added for type==3? |
Methods (by generic)
-
coef(GlobalGrowthComparison)
: table of parameter estimates -
summary(GlobalGrowthComparison)
: summary table for the comparison -
print(GlobalGrowthComparison)
: print of the model comparison -
plot(GlobalGrowthComparison)
: illustrations comparing the fitted models
Statistical indexes
GlobalGrowthComparison
implements two S3 methods to obtain numerical values to facilitate
model comparison and selection.
the
coef
method returns a tibble with the values of the parameter estimates and their corresponding standard errors for each model.the
summary
returns a tibble with the AIC, number of degrees of freedom, mean error and root mean squared error for each model.
Visual analyses
The S3 plot method can generate three types of plots:
when
type = 1
, the plot compares the fitted growth curves against the experimental data used to fit the model.when
type = 2
, the plot compares the parameter estimates using error bars, where the limits of the error bars are the expected value +/- one standard error. In case one model does not has some model parameter (i.e. either because it is not defined or because it was fixed), the parameter is not included in the plot.when
type=3
, the plot shows the tendency of the residuals for each model. This plot can be used to detect deviations from independence.
These plots are divided by facets for each experiment.
GlobalGrowthFit class
Description
The GlobalGrowthFit
class contains a growth model fitted to data
using a global approach. Its constructor is fit_growth()
.
It is a subclass of list with the items:
algorithm: type of algorithm as in
fit_growth()
data: data used for model fitting
start: initial guess of the model parameters
known: fixed model parameters
primary_model: a character describing the primary model
fit_results: an instance of modFit or modMCMC with the results of the fit
best_prediction: Instance of GrowthPrediction with the best growth fit
sec_models: a named vector with the secondary models assigned for each environmental factor.
NULL
forenvironment="constant"
env_conditions: a list with the environmental conditions used for model fitting.
NULL
forenvironment="constant"
niter: number of iterations of the Markov chain.
NULL
ifalgorithm != "MCMC"
logbase_mu: base of the logarithm for the definition of parameter mu (check the relevant vignette)
logbase_logN: base of the logarithm for the definition of the population size (check the relevant vignette)
environment: "dynamic". Always
Usage
## S3 method for class 'GlobalGrowthFit'
print(x, ...)
## S3 method for class 'GlobalGrowthFit'
coef(object, ...)
## S3 method for class 'GlobalGrowthFit'
summary(object, ...)
## S3 method for class 'GlobalGrowthFit'
predict(object, env_conditions, times = NULL, ...)
## S3 method for class 'GlobalGrowthFit'
residuals(object, ...)
## S3 method for class 'GlobalGrowthFit'
vcov(object, ...)
## S3 method for class 'GlobalGrowthFit'
deviance(object, ...)
## S3 method for class 'GlobalGrowthFit'
fitted(object, ...)
## S3 method for class 'GlobalGrowthFit'
logLik(object, ...)
## S3 method for class 'GlobalGrowthFit'
AIC(object, ..., k = 2)
## S3 method for class 'GlobalGrowthFit'
plot(
x,
y = NULL,
...,
add_factor = NULL,
ylims = NULL,
label_x = "time",
label_y1 = NULL,
label_y2 = add_factor,
line_col = "black",
line_size = 1,
line_type = "solid",
line_col2 = "black",
line_size2 = 1,
line_type2 = "dashed",
point_size = 3,
point_shape = 16,
subplot_labels = "AUTO"
)
## S3 method for class 'GlobalGrowthFit'
predictMCMC(
model,
times,
env_conditions,
niter,
newpars = NULL,
formula = . ~ time
)
Arguments
x |
an instance of GlobalGrowthFit |
... |
ignored |
object |
an instance of GlobalGrowthFit |
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. |
times |
Numeric vector of storage times for the predictions. |
k |
penalty for the parameters (k=2 by default) |
y |
ignored |
add_factor |
whether to plot also one environmental factor.
If |
ylims |
A two dimensional vector with the limits of the primary y-axis. |
label_x |
label of the x-axis |
label_y1 |
Label of the primary y-axis. |
label_y2 |
Label of the secondary y-axis. |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
line_col2 |
Same as lin_col, but for the environmental factor. |
line_size2 |
Same as line_size, but for the environmental factor. |
line_type2 |
Same as lin_type, but for the environmental factor. |
point_size |
Size of the data points |
point_shape |
shape of the data points |
subplot_labels |
labels of the subplots according to |
model |
An instance of GlobalGrowthFit |
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. |
formula |
A formula stating the column named defining the elapsed time in
|
Value
An instance of MCMCgrowth.
Methods (by generic)
-
print(GlobalGrowthFit)
: print of the model -
coef(GlobalGrowthFit)
: vector of fitted model parameters. -
summary(GlobalGrowthFit)
: statistical summary of the fit. -
predict(GlobalGrowthFit)
: vector of model predictions -
residuals(GlobalGrowthFit)
: model residuals. They are returned as a tibble with 4 columns: time (storage time), logN (observed count), exp (name of the experiment) and res (residual). -
vcov(GlobalGrowthFit)
: variance-covariance matrix of the model, estimated as 1/(0.5*Hessian) for regression and as the variance-covariance of the draws for MCMC -
deviance(GlobalGrowthFit)
: deviance of the model. -
fitted(GlobalGrowthFit)
: fitted values. They are returned as a tibble with 3 columns: time (storage time), exp (experiment identifier) and fitted (fitted value). -
logLik(GlobalGrowthFit)
: loglikelihood of the model -
AIC(GlobalGrowthFit)
: Akaike Information Criterion -
plot(GlobalGrowthFit)
: comparison between the fitted model and the experimental data. -
predictMCMC(GlobalGrowthFit)
: prediction including parameter uncertainty
GrowthComparison class
Description
The GrowthComparison
class contains several functions for model comparison
and model selection of growth models. It should not be instanced directly. Instead,
it should be constructed using compare_growth_fits()
.
It includes two type of tools for model selection and comparison: statistical indexes and visual analyses. Please check the sections below for details.
Note that all these tools use the names defined in compare_growth_fits()
, so
we recommend passing a named list to that function.
Usage
## S3 method for class 'GrowthComparison'
plot(x, y, ..., type = 1, add_trend = TRUE)
## S3 method for class 'GrowthComparison'
coef(object, ...)
## S3 method for class 'GrowthComparison'
print(x, ...)
## S3 method for class 'GrowthComparison'
summary(object, ...)
Arguments
x |
an instance of GrowthComparison |
y |
ignored |
... |
ignored |
type |
if type==1, the plot compares the model predictions. If type ==2, the plot compares the parameter estimates. If type==3, the plot shows the residuals |
add_trend |
should a trend line of the residuals be added for type==3? |
object |
an instance of GrowthComparison |
Methods (by generic)
-
plot(GrowthComparison)
: illustrations comparing the fitted models -
coef(GrowthComparison)
: table of parameter estimates -
print(GrowthComparison)
: print of the model comparison -
summary(GrowthComparison)
: summary table for the comparison
Statistical indexes
GrowthComparison
implements two S3 methods to obtain numerical values to facilitate
model comparison and selection.
the
coef
method returns a tibble with the values of the parameter estimates and their corresponding standard errors for each model.the
summary
returns a tibble with the AIC, number of degrees of freedom, mean error and root mean squared error for each model.
Visual analyses
The S3 plot method can generate three types of plots:
when
type = 1
, the plot compares the fitted growth curves against the experimental data used to fit the model.when
type = 2
, the plot compares the parameter estimates using error bars, where the limits of the error bars are the expected value +/- one standard error. In case one model does not have some model parameter (i.e. either because it is not defined or because it was fixed), the parameter is not included in the plot.when
type=3
, the plot shows the tendency of the residuals for each model. This plot can be used to detect deviations from independence.
GrowthFit class
Description
The GrowthFit
class contains a growth model fitted to data under
static or dynamic conditions. Its constructor is fit_growth()
.
It is a subclass of list with the items:
environment: type of environment as in
fit_growth()
algorithm: type of algorithm as in
fit_growth()
data: data used for model fitting
start: initial guess of the model parameters
known: fixed model parameters
primary_model: a character describing the primary model
fit_results: an instance of modFit or modMCMC with the results of the fit
best_prediction: Instance of GrowthPrediction with the best growth fit
sec_models: a named vector with the secondary models assigned for each environmental factor.
NULL
forenvironment="constant"
env_conditions: a tibble with the environmental conditions used for model fitting.
NULL
forenvironment="constant"
niter: number of iterations of the Markov chain.
NULL
ifalgorithm != "MCMC"
logbase_mu: base of the logarithm for the definition of parameter mu (check the relevant vignette)
logbase_logN: base of the logarithm for the definition of the population size (check the relevant vignette)
Usage
## S3 method for class 'GrowthFit'
print(x, ...)
## S3 method for class 'GrowthFit'
coef(object, ...)
## S3 method for class 'GrowthFit'
summary(object, ...)
## S3 method for class 'GrowthFit'
predict(object, times = NULL, env_conditions = NULL, ...)
## S3 method for class 'GrowthFit'
residuals(object, ...)
## S3 method for class 'GrowthFit'
vcov(object, ...)
## S3 method for class 'GrowthFit'
deviance(object, ...)
## S3 method for class 'GrowthFit'
fitted(object, ...)
## S3 method for class 'GrowthFit'
logLik(object, ...)
## S3 method for class 'GrowthFit'
AIC(object, ..., k = 2)
## S3 method for class 'GrowthFit'
plot(
x,
y = NULL,
...,
add_factor = NULL,
line_col = "black",
line_size = 1,
line_type = 1,
point_col = "black",
point_size = 3,
point_shape = 16,
ylims = NULL,
label_y1 = NULL,
label_y2 = add_factor,
label_x = "time",
line_col2 = "black",
line_size2 = 1,
line_type2 = "dashed"
)
## S3 method for class 'GrowthFit'
predictMCMC(
model,
times,
env_conditions,
niter,
newpars = NULL,
formula = . ~ time
)
Arguments
x |
The object of class GrowthFit to plot. |
... |
ignored. |
object |
an instance of GrowthFit |
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. |
k |
penalty for the parameters (k=2 by default) |
y |
ignored |
add_factor |
whether to plot also one environmental factor.
If |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
point_col |
Aesthetic parameter to change the colour of the point geom, see: |
point_size |
Aesthetic parameter to change the size of the point geom, see: |
point_shape |
Aesthetic parameter to change the shape of the point geom, see: |
ylims |
A two dimensional vector with the limits of the primary y-axis.
|
label_y1 |
Label of the primary y-axis. |
label_y2 |
Label of the secondary y-axis. Ignored if |
label_x |
Label of the x-axis |
line_col2 |
Same as lin_col, but for the environmental factor. Ignored if |
line_size2 |
Same as line_size, but for the environmental factor. Ignored if |
line_type2 |
Same as lin_type, but for the environmental factor. Ignored if |
model |
An instance of GrowthFit |
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. |
formula |
A formula stating the column named defining the elapsed time in
|
Value
An instance of MCMCgrowth.
Methods (by generic)
-
print(GrowthFit)
: print of the model -
coef(GrowthFit)
: vector of fitted model parameters. -
summary(GrowthFit)
: statistical summary of the fit. -
predict(GrowthFit)
: vector of model predictions. -
residuals(GrowthFit)
: vector of model residuals. -
vcov(GrowthFit)
: variance-covariance matrix of the model, estimated as 1/(0.5*Hessian) for regression and as the variance-covariance of the draws for MCMC -
deviance(GrowthFit)
: deviance of the model. -
fitted(GrowthFit)
: vector of fitted values. -
logLik(GrowthFit)
: loglikelihood of the model -
AIC(GrowthFit)
: Akaike Information Criterion -
plot(GrowthFit)
: compares the fitted model against the data. -
predictMCMC(GrowthFit)
: prediction including parameter uncertainty
GrowthPrediction class
Description
The GrowthPrediction
class contains the results of a growth prediction.
Its constructor is predict_growth()
.
It is a subclass of list with the items:
simulation: a tibble with the model simulation
primary model: a list describing the primary model as in
predict_growth()
environment: a character describing the type of environmental conditions as in
predict_growth()
env_conditions: a named list with the functions used to approximate the (dynamic) environmental conditions.
NULL
ifenvironment="constant"
.sec_models: a named list describing the secondary models as in
predict_growth()
.NULL
ifenvironment="constant"
.gammas: a tibble describing the variation of the gamma factors through the experiment.
NUll
ifenvironment="constant"
.logbase_mu: the log-base for the definition of parameter mu (see the relevant vignette)
logbase_logN: the log-base for the definition of the logarithm of the population size
Usage
## S3 method for class 'GrowthPrediction'
print(x, ...)
## S3 method for class 'GrowthPrediction'
summary(object, ...)
## S3 method for class 'GrowthPrediction'
plot(
x,
y = NULL,
...,
add_factor = NULL,
ylims = NULL,
label_y1 = NULL,
label_y2 = add_factor,
line_col = "black",
line_size = 1,
line_type = "solid",
line_col2 = "black",
line_size2 = 1,
line_type2 = "dashed",
label_x = "time"
)
## S3 method for class 'GrowthPrediction'
coef(object, ...)
Arguments
x |
The object of class |
... |
ignored |
object |
an instance of GrowthPrediction |
y |
ignored |
add_factor |
whether to plot also one environmental factor.
If |
ylims |
A two dimensional vector with the limits of the primary y-axis. |
label_y1 |
Label of the primary y-axis. |
label_y2 |
Label of the secondary y-axis. |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
line_col2 |
Same as lin_col, but for the environmental factor. |
line_size2 |
Same as line_size, but for the environmental factor. |
line_type2 |
Same as lin_type, but for the environmental factor. |
label_x |
Label of the x-axis. |
Methods (by generic)
-
print(GrowthPrediction)
: print of the model -
summary(GrowthPrediction)
: summary of the model -
plot(GrowthPrediction)
: predicted growth curve. -
coef(GrowthPrediction)
: coefficients of the model
GrowthUncertainty class
Description
The GrowthUncertainty
class contains the results of a growth prediction
under isothermal conditions considering parameter uncertainty. Its constructor
is predict_growth_uncertainty()
.
It is a subclass of list with the items:
sample: parameter sample used for the calculations.
simulations: growth curves predicted for each parameter.
quantiles: limits of the credible intervals (5%, 10%, 50%, 90%, 95%) for each time point.
model: Model used for the calculations.
mus: Mean parameter values used for the simulations.
sigma: Variance-covariance matrix used for the simulations.
logbase_mu: base of the logarithm for the definition of parameter mu (check the relevant vignette)
logbase_logN: base of the logarithm for the definition of the population size (check the relevant vignette)
Usage
## S3 method for class 'GrowthUncertainty'
print(x, ...)
## S3 method for class 'GrowthUncertainty'
plot(
x,
y = NULL,
...,
line_col = "black",
line_size = 0.5,
line_type = "solid",
ribbon80_fill = "grey",
ribbon90_fill = "grey",
alpha80 = 0.5,
alpha90 = 0.4
)
Arguments
x |
The object of class |
... |
ignored. |
y |
ignored |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
ribbon80_fill |
fill colour for the space between the 10th and 90th quantile, see: |
ribbon90_fill |
fill colour for the space between the 5th and 95th quantile, see: |
alpha80 |
transparency of the ribbon aesthetic for the space between the 10th and 90th quantile. Takes a value between 0 (fully transparant) and 1 (fully opaque) |
alpha90 |
transparency of the ribbon aesthetic for the space between the 5th and 95th quantile. Takes a value between 0 (fully transparant) and 1 (fully opaque). |
Methods (by generic)
-
print(GrowthUncertainty)
: print of the model -
plot(GrowthUncertainty)
: Growth prediction (prediction band) considering parameter uncertainty.
IsothermalGrowth class
Description
The class IsothermalGrowth has been superseded by the top-level class GrowthPrediction, which provides a unified approach for growth modelling.
Still, it is still returned if the superseded predict_isothermal_growth()
is called.
It is a subclass of list with the items:
simulation: A tibble with the model simulation.
model: The name of the model used for the predictions.
pars: A list with the values of the model parameters.
Usage
## S3 method for class 'IsothermalGrowth'
print(x, ...)
## S3 method for class 'IsothermalGrowth'
plot(
x,
y = NULL,
...,
line_col = "black",
line_size = 1,
line_type = "solid",
ylims = NULL,
label_y = NULL,
label_x = "time"
)
## S3 method for class 'IsothermalGrowth'
coef(object, ...)
Arguments
x |
The object of class IsothermalGrowth to plot. |
... |
ignored |
y |
ignored |
line_col |
Aesthetic parameter to change the colour of the line,
see: |
line_size |
Aesthetic parameter to change the thickness of the line,
see: |
line_type |
Aesthetic parameter to change the type of the line,
takes numbers (1-6) or strings ("solid") see: |
ylims |
Two-dimensional numeric vector with the limits of the y-axis
(or |
label_y |
Title of the y-axis |
label_x |
Title of the x-axis |
object |
an instance of IsothermalGrowth |
Methods (by generic)
-
print(IsothermalGrowth)
: print of the model -
plot(IsothermalGrowth)
: plot of the predicted growth curve. -
coef(IsothermalGrowth)
: coefficients of the model
MCMCgrowth class
Description
The MCMCgrowth
class contains the results of a growth prediction
consider parameter variability based on a model
fitted using an MCMC algorithm.
It is a subclass of list with items:
sample: Parameter sample used for the calculations.
simulations: Individual growth curves calculated based on the parameter sample.
quantiles: Tibble with the limits of the credible intervals (5%, 10%, 50%, 90% and 95%) for each time point.
model: Instance of
FitDynamicGrowthMCMC
used for predictions.env_conditions: A tibble with the environmental conditions of the simulation.
Usage
## S3 method for class 'MCMCgrowth'
print(x, ...)
## S3 method for class 'MCMCgrowth'
plot(
x,
y = NULL,
...,
add_factor = NULL,
alpha_80 = 0.5,
fill_80 = "grey",
alpha_90 = 0.5,
fill_90 = "grey",
label_y1 = "logN",
label_y2 = add_factor,
line_col = "black",
line_type = 1,
line_size = 1,
line_type2 = 2,
line_col2 = "black",
line_size2 = 1,
ylims = NULL
)
Arguments
x |
The object of class |
... |
ignored. |
y |
ignored |
add_factor |
Includes the variation of one environmental factor in the plot. It must be one of the column names in x$env_conditions. |
alpha_80 |
transparency of the ribbon for the 80th posterior. .5 by default. |
fill_80 |
fill colour of the ribbon for the 80th posterior. "grey" by default. |
alpha_90 |
transparency of the ribbon for the 90th posterior. .5 by default. |
fill_90 |
fill colour of the ribbon for the 90th posterior. "grey" by default. |
label_y1 |
label of the primary y axis. "logN" by default. |
label_y2 |
label of the secondary y axis. The name of the environmental factor by default. |
line_col |
colour of the line representing the median. "black" by default. |
line_type |
linetype for the line representing the median. solid by default. |
line_size |
size of the line representing the median. 1 by default. |
line_type2 |
linetype for the line representing the environmental condition. Dashed by default. |
line_col2 |
colour of the line representing the environmental condition. "black" by default. |
line_size2 |
size of the line representing the environmental condition. 1 by default. |
ylims |
limits of the primary y-axis. |
Methods (by generic)
-
print(MCMCgrowth)
: print of the model -
plot(MCMCgrowth)
: plot of predicted growth (prediction band).
Lag phase duration from Q0
Description
Convenience function to calculate the lag phase duration (lambda) of the Baranyi model from the maximum specific growth rate and the initial value of the variable Q.
Note that this function uses the unit system of biogrowth (i.e. log10). Care must be taken when using parameters obtained from other sources.
Usage
Q0_to_lambda(q0, mu, logbase_mu = 10)
Arguments
q0 |
Initial value of the variable Q. |
mu |
Specific growth rate in the exponential phase. |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, 10 (i.e. log10). See vignette about units for details. |
Secondary Rosso model for water activity
Description
Secondary model for water activity as defined by Aryani et al. (2001).
Usage
Rossoaw_model(x, xmin)
Arguments
x |
Value of the environmental factor (in principle, aw). |
xmin |
Minimum value for growth (in principle, aw). |
Value
The corresponding gamma factor.
SecondaryComparison class
Description
The SecondaryComparison
class contains several functions for model comparison
and model selection of growth models. It should not be instanced directly. Instead,
it should be constructed using compare_secondary_fits()
.
It includes two type of tools for model selection and comparison: statistical indexes and visual analyses. Please check the sections below for details.
Note that all these tools use the names defined in compare_secondary_fits()
, so
we recommend passing a named list to that function.
Usage
## S3 method for class 'SecondaryComparison'
coef(object, ...)
## S3 method for class 'SecondaryComparison'
summary(object, ...)
## S3 method for class 'SecondaryComparison'
print(x, ...)
## S3 method for class 'SecondaryComparison'
plot(x, y, ..., type = 1, add_trend = TRUE)
Arguments
object |
an instance of SecondaryComparison |
... |
ignored |
x |
an instance of SecondaryComparison |
y |
ignored |
type |
if type==1, the plot compares the model predictions. If type ==2, the plot compares the parameter estimates. |
add_trend |
should a trend line of the residuals be added for type==3? |
Methods (by generic)
-
coef(SecondaryComparison)
: table of parameter estimates -
summary(SecondaryComparison)
: summary table for the comparison -
print(SecondaryComparison)
: print of the model comparison -
plot(SecondaryComparison)
: illustrations comparing the fitted models
Statistical indexes
SecondaryComparison
implements two S3 methods to obtain numerical values to facilitate
model comparison and selection.
the
coef
method returns a tibble with the values of the parameter estimates and their corresponding standard errors for each model.the
summary
returns a tibble with the AIC, number of degrees of freedom, mean error and root mean squared error for each model.
Visual analyses
The S3 plot method can generate three types of plots:
when
type = 1
, the plot compares the observations against the model predictions for each model. The plot includes a linear model fitted to the residuals. In the case of a perfect fit, the line would have slope=1 and intercept=0 (shown as a black, dashed line).when
type = 2
, the plot compares the parameter estimates using error bars, where the limits of the error bars are the expected value +/- one standard error. In case one model does not has some model parameter (i.e. either because it is not defined or because it was fixed), the parameter is not included in the plot.
StochasticGrowth class
Description
The class StochasticGrowth has been deprecated by class GrowthUncertainty, which provides less misleading name.
Still, it is still returned if the deprecated predict_stochastic_growth()
is called.
The StochasticGrowth
class contains the results of a growth prediction
under isothermal conditions considering parameter unceratinty. Its constructor
is predict_stochastic_growth()
.
It is a subclass of list with the items:
sample: parameter sample used for the calculations.
simulations: growth curves predicted for each parameter.
quantiles: limits of the credible intervals (5%, 10%, 50%, 90%, 95%) for each time point.
model: Model used for the calculations.
mus: Mean parameter values used for the simulations.
sigma: Variance-covariance matrix used for the simulations.
Usage
## S3 method for class 'StochasticGrowth'
print(x, ...)
## S3 method for class 'StochasticGrowth'
plot(
x,
y = NULL,
...,
line_col = "black",
line_size = 0.5,
line_type = "solid",
ribbon80_fill = "grey",
ribbon90_fill = "grey",
alpha80 = 0.5,
alpha90 = 0.4
)
Arguments
x |
The object of class |
... |
ignored. |
y |
ignored |
line_col |
Aesthetic parameter to change the colour of the line geom in the plot, see: |
line_size |
Aesthetic parameter to change the thickness of the line geom in the plot, see: |
line_type |
Aesthetic parameter to change the type of the line geom in the plot, takes numbers (1-6) or strings ("solid") see: |
ribbon80_fill |
fill colour for the space between the 10th and 90th quantile, see: |
ribbon90_fill |
fill colour for the space between the 5th and 95th quantile, see: |
alpha80 |
transparency of the ribbon aesthetic for the space between the 10th and 90th quantile. Takes a value between 0 (fully transparant) and 1 (fully opaque) |
alpha90 |
transparency of the ribbon aesthetic for the space between the 5th and 95th quantile. Takes a value between 0 (fully transparant) and 1 (fully opaque). |
Details
FitIsoGrowth class
Methods (by generic)
-
print(StochasticGrowth)
: print of the model -
plot(StochasticGrowth)
: Growth prediction (prediction band) considering parameter uncertainty.
TimeDistribution class
Description
The TimeDistribution
class contains an estimate of the probability
distribution of the time to reach a given microbial count.
Its constructor is distribution_to_logcount()
.
It is a subclass of list with the items:
distribution Sample of the distribution of times to reach
log_count
.summary Summary statistics of distribution (mean, sd, median, q10 and q90).
Usage
## S3 method for class 'TimeDistribution'
print(x, ...)
## S3 method for class 'TimeDistribution'
summary(object, ...)
## S3 method for class 'TimeDistribution'
plot(x, y = NULL, ..., bin_width = NULL)
Arguments
x |
The object of class |
... |
ignored. |
object |
An instance of |
y |
ignored. |
bin_width |
A number that specifies the width of a bin in the histogram,
see: |
Methods (by generic)
-
print(TimeDistribution)
: print of the model -
summary(TimeDistribution)
: summary of the model -
plot(TimeDistribution)
: plot of the distribution of the time to reach a microbial count.
Generates functions for linear interpolation of environmental conditions
Description
Generates functions for linear interpolation of environmental conditions
Usage
approx_env(env_conditions)
Arguments
env_conditions |
A tibble describing the variation of the environmental
conditions through the storage time. Must contain a column named |
Value
A list of functions that return the value of each environmental condition for some storage time
Number of tractors in the Arab World according to the World Bank
Description
A dataset showing the increase in tractors in the Arab World. It was retrieved from https://data.worldbank.org/indicator/AG.AGR.TRAC.NO?end=2009&start=1961&view=chart.
Usage
arabian_tractors
Format
A tibble with 40 rows (each corresponding to one year) and 7 columns:
- year
Year for the recording
- tractors
Number of tractors
Bilinear model with lag phase
Description
Bilinear model with lag phase
Usage
bilinear_lag(times, logN0, mu, lambda)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
lambda |
Lag phase duration |
Bilinear model with stationary phase
Description
Bilinear model with stationary phase
Usage
bilinear_stationary(times, logN0, mu, logNmax)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
logNmax |
Maximum log microbial count |
Calculates every gamma factor
Description
A helper function for predict_dynamic_growth()
that
calculates the value of every gamma factor corresponding to some
storage time.
Usage
calculate_gammas(this_t, env_func, sec_models)
Arguments
this_t |
Storage time |
env_func |
A list of functions (generated using |
sec_models |
A nested list describing the secondary models. |
Value
A vector of gamma factors (one per environmental factor).
Gamma factors for fitting secondary models
Description
A helper for fitting the secondary gamma models. Calculates the gamma factors corresponding to the models defined and the experimental conditions. In order for it to work, the environmental factors must be named identically in the 3 arguments.
Usage
calculate_gammas_secondary(sec_model_names, my_data, secondary_models)
Arguments
sec_model_names |
named character vector defining the type of secondary model. Its names correspond to the environmental conditions and its values define the corresponding type of secondary model. |
my_data |
Tibble of experimental conditions. |
secondary_models |
A list defining the parameters of the secondary models. |
Value
a numeric vector of length nrow(my_data)
with the gamma factor
for each experimental condition.
Visual check of an initial guess of the model parameters
Description
Generates a plot comparing a set of data points against the model prediction corresponding to an initial guess of the model parameters
Usage
check_growth_guess(
fit_data,
model_keys,
guess,
environment = "constant",
env_conditions = NULL,
approach = "single",
logbase_mu = 10,
formula = logN ~ time
)
Arguments
fit_data |
Tibble (or data.frame) of data for the fit. It must have two columns, one with
the elapsed time ( |
model_keys |
Named the equations of the secondary model as in |
guess |
Named vector with the initial guess of the model parameters as in |
environment |
type of environment. Either "constant" (default) or "dynamic" (see below for details on the calculations for each condition) |
env_conditions |
Tibble describing the variation of the environmental
conditions for dynamic experiments. See |
approach |
whether "single" (default) or "global". Please see |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, 10 (i.e. log10). See vignette about units for details. |
formula |
an object of class "formula" describing the x and y variables.
|
Value
A ggplot2::ggplot()
comparing the model prediction against the data
Examples
## Examples under constant environmental conditions -------------------------
## We need some data
my_data <- data.frame(time = 0:9,
logN = c(2, 2.1, 1.8, 2.5, 3.1, 3.4, 4, 4.5, 4.8, 4.7)
)
## We can directly plot the comparison for some values
check_growth_guess(my_data, list(primary = "modGompertz"),
c(logN0 = 1.5, mu = .8, lambda = 4, C = 3)
)
## Ot it can be combined with the automatic initial guess
check_growth_guess(my_data, list(primary = "modGompertz"),
make_guess_primary(my_data, "modGompertz")
)
## Examples under dynamic environmental conditions --------------------------
## We will use the datasets included in the package
data("example_dynamic_growth")
data("example_env_conditions")
## Model equations are assigned as in fit_growth
sec_models <- list(temperature = "CPM", aw = "CPM")
## Guesses of model parameters are also defined as in fit_growth
guess <- list(Nmax = 1e4,
N0 = 1e0, Q0 = 1e-3,
mu_opt = 4,
temperature_n = 1,
aw_xmax = 1, aw_xmin = .9, aw_n = 1,
temperature_xmin = 25, temperature_xopt = 35,
temperature_xmax = 40, aw_xopt = .95
)
## We can now check our initial guess
check_growth_guess(example_dynamic_growth, sec_models, guess,
"dynamic",
example_env_conditions)
Basic check of parameters for primary models
Description
Checks that: the model name is correct, the right number of model parameters have been defined and that the parameters have the right names
Usage
check_primary_pars(model_name, pars)
Arguments
model_name |
Model identifier |
pars |
A named list of model parameters |
Value
If there is no error, the model function.
Basic checks of secondary parameters
Description
Checks that the model names are correct, that no parameter is defined twice, that every parameter is defined and that no unknown parameter has been defined. Raises an error if any of these conditions is not met.
Usage
check_secondary_pars(
starting_point,
known_pars,
sec_model_names,
primary_pars = "mu_opt"
)
Arguments
starting_point |
Named vector with initial values for the model parameters
to estimate from the data. The growth rate under optimum conditions must be named
|
known_pars |
Named vector of fixed model parameters. Must be named using the
same convention as |
sec_model_names |
Named character vector defining the secondary model for each environmental factor. |
primary_pars |
Character vector with the parameter names of the primary model. |
Model definition checks for predict_stochastic_growth
Description
Does several checks of the model parameters. Besides those by check_primary_pars, it checks that corr_matrix is square, that pars and corr_matrix have compatible dimensions, and that pars has the correct names.
Usage
check_stochastic_pars(model_name, pars, corr_matrix)
Arguments
model_name |
Character describing the primary growth model. |
pars |
A tibble describing the parameter uncertainty (see details). |
corr_matrix |
Correlation matrix of the model parameters. Defined in the
same order as in |
Model comparison and selection for growth models
Description
This function is a constructor for GrowthComparison or GlobalGrowthComparison,
a class that provides several functions for model comparison and model selection
for growth models fitted using fit_growth()
. Please see the help pages for
GrowthComparison or GlobalGrowthComparison for further details.
Although it is not necessary, we recommend passing the models as a named list, as these names will later be kept in plots and tables.
Usage
compare_growth_fits(models)
Arguments
models |
a (we recommend named) list of models fitted using |
Examples
## Example 1 - Fitting under static environmental conditions ----------------
## We will use the data on growth of Salmonella included in the package
data("growth_salmonella")
## We will fit 3 different models to the data
fit1 <- fit_growth(growth_salmonella,
list(primary = "Baranyi"),
start = c(lambda = 0, logNmax = 8, mu = .1, logN0 = 2),
known = c(),
environment = "constant",
)
fit2 <- fit_growth(growth_salmonella,
list(primary = "Baranyi"),
start = c(logNmax = 8, mu = .1, logN0 = 2),
known = c(lambda = 0),
environment = "constant",
)
fit3 <- fit_growth(growth_salmonella,
list(primary = "modGompertz"),
start = c(C = 8, mu = .1, logN0 = 2),
known = c(lambda = 0),
environment = "constant",
)
## We can now put them in a (preferably named) list
my_models <- list(`Baranyi` = fit1,
`Baranyi no lag` = fit2,
`Gompertz no lag` = fit3)
## And pass them to compare_growth_fits
model_comparison <- compare_growth_fits(my_models)
## The instance of GrowthComparison has useful S3 methods
print(model_comparison)
plot(model_comparison)
plot(model_comparison, type = 2)
plot(model_comparison, type = 3)
## The statistical indexes can be accessed through summary and coef
summary(model_comparison)
coef(model_comparison)
## Example 2 - Fitting under dynamic environmental conditions ---------------
## We will use one of the example datasets
data("example_dynamic_growth")
data("example_env_conditions")
## First model fitted
sec_models <- list(temperature = "CPM", aw = "CPM")
known_pars <- list(Nmax = 1e4,
N0 = 1e0, Q0 = 1e-3,
mu_opt = 4,
temperature_n = 1,
aw_xmax = 1, aw_xmin = .9, aw_n = 1
)
my_start <- list(temperature_xmin = 25, temperature_xopt = 35,
temperature_xmax = 40, aw_xopt = .95)
dynamic_fit <- fit_growth(example_dynamic_growth,
sec_models,
my_start, known_pars,
environment = "dynamic",
env_conditions = example_env_conditions
)
## Second model (different secondary model for temperature)
sec_models <- list(temperature = "Zwietering", aw = "CPM")
known_pars <- list(Nmax = 1e4,
N0 = 1e0, Q0 = 1e-3,
mu_opt = 4,
temperature_n = 1,
aw_xmax = 1, aw_xmin = .9, aw_n = 1
)
my_start <- list(temperature_xmin = 25, temperature_xopt = 35,
aw_xopt = .95)
dynamic_fit2 <- fit_growth(example_dynamic_growth,
sec_models,
my_start, known_pars,
environment = "dynamic",
env_conditions = example_env_conditions
)
## Once both models have been fitted, we can call the function
dynamic_comparison <- compare_growth_fits(list(m1 = dynamic_fit, m2 = dynamic_fit2))
## Which also returns an instance of GrowthComparison with the same S3 methods
print(dynamic_comparison)
plot(dynamic_comparison)
plot(dynamic_comparison, type = 2)
plot(dynamic_comparison, type = 3)
## The statistical indexes can be accessed through summary and coef
summary(dynamic_comparison)
coef(dynamic_comparison)
## Example 3 - Global fitting -----------------------------------------------
## We use the example data
data("multiple_counts")
data("multiple_conditions")
## We need to fit (at least) two models
sec_models <- list(temperature = "CPM", pH = "CPM")
known_pars <- 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)
my_start <- list(mu_opt = .8, temperature_xopt = 30)
global_fit <- fit_growth(multiple_counts,
sec_models,
my_start,
known_pars,
environment = "dynamic",
algorithm = "regression",
approach = "global",
env_conditions = multiple_conditions
)
sec_models <- list(temperature = "CPM", pH = "CPM")
known_pars <- list(Nmax = 1e8, N0 = 1e0, Q0 = 1e-3,
temperature_n = 1, temperature_xmin = 20,
temperature_xmax = 35,
pH_n = 2, pH_xmin = 5.5, pH_xmax = 7.5, pH_xopt = 6.5)
my_start <- list(mu_opt = .8, temperature_xopt = 30)
global_fit2 <- fit_growth(multiple_counts,
sec_models,
my_start,
known_pars,
environment = "dynamic",
algorithm = "regression",
approach = "global",
env_conditions = multiple_conditions
)
## We can now pass both models to the function as a (named) list
global_comparison <- compare_growth_fits(list(`n=2` = global_fit,
`n=1` = global_fit2)
)
## The residuals and model fits plots are divided by experiments
plot(global_comparison)
plot(global_comparison, type = 3)
## The remaining S3 methods are the same as before
print(global_comparison)
plot(global_comparison, type = 2)
summary(global_comparison)
coef(global_comparison)
Model comparison and selection for secondary growth models
Description
This function is a constructor for SecondaryComparison
a class that provides several functions for model comparison and model selection
for growth models fitted using fit_secondary_growth()
. Please see the help pages for
SecondaryComparison for further details.
Although it is not necessary, we recommend passing the models as a named list, as these names will later be kept in plots and tables.
Usage
compare_secondary_fits(models)
Arguments
models |
a (we recommend named) list of models fitted using |
Examples
## We first need to fit some models
data("example_cardinal")
sec_model_names <- c(temperature = "Zwietering", pH = "CPM")
known_pars <- list(mu_opt = 1.2, temperature_n = 1,
pH_n = 2, pH_xmax = 6.8, pH_xmin = 5.2)
my_start <- list(temperature_xmin = 5, temperature_xopt = 35,
pH_xopt = 6.5)
fit1 <- fit_secondary_growth(example_cardinal, my_start, known_pars, sec_model_names)
known_pars <- list(mu_opt = 1.2, temperature_n = 2,
pH_n = 2, pH_xmax = 6.8, pH_xmin = 5.2)
fit2 <- fit_secondary_growth(example_cardinal, my_start, known_pars, sec_model_names)
## We can now pass the models to the constructor
comparison <- compare_secondary_fits(list(`n=1` = fit1,
`n=2` = fit2))
## The function includes several S3 methods for model selection and comparison
print(comparison)
plot(comparison)
plot(comparison, type = 2)
## The numerical indexes can be accessed using coef and summary
coef(comparison)
summary(comparison)
Conditions during a dynamic growth experiment
Description
A dataset to demonstrate the use of fit_dynamic_growth. The observations environmental conditions are described in conditions_pH_temperature.
Usage
conditions_pH_temperature
Format
A tibble with 4 rows and 3 columns:
- time
elapsed time
- temperature
temperature
- pH
pH
Residuals of the coupled Baranyi model
Description
Residuals of the coupled Baranyi model
Usage
cost_coupled_onestep(p, this_data, known)
Arguments
p |
a numeric vector of model parameters. Must have entries |
this_data |
a tibble (or data.frame) with three columns: |
known |
a numeric vector of known model parameters |
Value
the vector of model residuals
Cost for the coupled model fitted in two-steps
Description
Cost for the coupled model fitted in two-steps
Usage
cost_coupled_twosteps(p, this_data, weight = NULL, known)
Arguments
p |
numeric vector (or list) of model parameters. Must have entries |
this_data |
tibble (or data.frame) of data. It must have one column named |
weight |
type of weights to apply. Either |
known |
vector of known model parameters |
Value
vector of weighted residuals
Baranyi growth model
Description
Microbial growth model as defined in Baranyi and Roberts (1994). It has
been implemented according to the requirements of
deSolve::ode()
. For consistency in the function for isothermal growth,
calculations are done assuming the user input for mu is in log10 scale. In other words,
the input is multiplied by ln(10).
Usage
dBaranyi(time, state, pars, env_func, sec_models)
Arguments
time |
numeric vector (length 1) of storage time |
state |
named numeric vector with two components: Q and N |
pars |
named numeric vector of model parameters (Nmax and mu_opt) |
env_func |
named list of functions returning the values of the environmental conditions for time (t) |
sec_models |
named list of parameters of the secondary model |
Value
A numeric vector of two components according to the requirements of
deSolve::ode()
.
Distribution of times to reach a certain microbial count
Description
The function distribution_to_logcount()
has been superseded by
function time_to_size()
, which provides more general interface.
Returns the probability distribution of the storage time required for
the microbial count to reach log_count
according to the predictions of
a stochastic model
.
Calculations are done using linear interpolation of the individual
model predictions.
Usage
distribution_to_logcount(model, log_count)
Arguments
model |
An instance of |
log_count |
The target microbial count. |
Value
An instance of TimeDistribution()
.
Examples
## We need an instance of StochasticGrowth
my_model <- "modGompertz"
my_times <- seq(0, 30, length = 100)
n_sims <- 3000
library(tibble)
pars <- tribble(
~par, ~mean, ~sd, ~scale,
"logN0", 0, .2, "original",
"mu", 2, .3, "sqrt",
"lambda", 4, .4, "sqrt",
"C", 6, .5, "original"
)
stoc_growth <- predict_stochastic_growth(my_model, my_times, n_sims, pars)
Growth rates obtained for several growth experiments
Description
An example dataset illustrating the requirements of the
fit_secondary_growth()
function.
Usage
example_cardinal
Format
A data frame with 64 rows and 3 variables:
- temperature
storage temperature (ºC)
- pH
pH of the media
- mu
specific growth rate (log10 CFU/h)
Example data for two-steps fitting of the Baranyi-Ratkowsky model
Description
This dataset serve as an example of the data input for fit_coupled_growth
using the
one-step mode.
Usage
example_coupled_onestep
Format
A tibble with three columns:
temp: the treatment temperature
time: the elapsed time of the sample
logN: the (decimal) log microbial concentration
Example data for two-steps fitting of the Baranyi-Ratkowsky model
Description
This dataset serve as an example of the data input for fit_coupled_growth
using the
two-steps mode.
Usage
example_coupled_twosteps
Format
A tibble with three columns:
temp: the treatment temperature
mu: the value of mu estimated at each temperature
lambda: the value of lambda estimated at each temperature
Microbial growth under dynamic conditions
Description
An example dataset illustrating the requirements of the
fit_dynamic_growth()
function.
Usage
example_dynamic_growth
Format
A data frame with 30 rows and 2 variables:
- time
elapsed time (h)
- logN
log population size (log10 CFU)
Environmental conditions during a dynamic experiment
Description
An example dataset illustrating the requirements of the
fit_dynamic_growth()
function.
Usage
example_env_conditions
Format
A data frame with 3 rows and 3 variables:
- time
elapsed time (h)
- temperature
storage temperature (ºC)
- aw
water activity
A helper to build the primary models
Description
Most of the functions for fitting mix in the vectors parameters for the primary and secondary models, but the functions for making predictions need that they are separated. This one extracts the parameters of the primary model.
Usage
extract_primary_pars(this_p, known_pars)
Arguments
this_p |
A named vector of model parameters (usually, the ones fitted). |
known_pars |
Another named vector of model parameters (usually the known ones). |
Value
A list with the parameters of the primary model
A helper to build the secondary models
Description
Most of the functions for fitting mix in the vectors parameters for the primary and secondary models, but the functions for making predictions need that they are separated. This one extracts the parameters of the secondary model.
Usage
extract_secondary_pars(this_p, known_pars, sec_model_names)
Arguments
this_p |
A named vector of model parameters (usually, the ones fitted). |
known_pars |
Another named vector of model parameters (usually the known ones). |
sec_model_names |
A named character vector defining for each environmental factor (vector names) the type of secondary model (vector values). |
Value
A nested list defining the secondary models.
Fit growth models using MCMC
Description
The function fit_MCMC_growth()
has been superseded by the top-level
function fit_growth()
, which provides a unified approach for growth modelling.
But, it can still fit a growth model to a data obtained under dynamic conditions using the one-step approach (MCMC algorithm).
Usage
fit_MCMC_growth(
fit_data,
env_conditions,
starting_point,
known_pars,
sec_model_names,
niter,
...,
check = TRUE,
formula = logN ~ time,
logbase_mu = logbase_logN,
logbase_logN = 10
)
Arguments
fit_data |
Tibble with the data to use for model fit. It must contain a column with the elapsed time (named "time" by default) and another one with the decimal logarithm of the observed population size (named "logN" by default). Different column names can be specified using the "formula" argument. |
env_conditions |
Tibble with the (dynamic) environmental conditions during the experiment. It must have one column with the elapsed time (named "time" by default) and as many columns as required with the environmental conditions. A different column name can be specified using the "formula" argument, although it must be the same one as in "fit_data". Note that only those defined in "sec_model_names" will be considered for the model fit. |
starting_point |
A named vector of starting values for the model parameters.
Parameters for the primary model must be named in the usual way. Parameters for the
secondary model are named as |
known_pars |
A named vector of known model parameters (i.e. not fitted). They
must be named using the same convention as for |
sec_model_names |
A named character vector defining the secondary model for each
environmental factor. The names define the factor and the value the type of model.
Names must match columns in |
niter |
number of iterations of the MCMC algorithm. |
... |
Additional arguments passed to modFit. |
check |
Whether to check model parameters (TRUE by default). |
formula |
an object of class "formula" describing the x and y variables.
|
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Value
An instance of FitDynamicGrowthMCMC()
.
Examples
## We use the example data included in the package
data("example_dynamic_growth")
data("example_env_conditions")
## Definition of the secondary models
sec_model_names <- c(temperature = "CPM", aw= "CPM")
## Any model parameter can be fixed
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
)
## We need starting values for the remaining parameters
my_start <- list(temperature_xmin = 25, temperature_xopt = 35,
temperature_xmax = 40,
aw_xopt = .95)
## We can now call the fitting function
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)
## Always check the MCMC chain!!
plot(my_MCMC_fit$fit_results)
## We can compare data against fitted curve
plot(my_MCMC_fit)
## Any environmental factor can be included using add_factor
plot(my_MCMC_fit, add_factor = "temperature",
label_y1 = "Count (log CFU/ml)", label_y2 = "Temperature (C)")
Growth fitting considering link between mu and lambda for the Baranyi-Ratkowsky model
Description
This function implements the methodology suggested by Garre et al. (2025; doi: 10.1016/j.ijfoodmicro.2025.111078) for the Baranyi-Ratkowsky model. Rather than fitting independent models for mu and lambda, this approach considers a link between both secondary models, reducing the number of unknown parameters from 3 to 4.
The function implements too modes of fitting: two-steps and one-step. Please see the respective sections for further information.
Usage
fit_coupled_growth(
fit_data,
start,
known = c(),
mode = "two_steps",
weight = "sd",
...,
logbase_mu = exp(1),
logbase_logN = 10
)
Arguments
fit_data |
a tibble (or data.frame) with the data for the fit. The content must be different depending on the fitting mode (see relevant sections within the help page). |
start |
a numeric vector of initial guesses for the parameter estimates |
known |
a numeric vector of known mode parameters. An empty vector by default (no knonw parameter) |
mode |
the type of model fitting approach. Either |
weight |
weights to apply for the |
... |
ignored |
logbase_mu |
Base for the definition of mu. By default, |
logbase_logN |
Base for the definition of logN. By default, 10 (decimal logarithm). |
Two-steps fitting
In this mode, it is assumed that primary models have been already fitted to each experiment. Therefore,
the data is available as a table of values of mu and lambda estimated at each temperature. Hence,
fit_data
must be a tibble (or data.frame) with three columns: temp
(storage temperature),
mu
(specific growth rate) and lambda
(lag phase duration). By default, mu
must be
defined in the scale of natural logarithm, although this can be modified using the logbase_mu
argument.
The package includes the dataset example_coupled_twosteps
as an illustration of the type of data.
One-step fitting
In this mode, secondary models are directly fitted to the observed (log) microbial counts. Hence,
fit_data
must be a tibble (or data.frame) with three columns: temp
(storage temperature),
time
(the elapsed time) and logN
(the log-microbial concentration). By default, logN
must be
defined in the scale of decimal logarithm, although this can be modified using the logbase_logN
argument.
The package includes the dataset example_coupled_onestep
as an illustration of the type of data.
Examples
## Example 1: Two-steps fitting-------------------------------------------------
## We can use the example dataset
data(example_coupled_twosteps)
## We need to define initial guesses for every parameter
guess <- c(logC0 = -1, b = .1, Tmin = 5)
## We can now call the fitting function
my_fit <- fit_coupled_growth(example_coupled_twosteps,
start = guess,
mode = "two_steps")
## Common S3 methods are included
print(my_fit)
coef(my_fit)
summary(my_fit)
plot(my_fit)
## Any model parameter can be fixed using the known argument
known <- c(b = .01)
## Please note that the guess must be updated, as now parameter can appear both as a guess and known
guess <- c(logC0 = -1, Tmin = 0)
fixed_fit <- fit_coupled_growth(example_coupled_twosteps,
start = guess,
known = known,
mode = "two_steps")
print(fixed_fit)
coef(fixed_fit)
summary(fixed_fit)
plot(fixed_fit)
## Example 2: One-step fitting--------------------------------------------------
## We can use an example dataset with the right format
data("example_coupled_onestep")
## The function requires initial guesses for every model parameter
guess <- c(logN0 = 2, logNmax = 8, b = 0.04, logC0 = -4, Tmin = 5)
## We can now call the fitting function
my_fit <- fit_coupled_growth(example_coupled_onestep,
start = guess,
mode = "one_step")
## The package includes common S3 methods
print(my_fit)
coef(my_fit)
summary(my_fit)
plot(my_fit)
## Any model parameter can be fixed before fitting
known <- c(logNmax = 7)
## Guesses must be updated, so no parameter appears twice
guess <- c(logN0 = 2, b = 0.04, logC0 = -4, Tmin = 5)
## We can now call the fitting function
my_fit <- fit_coupled_growth(example_coupled_onestep,
start = guess,
known = known,
mode = "one_step")
## The package includes common S3 methods
print(my_fit)
coef(my_fit)
summary(my_fit)
plot(my_fit)
Fit dynamic growth models
Description
The function fit_dynamic_growth()
has been superseded by the top-level
function fit_growth()
, which provides a unified approach for growth modelling.
Nonetheless, it can still fit a growth model to data obtained under dynamic conditions using the one-step approach (non-linear regression).
Usage
fit_dynamic_growth(
fit_data,
env_conditions,
starting_point,
known_pars,
sec_model_names,
...,
check = TRUE,
logbase_mu = logbase_logN,
logbase_logN = 10,
formula = logN ~ time
)
Arguments
fit_data |
Tibble with the data to use for model fit. It must contain a column with the elapsed time (named "time" by default) and another one with the decimal logarithm of the observed population size (named "logN" by default). Different column names can be specified using the "formula" argument. |
env_conditions |
Tibble with the (dynamic) environmental conditions during the experiment. It must have one column with the elapsed time (named "time" by default) and as many columns as required with the environmental conditions. A different column name can be specified using the "formula" argument, although it must be the same one as in "fit_data". Note that only those defined in "sec_model_names" will be considered for the model fit. |
starting_point |
A named vector of starting values for the model parameters.
Parameters for the primary model must be named in the usual way. Parameters for the
secondary model are named as |
known_pars |
A named vector of known model parameters (i.e. not fitted). They
must be named using the same convention as for |
sec_model_names |
A named character vector defining the secondary model for each
environmental factor. The names define the factor and the value the type of model.
Names must match columns in |
... |
Additional arguments passed to modFit. |
check |
Whether to check model parameters (TRUE by default). |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
formula |
an object of class "formula" describing the x and y variables.
|
Value
An instance of FitDynamicGrowth()
.
Examples
## We use the datasets included in the package
data("example_dynamic_growth")
data("example_env_conditions")
## Define the secondary models
sec_model_names <- c(temperature = "CPM", aw= "CPM")
## Any model parameter can be fixed
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
)
## The remaining parameters need initial values
my_start <- list(temperature_xmin = 25, temperature_xopt = 35,
temperature_xmax = 40, aw_xopt = .95)
## We can now call the fitting function
my_dyna_fit <- fit_dynamic_growth(example_dynamic_growth, example_env_conditions,
my_start, known_pars, sec_model_names)
summary(my_dyna_fit)
## We can compare the data and the fitted curve
plot(my_dyna_fit)
## We can plot any environmental condition using add_factor
plot(my_dyna_fit, add_factor = "aw",
label_y1 = "Log count (log CFU/ml)",
label_y2 = "Water activity")
Fitting microbial growth
Description
This function provides a top-level interface for fitting growth models to data describing the variation of the population size through time, either under constant or dynamic environment conditions. See below for details on the calculations.
Usage
fit_growth(
fit_data,
model_keys,
start,
known,
environment = "constant",
algorithm = "regression",
approach = "single",
env_conditions = NULL,
niter = NULL,
...,
check = TRUE,
logbase_mu = logbase_logN,
logbase_logN = 10,
formula = logN ~ time
)
Arguments
fit_data |
observed microbial growth. The format varies depending on the type of model fit. See the relevant sections (and examples) below for details. |
model_keys |
a named list assigning equations for the primary and secondary models. See the relevant sections (and examples) below for details. |
start |
a named numeric vector assigning initial guesses to the model parameters to estimate from the data. See relevant section (and examples) below for details. |
known |
named numeric vector of fixed model parameters, using the same conventions as for "start". |
environment |
type of environment. Either "constant" (default) or "dynamic" (see below for details on the calculations for each condition) |
algorithm |
either "regression" (default; Levenberg-Marquard algorithm) or "MCMC" (Adaptive Monte Carlo algorithm). |
approach |
approach for model fitting. Either "single" (the model is fitted to a unique experiment) or "global" (the model is fitted to several dynamic experiments). |
env_conditions |
Tibble describing the variation of the environmental conditions for dynamic experiments. See the relevant sections (and examples) below for details. Ignored for environment="constant". |
niter |
number of iterations of the MCMC algorithm. Ignored when algorithm!="MCMC". |
... |
Additional arguments for |
check |
Whether to check the validity of the models. TRUE by default. |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
formula |
An object of class "formula" defining the names of the x and y variables in
the data. |
Value
If approach="single
, an instance of GrowthFit. If approach="multiple"
,
an instance of GlobalGrowthFit
Please check the help pages of each class for additional information.
Fitting under constant conditions
When environment="constant", the functions fits a primary growth model to the population size observed during an experiment. In this case, the data has to be a tibble (or data.frame) with two columns:
time: the elapsed time
logN: the logarithm of the observed population size Nonetheless, the names of the columns can be modified with the formula argument.
The model equation is defined through the model_keys argument. It must include
an entry named "primary" assigned to a model. Valid model keys can be retrieved
calling primary_model_data()
.
The model is fitted by non-linear regression (using FME::modFit()
). This algorithm
needs initial guesses for every model parameter. This are defined as a named numeric
vector. The names must be valid model keys, which can be retrieved using primary_model_data()
(see example below). Apart from that, any model parameter can be fixed using the
"known" argument. This is a named numeric vector, with the same convenctions as "start".
Fitting under dynamic conditions to a single experiment
When environment="constant" and approach="single", a dynamic growth model combining the Baranyi primary growth model with the gamma approach for the effect of the environmental conditions on the growth rate is fitted to an experiment gathered under dynamic conditions. In this case, the data is similar to fitting under constant conditions: a tibble (or data.frame) with two columns:
time: the elapsed time
logN: the logarithm of the observed population size Note that these default names can be changed using the formula argument.
The values of the experimental conditions during the experiment are defined using the "env_conditions" argument. It is a tibble (or data.frame) with one column named ("time") defining the elapsed time. Note that this default name can be modified using the formula argument of the function. The tibble needs to have as many additional columns as environmental conditions included in the model, providing the values of the environmental conditions.
The model equations are defined through the model_keys argument. It must be a named
list where the names match the column names of "env_conditions" and the values
are model keys. These can be retrieved using secondary_model_data()
.
The model can be fitted using regression (FME::modFit()
) or an adaptive Monte Carlo
algorithm (FME::modMCMC()
). Both algorithms require initial guesses for every model
parameter to fit. These are defined through the named numeric vector "start". Each
parameter must be named as factor+"_"+parameter, where factor is the name of the
environmental factor defined in "model_keys". The parameter is a valid key
that can be retrieved from secondary_model_data()
. For instance, parameter Xmin for
the factor temperature would be defined as "temperature_xmin".
Note that the argument ... allows passing additional arguments to the fitting functions.
Fitting under dynamic conditions to multiple experiments (global fitting)
When environment="constant" and approach="global", fit_growth tries to find the vector of model parameters that best describe the observations of several growth experiments.
The input requirements are very similar to the case when approach="single". The models (equations, initial guesses, known parameters, algorithms...) are identical. The only difference is that "fit_data" must be a list, where each element describes the results of an experiment (using the same conventions as when approach="single"). In a similar fashion, "env_conditions" must be a list describing the values of the environmental factors during each experiment. Although it is not mandatory, it is recommended that the elements of both lists are named. Otherwise, the function assigns automatically-generated names, and matches them by order.#'
Examples
## Example 1 - Fitting a primary model --------------------------------------
## A dummy dataset describing the variation of the population size
my_data <- data.frame(time = c(0, 25, 50, 75, 100),
logN = c(2, 2.5, 7, 8, 8))
## A list of model keys can be gathered from
primary_model_data()
## The primary model is defined as a list
models <- list(primary = "Baranyi")
## The keys of the model parameters can also be gathered from primary_model_data
primary_model_data("Baranyi")$pars
## Any model parameter can be fixed
known <- c(mu = .2)
## The remaining parameters need initial guesses
start <- c(logNmax = 8, lambda = 25, logN0 = 2)
primary_fit <- fit_growth(my_data, models, start, known,
environment = "constant",
)
## The instance of FitIsoGrowth includes several useful methods
print(primary_fit)
plot(primary_fit)
coef(primary_fit)
summary(primary_fit)
## time_to_size can be used to calculate the time for some concentration
time_to_size(primary_fit, 4)
## Example 2 - Fitting under dynamic conditions------------------------------
## We will use the example data included in the package
data("example_dynamic_growth")
## And the example environmental conditoins (temperature & aw)
data("example_env_conditions")
## Valid keys for secondary models can be retrived from
secondary_model_data()
## We need to assign a model equation (secondary model) to each environmental factor
sec_models <- list(temperature = "CPM", aw = "CPM")
## The keys of the model parameters can be gathered from the same function
secondary_model_data("CPM")$pars
## Any model parameter (of the primary or secondary models) can be fixed
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
)
## The rest, need initial guesses (you know, regression)
my_start <- list(temperature_xmin = 25, temperature_xopt = 35,
temperature_xmax = 40, aw_xopt = .95)
## We can now fit the model
dynamic_fit <- fit_growth(example_dynamic_growth,
sec_models,
my_start, known_pars,
environment = "dynamic",
env_conditions = example_env_conditions
)
## The instance of FitDynamicGrowth has several S3 methods
plot(dynamic_fit, add_factor = "temperature")
summary(dynamic_fit)
## We can use time_to_size to calculate the time required to reach a given size
time_to_size(dynamic_fit, 3)
## Example 3- Fitting under dynamic conditions using MCMC -------------------
## We can reuse most of the arguments from the previous example
## We just need to define the algorithm and the number of iterations
set.seed(12421)
MCMC_fit <- fit_growth(example_dynamic_growth,
sec_models,
my_start, known_pars,
environment = "dynamic",
env_conditions = example_env_conditions,
algorithm = "MCMC",
niter = 1000
)
## The instance of FitDynamicGrowthMCMC has several S3 methods
plot(MCMC_fit, add_factor = "aw")
summary(MCMC_fit)
## We can use time_to_size to calculate the time required to reach a given size
time_to_size(MCMC_fit, 3)
## It can also make growth predictions including uncertainty
uncertain_growth <- predictMCMC(MCMC_fit,
seq(0, 10, length = 1000),
example_env_conditions,
niter = 1000)
## The instance of MCMCgrowth includes several nice S3 methods
plot(uncertain_growth)
print(uncertain_growth)
## time_to_size can calculate the time to reach some count
time_to_size(uncertain_growth, 2)
time_to_size(uncertain_growth, 2, type = "distribution")
## Example 4 - Fitting a unique model to several dynamic experiments --------
## We will use the data included in the package
data("multiple_counts")
data("multiple_conditions")
## We need to assign a model equation for each environmental factor
sec_models <- list(temperature = "CPM", pH = "CPM")
## Any model parameter (of the primary or secondary models) can be fixed
known_pars <- 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, need initial guesses
my_start <- list(mu_opt = .8, temperature_xopt = 30)
## We can now fit the model
global_fit <- fit_growth(multiple_counts,
sec_models,
my_start,
known_pars,
environment = "dynamic",
algorithm = "regression",
approach = "global",
env_conditions = multiple_conditions
)
## The instance of FitMultipleDynamicGrowth has nice S3 methods
plot(global_fit)
summary(global_fit)
print(global_fit)
## We can use time_to_size to calculate the time to reach a given size
time_to_size(global_fit, 4.5)
## Example 5 - MCMC fitting a unique model to several dynamic experiments ---
## Again, we can re-use all the arguments from the previous example
## We just need to define the right algorithm and the number of iterations
## On top of that, we will also pass upper and lower bounds to modMCMC
set.seed(12421)
global_MCMC <- fit_growth(multiple_counts,
sec_models,
my_start,
known_pars,
environment = "dynamic",
algorithm = "MCMC",
approach = "global",
env_conditions = multiple_conditions,
niter = 1000,
lower = c(.2, 29), # lower limits of the model parameters
upper = c(.8, 34) # upper limits of the model parameters
)
## The instance of FitMultipleDynamicGrowthMCMC has nice S3 methods
plot(global_MCMC)
summary(global_MCMC)
print(global_MCMC)
## We can use time_to_size to calculate the time to reach a given size
time_to_size(global_MCMC, 3)
## It can also be used to make model predictions with parameter uncertainty
uncertain_prediction <- predictMCMC(global_MCMC,
seq(0, 50, length = 1000),
multiple_conditions[[1]],
niter = 100
)
## The instance of MCMCgrowth includes several nice S3 methods
plot(uncertain_growth)
print(uncertain_growth)
## time_to_size can calculate the time to reach some count
time_to_size(uncertain_growth, 2)
time_to_size(uncertain_growth, 2, type = "distribution")
Fit primary growth models
Description
The function fit_isothermal_growth()
has been superseded by the top-level
function fit_growth()
, which provides a unified approach for growth modelling.
Nonetheless, it can still fit a primary growth model to data obtained under static environmental conditions.
Usage
fit_isothermal_growth(
fit_data,
model_name,
starting_point,
known_pars,
...,
check = TRUE,
formula = logN ~ time,
logbase_mu = logbase_logN,
logbase_logN = 10
)
Arguments
fit_data |
Tibble of data for the fit. It must have two columns, one with
the elapsed time ( |
model_name |
Character defining the primary growth model |
starting_point |
Named vector of initial values for the model parameters. |
known_pars |
Named vector of known model parameters (not fitted). |
... |
Additional arguments passed to |
check |
Whether to do some basic checks (TRUE by default). |
formula |
an object of class "formula" describing the x and y variables.
|
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Value
An instance of FitIsoGrowth()
.
Examples
## Some dummy data
library(tibble)
my_data <- tibble(time = c(0, 25, 50, 75, 100),
logN = c(2, 2.5, 7, 8, 8))
## Choose the model
my_model <- "Baranyi"
## Initial values for the model parameters
start = c(logNmax = 8, lambda = 25, logN0 = 2)
## Any model parameter can be fixed
known <- c(mu = .2)
## Now, we can call the function
static_fit <- fit_isothermal_growth(my_data, my_model, start, known)
summary(static_fit)
## We can plot the fitted model against the observations
plot(static_fit)
Fitting growth models to multiple dynamic experiments
Description
The function fit_multiple_growth()
has been superseded by the top-level
function fit_growth()
, which provides a unified approach for growth modelling.
But, if you so wish, this function still enables fitting a growth model using a dataset comprised of
several experiments with potentially different dynamic experimental conditions.
Note that the definition of secondary models must comply with the
secondary_model_data
function.
Usage
fit_multiple_growth(
starting_point,
experiment_data,
known_pars,
sec_model_names,
...,
check = TRUE,
formula = logN ~ time,
logbase_mu = logbase_logN,
logbase_logN = 10
)
Arguments
starting_point |
a named vector of starting values for the model parameters. |
experiment_data |
a nested list with the experimental data. Each entry describes
one experiment as a list with two elements: data and conditions. |
known_pars |
named vector of known model parameters |
sec_model_names |
named character vector with names of the environmental conditions and values of the secondary model (see secondary_model_data). |
... |
additional arguments for |
check |
Whether to check the validity of the models. |
formula |
an object of class "formula" describing the x and y variables.
|
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Value
An instance of FitMultipleDynamicGrowth()
.
Examples
## We will use the multiple_experiments data set
data("multiple_experiments")
## 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)
## We can now call the fitting function
global_fit <- fit_multiple_growth(start, multiple_experiments, known, sec_names)
## Parameter estimates can be retrieved with summary
summary(global_fit)
## We can compare fitted model against observations
plot(global_fit)
## Any single environmental factor can be added to the plot using add_factor
plot(global_fit, add_factor = "temperature")
Fitting growth models to multiple dynamic experiments using MCMC
Description
The function fit_multiple_growth_MCMC()
has been superseded by the top-level
function fit_growth()
, which provides a unified approach for growth modelling.
However, this functions can still be used to fit a growth model using a dataset comprised of several experiments with potentially different dynamic experimental conditions.
Usage
fit_multiple_growth_MCMC(
starting_point,
experiment_data,
known_pars,
sec_model_names,
niter,
...,
check = TRUE,
formula = logN ~ time,
logbase_mu = logbase_logN,
logbase_logN = 10
)
Arguments
starting_point |
a named vector of starting values for the model parameters. |
experiment_data |
a nested list with the experimental data. Each entry describes
one experiment as a list with two elements: data and conditions. |
known_pars |
named vector of known model parameters |
sec_model_names |
named character vector with names of the environmental conditions and values of the secondary model (see secondary_model_data). |
niter |
number of samples of the MCMC algorithm. |
... |
additional arguments for FME::modMCMC (e.g. upper and lower bounds). |
check |
Whether to check the validity of the models. |
formula |
an object of class "formula" describing the x and y variables.
|
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Value
An instance of FitMultipleGrowthMCMC()
.
Examples
## We will use the multiple_experiments data set
data("multiple_experiments")
## 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)
## We can now call the fitting function
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
## Parameter estimates can be retrieved with summary
summary(global_MCMC)
## We can compare fitted model against observations
plot(global_MCMC)
## Any single environmental factor can be added to the plot using add_factor
plot(global_MCMC, add_factor = "temperature")
Fit secondary growth models
Description
Fits a secondary growth model to a set of growth rates obtained experimentally. Modelling is done according to the gamma concept proposed by Zwietering (1992) and cardinal parameter models.
Usage
fit_secondary_growth(
fit_data,
starting_point,
known_pars,
sec_model_names,
transformation = "sq",
...,
check = TRUE,
formula = mu ~ .
)
Arguments
fit_data |
Tibble with the data used for the fit. It must have
one column with the observed growth rate (named |
starting_point |
Named vector with initial values for the model parameters
to estimate from the data. The growth rate under optimum conditions must be named
|
known_pars |
Named vector of fixed model parameters. Must be named using the
same convention as |
sec_model_names |
Named character vector defining the secondary model for each environmental factor. |
transformation |
Character defining the transformation of |
... |
Additional arguments passed to |
check |
Whether to do some basic checks (TRUE by default). |
formula |
an object of class "formula" describing the y variable. The
right hand side must be ".". By default |
Value
An instance of FitSecondaryGrowth()
.
Examples
## We use the data included in the package
data("example_cardinal")
## Define the models to fit
sec_model_names <- c(temperature = "Zwietering", pH = "CPM")
## Any model parameter can be fixed
known_pars <- list(mu_opt = 1.2, temperature_n = 1,
pH_n = 2, pH_xmax = 6.8, pH_xmin = 5.2)
## Initial values must be given for every other parameter
my_start <- list(temperature_xmin = 5, temperature_xopt = 35,
pH_xopt = 6.5)
## We can now call the fitting function
fit_cardinal <- fit_secondary_growth(example_cardinal, my_start, known_pars, sec_model_names)
## With summary, we can look at the parameter estimates
summary(fit_cardinal)
## The plot function compares predictions against observations
plot(fit_cardinal)
## Passing which = 2, generates a different kind of plot
plot(fit_cardinal, which = 2)
plot(fit_cardinal, which = 2, add_trend = TRUE)
plot(fit_cardinal, which = 2, add_segment = TRUE)
Full Ratkowsky model
Description
Gamma model adapted from the one by Ratkowsky et al. (1983).
Usage
full_Ratkowski(x, xmin, xmax, c)
Arguments
x |
Value of the environmental factor. |
xmin |
Minimum value for growth |
xmax |
Maximum value for growth |
c |
Parameter defining the speed of the decline |
A helper for making the plots
Description
A helper for making the plots
Usage
get_all_predictions(model)
Arguments
model |
An instance of FitMultipleDynamicGrowth |
Residuals of dynamic prediction
Description
Function for calculating residuals of a dynamic prediction according
to the requirements of FME::modFit()
.
Usage
get_dyna_residuals(
this_p,
fit_data,
env_conditions,
known_pars,
sec_model_names,
cost = NULL,
logbase_mu = logbase_logN,
logbase_logN = 10
)
Arguments
this_p |
named vector of model parameters |
fit_data |
tibble with the data for the fit |
env_conditions |
tibble with the environmental conditions |
known_pars |
named vector of known model parameters |
sec_model_names |
named character vector with names the environmental conditions and values the secondary model (e.g. 'CPM'). |
cost |
an instance of modCost to be combined (to fit multiple models). |
logbase_mu |
Base of the logarithm of the growthrate. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Value
An instance of FME::modCost()
.
Residuals of isothermal prediction
Description
Residuals of isothermal prediction
Usage
get_iso_residuals(
this_p,
fit_data,
model_name,
known_pars,
logbase_mu = logbase_logN,
logbase_logN = 10
)
Arguments
this_p |
named vector of model parameters to fit |
fit_data |
tibble with the data for the fit |
model_name |
character defining the primary growth model |
known_pars |
named vector of fixed model parameters |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Value
An instance of modCost
.
Residuals of multiple dynamic predictions
Description
Function for calculating residuals of dynamic predictions under
different conditions for the same model parameters according
to the requirements of FME::modFit()
.
Usage
get_multi_dyna_residuals(
this_p,
experiment_data,
known_pars,
sec_model_names,
logbase_mu = logbase_logN,
logbase_logN = 10
)
Arguments
this_p |
named vector of model parameters |
experiment_data |
a nested list with the experimental data. Each entry describes
one experiment as a list with two elements: data and conditions. |
known_pars |
named vector of known model parameters |
sec_model_names |
named character vector with names of the environmental conditions and values of the secondary model (see secondary_model_data). |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Value
an instance of modCost
.
Residuals of secondary models
Description
Residual function for fit_secondary_growth()
.
Usage
get_secondary_residuals(
this_p,
my_data,
known_pars,
sec_model_names,
transformation
)
Arguments
this_p |
Named vector of model parameter values. |
my_data |
Tibble with the data used for the fit. |
known_pars |
Named vector of fixed model paramaters. |
sec_model_names |
Named character vector defining the secondary model for each environmental factor. |
transformation |
Character defining the tranformation of |
Value
A numeric vector of residuals.
Number of tractors in Greece according to the World Bank
Description
A dataset showing the increase in tractors in Greece. It was retrieved from https://data.worldbank.org/indicator/AG.AGR.TRAC.NO?end=2009&start=1961&view=chart.
Usage
greek_tractors
Format
A tibble with 46 rows (each corresponding to one year) and 7 columns:
- year
Year for the recording
- tractors
Number of tractors
Example of dynamic growth
Description
A dataset to demonstrate the use of fit_dynamic_growth. The values of the environmental conditions are described in conditions_pH_temperature.
Usage
growth_pH_temperature
Format
A tibble with 20 rows and 2 columns:
- time
elapsed time
- logN
decimal logarithm of the population size
Growth of Salmonella spp in broth
Description
An example dataset to illustrate fit_isothermal_growth()
. It
describes the growth of Salmonella spp. in broth. It was retrieved from
ComBase (ID: B092_10).
Usage
growth_salmonella
Format
A tibble with 21 rows and 2 columns:
- time
elapsed time in hours.
- logN
observed population size (log CFU/g).
Secondary model for inhibitory compounds
Description
Secondary model for the effect of inhibitory compounds.
Usage
inhibitory_model(x, MIC, alpha)
Arguments
x |
Value of the environmental factor (in principle, concentration of compound). |
MIC |
Minimum Inhibitory Concentration |
alpha |
shape factor of the miodel |
Value
The corresponding gamma factor.
Test of DynamicGrowth object
Description
Tests if an object is of class DynamicGrowth
.
Usage
is.DynamicGrowth(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
DynamicGrowth
Test of FitDynamicGrowth object
Description
Tests if an object is of class FitDynamicGrowth
.
Usage
is.FitDynamicGrowth(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
FitDynamicGrowth
Test of FitDynamicGrowthMCMC object
Description
Tests if an object is of class FitDynamicGrowthMCMC
.
Usage
is.FitDynamicGrowthMCMC(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
FitDynamicGrowthMCMC
Test of FitIsoGrowth object
Description
Tests if an object is of class FitIsoGrowth
.
Usage
is.FitIsoGrowth(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
FitIsoGrowth
Test of FitMultipleDynamicGrowth object
Description
Tests if an object is of class FitMultipleDynamicGrowth
.
Usage
is.FitMultipleDynamicGrowth(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
FitMultipleDynamicGrowth
Test of FitMultipleDynamicGrowthMCMC object
Description
Tests if an object is of class FitMultipleDynamicGrowthMCMC
.
Usage
is.FitMultipleDynamicGrowthMCMC(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
FitMultipleDynamicGrowthMCMC
Test of FitSecondaryGrowth object
Description
Tests if an object is of class FitSecondaryGrowth
.
Usage
is.FitSecondaryGrowth(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
FitSecondaryGrowth
Test of GlobalGrowthFit object
Description
Tests if an object is of class GlobalGrowthFit
Usage
is.GlobalGrowthFit(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class GlobalGrowthFit
Test of GrowthFit object
Description
Tests if an object is of class GrowthFit
Usage
is.GrowthFit(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class GrowthFit
Test of GrowthPrediction object
Description
Tests if an object is of class GrowthPrediction
Usage
is.GrowthPrediction(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class GrowthPrediction
Test of GrowthUncertainty object
Description
Tests if an object is of class GrowthUncertainty
Usage
is.GrowthUncertainty(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class GrowthUncertainty
Test of IsothermalGrowth object
Description
Tests if an object is of class IsothermalGrowth
.
Usage
is.IsothermalGrowth(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
IsothermalGrowth
Test of MCMCgrowth object
Description
Tests if an object is of class MCMCgrowth
.
Usage
is.MCMCgrowth(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
MCMCgrowth
Test of StochasticGrowth object
Description
Tests if an object is of class StochasticGrowth
.
Usage
is.StochasticGrowth(x)
Arguments
x |
object to be checked. |
Value
A boolean specifying whether x
is of class
StochasticGrowth
Isothermal Baranyi model
Description
Baranyi growth model as defined by Baranyi and Roberts (1994). We use the solution calculated by Poschet et al. (2005, doi: https://doi.org/10.1016/j.ijfoodmicro.2004.10.008) after log-transformation according to MONTE CARLO ANALYSIS FOR MICROBIAL GROWTH CURVES, by Oksuz and Buzrul.
Usage
iso_Baranyi(times, logN0, mu, lambda, logNmax)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
lambda |
Lag phase duration |
logNmax |
Maximum log microbial count |
Value
Numeric vector with the predicted microbial count.
Isothermal Baranyi model without lag phase
Description
Baranyi growth model as defined by Baranyi and Roberts (1994). We use the solution calculated by Poschet et al. (2005, doi: https://doi.org/10.1016/j.ijfoodmicro.2004.10.008) after log-transformation according to MONTE CARLO ANALYSIS FOR MICROBIAL GROWTH CURVES, by Oksuz and Buzrul.
Usage
iso_Baranyi_noLag(times, logN0, mu, logNmax)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
logNmax |
Maximum log microbial count |
Value
Numeric vector with the predicted microbial count.
Isothermal Baranyi model without stationary phase
Description
Baranyi growth model as defined by Baranyi and Roberts (1994). We use the solution calculated by Poschet et al. (2005, doi: https://doi.org/10.1016/j.ijfoodmicro.2004.10.008) after log-transformation according to MONTE CARLO ANALYSIS FOR MICROBIAL GROWTH CURVES, by Oksuz and Buzrul.
Usage
iso_Baranyi_noStat(times, logN0, mu, lambda)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
lambda |
Lag phase duration |
Value
Numeric vector with the predicted microbial count.
Reparameterized Gompertz model
Description
Reparameterized Gompertz growth model defined by Zwietering et al. (1990).
Usage
iso_repGompertz(times, logN0, C, mu, lambda)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
C |
Difference between |
mu |
Maximum specific growth rate (in ln CFU/t) |
lambda |
Lag phase duration |
Value
Numeric vector with the predicted microbial count.
Q0 from lag phase duration
Description
Convenience function to calculate the value of Q0 for the Baranyi model from the duration of the lag phase
Usage
lambda_to_Q0(lambda, mu, logbase_mu = 10)
Arguments
lambda |
Duration of the lag phase. |
mu |
Specific growth rate in the exponential phase. |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, 10 (i.e. log10). See vignette about units for details. |
Logistic growth model
Description
Logistic growth model
Usage
logistic_model(times, logN0, mu, lambda, C)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
lambda |
Lag phase duration |
C |
Difference between |
Value
Numeric vector with the predicted microbial count
Loglinear model
Description
Loglinear model
Usage
loglinear_model(times, logN0, mu)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
Initial guesses for the secondary model of one factor
Description
Initial guesses for the secondary model of one factor
Usage
make_guess_factor(fit_data, sec_model, factor)
Arguments
fit_data |
Tibble with the data used for the fit. It must have
one column with the observed growth rate (named |
sec_model |
character defining the secondary model equation according
to |
factor |
character defining the environmental factor |
Initial guesses for fitting primary growth models
Description
The function uses some heuristics to provide initial guesses for the parameters
of the growth model selected that can be used with fit_growth()
.
Usage
make_guess_primary(
fit_data,
primary_model,
logbase_mu = 10,
formula = logN ~ time
)
Arguments
fit_data |
the experimental data. A tibble (or data.frame) with a column
named |
primary_model |
a string defining the equation of the primary model,
as defined in |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, 10 (i.e. log10). See vignette about units for details. |
formula |
an object of class "formula" describing the x and y variables.
|
Value
A named numeric vector of initial guesses for the model parameters
Examples
## An example of experimental data
my_data <- data.frame(time = 0:9,
logN = c(2, 2.1, 1.8, 2.5, 3.1, 3.4, 4, 4.5, 4.8, 4.7))
## We just need to pass the data and the model equation
make_guess_primary(my_data, "Logistic")
## We can use this together with fit_growth()
fit_growth(my_data,
list(primary = "Logistic"),
make_guess_primary(my_data, "Logistic"),
c()
)
## The parameters returned by the function are adapted to the model
make_guess_primary(my_data, "Baranyi")
## It can express mu in other logbases
make_guess_primary(my_data, "Baranyi", logbase_mu = exp(1)) # natural
make_guess_primary(my_data, "Baranyi", logbase_mu = 2) # base2
Initial guesses for the parameters of a secondary model
Description
Uses some heuristic rules to generate an initial guess of the model parameters
of secondary growth models that can be used for model fitting with
fit_secondary_growth()
.
Usage
make_guess_secondary(fit_data, sec_model_names)
Arguments
fit_data |
Tibble with the data used for the fit. It must have
one column with the observed growth rate (named |
sec_model_names |
Named character vector defining the secondary model for each environmental factor. |
Examples
## We can use the example dataset included in the package
data("example_cardinal")
## We assign model equations to factors as usual
sec_model_names <- c(temperature = "Zwietering", pH = "fullRatkowsky")
## We can then calculate the initial guesses
make_guess_secondary(example_cardinal, sec_model_names)
## We can pass these parameters directly to fit_secondary_growth
fit_secondary_growth(example_cardinal,
make_guess_secondary(example_cardinal, sec_model_names),
c(),
sec_model_names)
Environmental conditions during several dynamic experiments
Description
This dataset is paired with multiple_counts to illustrate the global
fitting of fit_growth()
.
Usage
multiple_conditions
Format
A nested list with two elements, each one corresponding to one experiment. Each element is a data.frame with three columns:
time: elapsed time
temperature: observed temperature
pH: observed pH
Population growth observed in several dynamic experiments
Description
This dataset is paired with multiple_conditions to illustrate the global
fitting of fit_growth()
.
Usage
multiple_counts
Format
A nested list with two elements, each one corresponding to one experiment. Each element is a data.frame with two columns:
time: elapsed time
logN: log10 of the microbial concentration
A set of growth experiments under dynamic conditions
Description
An example dataset illustrating the requirements of
fit_multiple_growth()
and
fit_multiple_growth_MCMC()
.
Usage
multiple_experiments
Format
A nested list with two elements. Each element corresponds to one experiment and is described by a list with two data frames:
- data
a tibble describing the microbial counts. It has 2 columns: time (elapsed time) and logN (logarithm of the microbial count)
.
- conditions
a tibble describing the environmental conditions. It has 3 columns: time (elapsed time), temperature (storage temperature) and pH (pH of the media).
Predictions of the coupled Baranyi model
Description
Predictions of the coupled Baranyi model
Usage
pred_coupled_baranyi(p, temp, times)
Arguments
p |
a numeric vector of model parameters. Must have entries |
temp |
a numeric vector of temperature values |
times |
a numeric vector of time points for the prediction |
Value
a numeric vector of predicted logN (in log CFU/TIME)
Prediction of lambda for the coupled model
Description
Prediction of lambda for the coupled model
Usage
pred_lambda(p, temp)
Arguments
p |
numeric vector (or list) of model parameters. Must have entries |
temp |
numeric vector of temperatures |
Value
the values of lambda
Prediction of the square root of mu for the coupled model
Description
Prediction of the square root of mu for the coupled model
Usage
pred_sqmu(p, temp)
Arguments
p |
numeric vector (or list) of model parameters. Must have entries |
temp |
numeric vector of temperatures |
Value
the values of the square root of mu (in ln CFU/TIME)
Generic for calculating predictions with uncertainty from fits
Description
Generic for calculating predictions with uncertainty from fits
Usage
predictMCMC(
model,
times,
env_conditions,
niter,
newpars = NULL,
formula = . ~ time
)
Arguments
model |
Fit object |
times |
see specific methods for each class |
env_conditions |
see specific methods for each class |
niter |
see specific methods for each class |
newpars |
see specific methods for each class |
formula |
A formula stating the column named defining the elapsed time in
|
Stochastic growth of MCMC fit
Description
The function predict_MCMC_growth()
has been superseded by predictMCMC()
S3 methods of the relevant classes.
Nonetheless, it can still make a prediction of microbial growth including
parameter uncertainty 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,
formula = . ~ time
)
Arguments
MCMCfit |
An instance of |
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. |
formula |
A formula stating the column named defining the elapsed time in
|
Value
An instance of MCMCgrowth()
.
Examples
## 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)
Growth under dynamic conditions
Description
The function predict_dynamic_growth()
has been superseded by the top-level
function predict_growth()
, which provides a unified approach for growth modelling.
Regardless on that, it can still predict population growth under dynamic conditions based on the Baranyi model (Baranyi and Roberts, 1994) and secondary models based on the gamma concept (Zwietering et al. 1992).
Model predictions are done by linear interpolation of the environmental
conditions defined in env_conditions
.
Usage
predict_dynamic_growth(
times,
env_conditions,
primary_pars,
secondary_models,
...,
check = TRUE,
logbase_logN = 10,
logbase_mu = logbase_logN,
formula = . ~ time
)
Arguments
times |
Numeric vector of storage times to make the predictions |
env_conditions |
Tibble (or data.frame) describing the variation of the environmental
conditions during storage. It must have with the elapsed time (named |
primary_pars |
A named list defining the parameters of the primary model
and the initial values of the model variables. That is, with names |
secondary_models |
A nested list describing the secondary models. |
... |
Additional arguments for |
check |
Whether to check the validity of the models. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
formula |
An object of class "formula" describing the x variable.
|
Value
An instance of DynamicGrowth()
.
Examples
## Definition of the environmental conditions
library(tibble)
my_conditions <- tibble(time = c(0, 5, 40),
temperature = c(20, 30, 35),
pH = c(7, 6.5, 5)
)
## Definition of the model parameters
my_primary <- list(mu_opt = 2,
Nmax = 1e8,N0 = 1e0,
Q0 = 1e-3)
sec_temperature <- list(model = "Zwietering",
xmin = 25, xopt = 35, n = 1)
sec_pH = list(model = "CPM",
xmin = 5.5, xopt = 6.5,
xmax = 7.5, n = 2)
my_secondary <- list(
temperature = sec_temperature,
pH = sec_pH
)
my_times <- seq(0, 50, length = 1000)
## Do the simulation
dynamic_prediction <- predict_dynamic_growth(my_times,
my_conditions, my_primary,
my_secondary)
## Plot the results
plot(dynamic_prediction)
## We can plot some environmental factor with add_factor
plot(dynamic_prediction, add_factor = "temperature", ylims= c(0, 8),
label_y1 = "Microbial count (log CFU/ml)",
label_y2 = "Storage temperature (C)")
Prediction of microbial growth
Description
This function provides a top-level interface for predicting population growth. Predictions can be made either under constant or dynamic environmental conditions. See below for details on the calculations.
Usage
predict_growth(
times,
primary_model,
environment = "constant",
secondary_models = NULL,
env_conditions = NULL,
...,
check = TRUE,
logbase_mu = logbase_logN,
logbase_logN = 10,
formula = . ~ time
)
Arguments
times |
numeric vector of time points for making the predictions |
primary_model |
named list defining the values of the parameters of the primary growth model |
environment |
type of environment. Either "constant" (default) or "dynamic" (see below for details on the calculations for each condition) |
secondary_models |
a nested list describing the secondary models. See below for details |
env_conditions |
Tibble describing the variation of the environmental
conditions for dynamic experiments. It must have with the elapsed time (named |
... |
Additional arguments for |
check |
Whether to check the validity of the models. |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
formula |
An object of class "formula" describing the x variable for predictions
under dynamic conditions. |
Details
To ease data input, the functions can convert between parameters defined in different scales. Namely, for predictions in constant environments (environment="constant"):
"logN0" can be defined as "N0". The function automatically calculates the log-transformation.
"logNmax" can be defined as "Nmax". The function automatically calculates the log-transformation.
"mu" can be defined as "mu_opt". The function assumes the prediction is under optimal growth conditions.
"lambda" can be defined by "Q0". The duration of the lag phase is calculated using
Q0_to_lambda()
.
And, for predictions in dynamic environments (environment="dynamic"):
"N0" can be defined as "N0". The function automatically calculates the antilog-transformation.
"Nmax" can be defined as "logNmax". The function automatically calculates the antilog-transformation.
"mu" can be defined as "mu_opt". The function assumes mu was calculated under optimal growth conditions.
"Q0" can be defined by the value of "lambda" under dynamic conditions. Then, the value of Q0 is calculated using
lambda_to_Q0()
.
Value
An instance of GrowthPrediction.
Predictions in constant environments
Predictions under constant environments are calculated using only primary models. Consequently, the arguments "secondary_models" and "env_conditions" are ignored. If these were passed, the function would return a warning. In this case, predictions are calculated using the algebraic form of the primary model (see vignette for details).
The growth model is defined through the "primary_model" argument using a named list.
One of the list elements must be named "model" and must take take one of the valid
keys returned by primary_model_data()
. The remaining entries of the list define the
values of the parameters of the selected model. A list of valid keys can be retrieved
using primary_model_data()
(see example below). Note that the functions can do
some operations to facilitate the compatibility between constant and dynamic environments
(see Details).
Predictions in dynamic environments
Predictions under dynamic environments are calculated by solving numerically the differential equation of the Baranyi growth model. The effect of changes in the environmental conditions in the growth rate are calculated according to the gamma approach. Therefore, one must define both primary and secondary models.
The dynamic environmental conditions are defined using a tibble (or data.frame) through the "env_conditions" argument. It must include one column named "time" stating the elapsed time and as many additional columns as environmental conditions included in the prediction. For values of time not included in the tibble, the values of the environmental conditions are calculated by linear interpolation.
Primary models are defined as a named list through the "primary_model" argument. It must include the following elements:
N0: initial population size
Nmax: maximum population size in the stationary growth phase
mu_opt: growth rate under optimal growth conditions
Q0: value defining the duration of the lag phase Additional details on these parameters can be found in the package vignettes.
Secondary models are defined as a nested list through the "secondary_models" argument.
The list must have one entry per environmental condition, whose name must match
those used in the "env_conditions" argument. Each of these entries must be a named list
defining the secondary model for each environmental condition. The model equation is defined
in an entry named "model" (valid keys can be retrieved from secondary_model_data()
). Then,
additional entries defined the values of each model parameters (valid keys can be retrieved from secondary_model_data()
)
For additional details on how to define the secondary models, please see the package vignettes (and examples below).
Examples
## Example 1 - Growth under constant conditions -----------------------------
## Valid model keys can be retrieved calling primary_model_data()
primary_model_data()
my_model <- "modGompertz" # we will use the modified-Gompertz
## The keys of the model parameters can also be obtained from primary_model_data()
primary_model_data(my_model)$pars
## We define the primary model as a list
my_model <- list(model = "modGompertz", logN0 = 0, C = 6, mu = .2, lambda = 20)
## We can now make the predictions
my_time <- seq(0, 100, length = 1000) # Vector of time points for the calculations
my_prediction <- predict_growth(my_time, my_model, environment = "constant")
## The instance of IsothermalGrowth includes several S3 methods
print(my_prediction)
plot(my_prediction)
coef(my_prediction)
## Example 2 - Growth under dynamic conditions ------------------------------
## We will consider the effect of two factors: temperature and pH
my_conditions <- data.frame(time = c(0, 5, 40),
temperature = c(20, 30, 35),
pH = c(7, 6.5, 5)
)
## The primary model is defined as a named list
my_primary <- list(mu = 2, Nmax = 1e7, N0 = 1, Q0 = 1e-3)
## The secondary model is defined independently for each factor
sec_temperature <- list(model = "Zwietering",
xmin = 25, xopt = 35, n = 1)
sec_pH = list(model = "CPM",
xmin = 5.5, xopt = 6.5,
xmax = 7.5, n = 2)
## Then, they are assigned to each factor using a named list
my_secondary <- list(
temperature = sec_temperature,
pH = sec_pH
)
## We can call the function now
my_times <- seq(0, 50, length = 1000) # Where the output is calculated
dynamic_prediction <- predict_growth(environment = "dynamic",
my_times, my_primary, my_secondary,
my_conditions
)
## The instance of DynamicGrowth includes several useful S3 methods
print(dynamic_prediction)
plot(dynamic_prediction)
plot(dynamic_prediction, add_factor = "pH")
coef(dynamic_prediction)
## The time_to_size function can predict the time to reach a population size
time_to_size(my_prediction, 3)
Isothermal growth with parameter uncertainty
Description
Simulation of microbial growth considering uncertianty in the model parameters. Calculations are based on Monte Carlo simulations, considering the parameters follow a multivariate normal distribution.
Usage
predict_growth_uncertainty(
model_name,
times,
n_sims,
pars,
corr_matrix = diag(nrow(pars)),
check = TRUE,
logbase_mu = logbase_logN,
logbase_logN = 10
)
Arguments
model_name |
Character describing the primary growth model. |
times |
Numeric vector of storage times for the simulations. |
n_sims |
Number of simulations. |
pars |
A tibble describing the parameter uncertainty (see details). |
corr_matrix |
Correlation matrix of the model parameters. Defined in the
same order as in |
check |
Whether to do some tests. |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Details
The distributions of the model parameters are
defined in the pars
argument using a tibble with 4 columns:
par: identifier of the model parameter (according to
primary_model_data()
),mean: mean value of the model parameter.,
sd: standard deviation of the model parameter.,
scale: scale at which the model parameter is defined. Valid values are 'original' (no transformation), 'sqrt' square root or 'log' log-scale. The parameter sample is generated considering the parameter follows a marginal normal distribution at this scale, and is later converted to the original scale for calculations.
Value
An instance of GrowthUncertainty()
.
Examples
## Definition of the simulation settings
my_model <- "Baranyi"
my_times <- seq(0, 30, length = 100)
n_sims <- 3000
library(tibble)
pars <- tribble(
~par, ~mean, ~sd, ~scale,
"logN0", 0, .2, "original",
"mu", 2, .3, "sqrt",
"lambda", 4, .4, "sqrt",
"logNmax", 6, .5, "original"
)
## Calling the function
stoc_growth <- predict_growth_uncertainty(my_model, my_times, n_sims, pars)
## We can plot the results
plot(stoc_growth)
## Adding parameter correlation
my_cor <- matrix(c(1, 0, 0, 0,
0, 1, 0.7, 0,
0, 0.7, 1, 0,
0, 0, 0, 1),
nrow = 4)
stoc_growth2 <- predict_growth_uncertainty(my_model, my_times, n_sims, pars, my_cor)
plot(stoc_growth2)
## The time_to_size function can calculate the median growth curve to reach a size
time_to_size(stoc_growth, 4)
## Or the distribution of times
dist <- time_to_size(stoc_growth, 4, type = "distribution")
plot(dist)
Isothermal microbial growth
Description
The function predict_isothermal_growth()
has been superseded by the top-level
function predict_growth()
, which provides a unified approach for growth modelling.
Regardless of that, it can still be used to predict population growth under static environmental conditions (i.e. using primary models).
Usage
predict_isothermal_growth(
model_name,
times,
model_pars,
check = TRUE,
logbase_mu = 10,
logbase_logN = 10
)
Arguments
model_name |
Character defining the growth model. |
times |
Numeric vector of storage times for the predictions. |
model_pars |
Named vector or list defining the values of the model parameters. |
check |
Whether to do basic checks (TRUE by default). |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, the same as logbase_logN. See vignette about units for details. |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Value
An instance of IsothermalGrowth()
.
Examples
## Define the simulations parameters
my_model <- "modGompertz"
my_pars <- list(logN0 = 2, C = 6, mu = .2, lambda = 25)
my_time <- seq(0, 100, length = 1000)
## Do the simulation
static_prediction <- predict_isothermal_growth(my_model, my_time, my_pars)
## Plot the results
plot(static_prediction)
Deprecated isothermal growth with parameter uncertainty
Description
predict_stochastic_growth()
was renamed predict_growth_uncertainty()
because
the original function name may be misleading, as this is not a stochastic
differential equation
Usage
predict_stochastic_growth(
model_name,
times,
n_sims,
pars,
corr_matrix = diag(nrow(pars)),
check = TRUE
)
Arguments
model_name |
Character describing the primary growth model. |
times |
Numeric vector of storage times for the simulations. |
n_sims |
Number of simulations. |
pars |
A tibble describing the parameter uncertainty (see details). |
corr_matrix |
Correlation matrix of the model parameters. Defined in the
same order as in |
check |
Whether to do some tests. |
Metainformation of primary growth models
Description
Provides different types of meta-data about the primary growth models included
in biogrowth. This information is the basis of the automatic checks, and can also
help in the definition of models for predict_growth()
and fit_growth()
.
Usage
primary_model_data(model_name = NULL)
Arguments
model_name |
The name of the model or |
Value
If model_name is NULL
, returns a character string with the available models.
If is a valid identifier, it returns a list with metainformation about the model.
If model_name name is not a valid identifier, raises an error.
Temperature recorded in refrigerators
Description
This dataset includes the temperature recorded in refrigerators in households of the Catalonia region. The data was published as part of Jofre et al. (2019) Domestic refrigerator temperatures in Spain: Assessment of its impact on the safety and shelf-life of cooked meat products. Food Research International, 126, 108578. And was kindly provided by the original authors of the study.
Usage
refrigeratorSpain
Format
A tibble with three columns:
time: elapsed time in hours
A1: temperature observed in refrigerator "1"
A2: temperature observed in refrigerator "2"
Residuals for lambda for the coupled model
Description
Residuals for lambda for the coupled model
Usage
residuals_lambda(p, my_d)
Arguments
p |
numeric vector (or list) of model parameters. Must have entries |
my_d |
tibble (or data.frame) of data. It must have one column named |
Value
vector of residuals
Residuals for the square root of mu for the coupled model
Description
Residuals for the square root of mu for the coupled model
Usage
residuals_sqmu(p, my_d)
Arguments
p |
numeric vector (or list) of model parameters. Must have entries |
my_d |
tibble (or data.frame) of data. It must have one column named |
Value
vector of residuals
Richards growth model
Description
Richards growth model
Usage
richards_model(times, logN0, mu, lambda, C, nu)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
lambda |
Lag phase duration |
C |
Difference between |
nu |
Parameter describing the transition between growth phases |
Metainformation of secondary growth models
Description
Provides different types of meta-data about the secondary growth models included
in biogrowth. This information is the basis of the automatic checks, and can also
help in the definition of models for predict_growth()
and fit_growth()
.
Usage
secondary_model_data(model_name = NULL)
Arguments
model_name |
The name of the model or |
Value
If model_name is NULL
, returns a character string with the available models.
If is a valid identifier, it returns a list with metainformation about the model.
If model_name name is not a valid identifier, raises an error.
Plot of the initial guess for growth under dynamic environmental conditions
Description
Compares the prediction corresponding to a guess of the parameters of the model against experimental data
Usage
show_guess_dynamic(
fit_data,
model_keys,
guess,
env_conditions,
logbase_mu = 10,
formula = logN ~ time
)
Arguments
fit_data |
Tibble (or data.frame) of data for the fit. It must have two columns, one with
the elapsed time ( |
model_keys |
Named the equations of the secondary model as in |
guess |
Named vector with the initial guess of the model parameters as in |
env_conditions |
Tibble describing the variation of the environmental
conditions for dynamic experiments. See |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, 10 (i.e. log10). See vignette about units for details. |
formula |
an object of class "formula" describing the x and y variables.
|
Value
A ggplot2::ggplot()
comparing the model prediction against the data
Plot of the initial guess for growth under constant environmental conditions
Description
Compares the prediction corresponding to a guess of the parameters of the primary model against experimental data
Usage
show_guess_primary(
fit_data,
model_name,
guess,
logbase_mu = 10,
formula = logN ~ time
)
Arguments
fit_data |
Tibble (or data.frame) of data for the fit. It must have two columns, one with
the elapsed time ( |
model_name |
Character defining the primary growth model as per |
guess |
Named vector with the initial guess of the model parameters |
logbase_mu |
Base of the logarithm the growth rate is referred to. By default, 10 (i.e. log10). See vignette about units for details. |
formula |
an object of class "formula" describing the x and y variables.
|
Value
A ggplot2::ggplot()
comparing the model prediction against the data
Time to reach a given microbial count
Description
The function time_to_logcount()
has been superseded by
function time_to_size()
, which provides a more general interface.
But it still returns the storage time required for the microbial count to
reach log_count
according to the predictions of model
.
Calculations are done using linear interpolation of the model predictions.
Usage
time_to_logcount(model, log_count)
Arguments
model |
An instance of |
log_count |
The target log microbial count. |
Value
The predicted time to reach log_count
.
Examples
## First of all, we will get an IsothermalGrowth object
my_model <- "modGompertz"
my_pars <- list(logN0 = 2, C = 6, mu = .2, lambda = 25)
my_time <- seq(0, 100, length = 1000)
static_prediction <- predict_isothermal_growth(my_model, my_time, my_pars)
plot(static_prediction)
## And now we calculate the time to reach a microbial count
time_to_logcount(static_prediction, 2.5)
## If log_count is outside the range of the predicted values, NA is returned
time_to_logcount(static_prediction, 20)
Time for the population to reach a given size
Description
Calculates the elapsed time required for the population to reach a given size (in log scale)
Usage
time_to_size(model, size, type = "discrete", logbase_logN = NULL)
Arguments
model |
An instance of GrowthPrediction, GrowthFit, GlobalGrowthFit, GrowthUncertainty or MCMCgrowth. |
size |
Target population size (in log scale) |
type |
Tye of calculation, either "discrete" (default) or "distribution" |
logbase_logN |
Base of the logarithm for the population size. By default, 10 (i.e. log10). See vignette about units for details. |
Details
The calculation method differs depending on the value of type
. If type="discrete"
(default), the function calculates by linear interpolation a discrete time to
reach the target population size. If type="distribution"
, this calculation
is repeated several times, generating a distribution of the time. Note that this
is only possible for instances of GrowthUncertainty or MCMCgrowth.
Value
If type="discrete"
, a number. If type="distribution"
, an instance of
TimeDistribution.
Examples
## Example 1 - Growth predictions -------------------------------------------
## The model is defined as usual with predict_growth
my_model <- list(model = "modGompertz", logN0 = 0, C = 6, mu = .2, lambda = 20)
my_time <- seq(0, 100, length = 1000) # Vector of time points for the calculations
my_prediction <- predict_growth(my_time, my_model, environment = "constant")
plot(my_prediction)
## We just have to pass the model and the size (in log10)
time_to_size(my_prediction, 3)
## If the size is not reached, it returns NA
time_to_size(my_prediction, 8)
## By default, it considers the population size is defined in the same log-base
## as the prediction. But that can be changed using logbase_logN
time_to_size(my_prediction, 3)
time_to_size(my_prediction, 3, logbase_logN = 10)
time_to_size(my_prediction, log(100), logbase_logN = exp(1))
## Example 2 - Model fit ----------------------------------------------------
my_data <- data.frame(time = c(0, 25, 50, 75, 100),
logN = c(2, 2.5, 7, 8, 8))
models <- list(primary = "Baranyi")
known <- c(mu = .2)
start <- c(logNmax = 8, lambda = 25, logN0 = 2)
primary_fit <- fit_growth(my_data, models, start, known,
environment = "constant",
)
plot(primary_fit)
time_to_size(primary_fit, 4)
## Example 3 - Global fitting -----------------------------------------------
## We need a model first
data("multiple_counts")
data("multiple_conditions")
sec_models <- list(temperature = "CPM", pH = "CPM")
known_pars <- list(Nmax = 1e8, N0 = 1e0, Q0 = 1e-3,
temperature_n = 2, temperature_xmin = 20,
temperature_xmax = 35,
temperature_xopt = 30,
pH_n = 2, pH_xmin = 5.5, pH_xmax = 7.5, pH_xopt = 6.5)
my_start <- list(mu_opt = .8)
global_fit <- fit_growth(multiple_counts,
sec_models,
my_start,
known_pars,
environment = "dynamic",
algorithm = "regression",
approach = "global",
env_conditions = multiple_conditions
)
plot(global_fit)
## The function calculates the time for each experiment
time_to_size(global_fit, 3)
## It returns NA for the particular experiment if the size is not reached
time_to_size(global_fit, 4.5)
Trilinear growth model
Description
Trilinear growth model defined by Buchanan et al. (1997).
Usage
trilinear_model(times, logN0, mu, lambda, logNmax)
Arguments
times |
Numeric vector of storage times |
logN0 |
Initial log microbial count |
mu |
Maximum specific growth rate (in ln CFU/t) |
lambda |
Lag phase duration |
logNmax |
Maximum log microbial count |
Value
Numeric vector with the predicted microbial count.
Zwietering gamma model
Description
Gamma model as defined by Zwietering et al. (1992). To avoid unreasonable predictions, it has been modified setting gamma=0 for values of x outside (xmin, xopt)
Usage
zwietering_gamma(x, xmin, xopt, n)
Arguments
x |
Value of the environmental factor. |
xmin |
Minimum value of the environmental factor for growth. |
xopt |
Maximum value for growth |
n |
Exponent of the secondary model |
Value
The corresponding gamma factor.