Linearize#

Create a linearize model based on a given input model.

The linearization procedure will produce and run two new models. Given an input model, a derivative model is created which will extract all derivatives for ETAs and EPSILONs. This is followed by the creation of a linearized model with input values of the ETAs updated according to the results from the derivative model.

Running#

To create a linearized model, please run

from pharmpy.modeling import load_example_model
from pharmpy.tools import run_linearize

start_model = load_example_model("pheno")
linres = run_linearize(start_model)
linearized_model = linres.final_model

Arguments#

Argument

Description

model

Input model to linaerize

model_name

Name to use for the linearized model. Default is “linbase”

description

New description for linaerized model. Default is “”

De-linearization#

A linearized model can be de-linearized as well. For this, a base model is required for parameters not stored in the linearized model. Such as thetas.

from pharmpy.tools import delinearize_model

start_model = read_model('path/to/model')
res = run_linearize(start_model)
linearized_model = res.final_model

delinearized_model = delinearize_model(linearized_model, start_model)

For this tool, the option param_mapping can also be set, if the ETAs from the linearized model should be mapped to some other parameter in the base model. An example of this can be seen below.

Note

If param_mapping is used, then all ETAs in the linearized model are expected to be mapped to a parameter.

from pharmpy.modeling import load_example_model
from pharmpy.tools import delinearize_model

start_model = load_example_model("pheno")
linres = run_linearize(start_model)
linearized_model = linres.final_model

param_mapping = {"ETA_1":"V", "ETA_2": "CL"}

delinearized_model = delinearize_model(linearized_model, start_model)

The linearize results#

OFVs#

The OFVs of the input model and the linearized model before and after estimation are summarized in the ofv table. These values should be close. A difference signals problems with the linearization.

ofv
base 730.894727
lin_evaluated 730.894727
lin_estimated 730.847272

Individual OFVs#

The individual OFVs for the base and linearized models together with their difference is in the iofv table. If there was a deviation in the ofv these values can be used to see if some particular individual was problematic to linearize.

base linear delta
ID
1 7.742853 7.722681 -0.020172
2 12.049270 12.072922 0.023652
3 12.042005 12.025071 -0.016933
4 12.812731 12.767326 -0.045405
5 10.092668 10.052741 -0.039927
6 14.345523 14.466217 0.120694
7 11.092993 11.062696 -0.030297
8 13.515740 13.483016 -0.032724
9 15.320532 15.253131 -0.067401
10 10.998789 10.959488 -0.039301
11 5.216717 5.214554 -0.002163
12 12.099921 12.125228 0.025306
13 10.321679 10.306275 -0.015405
14 18.261241 18.333707 0.072466
15 7.671243 7.651480 -0.019763
16 12.330720 12.297562 -0.033158
17 12.936161 12.906483 -0.029678
18 19.714069 19.871090 0.157021
19 12.019825 12.011817 -0.008008
20 12.056142 12.013498 -0.042644
21 12.248747 12.213924 -0.034823
22 7.605213 7.571494 -0.033719
23 19.815937 19.898911 0.082974
24 27.454128 27.483765 0.029637
25 27.964631 28.119373 0.154742
26 13.186715 13.170103 -0.016612
27 9.077661 9.064019 -0.013642
28 7.940635 7.941894 0.001260
29 5.074883 5.073446 -0.001437
30 9.256369 9.245489 -0.010881
31 5.103887 5.101956 -0.001932
32 19.907728 19.900485 -0.007243
33 7.743720 7.709980 -0.033740
34 8.047324 8.021009 -0.026315
35 9.430306 9.400894 -0.029412
36 13.781609 13.798011 0.016402
37 8.378940 8.371430 -0.007511
38 16.194729 16.237151 0.042422
39 15.599213 15.525654 -0.073559
40 6.709166 6.667521 -0.041645
41 11.219054 11.180075 -0.038978
42 18.122738 18.296506 0.173768
43 6.229686 6.228531 -0.001156
44 10.756406 10.734272 -0.022134
45 10.979740 10.927830 -0.051910
46 4.813988 4.812185 -0.001803
47 6.234962 6.233799 -0.001163
48 35.389988 35.431669 0.041681
49 12.057167 12.047647 -0.009521
50 19.429917 19.365265 -0.064652
51 15.011212 15.105276 0.094064
52 16.302735 16.342891 0.040156
53 9.292516 9.307608 0.015092
54 15.067193 14.977095 -0.090098
55 4.359971 4.357379 -0.002592
56 7.340768 7.341140 0.000372
57 9.515376 9.511708 -0.003668
58 11.970486 11.940640 -0.029846
59 13.638461 13.592266 -0.046195

This is also plotted in iofv_plot