| Title: | Fitting Predictive Microbiology Models |
|---|---|
| Description: | Provides predictive microbiology model functions and convenience wrappers for fitting primary growth, microbial inactivation, dynamic, omnibus, and cardinal parameter models to experimental data using nonlinear least squares and related mixed-effects or time-varying workflows. Includes helper functions for extracting fitted values, calculating model diagnostics, and comparing fitted models. Implemented model families include those described by: Zwietering et al. (1990) <doi:10.1128/AEM.56.6.1875-1881.1990>, Baranyi and Roberts (1994) <doi:10.1016/0168-1605(94)90157-0>, Baranyi and Roberts (1995) <doi:10.1016/0168-1605(94)00121-L>, Buchanan et al. (1997) <doi:10.1006/fmic.1997.0125>, Richards (1959) <doi:10.1093/jxb/10.2.290>, Fang et al. (2012) <doi:10.1111/j.1750-3841.2012.02873.x>, Fang et al. (2013) <doi:10.1016/j.fm.2012.12.005>, Huang (2008) <doi:10.1111/j.1750-3841.2008.00785.x>, Huang (2009) <doi:10.1016/j.jfoodeng.2008.07.011>, Huang (2013) <doi:10.1016/j.foodcont.2012.11.019>, Geeraerd et al. (2005) <doi:10.1016/j.ijfoodmicro.2004.11.038>, van Boekel (2002) <doi:10.1016/S0168-1605(01)00742-5>, Peleg (1999) <doi:10.1016/S0963-9969(99)00081-2>, Mafart et al. (2002) <doi:10.1016/S0168-1605(01)00624-9>, Albert and Mafart (2005) <doi:10.1016/j.ijfoodmicro.2004.10.016>, Rosso et al. (1993) <doi:10.1006/jtbi.1993.1099>, Rosso et al. (1995) <doi:10.1128/AEM.61.2.610-616.1995>, and Rosso et al. (1996) <doi:10.4315/0362-028X-59.9.944>. |
| Authors: | Vasco Cadavez [aut, cre] (ORCID: <https://orcid.org/0000-0002-3077-7414>), Ursula Gonzales-Barron [aut] (ORCID: <https://orcid.org/0000-0002-8462-9775>) |
| Maintainer: | Vasco Cadavez <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.3.2 |
| Built: | 2026-06-19 18:41:07 UTC |
| Source: | https://github.com/cran/predmicror |
A dataset containing water activity and growth rate data
data(aw)data(aw)
A data frame with 9 rows and 3 variables:
Water activity
Square root of the growth rate
Growth rate
BaranyiFM function to fit the Baranyi & Roberts full growth model to a complete microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
BaranyiFM(t, Y0, Ymax, MUmax, lag)BaranyiFM(t, Y0, Ymax, MUmax, lag)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
Ymax |
is the natural logarithm of the maximum concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
lag |
is the duration of the lag phase in time units |
The model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Baranyi J, Roberts TA (1994). “A dynamic approach to predicting bacterial growth in food.” International Journal of Food Microbiology, 23, 277-294.
library(gslnls) data(growthfull) initial_values <- list(Y0 = -0.1, Ymax = 22, MUmax = 1.7, lag = 5) fit <- gsl_nls(lnN ~ BaranyiFM(Time, Y0, Ymax, MUmax, lag), data = growthfull, start = initial_values ) summary(fit)library(gslnls) data(growthfull) initial_values <- list(Y0 = -0.1, Ymax = 22, MUmax = 1.7, lag = 5) fit <- gsl_nls(lnN ~ BaranyiFM(Time, Y0, Ymax, MUmax, lag), data = growthfull, start = initial_values ) summary(fit)
BaranyiRM function to fit the Baranyi and Roberts growth model to a reduced microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
BaranyiRM(t, Y0, MUmax, lag)BaranyiRM(t, Y0, MUmax, lag)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
lag |
is the duration of the lag phase in time units |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez, [email protected] and Ursula Gonzales-Barron, [email protected]
Baranyi J, Roberts TA (1995). “Mathematics of predictive microbiology.” International Journal of Food Microbiology, 26, 199-218.
## Example: Baranyi reduced model library(gslnls) data(growthred) # simulated data set. initial_values <- list(Y0 = 0.1, MUmax = 1.7, lag = 5) # define the initial values fit <- gsl_nls(lnN ~ BaranyiRM(Time, Y0, MUmax, lag), data = growthred, start = initial_values ) summary(fit)## Example: Baranyi reduced model library(gslnls) data(growthred) # simulated data set. initial_values <- list(Y0 = 0.1, MUmax = 1.7, lag = 5) # define the initial values fit <- gsl_nls(lnN ~ BaranyiRM(Time, Y0, MUmax, lag), data = growthred, start = initial_values ) summary(fit)
bias_factor() and accuracy_factor() calculate the multiplicative model
bias and accuracy factors commonly used in predictive microbiology model
validation.
bias_factor(observed, predicted) accuracy_factor(observed, predicted)bias_factor(observed, predicted) accuracy_factor(observed, predicted)
observed, predicted
|
Numeric vectors. Values must be positive. |
A numeric scalar.
observed <- c(7.0, 6.0, 5.0) predicted <- c(7.1, 5.9, 5.2) bias_factor(observed, predicted) accuracy_factor(observed, predicted)observed <- c(7.0, 6.0, 5.0) predicted <- c(7.1, 5.9, 5.2) bias_factor(observed, predicted) accuracy_factor(observed, predicted)
A dataset containing time (minutes), repetition and number of microrganisms (ln N).
data(bixina)data(bixina)
A data frame with 18 rows and 3 variables:
Time in minutes
Repetition
Number of microrganism in ln scale
BuchananRM function to fit the Buchanan reduced growth model to a reduced microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
BuchananRM(t, Y0, MUmax, lag)BuchananRM(t, Y0, MUmax, lag)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
lag |
is the duration of the lag phase in time units |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez, [email protected] and Ursula Gonzales-Barron, [email protected]
Buchanan RL, Whiting RC, Damert WC (1997). “When is simple good enough: a comparison of the Gompertz, Baranyi, and three-phase linear models for fitting bacterial growth curves.” Food Microbiology, 14(4), 313-326. ISSN 0740-0020. doi:10.1006/fmic.1997.0125.
## Example: Buchanan reduced model library(gslnls) data(growthred) # simulated data set. initial_values <- list(Y0 = 0, MUmax = 1.7, lag = 5) # define the initial values fit <- gsl_nls(lnN ~ BuchananRM(Time, Y0, MUmax, lag), data = growthred, start = initial_values ) summary(fit)## Example: Buchanan reduced model library(gslnls) data(growthred) # simulated data set. initial_values <- list(Y0 = 0, MUmax = 1.7, lag = 5) # define the initial values fit <- gsl_nls(lnN ~ BuchananRM(Time, Y0, MUmax, lag), data = growthred, start = initial_values ) summary(fit)
CMAW function to fit the water activity cardinal model (Rosso et al., 1993).
Returns the model parameters estimated according to data collected in microbial growth experiments.
CMAW(x, AWmin, MUopt, AWopt)CMAW(x, AWmin, MUopt, AWopt)
x |
is a numeric vector indicating the water activity of the experiment |
AWmin |
is minimum water activity for growth |
MUopt |
is the optimum growth rate |
AWopt |
is optimum water activity for growth |
The model's inputs are:
x: Water activity
sqrtGR: the square root of the growth rate ()
Users should make sure that the growth rate input is entered after a square root transformation, sqrGR = sqrt(GR).
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Rosso L, Lobry J, Charles (Bajard) S, Flandrois J (1995). “Convenient Model To Describe the Combined Effects of Temperature and pH on Microbial Growth.” Applied and environmental microbiology, 61, 610–6. doi:10.1128/AEM.61.2.610-616.1995.
library(gslnls) data(aw) initial_values <- list(AWmin = 0.89, MUopt = 1.0, AWopt = 0.98) fit <- gsl_nls(sqrtGR ~ CMAW(aw, AWmin, MUopt, AWopt), data = aw, start = initial_values ) summary(fit)library(gslnls) data(aw) initial_values <- list(AWmin = 0.89, MUopt = 1.0, AWopt = 0.98) fit <- gsl_nls(sqrtGR ~ CMAW(aw, AWmin, MUopt, AWopt), data = aw, start = initial_values ) summary(fit)
CMInh function to fit the growth inhibitors cardinal model (Rosso et al, 1993).
Returns the model parameters estimated according to data collected in microbial growth experiments.
CMInh(x, MIC, MUopt, alpha)CMInh(x, MIC, MUopt, alpha)
x |
is a numeric vector indicating the inhibitor concentration of the experiment |
MIC |
is the minimum inhibitory concentration (mM or %, accordingly) |
MUopt |
is the optimum growth rate |
alpha |
is the shape parameter of the curve ( |
The model's inputs are:
x: growth inhibitor concentration
sqrtGR: the square root of the growth rate ()
Users should make sure that the growth rate input is entered after a square root transformation, $sqrGR = sqrt(GR)$.
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Rosso L, Lobry J, Charles (Bajard) S, Flandrois J (1995). “Convenient Model To Describe the Combined Effects of Temperature and pH on Microbial Growth.” Applied and environmental microbiology, 61, 610–6. doi:10.1128/AEM.61.2.610-616.1995.
library(gslnls) data(inh) initial_values <- list(MIC = 0.89, MUopt = 1.0, alpha = 1) fit <- gsl_nls(sqrtGR ~ CMInh(Conce, MIC, MUopt, alpha), data = inh, start = initial_values ) summary(fit)library(gslnls) data(inh) initial_values <- list(MIC = 0.89, MUopt = 1.0, alpha = 1) fit <- gsl_nls(sqrtGR ~ CMInh(Conce, MIC, MUopt, alpha), data = inh, start = initial_values ) summary(fit)
CMPH function to fit the pH cardinal model (Rosso et al, 1993).
Returns the model parameters estimated according to data collected in microbial growth experiments.
CMPH(x, pHmax, pHmin, MUopt, pHopt)CMPH(x, pHmax, pHmin, MUopt, pHopt)
x |
is a numeric vector indicating the pH of the experiment |
pHmax |
is the maximum pH for growth |
pHmin |
is the minimum pH for growth |
MUopt |
is the optimum growth rate |
pHopt |
is the optimum pH for growth |
The model's inputs are:
x: pH
sqrtGR: the square root of the growth rate ()
Users should make sure that the growth rate input is entered after a square root transformation, sqrGR = sqrt(GR).
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Rosso L, Lobry J, Charles (Bajard) S, Flandrois J (1995). “Convenient Model To Describe the Combined Effects of Temperature and pH on Microbial Growth.” Applied and environmental microbiology, 61, 610–6. doi:10.1128/AEM.61.2.610-616.1995.
library(gslnls) data(ph) initial_values <- list(pHmax = 9, pHmin = 3, MUopt = 1.0, pHopt = 7) fit <- gsl_nls(sqrtGR ~ CMPH(pH, pHmax, pHmin, MUopt, pHopt), data = ph, start = initial_values ) summary(fit)library(gslnls) data(ph) initial_values <- list(pHmax = 9, pHmin = 3, MUopt = 1.0, pHopt = 7) fit <- gsl_nls(sqrtGR ~ CMPH(pH, pHmax, pHmin, MUopt, pHopt), data = ph, start = initial_values ) summary(fit)
CMTI function to fit the temperature cardinal model (Rosso et al, 1993).
Returns the model parameters estimated according to data collected in microbial growth experiments.
CMTI(x, Tmax, Tmin, MUopt, Topt)CMTI(x, Tmax, Tmin, MUopt, Topt)
x |
is a numeric vector indicating the temperature of the experiment |
Tmax |
maximum temperature for growth |
Tmin |
is minimum temperature for growth |
MUopt |
is the optimum growth rate |
Topt |
is optimum temperature for growth |
The model's inputs are:
x: Temperature
sqrtGR: the square root of the growth rate ()
Users should make sure that the growth rate input is entered after a square root transformation, sqrGR = sqrt(GR).
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Rosso L, Lobry J, Charles (Bajard) S, Flandrois J (1995). “Convenient Model To Describe the Combined Effects of Temperature and pH on Microbial Growth.” Applied and environmental microbiology, 61, 610–6. doi:10.1128/AEM.61.2.610-616.1995.
library(gslnls) data(salmonella) initial_values <- list(Tmax = 42, Tmin = 1, MUopt = 1.0, Topt = 37) fit <- gsl_nls(sqrtGR ~ CMTI(Temp, Tmax, Tmin, MUopt, Topt), data = salmonella, start = initial_values ) summary(fit) plot(salmonella$Temp, salmonella$sqrtGR^2) lines(salmonella$Temp, fitted(fit)^2, col = "green") plot(salmonella$Temp, salmonella$sqrtGR) lines(salmonella$Temp, fitted(fit), col = "red")library(gslnls) data(salmonella) initial_values <- list(Tmax = 42, Tmin = 1, MUopt = 1.0, Topt = 37) fit <- gsl_nls(sqrtGR ~ CMTI(Temp, Tmax, Tmin, MUopt, Topt), data = salmonella, start = initial_values ) summary(fit) plot(salmonella$Temp, salmonella$sqrtGR^2) lines(salmonella$Temp, fitted(fit)^2, col = "green") plot(salmonella$Temp, salmonella$sqrtGR) lines(salmonella$Temp, fitted(fit), col = "red")
compare_models() combines the output of fit_metrics() for two or more
fitted models. It is useful when choosing between alternative primary growth,
inactivation, or cardinal models fitted to the same response scale.
compare_models(..., sort_by = c("AIC", "BIC", "RMSE", "MAE", "none"))compare_models(..., sort_by = c("AIC", "BIC", "RMSE", "MAE", "none"))
... |
|
sort_by |
Character string. One of |
A data frame with one row per fitted model.
data(growthfull) huang <- fit_growth( growthfull, model = "HuangFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) baranyi <- fit_growth( growthfull, model = "BaranyiFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) compare_models(huang = huang, baranyi = baranyi)data(growthfull) huang <- fit_growth( growthfull, model = "HuangFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) baranyi <- fit_growth( growthfull, model = "BaranyiFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) compare_models(huang = huang, baranyi = baranyi)
dynamic_profile() stores time-varying environmental conditions such as
temperature, pH, or water activity for dynamic predictive microbiology
simulations. The profile is interpolated internally when dynamic models are
solved between observed profile points.
dynamic_profile(time, temperature = NULL, ph = NULL, aw = NULL, ...)dynamic_profile(time, temperature = NULL, ph = NULL, aw = NULL, ...)
time |
Numeric vector with profile times. |
temperature |
Optional numeric vector with temperatures at |
ph |
Optional numeric vector with pH values at |
aw |
Optional numeric vector with water activity values at |
... |
Additional named numeric vectors with the same length as |
A predmicror_dynamic_profile data frame sorted by time.
predict_dynamic_growth(), predict_dynamic_inactivation()
profile <- dynamic_profile( time = c(0, 5, 10, 15), temperature = c(10, 4, 12, 20) ) profileprofile <- dynamic_profile( time = c(0, 5, 10, 15), temperature = c(10, 4, 12, 20) ) profile
dynamic_sensitivity() perturbs parameters in a dynamic prediction and
returns unscaled and scaled sensitivity coefficients. It is designed as a
lightweight diagnostic for sampling design and parameter identifiability.
dynamic_sensitivity( type = c("growth", "inactivation"), profile, start, parameters = NULL, relative_delta = 1e-06, times = NULL, ... )dynamic_sensitivity( type = c("growth", "inactivation"), profile, start, parameters = NULL, relative_delta = 1e-06, times = NULL, ... )
type |
Character string. One of |
profile |
A |
start |
Named list of parameter values passed to the dynamic prediction function. |
parameters |
Character vector of parameter names to perturb. Defaults to
all numeric scalar entries in |
relative_delta |
Relative perturbation size. |
times |
Optional output times. |
... |
Additional arguments passed to |
A data frame with time, parameter, prediction, sensitivity, and scaled sensitivity.
profile <- dynamic_profile(time = c(0, 5, 10), temperature = c(10, 15, 20)) sens <- dynamic_sensitivity( "growth", profile = profile, start = list(logN0 = 2, logNmax = 8, a = 0.08, Tmin = 7, lag = 1), times = seq(0, 10, by = 2), dt = 0.25 ) head(sens)profile <- dynamic_profile(time = c(0, 5, 10), temperature = c(10, 15, 20)) sens <- dynamic_sensitivity( "growth", profile = profile, start = list(logN0 = 2, logNmax = 8, a = 0.08, Tmin = 7, lag = 1), times = seq(0, 10, by = 2), dt = 0.25 ) head(sens)
FangNLM function to fit the Fang no lag growth model to an incomplete microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
FangNLM(t, Y0, Ymax, MUmax)FangNLM(t, Y0, Ymax, MUmax)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
Ymax |
is the natural logarithm of the maximum concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez, [email protected] and Ursula Gonzales-Barron, [email protected]
Fang T, Gurtler JB, Huang L (2012). “Growth Kinetics and Model Comparison of Cronobacter sakazakii in Reconstituted Powdered Infant Formula.” Journal of Food Science, 77(9), E247-E255. doi:10.1111/j.1750-3841.2012.02873.x. Fang T, Liu Y, Huang L (2013). “Growth kinetics of Listeria monocytogenes and spoilage microorganisms in fresh-cut cantaloupe.” Food Microbiology, 34(1), 174-181. ISSN 0740-0020. doi:10.1016/j.fm.2012.12.005.
## Example: Fang no lag model library(gslnls) data(growthnolag) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7) # define the initial values fit <- gsl_nls(lnN ~ FangNLM(Time, Y0, Ymax, MUmax), data = growthnolag, start = initial_values ) summary(fit)## Example: Fang no lag model library(gslnls) data(growthnolag) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7) # define the initial values fit <- gsl_nls(lnN ~ FangNLM(Time, Y0, Ymax, MUmax), data = growthnolag, start = initial_values ) summary(fit)
fit_cardinal() validates the input data, builds the nonlinear model formula,
fits it with gslnls::gsl_nls(), and returns a predmicror_fit object.
fit_cardinal(data, model, x, response = "sqrtGR", start, ...)fit_cardinal(data, model, x, response = "sqrtGR", start, ...)
data |
A data frame containing the environmental factor and response variables. |
model |
A model name, either quoted or unquoted. See
|
x |
Column containing the environmental factor values, either quoted or unquoted. |
response |
Column containing the response values, either quoted or
unquoted. Defaults to |
start |
Named list of initial parameter values for the selected model. |
... |
Additional arguments passed to |
Cardinal models expect the response to be the square root of the growth rate,
usually sqrtGR.
A predmicror_fit object with the fitted model and metadata.
data(salmonella) fit <- fit_cardinal( salmonella, model = "CMTI", x = "Temp", response = "sqrtGR", start = list(Tmax = 42, Tmin = 1, MUopt = 1, Topt = 37) ) coef(fit)data(salmonella) fit <- fit_cardinal( salmonella, model = "CMTI", x = "Temp", response = "sqrtGR", start = list(Tmax = 42, Tmin = 1, MUopt = 1, Topt = 37) ) coef(fit)
fit_dynamic_growth() estimates selected parameters of a dynamic Huang-type
growth model by repeatedly solving the dynamic model and minimizing the
residual sum of squares against observed data.
fit_dynamic_growth( data, profile, time, response, start, estimate = NULL, fixed = NULL, lower = NULL, upper = NULL, model = "huang", secondary = "huang_sqrt", scale = c("log10", "ln"), dt = 0.01, method = "rk4", temperature = "temperature", optimizer = "L-BFGS-B", control = list(), ... )fit_dynamic_growth( data, profile, time, response, start, estimate = NULL, fixed = NULL, lower = NULL, upper = NULL, model = "huang", secondary = "huang_sqrt", scale = c("log10", "ln"), dt = 0.01, method = "rk4", temperature = "temperature", optimizer = "L-BFGS-B", control = list(), ... )
data |
Data frame with observed microbial counts. |
profile |
A |
time, response
|
Column names in |
start |
Named list of starting parameter values passed to
|
estimate |
Character vector of parameter names to estimate. If |
fixed |
Optional named list of parameters to keep fixed during fitting. |
lower, upper
|
Optional named numeric vectors or lists with lower and upper bounds for estimated parameters. |
model, secondary, scale, dt, method, temperature
|
Arguments passed to
|
optimizer |
Optimization method passed to |
control |
Optional control list passed to |
... |
Additional arguments passed to |
A predmicror_dynamic_fit object.
profile <- dynamic_profile(time = c(0, 10), temperature = c(20, 20)) obs <- data.frame(time = c(0, 5, 10), logN = c(2, 3.3, 5.1)) fit <- fit_dynamic_growth( obs, profile = profile, time = "time", response = "logN", start = list(logN0 = 2, logNmax = 8, MUmax = 0.4, lag = 0), estimate = "MUmax", secondary = "constant", dt = 0.25 ) coef(fit)profile <- dynamic_profile(time = c(0, 10), temperature = c(20, 20)) obs <- data.frame(time = c(0, 5, 10), logN = c(2, 3.3, 5.1)) fit <- fit_dynamic_growth( obs, profile = profile, time = "time", response = "logN", start = list(logN0 = 2, logNmax = 8, MUmax = 0.4, lag = 0), estimate = "MUmax", secondary = "constant", dt = 0.25 ) coef(fit)
fit_dynamic_inactivation() estimates selected parameters of a dynamic
Weibull-Peleg inactivation model by minimizing the residual sum of squares
against observed data.
fit_dynamic_inactivation( data, profile, time, response, start, estimate = NULL, fixed = NULL, lower = NULL, upper = NULL, model = "weibull_peleg", secondary = "constant", dt = 0.01, method = "rk4", temperature = "temperature", optimizer = "L-BFGS-B", control = list(), ... )fit_dynamic_inactivation( data, profile, time, response, start, estimate = NULL, fixed = NULL, lower = NULL, upper = NULL, model = "weibull_peleg", secondary = "constant", dt = 0.01, method = "rk4", temperature = "temperature", optimizer = "L-BFGS-B", control = list(), ... )
data |
Data frame with observed microbial counts. |
profile |
A |
time, response
|
Column names in |
start |
Named list of starting parameter values passed to
|
estimate |
Character vector of parameter names to estimate. If |
fixed |
Optional named list of parameters to keep fixed during fitting. |
lower, upper
|
Optional named numeric vectors or lists with lower and upper bounds for estimated parameters. |
model, secondary, dt, method, temperature
|
Arguments passed to
|
optimizer |
Optimization method passed to |
control |
Optional control list passed to |
... |
Additional arguments passed to |
A predmicror_dynamic_fit object.
profile <- dynamic_profile(time = c(0, 10), temperature = c(60, 60)) obs <- data.frame(time = c(0, 5, 10), logN = c(7, 6, 5)) fit <- fit_dynamic_inactivation( obs, profile = profile, time = "time", response = "logN", start = list(logN0 = 7, b = 0.15, n = 1), estimate = "b", dt = 0.25 ) coef(fit)profile <- dynamic_profile(time = c(0, 10), temperature = c(60, 60)) obs <- data.frame(time = c(0, 5, 10), logN = c(7, 6, 5)) fit <- fit_dynamic_inactivation( obs, profile = profile, time = "time", response = "logN", start = list(logN0 = 7, b = 0.15, n = 1), estimate = "b", dt = 0.25 ) coef(fit)
fit_growth() validates the input data, builds the nonlinear model formula,
fits it with gslnls::gsl_nls(), and returns a predmicror_fit object.
fit_growth(data, model, time, response = "lnN", start, ...)fit_growth(data, model, time, response = "lnN", start, ...)
data |
A data frame containing the time and response variables. |
model |
A model name, either quoted or unquoted. See
|
time |
Column containing time values, either quoted or unquoted. |
response |
Column containing the response values, either quoted or
unquoted. Defaults to |
start |
Named list of initial parameter values for the selected model. |
... |
Additional arguments passed to |
Growth models expect the response to be the natural logarithm of the microbial
concentration, usually lnN.
A predmicror_fit object with the fitted model and metadata.
data(growthfull) fit <- fit_growth( growthfull, model = "HuangFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) coef(fit)data(growthfull) fit <- fit_growth( growthfull, model = "HuangFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) coef(fit)
fit_inactivation() validates the input data, builds the nonlinear model
formula, fits it with gslnls::gsl_nls(), and returns a predmicror_fit
object.
fit_inactivation(data, model, time, response = "logN", start, ...)fit_inactivation(data, model, time, response = "logN", start, ...)
data |
A data frame containing the time and response variables. |
model |
A model name, either quoted or unquoted. See
|
time |
Column containing time values, either quoted or unquoted. |
response |
Column containing the response values, either quoted or
unquoted. Defaults to |
start |
Named list of initial parameter values for the selected model. |
... |
Additional arguments passed to |
Inactivation models expect the response to be the base 10 logarithm of the
microbial concentration, usually logN.
A predmicror_fit object with the fitted model and metadata.
data(mafart2005Li11) fit <- fit_inactivation( mafart2005Li11, model = "WeibullM", time = "Time", response = "logN", start = list(Y0 = 10, sigma = 3, alpha = 1) ) coef(fit)data(mafart2005Li11) fit <- fit_inactivation( mafart2005Li11, model = "WeibullM", time = "Time", response = "logN", start = list(Y0 = 10, sigma = 3, alpha = 1) ) coef(fit)
fit_metrics() summarizes goodness-of-fit and information criteria for a
predmicror_fit object. The metrics are calculated on the response scale used
in the fitted model.
fit_metrics(object, ...) ## Default S3 method: fit_metrics(object, ...) ## S3 method for class 'predmicror_fit' fit_metrics(object, ...)fit_metrics(object, ...) ## Default S3 method: fit_metrics(object, ...) ## S3 method for class 'predmicror_fit' fit_metrics(object, ...)
object |
A |
... |
Currently unused. Included for future extension and S3 compatibility. |
A one-row data frame with columns: fit, model, type,
response, response_scale, n (observations), p (parameters),
SSE, RMSE, MAE, bias, RSE, R2, adj_R2, logLik, AIC,
BIC, and converged.
data(growthfull) fit <- fit_growth( data = growthfull, model = "HuangFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) fit_metrics(fit)data(growthfull) fit <- fit_growth( data = growthfull, model = "HuangFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) fit_metrics(fit)
fit_omnibus() fits a nonlinear mixed-effects model in which the primary
model is one of the parameterised predmicror primary models and one or more
primary-model parameters are described by secondary covariate formulas.
fit_omnibus( data, type = c("growth", "inactivation"), primary, time, response, group, secondary = NULL, random, correlation = NULL, start, method = "ML", control = NULL, ... ) fit_omnibus_growth( data, primary, time, response, group, secondary = NULL, random, correlation = NULL, start, method = "ML", control = NULL, ... ) fit_omnibus_inactivation( data, primary, time, response, group, secondary = NULL, random, correlation = NULL, start, method = "ML", control = NULL, ... )fit_omnibus( data, type = c("growth", "inactivation"), primary, time, response, group, secondary = NULL, random, correlation = NULL, start, method = "ML", control = NULL, ... ) fit_omnibus_growth( data, primary, time, response, group, secondary = NULL, random, correlation = NULL, start, method = "ML", control = NULL, ... ) fit_omnibus_inactivation( data, primary, time, response, group, secondary = NULL, random, correlation = NULL, start, method = "ML", control = NULL, ... )
data |
A data frame. |
type |
Character string. One of |
primary |
Character string naming a primary model registered in
|
time, response, group
|
Column names for time, response, and grouping variable. |
secondary |
Optional named list of formulas, one per primary-model parameter. Parameters not listed are modelled as intercept-only effects. |
random |
Random-effects formula passed to |
correlation |
Optional correlation structure. Use |
start |
Numeric vector of starting values for fixed effects, in the order
expected by |
method |
Estimation method passed to |
control |
Optional |
... |
Additional arguments passed to |
A predmicror_omnibus_fit object.
set.seed(1) dat <- do.call(rbind, lapply(1:4, function(g) { Time <- c(1, 2, 4, 6, 8, 10) sigma <- 5 + 0.4 * g data.frame( Condition = g, Time = Time, Temp = 55 + g, logN = WeibullM(Time, Y0 = 7, sigma = sigma, alpha = 1.1) + rnorm(length(Time), 0, 0.03) ) })) fit <- fit_omnibus_inactivation( dat, primary = "WeibullM", time = "Time", response = "logN", group = "Condition", secondary = list(sigma = ~ Temp), random = Y0 ~ 1, start = c(Y0 = 7, sigma = 1, sigma.Temp = 0.08, alpha = 1) ) fit_metrics(fit)set.seed(1) dat <- do.call(rbind, lapply(1:4, function(g) { Time <- c(1, 2, 4, 6, 8, 10) sigma <- 5 + 0.4 * g data.frame( Condition = g, Time = Time, Temp = 55 + g, logN = WeibullM(Time, Y0 = 7, sigma = sigma, alpha = 1.1) + rnorm(length(Time), 0, 0.03) ) })) fit <- fit_omnibus_inactivation( dat, primary = "WeibullM", time = "Time", response = "logN", group = "Condition", secondary = list(sigma = ~ Temp), random = Y0 ~ 1, start = c(Y0 = 7, sigma = 1, sigma.Temp = 0.08, alpha = 1) ) fit_metrics(fit)
GeeraerdST inactivation model for microbial inactivation curve.
Returns the model parameters estimated according to data collected in microbial inactivation experiments.
GeeraerdST(x, Y0, Yres, kmax, Sl)GeeraerdST(x, Y0, Yres, kmax, Sl)
x |
is a numeric vector indicating the heating time under a constant temperature of the experiment |
Y0 |
is the initial (time=0) bacterial concentration (ln(N0)) |
Yres |
is a low asymptote reflecting the presence of a resistant sub-population (ln(Nres)) |
kmax |
is the maximum inactivation rate |
Sl |
represents shoulder phase preceding the sharp inactivation slope of the curve |
The model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
N(t): the bacterial concentration measured at time t.
Users should make sure that the bacterial concentration input is entered
in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Geeraerd AH, Valdramidis VP, Van Impe JF (2005). “GInaFiT, a freeware tool to assess non-log-linear microbial survivor curves.” International Journal of Food Microbiology, 102(1), 95-105. ISSN 0168-1605. doi:10.1016/j.ijfoodmicro.2004.11.038.
library(gslnls) data(mafart2005Li11) mafart2005Li11$lnN <- log(10) * mafart2005Li11$logN initial_values <- list(Y0 = 18, Yres = 2, kmax = 0.7, Sl = 4) fit <- gsl_nls(lnN ~ GeeraerdST(Time, Y0, Yres, kmax, Sl), data = mafart2005Li11, start = initial_values ) summary(fit) plot(lnN ~ Time, data = mafart2005Li11) lines(mafart2005Li11$Time, predict(fit), col = "blue")library(gslnls) data(mafart2005Li11) mafart2005Li11$lnN <- log(10) * mafart2005Li11$logN initial_values <- list(Y0 = 18, Yres = 2, kmax = 0.7, Sl = 4) fit <- gsl_nls(lnN ~ GeeraerdST(Time, Y0, Yres, kmax, Sl), data = mafart2005Li11, start = initial_values ) summary(fit) plot(lnN ~ Time, data = mafart2005Li11) lines(mafart2005Li11$Time, predict(fit), col = "blue")
A dataset containing simulated data for a full growth model
data(growthfull)data(growthfull)
A data frame with 13 rows and 3 variables.
Time in minutes
Number of microrganism in log10 scale
Number of microrganism in ln scale
A dataset containing simulated data for a no lag growth model
data(growthnolag)data(growthnolag)
A data frame with 10 rows and 3 variables.
Time in minutes
Number of microrganism in log10 scale
Number of microrganism in ln scale
A dataset containing simulated data for a reduced growth model
data(growthred)data(growthred)
A data frame with 9 rows and 3 variables.
Time in minutes
Number of microrganism in log10 scale
Number of microrganism in ln scale
HuangFM function to fit the Huang full growth model to complete microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
HuangFM(t, Y0, Ymax, MUmax, lag)HuangFM(t, Y0, Ymax, MUmax, lag)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
Ymax |
is the natural logarithm of the maximum concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
lag |
is the duration of the lag phase in time units |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(X(t)).
A numeric vector with the fitted values
Vasco Cadavez, [email protected] and Ursula Gonzales-Barron, [email protected]
Huang L (2008). “Growth Kinetics of Listeria monocytogenes in Broth and Beef Frankfurters-Determination of Lag Phase Duration and Exponential Growth Rate under Isothermal Conditions.” Journal of Food Science, 73(5), E235-E242. doi:10.1111/j.1750-3841.2008.00785.x.
## Example: Huang full model library(gslnls) data(growthfull) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) # define the initial values ## Call the fitting function fit <- gsl_nls(lnN ~ HuangFM(Time, Y0, Ymax, MUmax, lag), data = growthfull, start = initial_values ) summary(fit) confint(fit) preds <- data.frame(predict(fit, interval = "prediction", level = 0.95)) plot(lnN ~ Time, data = growthfull, ylim = c(-1, 22)) lines(growthfull$Time, preds$fit, col = "blue") lines(growthfull$Time, preds$upr, col = "red") lines(growthfull$Time, preds$lwr, col = "red")## Example: Huang full model library(gslnls) data(growthfull) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) # define the initial values ## Call the fitting function fit <- gsl_nls(lnN ~ HuangFM(Time, Y0, Ymax, MUmax, lag), data = growthfull, start = initial_values ) summary(fit) confint(fit) preds <- data.frame(predict(fit, interval = "prediction", level = 0.95)) plot(lnN ~ Time, data = growthfull, ylim = c(-1, 22)) lines(growthfull$Time, preds$fit, col = "blue") lines(growthfull$Time, preds$upr, col = "red") lines(growthfull$Time, preds$lwr, col = "red")
HuangNLM function to fit the Huang no lag growth model to an incomplete microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
HuangNLM(t, Y0, Ymax, MUmax)HuangNLM(t, Y0, Ymax, MUmax)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
Ymax |
is the natural logarithm of the maximum concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t)) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez, [email protected] and Ursula Gonzales-Barron, [email protected]
Huang (2013).
## Example: Huang no lag model library(gslnls) data(growthnolag) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7) # define the initial values ## Call the fitting function fit <- gsl_nls(lnN ~ HuangNLM(Time, Y0, Ymax, MUmax), data = growthnolag, start = initial_values ) summary(fit)## Example: Huang no lag model library(gslnls) data(growthnolag) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7) # define the initial values ## Call the fitting function fit <- gsl_nls(lnN ~ HuangNLM(Time, Y0, Ymax, MUmax), data = growthnolag, start = initial_values ) summary(fit)
HuangRGS reparametrized Gompertz survival model for microbial inactivation.
Returns the model parameters estimated according to data collected in microbial inactivation experiments.
HuangRGS(x, Y0, k, M)HuangRGS(x, Y0, k, M)
x |
is a numeric vector indicating the heating time under a constant temperature of the experiment |
Y0 |
is the initial microbial concentration (ln(cfu 1/g)) |
k |
is the inactivation rate (1/s) |
M |
is a time constant (s) |
The model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the bacterial concentration (ln(X(t))) measured at time t.
Users should make sure that the bacterial concentration input is entered
in natural logarithm, Y(t) = ln(X(t)).
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Huang L (2009). “Thermal inactivation of Listeria monocytogenes in ground beef under isothermal and dynamic temperature conditions.” Journal of Food Engineering, 90(3), 380-387. ISSN 0260-8774. doi:10.1016/j.jfoodeng.2008.07.011.
library(gslnls) data(bixina) initial_values <- list(Y0 = 5.6, k = 0.37, M = 6.8) fit <- gsl_nls(lnN ~ HuangRGS(Time, Y0, k, M), data = bixina, start = initial_values ) summary(fit) plot(lnN ~ Time, data = bixina) lines(bixina$Time, predict(fit), col = "blue")library(gslnls) data(bixina) initial_values <- list(Y0 = 5.6, k = 0.37, M = 6.8) fit <- gsl_nls(lnN ~ HuangRGS(Time, Y0, k, M), data = bixina, start = initial_values ) summary(fit) plot(lnN ~ Time, data = bixina) lines(bixina$Time, predict(fit), col = "blue")
HuangRM function to fit the Huang reduced growth model to a reduced microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
HuangRM(t, Y0, MUmax, lag)HuangRM(t, Y0, MUmax, lag)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
lag |
is the duration of the lag phase in time units |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez, [email protected] & Ursula Gonzales-Barron, [email protected]
Huang L (2008). “Growth Kinetics of Listeria monocytogenes in Broth and Beef Frankfurters-Determination of Lag Phase Duration and Exponential Growth Rate under Isothermal Conditions.” Journal of Food Science, 73(5), E235-E242. doi:10.1111/j.1750-3841.2008.00785.x.
## Example: Huang reduced model library(gslnls) data(growthred) # simulated data set. initial_values <- list(Y0 = 0, MUmax = 1.7, lag = 5) # define the initial values fit <- gsl_nls(lnN ~ HuangRM(Time, Y0, MUmax, lag), data = growthred, start = initial_values ) summary(fit)## Example: Huang reduced model library(gslnls) data(growthred) # simulated data set. initial_values <- list(Y0 = 0, MUmax = 1.7, lag = 5) # define the initial values fit <- gsl_nls(lnN ~ HuangRM(Time, Y0, MUmax, lag), data = growthred, start = initial_values ) summary(fit)
A dataset containing antimicrobial concentration and growth rate data
data(inh)data(inh)
A data frame with 8 rows and 3 variables.
Antimicrobial concentration
Square root of the growth rate
Growth rate
A dataset containing time and log10 counts for microbial inactivation
data(mafart2005Li11)data(mafart2005Li11)
A data frame with 10 rows and 2 variables.
Time
Number of microrganism in log10 scale
omnibus_secondary() defines a secondary model specification that can be used
inside fit_omnibus(), fit_omnibus_growth(), or
fit_omnibus_inactivation(). It allows a primary-model parameter to be
described by another parameterised model already available in predmicror.
omnibus_secondary(model, x, transform = c("identity", "square"))omnibus_secondary(model, x, transform = c("identity", "square"))
model |
Character string naming a registered |
x |
Character string naming the covariate column used by the secondary model. |
transform |
Character string. One of |
An omnibus_secondary specification.
omnibus_secondary("CMTI", x = "Temp") omnibus_secondary("CMTI", x = "Temp", transform = "square")omnibus_secondary("CMTI", x = "Temp") omnibus_secondary("CMTI", x = "Temp", transform = "square")
A dataset containing pH and growth rate data
data(ph)data(ph)
A data frame with 14 rows and 3 variables.
pH of food
Square root of the growth rate
Growth rate
predict_dynamic_growth() solves a differential Huang-type growth model over
a time-varying environmental profile. It is intended for forward prediction
under dynamic temperature conditions and uses an internal fourth-order
Runge-Kutta solver.
predict_dynamic_growth( profile, model = "huang", secondary = "huang_sqrt", start, times = NULL, scale = c("log10", "ln"), dt = 0.01, method = "rk4", temperature = "temperature" )predict_dynamic_growth( profile, model = "huang", secondary = "huang_sqrt", start, times = NULL, scale = c("log10", "ln"), dt = 0.01, method = "rk4", temperature = "temperature" )
profile |
A |
model |
Character string. Currently only |
secondary |
Character string defining the secondary model for the growth
rate. One of |
start |
Named list of parameters. Use |
times |
Optional numeric vector of output times. If |
scale |
Scale of the returned |
dt |
Maximum integration step used by the internal RK4 solver. |
method |
Solver method. Currently only |
temperature |
Name of the temperature column in |
A predmicror_dynamic_prediction data frame with time, prediction,
lnN, logN, temperature, and metadata attributes.
profile <- dynamic_profile( time = c(0, 5, 10, 15, 20), temperature = c(10, 4, 15, 15, 10) ) pred <- predict_dynamic_growth( profile = profile, start = list(logN0 = 2, logNmax = 8.8, a = 0.0886, Tmin = 8.91, lag = 2), dt = 0.25 ) head(pred)profile <- dynamic_profile( time = c(0, 5, 10, 15, 20), temperature = c(10, 4, 15, 15, 10) ) pred <- predict_dynamic_growth( profile = profile, start = list(logN0 = 2, logNmax = 8.8, a = 0.0886, Tmin = 8.91, lag = 2), dt = 0.25 ) head(pred)
predict_dynamic_inactivation() solves a dynamic Weibull-Peleg type
inactivation model over a time-varying environmental profile. The output is
returned on the base-10 logarithmic scale.
predict_dynamic_inactivation( profile, model = "weibull_peleg", secondary = "constant", start, times = NULL, dt = 0.01, method = "rk4", temperature = "temperature" )predict_dynamic_inactivation( profile, model = "weibull_peleg", secondary = "constant", start, times = NULL, dt = 0.01, method = "rk4", temperature = "temperature" )
profile |
A |
model |
Character string. Currently only |
secondary |
Character string defining the secondary model for the Peleg
rate parameter |
start |
Named list. Supply |
times |
Optional numeric vector of output times. |
dt |
Maximum integration step used by the internal RK4 solver. |
method |
Solver method. Currently only |
temperature |
Name of the temperature column in |
A predmicror_dynamic_prediction data frame with time, logN,
log_survival, temperature, and metadata attributes.
profile <- dynamic_profile(time = c(0, 10, 20), temperature = c(55, 58, 60)) pred <- predict_dynamic_inactivation( profile = profile, start = list(logN0 = 7, b_ref = 0.15, T_ref = 55, z = 8, n = 1.2), secondary = "z_value", dt = 0.25 ) head(pred)profile <- dynamic_profile(time = c(0, 10, 20), temperature = c(55, 58, 60)) pred <- predict_dynamic_inactivation( profile = profile, start = list(logN0 = 7, b_ref = 0.15, T_ref = 55, z = 8, n = 1.2), secondary = "z_value", dt = 0.25 ) head(pred)
Answer questions about predmicror models using a deterministic local registry and, when available, an optional local Ollama model for prose. Model-fitting code is generated from package metadata and statically checked before being returned.
predmicror_assistant( query, model = "llama3-groq-tool-use:8b", root = NULL, data = NULL, file = NULL, sheet = NULL, sep = NULL, dec = ".", na.strings = c("", "NA"), task = NULL, time = NULL, response = NULL, temperature = NULL, ph = NULL, aw = NULL, inhibitor = NULL, return_context = FALSE, conversation = NULL, backend = c("auto", "ollama", "deterministic"), prefer_wrappers = TRUE, verify_code = TRUE, return_trace = FALSE )predmicror_assistant( query, model = "llama3-groq-tool-use:8b", root = NULL, data = NULL, file = NULL, sheet = NULL, sep = NULL, dec = ".", na.strings = c("", "NA"), task = NULL, time = NULL, response = NULL, temperature = NULL, ph = NULL, aw = NULL, inhibitor = NULL, return_context = FALSE, conversation = NULL, backend = c("auto", "ollama", "deterministic"), prefer_wrappers = TRUE, verify_code = TRUE, return_trace = FALSE )
query |
Character question to ask. |
model |
Ollama model name used when |
root |
Path to the package root for context collection. Defaults to the installed package path when available, otherwise the current working directory. |
data |
Optional data frame to profile and use for data-aware code generation. |
file |
Optional path to a .csv, .txt, .tsv, .xls, or .xlsx file to read, profile, and use for data-aware code generation. |
sheet |
Optional Excel sheet name or index when |
sep |
Optional field separator for delimited text files. If NULL, a simple separator detector is used. |
dec |
Decimal mark for delimited text files. |
na.strings |
Character vector of strings to treat as missing values when reading delimited text files. |
task |
Optional data task override. Use one of |
time, response, temperature, ph, aw, inhibitor
|
Optional column-name overrides
used when |
return_context |
Logical; if TRUE, returns a list with answer and context. |
conversation |
Optional list or character vector with prior questions and answers to include as conversational context. |
backend |
Character string. One of |
prefer_wrappers |
Logical; if TRUE, generated fitting examples prefer
|
verify_code |
Logical; if TRUE, statically checks generated R code with
|
return_trace |
Logical; if TRUE, returns prompt, backend, candidates, generated code, and validation metadata for debugging. |
Character response by default; list with answer and context when
return_context = TRUE or list with trace when return_trace = TRUE.
predmicror_assistant("How do I fit a Huang model?", backend = "deterministic")predmicror_assistant("How do I fit a Huang model?", backend = "deterministic")
Starts the local assistant app bundled with the package. The app can read
delimited text and Excel files, preview uploaded data, profile columns, apply
optional manual column overrides, and pass the data profile to
predmicror_assistant(). If the bundled app is not available, a fallback app
is created from the installed R functions.
predmicror_assistant_app( model = "llama3-groq-tool-use:8b", root = NULL, host = "127.0.0.1", port = NULL, launch.browser = interactive() )predmicror_assistant_app( model = "llama3-groq-tool-use:8b", root = NULL, host = "127.0.0.1", port = NULL, launch.browser = interactive() )
model |
Default Ollama model name used by |
root |
Optional package root used for assistant context collection. |
host |
Host passed to |
port |
Optional port passed to |
launch.browser |
Logical; whether to launch a browser. |
Runs the Shiny app.
predmicror_assistant_app()predmicror_assistant_app()
predmicror_augment() returns the original data, or optional new data, with
columns containing fitted values and residuals. It is intentionally lightweight
and does not require the broom package.
predmicror_augment(object, ...) ## Default S3 method: predmicror_augment(object, ...) ## S3 method for class 'predmicror_fit' predmicror_augment(object, newdata = NULL, ...) ## S3 method for class 'predmicror_fit' as.data.frame(x, row.names = NULL, optional = FALSE, ...)predmicror_augment(object, ...) ## Default S3 method: predmicror_augment(object, ...) ## S3 method for class 'predmicror_fit' predmicror_augment(object, newdata = NULL, ...) ## S3 method for class 'predmicror_fit' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
object, x
|
A |
... |
Additional arguments passed to |
newdata |
Optional data frame used for prediction. If |
row.names, optional
|
Arguments required by the base |
A data frame containing the original columns plus .fitted, .resid
when the response column is available, .model, and .type.
data(growthfull) fit <- fit_growth( data = growthfull, model = "HuangFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) head(predmicror_augment(fit))data(growthfull) fit <- fit_growth( data = growthfull, model = "HuangFM", time = "Time", response = "lnN", start = list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) ) head(predmicror_augment(fit))
predmicror_fit objectsThese methods delegate to the fitted nonlinear least-squares object returned
by gslnls::gsl_nls(), while preserving the model metadata added by the
fit_*() wrappers.
## S3 method for class 'predmicror_fit' print(x, ...) ## S3 method for class 'predmicror_fit' summary(object, ...) ## S3 method for class 'predmicror_fit' predict(object, newdata = NULL, ...) ## S3 method for class 'predmicror_fit' plot( x, xlab = x$x, ylab = paste0(x$response, " (", x$response_scale, ")"), ... ) ## S3 method for class 'predmicror_fit' coef(object, ...) ## S3 method for class 'predmicror_fit' fitted(object, ...) ## S3 method for class 'predmicror_fit' residuals(object, ...) ## S3 method for class 'predmicror_fit' vcov(object, ...) ## S3 method for class 'predmicror_fit' logLik(object, ...) ## S3 method for class 'predmicror_fit' AIC(object, ..., k = 2) ## S3 method for class 'predmicror_fit' BIC(object, ...)## S3 method for class 'predmicror_fit' print(x, ...) ## S3 method for class 'predmicror_fit' summary(object, ...) ## S3 method for class 'predmicror_fit' predict(object, newdata = NULL, ...) ## S3 method for class 'predmicror_fit' plot( x, xlab = x$x, ylab = paste0(x$response, " (", x$response_scale, ")"), ... ) ## S3 method for class 'predmicror_fit' coef(object, ...) ## S3 method for class 'predmicror_fit' fitted(object, ...) ## S3 method for class 'predmicror_fit' residuals(object, ...) ## S3 method for class 'predmicror_fit' vcov(object, ...) ## S3 method for class 'predmicror_fit' logLik(object, ...) ## S3 method for class 'predmicror_fit' AIC(object, ..., k = 2) ## S3 method for class 'predmicror_fit' BIC(object, ...)
x, object
|
A |
... |
Additional arguments passed to the underlying method. |
newdata |
Optional data frame for prediction. If omitted, predictions are computed for the original data. |
xlab, ylab
|
Axis labels used by |
k |
Penalty used by |
The value returned by the corresponding method for the underlying
nonlinear model object. plot() invisibly returns x.
List models available through the fitting wrappers
predmicror_models(type = "all")predmicror_models(type = "all")
type |
Character string. One of |
A data frame with the model type, model name, expected response scale,
and parameters that must be supplied in start.
predmicror_models() predmicror_models("growth")predmicror_models() predmicror_models("growth")
Methods for omnibus fits
## S3 method for class 'predmicror_omnibus_fit' print(x, ...) ## S3 method for class 'predmicror_omnibus_fit' summary(object, ...) ## S3 method for class 'predmicror_omnibus_fit' coef(object, ...) ## S3 method for class 'predmicror_omnibus_fit' fitted(object, ...) ## S3 method for class 'predmicror_omnibus_fit' residuals(object, ...) ## S3 method for class 'predmicror_omnibus_fit' predict(object, newdata = NULL, level = 0, ...) ## S3 method for class 'predmicror_omnibus_fit' logLik(object, ...) ## S3 method for class 'predmicror_omnibus_fit' AIC(object, ..., k = 2) ## S3 method for class 'predmicror_omnibus_fit' BIC(object, ...)## S3 method for class 'predmicror_omnibus_fit' print(x, ...) ## S3 method for class 'predmicror_omnibus_fit' summary(object, ...) ## S3 method for class 'predmicror_omnibus_fit' coef(object, ...) ## S3 method for class 'predmicror_omnibus_fit' fitted(object, ...) ## S3 method for class 'predmicror_omnibus_fit' residuals(object, ...) ## S3 method for class 'predmicror_omnibus_fit' predict(object, newdata = NULL, level = 0, ...) ## S3 method for class 'predmicror_omnibus_fit' logLik(object, ...) ## S3 method for class 'predmicror_omnibus_fit' AIC(object, ..., k = 2) ## S3 method for class 'predmicror_omnibus_fit' BIC(object, ...)
x, object
|
A |
... |
Additional arguments passed to the underlying |
newdata |
Optional data frame for prediction. |
level |
Prediction level passed to |
k |
Penalty used by |
The value returned by the corresponding method.
RichardsNLM function to fit the Richards no lag growth model to an incomplete microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
RichardsNLM(t, Y0, Ymax, MUmax, m = 1)RichardsNLM(t, Y0, Ymax, MUmax, m = 1)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
Ymax |
is the natural logarithm of the maximum concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
m |
is the shape parameter of the Richards model (default = 1) |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez, [email protected] and Ursula Gonzales-Barron, [email protected]
Richards JF (1959). “A flexible growth function for empirical use.” J Exp Bot, 1(10), 290-310.
## Example: Richards no lag model library(gslnls) data(growthnolag) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7) ## Fitting the function to the experimental data fit <- gsl_nls(lnN ~ RichardsNLM(Time, Y0, Ymax, MUmax), data = growthnolag, start = initial_values ) summary(fit)## Example: Richards no lag model library(gslnls) data(growthnolag) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7) ## Fitting the function to the experimental data fit <- gsl_nls(lnN ~ RichardsNLM(Time, Y0, Ymax, MUmax), data = growthnolag, start = initial_values ) summary(fit)
RossoFM function to fit the Rosso full growth model to complete microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
RossoFM(t, Y0, Ymax, MUmax, lag)RossoFM(t, Y0, Ymax, MUmax, lag)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
Ymax |
is the natural logarithm of the maximum concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
lag |
is the duration of the lag phase in time units |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(X(t)).
A numeric vector with the fitted values
Vasco Cadavez ([email protected]) and Ursula Gonzales-Barron ([email protected])
Rosso L, Bajard S, Flandrois JP, Lahellec C, Fournaud J, Veit P (1996). “Differential growth of Listeria monocytogenes at 4 and 8 ºC: Consequences for the Shelf Life of Chilled Products.” Journal of Food Protection, 59(9), 944-949. ISSN 0362-028X. doi:10.4315/0362-028X-59.9.944.
## Example: Rosso full model library(gslnls) data(growthfull) # simulated data set. initial_values <- list(Y0 = 0.04, Ymax = 21, MUmax = 1.9, lag = 5.0) # define the initial values fit <- gsl_nls(lnN ~ RossoFM(Time, Y0, Ymax, MUmax, lag), data = growthfull, start = initial_values ) summary(fit)## Example: Rosso full model library(gslnls) data(growthfull) # simulated data set. initial_values <- list(Y0 = 0.04, Ymax = 21, MUmax = 1.9, lag = 5.0) # define the initial values fit <- gsl_nls(lnN ~ RossoFM(Time, Y0, Ymax, MUmax, lag), data = growthfull, start = initial_values ) summary(fit)
A dataset containing the specific growth rate of Salmonella typhimurium on cooked chicken
data(salmonella)data(salmonella)
A data frame with 21 rows and 3 variables:
Temperature (ºC)
Specific growth rate (log10/h)
Square root of the specific growth rate (GR)
Oscar TP (2002). “Development and validation of a tertiary simulation model for predicting the potential growth of Salmonella typhimurium on cooked chicken.” International Journal of Food Microbiology, 76(3), 177-190. ISSN 0168-1605. doi:10.1016/S0168-1605(02)00025-9.
Validate an omnibus fit by leaving out one group
validate_omnibus_leave_one_out(object, group_value, level = 0, ...)validate_omnibus_leave_one_out(object, group_value, level = 0, ...)
object |
A |
group_value |
Group value to leave out. |
level |
Prediction level. Defaults to |
... |
Additional arguments passed to |
A list with the refitted model, validation data, predictions, residuals, bias factor, and accuracy factor.
WeibullM inactivation model for microbial inactivation curve.
Returns the model parameters estimated according to data collected in microbial inactivation experiments.
WeibullM(x, Y0, sigma, alpha)WeibullM(x, Y0, sigma, alpha)
x |
is a numeric vector indicating the heating time under a constant temperature of the experiment |
Y0 |
is the natural logarithm of the initial (time=0) bacterial concentration (N0) |
sigma |
is the time of first decimal reduction |
alpha |
which is a shape parameter |
The model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the bacterial concentration (ln(N(t))) measured at time t.
Users should make sure that the bacterial concentration input is entered
in natural logarithm, Y(t) = ln(N(t)).
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Mafart P, Couvert O, Gaillard S, Leguerinel (2002). “On calculating sterility in thermal preservation methods: application of the Weibull frequency distribution model.” International Journal of Food Microbiology, 72, 107-113.
library(gslnls) data(bixina) initial_values <- list(Y0 = 5.75, sigma = 12.8, alpha = 2.4) fit <- gsl_nls(lnN ~ WeibullM(Time, Y0, sigma, alpha), data = bixina, start = initial_values ) summary(fit) plot(lnN ~ Time, data = bixina) lines(bixina$Time, predict(fit), col = "blue")library(gslnls) data(bixina) initial_values <- list(Y0 = 5.75, sigma = 12.8, alpha = 2.4) fit <- gsl_nls(lnN ~ WeibullM(Time, Y0, sigma, alpha), data = bixina, start = initial_values ) summary(fit) plot(lnN ~ Time, data = bixina) lines(bixina$Time, predict(fit), col = "blue")
WeibullMM inactivation model for microbial inactivation curve.
Returns the model parameters estimated according to data collected in microbial inactivation experiments.
WeibullMM(x, Y0, Yres, sigma, alpha)WeibullMM(x, Y0, Yres, sigma, alpha)
x |
is a numeric vector indicating the heating time under a constant temperature of the experiment |
Y0 |
is the log10 of the initial bacterial concentration (at time t=0) |
Yres |
is the log10 of the residual bacterial concentration (at the end of the experiment) |
sigma |
represents the time of the first decimal reduction concentration for the part of the population not belonging to Yres |
alpha |
is the shape parameter and allows to catch the curve concavity or convexity |
The model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the bacterial concentration ($Y(t)$) measured at time t.
Users should make sure to use the base 10 logarithm bacterial concentration (Y(t)) as input.
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Mafart et al. (2005).
library(gslnls) data(bixina) initial_values <- list(Y0 = 5.6, Yres = 1, sigma = 2, alpha = 1) bixina$logN <- log10(exp(bixina$lnN)) fit <- gsl_nls(logN ~ WeibullMM(Time, Y0, Yres, sigma, alpha), data = bixina, start = initial_values ) summary(fit) plot(logN ~ Time, data = bixina) lines(bixina$Time, predict(fit), col = "blue")library(gslnls) data(bixina) initial_values <- list(Y0 = 5.6, Yres = 1, sigma = 2, alpha = 1) bixina$logN <- log10(exp(bixina$lnN)) fit <- gsl_nls(logN ~ WeibullMM(Time, Y0, Yres, sigma, alpha), data = bixina, start = initial_values ) summary(fit) plot(logN ~ Time, data = bixina) lines(bixina$Time, predict(fit), col = "blue")
WeibullPH inactivation model for microbial inactivation curve.
Returns the model parameters estimated according to data collected in microbial inactivation experiments.
WeibullPH(t, Y0, k, alpha)WeibullPH(t, Y0, k, alpha)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial (time=0) bacterial concentration |
k |
is the inactivation rate (ln units/time) |
alpha |
is the shape parameter |
The model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the bacterial concentration X(t) measured at time t.
Users should make sure that the bacterial concentration input is entered in natural logarithm, Y(t) = ln(X(t)).
The following parameters can be estimated using Weibull function:
t: is heating time under a constant temperature
Y0: is the initial (time=0) bacterial counts in natural logarithm of the initial bacterial counts;
k: is the inactivation rate (ln units/time)
alpha: is the shape parameter of the survival curve
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Huang L (2009). “Thermal inactivation of Listeria monocytogenes in ground beef under isothermal and dynamic temperature conditions.” Journal of Food Engineering, 90(3), 380-387. ISSN 0260-8774. doi:10.1016/j.jfoodeng.2008.07.011.
library(gslnls) data(bixina) initial_values <- list(Y0 = 6.0, k = 1.0, alpha = 0.2) fit <- gsl_nls(lnN ~ WeibullPH(Time, Y0, k, alpha), data = bixina, start = initial_values ) summary(fit) plot(lnN ~ Time, data = bixina) lines(bixina$Time, predict(fit), col = "blue")library(gslnls) data(bixina) initial_values <- list(Y0 = 6.0, k = 1.0, alpha = 0.2) fit <- gsl_nls(lnN ~ WeibullPH(Time, Y0, k, alpha), data = bixina, start = initial_values ) summary(fit) plot(lnN ~ Time, data = bixina) lines(bixina$Time, predict(fit), col = "blue")
ZwieteringFM function to fit the Zwietering full growth model to a complete microbial growth curve.
Returns the model parameters estimated according to data collected in microbial growth experiments.
ZwieteringFM(t, Y0, Ymax, MUmax, lag)ZwieteringFM(t, Y0, Ymax, MUmax, lag)
t |
is a numeric vector indicating the time of the experiment |
Y0 |
is the natural logarithm of the initial microbial concentration ( |
Ymax |
is the natural logarithm of the maximum concentration ( |
MUmax |
is the maximum specific growth rate given in time units |
lag |
is the duration of the lag phase in time units |
Model's inputs are:
t: time, assuming time zero as the beginning of the experiment.
Y(t): the natural logarithm of the microbial concentration (ln(N(t))) measured at time t.
Users should make sure that the microbial concentration input is entered in natural logarithm, Y(t) = ln(X(t)).
A numeric vector with the fitted values
Vasco Cadavez [email protected] and Ursula Gonzales-Barron [email protected]
Zwietering MH, Jongenburger I, Rombouts FM, van't Riet K (1990). “Modeling of the Bacterial Growth Curve.” Applied and Environmental Microbiology, 56(6), 1875-1881. ISSN 0099-2240.
## Example: Zwietering full model library(gslnls) data(growthfull) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) # define the initial values fit <- gsl_nls(lnN ~ ZwieteringFM(Time, Y0, Ymax, MUmax, lag), data = growthfull, start = initial_values ) summary(fit)## Example: Zwietering full model library(gslnls) data(growthfull) # simulated data set. initial_values <- list(Y0 = 0, Ymax = 22, MUmax = 1.7, lag = 5) # define the initial values fit <- gsl_nls(lnN ~ ZwieteringFM(Time, Y0, Ymax, MUmax, lag), data = growthfull, start = initial_values ) summary(fit)