pharmpy.modeling.convert_unit#

pharmpy.modeling.convert_unit(model, variable, unit, original_unit=None, in_dataset=False)[source]#

Convert between units for a data variable

The conversion could either be handled in the model code or optionally in the dataset (if applicable).

Parameters:
  • model (Model) – Pharmpy model

  • variable (str) – Which variable in the dataset or the model code to convert

  • unit (str) – The new unit

  • original_unit (str) – If no original unit is available in the datainfo this will be used

  • in_dataset (bool) – Set to True if the conversion should be done in the dataset instead of in model code

Returns:

Model – Updated Pharmpy model

Examples

>>> from pharmpy.modeling import load_example_model, convert_unit
>>> model = load_example_model("pheno")
>>> model = convert_unit(model, "WGT", "g")