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 1 0 11 2 13 0 19 1 26 3 .. 719 1 727 3 729 0 736 1 743 3 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 ])