bin_observations#

pharmpy.modeling.bin_observations(model, method, nbins)[source]#

Bin all observations on the independent variable

Available binning methods:

Method

Description

equal_width

Bins with equal width based on the idv

equal_number

Bins containing an equal number of observations

Parameters:
  • model (Model) – Pharmpy model

  • method (str) – Name of the binning method to use

  • nbins (int) – The number of bins wanted

Returns:

  • pd.Series – A series of bin ids indexed on the original record index of the dataset

  • list – A list of bin edges

Example

>>> from pharmpy.modeling import load_example_model, bin_observations
>>> model = load_example_model("pheno")
>>> bins, boundaries = bin_observations(model, method="equal_width", nbins=10)
>>> bins
421     0
527     0
118     0
135     0
512     0
       ..
203     7
475     7
510     7
133     8
267     9
Name: TIME, Length: 155, dtype: int64
>>> boundaries
array([  0.  ,  39.88,  78.76, 117.64, 156.52, 195.4 , 234.28, 273.16,
       312.04, 350.92, 389.8 ])