binarize_dataset#
- pharmpy.modeling.binarize_dataset(model, columns, keep=False, all_levels=False)[source]#
Binarize dataset
Will create one column per category if specified, otherwise for all columns except for the last one. Will also update datainfo so that new columns have type covariate and is categorical.
- Parameters:
model (Model) – Pharmpy model
columns (list[str]) – The columns to binarize or None for all marked as categorical
keep (bool) – Keep the original column in dataset (default is False)
all_levels (bool) – Create one column per level, otherwise skip last value (default is False)
- Returns:
Model – Updated Pharmpy model
Examples
>>> from pharmpy.modeling import * >>> model = load_example_model("pheno") >>> model = binarize_dataset(model, ['APGR']) >>> model.dataset ID TIME AMT WGT DV FA1 FA2 APGR_1 APGR_2 APGR_3 APGR_4 APGR_5 APGR_6 APGR_7 APGR_8 APGR_9 0 1 0.0 25.0 1.4 0.0 1.0 1.0 0 0 0 0 0 0 1 0 0 1 1 2.0 0.0 1.4 17.3 0.0 0.0 0 0 0 0 0 0 1 0 0 2 1 12.5 3.5 1.4 0.0 1.0 1.0 0 0 0 0 0 0 1 0 0 3 1 24.5 3.5 1.4 0.0 1.0 1.0 0 0 0 0 0 0 1 0 0 4 1 37.0 3.5 1.4 0.0 1.0 1.0 0 0 0 0 0 0 1 0 0 .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 739 59 108.3 3.0 1.1 0.0 1.0 1.0 0 0 0 0 0 1 0 0 0 740 59 120.5 3.0 1.1 0.0 1.0 1.0 0 0 0 0 0 1 0 0 0 741 59 132.3 3.0 1.1 0.0 1.0 1.0 0 0 0 0 0 1 0 0 0 742 59 144.8 3.0 1.1 0.0 1.0 1.0 0 0 0 0 0 1 0 0 0 743 59 146.8 0.0 1.1 40.2 0.0 0.0 0 0 0 0 0 1 0 0 0 [744 rows x 16 columns]