Skip to content

Custom secondary models

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

Defining new secondary models in biogrowth

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

Definition of model equation

  1. Go to file gamma_models.R (you could do it in a different file, but it is easier this way).
  2. Define the function for the gamma function with any name (as long as it is not already within the package namespace).
  3. The first argument should be named x and represent the value of the environmental conditions as a numeric vector of any dimension. Additional arguments define the model parameters.
  4. The function should return a numeric vector with the values of gamma with the same length as x. All these values should be between 0 and 1 (unless you REALLY know what you are doing).

Definition of model meta-data

  1. Go to the file metainfo_secondary.R
  2. Within the function secondary_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 gamma calculation

  1. Go to file gamma_models.R
  2. Go to function calculate_gammas().
  3. Modify the definition of variable this_gamma adding an additional option for the switch.
  4. This new entry should be named with the same key defined in secondary_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 this_x. Then, as many additional arguments as model parameters, passed as this_sec$ + "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.