```
library(biogrowth)
library(tidyverse)
library(cowplot)
```

The **biogrowth** package implements two modeling
approaches. The first one is based on the use of primary growth models
to describe the relationship between the population size and the elapsed
time. The second one, expands the primary model considering the effect
of changes in the experimental conditions on the specific growth rate
(parameter \(\mu\)). This is reflected
in the argument `environment`

of
`predict_growth()`

(and also `fit_growth()`

),
which can take two values: “constant” or “dynamic”. In the first case,
the function only takes a `primary_model`

(indeed, passing a
`secondary_model`

will return a warning). The logic for this
is that the secondary model describes how the environmental conditions
affect the kinetic parameters of the primary model (the growth rate).
Therefore, the minimum model to describe growth under static conditions
is the one that only includes a primary model. Nonetheless, the function
can still predict microbial growth under isothermal conditions using
`environment="dynamic"`

. This can be useful in situations
were the environmental conditions are constant, but the response of the
population is described using secondary models.

To show this, let’s define an environmental profile where we only consider a constant temperature of 35ºC.

```
<- data.frame(time = c(0, 50),
my_conditions temperature = c(35, 35)
)
```

Next, we define primary and secondary models as usual.

```
<- 1e-4
q0 <- .5
mu_opt
<- list(mu_opt = mu_opt,
my_primary Nmax = 1e8,N0 = 1e2,
Q0 = q0)
<- list(model = "CPM",
sec_temperature xmin = 5, xopt = 35, xmax = 40, n = 2)
<- list(temperature = sec_temperature) my_secondary
```

Finally, we call `predict_growth`

after defining the time
points of the simulation.

```
<- seq(0, 50, length = 1000)
my_times
## Do the simulation
<- predict_growth(environment = "dynamic",
dynamic_prediction
my_times,
my_primary,
my_secondary, my_conditions)
```

Because the temperature during the simulation equals the cardinal
parameter \(X_{opt}\), the predicted
population size is identical to the one calculated using
`predict_growth`

with `environment="constant"`

for
the Baranyi model (calculations for `environment="dynamic"`

are always based on the Baranyi model) when \(\mu = \mu_{opt}\) and \(\lambda = \frac{ \ln \left(1 +1/Q_0 \right)
}{\mu_{opt}}\).

```
<- Q0_to_lambda(q0, mu_opt)
lambda
<- list(model = "Baranyi",
primary_model logN0 = 2, logNmax = 8, mu = mu_opt, lambda = lambda)
<- predict_growth(my_times, primary_model)
static_prediction
plot(static_prediction) +
geom_line(aes(x = time, y = logN), linetype = 2,
data = dynamic_prediction$simulation,
colour = "green")
```

The advantages of using a model including a secondary model for
modeling growth under constant environmental conditions are evident when
simulations are made for several temperatures. Using
`environment="constant"`

would require a calculation of the
value of \(\mu\) for each temperature
separately. Because the relationship between \(\mu\) and temperature is included in the
secondary model, a separate calculation is not required when using
`environment="dynamic"`

.

```
<- 100
max_time
c(15, 20, 25, 30, 35) %>% # Temperatures for the calculation
set_names(., .) %>%
map(., # Definition of constant temperature profile
~ data.frame(time = c(0, max_time),
temperature = c(., .))
%>%
) map(., # Growth simulation for each temperature
~ predict_growth(environment = "dynamic",
my_times,
my_primary,
my_secondary,env_conditions = .,
logbase_mu = 10)
%>%
) imap_dfr(., # Extract the simulation
~ mutate(.x$simulation, temperature = .y)
%>%
) ggplot() +
geom_line(aes(x = time, y = logN, colour = temperature)) +
theme_cowplot()
```

Note, however, that `predict_growth()`

does not include
any secondary model for the lag phase. The reason for this is that there
are no broadly accepted secondary models for the lag phase in predictive
microbiology. Therefore, the value of \(\lambda\) varies among the simulations
according to \(\lambda(T) = \frac{ \ln \left(1
+1/Q_0 \right) }{\mu(T)}\).

Another application of `predict_growth()`

with
`environment="dynamic"`

is including the impact of another
environmental factor when temperature is kept constant. This can be done
by defining a second secondary model.

```
<- list(mu_opt = mu_opt,
my_primary Nmax = 1e8,N0 = 1e2,
Q0 = q0)
<- list(model = "CPM",
sec_temperature xmin = 5, xopt = 35, xmax = 40, n = 2)
<- list(model = "CPM",
sec_pH xmin = 4, xopt = 7, xmax = 8, n = 2)
<- list(temperature = sec_temperature,
my_secondary_2 pH = sec_pH)
```

Then, we can call `predict_growth()`

.

```
<- 100
max_time
c(5, 5.5, 6, 6.5, 7, 7.5) %>% # pH values for the calculation
set_names(., .) %>%
map(., # Definition of constant temperature profile
~ tibble(time = c(0, max_time),
temperature = c(35, 35),
pH = c(., .))
%>%
) map(., # Growth simulation for each temperature
~ predict_growth(environment = "dynamic",
my_times,
my_primary,
my_secondary_2,env_conditions = .,
logbase_mu = 10)
%>%
) imap_dfr(., # Extract the simulation
~ mutate(.x$simulation, pH = .y)
%>%
) ggplot() +
geom_line(aes(x = time, y = logN, colour = pH)) +
theme_cowplot()
```

As above, note that the lag phase varies between the simulations according to \(\lambda(T, pH) = \frac{ \ln \left(1 +1/Q_0 \right) }{\mu(T, pH)}\).