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). Note that when doing the conversion in the model the unit of the data variable itself will not change. The change will affect the unit of relevant parameters in the model.
Note that only ratio units are supported (i.e. not interval scale units like °C).
- 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")