Skip to content

Custom primary models

Alberto Garre edited this page May 9, 2022 · 1 revision

Defining new primary models in biogrowth

This page shows how to define new functions as primary growth models. Please note that this is intended only for advanced users.

Definition of model equation

  1. Go to file predict_isothermal_growth.R (you could do it in a different file, but it is easier this way).
  2. Define the function for the primary model with any name (as long as it is not already within the package namespace).
  3. The first argument should be named times and represent the elapsed time as a numeric vector of any dimension. Additional arguments define the model parameters.
  4. The function should return a numeric vector with logarithm (in log10 scale) of the population size with same length as times.

Definition of model meta-data

  1. Go to the file metainfo_primary.R
  2. Within the function primary_model_data(), extend model_data with the meta-data of the new model.
  3. This information should be a named list with 5 entries: identifier (the model key), name (the full name of the model), pars (a character vector of model parameters), model (the model function defined before), ref (the paper where the model was first published).

Definition of the calculation

  1. Go to file predict_isothermal_growth.R
  2. Go to function predict_isothermal_growth().
  3. Modify the definition of variable logN adding an additional option for the switch.
  4. This new entry should be named with the same key defined in primary_model_data().
  5. Its value should be a call to the function defined in the first step. The first argument calling this function should be times. Then, as many additional arguments as model parameters, passed as simul_pars$ + "parameter name".

Build the package

  1. You would need to build the package locally using the functions included in devtools. Please check the documentation of that package for details on how to do that.

Run the model

  1. After taking the steps above, the functions for prediction and model fitting should work.
  2. If they do not, feel free to contact us.

Sharing with the community (optional kindness)

  1. We will gladly include your model in the next CRAN release of biogrowth. We would appreciate if you could send a pull request, so we can review your changes and include the new model.