pharmpy.modeling.calculate_summary_statistic#

pharmpy.modeling.calculate_summary_statistic(model, stat, expr, default=None)[source]#

Calculate a summary statistic for an expression over the dataset

The expression can be a dataset column name, a variable from the model, e.g. a derived covariate or a matematical expression involving dataset columns or model variables. If a calculation involves population parameters, the initial estimates will be used.

Parameters:
  • model (Model) – Pharmpy model

  • stat (str) – The summary statistic. Can be “max”, “min”, “median” or “mean”

  • expr (str) – A mathematical expression containing column or variable names

  • default (float) – An optional default value to use in case the statistic couldn’t be calculated. For example if the model has no dataset.

Returns:

float – The summary statistic

Example

>>> from pharmpy.modeling import load_example_model, calculate_summary_statistic
>>> model = load_example_model("pheno")
>>> calculate_summary_statistic(model, "max", "TIME")
389.8
>>> calculate_summary_statistic(model, "median", "log(WGT)")
0.26236426446749106
>>> calculate_summary_statistic(model, "median", "TVCL")
0.006100991