Model estimation and results#
Pharmpy can both estimate a model and retrieve results from a NONMEM run (including runs that were not started by Pharmpy).
Fitting a model#
You can fit a model using the pharmpy.tools.fit() function:
from pharmpy.modeling import load_example_model
from pharmpy.tools import fit
model = load_example_model('pheno')
results = fit(model)
model <- load_example_model('pheno')
results <- fit(model)
It is also possible to specify which estimation tool:
results = fit(model, tool='nlmixr')
results <- fit(model, tool='nlmixr')
Note
In order to esimate using any of the supported softwares (NONMEM and nlmixr2) you need to have a configuration file set up with a path to NONMEM, instructions can be found here.
Modelfit results#
To read in the results (if not fitted in Pharmpy), you can use the pharmpy.tools.read_modelfit_results()
function.
from pharmpy.tools import read_modelfit_results
results = read_modelfit_results('tests/testdata/nonmem/pheno_real.mod')
results <- read_modelfit_results('tests/testdata/nonmem/pheno_real.mod')
Minimization successful#
If the minimization was successful the minimization_successful-attribute is True.
results.minimization_successful
results$minimization_successful
True
Final OFV#
The final OFV is available in the ofv-attribute:
results.ofv
results$ofv
586.2760562818805
Parameter estimates#
The parameter_estimates series contains the final estimates of all estimated parameters.
results.parameter_estimates
results$parameter_estimates
PTVCL        0.004696
PTVV         0.984258
THETA_3      0.158920
IVCL         0.029351
IVV          0.027906
SIGMA_1_1    0.013241
Name: estimates, dtype: float64
It is also possible to get the parameters with all variability parameters as standard deviations or correlations.
results.parameter_estimates_sdcorr
results$parameter_estimates_sdcorr
PTVCL        0.004696
PTVV         0.984258
THETA_3      0.158920
IVCL         0.171321
IVV          0.167051
SIGMA_1_1    0.115069
Name: estimates, dtype: float64
Standard errors of parameter estimates#
The standard errors of the parameter estimates are in the standard_errors series.
results.standard_errors
results$standard_errors
PTVCL        0.000210
PTVV         0.026895
THETA_3      0.083762
IVCL         0.013415
IVV          0.007477
SIGMA_1_1    0.002279
Name: SE, dtype: float64
Or in standard_errors_sdcorr with variability parameters as standard deviations or correlations.
results.standard_errors_sdcorr
results$standard_errors_sdcorr
PTVCL        0.000210
PTVV         0.026895
THETA_3      0.083762
IVCL         0.039153
IVV          0.022378
SIGMA_1_1    0.009904
Name: SE, dtype: float64
Relative standard errors of parameter estimates#
The relative standard errors of the parameter estimates
results.relative_standard_errors
results$relative_standard_errors
PTVCL        0.044731
PTVV         0.027325
THETA_3      0.527072
IVCL         0.457068
IVV          0.267918
SIGMA_1_1    0.172147
Name: RSE, dtype: float64
Covariance matrix#
The covariance matrix for all estimated parameters
results.covariance_matrix
results$covariance_matrix
| PTVCL | PTVV | THETA_3 | IVCL | IVV | SIGMA_1_1 | |
|---|---|---|---|---|---|---|
| PTVCL | 4.411510e-08 | 4.010000e-08 | -0.000002 | -0.000001 | 1.538630e-07 | 8.178090e-08 | 
| PTVV | 4.010000e-08 | 7.233530e-04 | -0.000804 | 0.000050 | 7.171840e-05 | 1.461760e-05 | 
| THETA_3 | -1.665010e-06 | -8.040250e-04 | 0.007016 | -0.000108 | -3.944800e-05 | 2.932950e-05 | 
| IVCL | -1.093430e-06 | 4.981380e-05 | -0.000108 | 0.000180 | -1.856650e-05 | 4.867230e-06 | 
| IVV | 1.538630e-07 | 7.171840e-05 | -0.000039 | -0.000019 | 5.589820e-05 | -4.685650e-07 | 
| SIGMA_1_1 | 8.178090e-08 | 1.461760e-05 | 0.000029 | 0.000005 | -4.685650e-07 | 5.195640e-06 | 
Correlation Matrix#
The correlation matrix for all estimated parameters.
Note
Note to NONMEM users. This is a proper correlation matrix meaning that diagonal elements are 1. Standard errors can be retrieved from standard_errors.
results.correlation_matrix
results$correlation_matrix
| PTVCL | PTVV | THETA_3 | IVCL | IVV | SIGMA_1_1 | |
|---|---|---|---|---|---|---|
| PTVCL | 1.000000 | 0.007099 | -0.094640 | -0.388058 | 0.097981 | 0.170820 | 
| PTVV | 0.007099 | 1.000000 | -0.356900 | 0.138062 | 0.356662 | 0.238442 | 
| THETA_3 | -0.094640 | -0.356900 | 1.000000 | -0.096516 | -0.062991 | 0.153616 | 
| IVCL | -0.388058 | 0.138062 | -0.096516 | 1.000000 | -0.185111 | 0.159170 | 
| IVV | 0.097981 | 0.356662 | -0.062991 | -0.185111 | 1.000000 | -0.027495 | 
| SIGMA_1_1 | 0.170820 | 0.238442 | 0.153616 | 0.159170 | -0.027495 | 1.000000 | 
Precision Matrix#
The precision matrix for all estimated parameters. This is the inverse of the covariance matrix.
results.precision_matrix
results$precision_matrix
| PTVCL | PTVV | THETA_3 | IVCL | IVV | SIGMA_1_1 | |
|---|---|---|---|---|---|---|
| PTVCL | 29955600.0 | 22660.100 | 16057.800 | 203511.000 | -39474.400 | -820116.00 | 
| PTVV | 22660.1 | 2129.910 | 260.177 | -375.267 | -2800.820 | -7718.80 | 
| THETA_3 | 16057.8 | 260.177 | 187.039 | 177.207 | -205.809 | -2225.15 | 
| IVCL | 203511.0 | -375.267 | 177.207 | 7527.520 | 2462.980 | -9977.45 | 
| IVV | -39474.4 | -2800.820 | -205.809 | 2462.980 | 22343.200 | 9370.81 | 
| SIGMA_1_1 | -820116.0 | -7718.800 | -2225.150 | -9977.450 | 9370.810 | 249847.00 | 
Indiviudal OFV#
The OFV for each individual or iOFV is in the individual_ofv series.
results.individual_ofv
results$individual_ofv
ID
1      5.947352
2     12.970591
3      9.982342
4      8.457091
5     10.839437
6     13.257230
7      8.098338
8     11.538621
9     14.647969
10     8.394643
11     9.480164
12     9.650233
13     7.991406
14    15.378880
15     5.739902
16    10.328800
17    10.113284
18    21.212096
19     9.334047
20     9.327778
21     8.821533
22     5.631281
23    11.861669
24    12.915261
25    27.988977
26     7.279273
27     9.733181
28     2.830053
29     2.851724
30     5.212095
31     3.774791
32    12.352283
33     6.172643
34     7.427376
35    11.381444
36    10.624014
37     5.970627
38    14.177028
39    10.206540
40     4.955029
41     8.982447
42    15.051499
43     4.424503
44     7.734342
45     7.018477
46     2.810285
47     3.279258
48    28.168486
49    10.190508
50    16.749134
51    14.598565
52    14.237467
53     8.568934
54    15.800062
55     5.098025
56     2.586253
57     5.663948
58     9.850993
59    10.605845
Name: iOFV, dtype: float64
Predictions#
Different predictions can be found in predictions
results.predictions
results$predictions
| PRED | IPRED | |
|---|---|---|
| 0 | 18.143 | 18.045 | 
| 1 | 17.971 | 17.881 | 
| 2 | 19.633 | 19.575 | 
| 3 | 21.080 | 21.063 | 
| 4 | 22.400 | 22.427 | 
| ... | ... | ... | 
| 739 | 32.616 | 35.668 | 
| 740 | 33.543 | 36.662 | 
| 741 | 34.478 | 37.667 | 
| 742 | 35.253 | 38.495 | 
| 743 | 34.918 | 38.123 | 
744 rows × 2 columns
Residuals#
Different residual metrics can be found in residuals
results.residuals
results$residuals
| RES | CWRES | |
|---|---|---|
| 1 | -0.67071 | -0.401100 | 
| 11 | 2.35080 | 0.587770 | 
| 13 | -0.36360 | -1.278800 | 
| 19 | 6.19730 | 1.670700 | 
| 26 | 7.21710 | 1.352600 | 
| ... | ... | ... | 
| 719 | 4.86050 | 1.067200 | 
| 727 | 1.35060 | -0.059269 | 
| 729 | 1.72100 | -0.036754 | 
| 736 | 5.10860 | 0.814140 | 
| 743 | 5.28180 | 0.699410 | 
155 rows × 2 columns
Individual estimates#
Individual estimates (or EBEs)
results.individual_estimates
results$individual_estimates
| ETA_1 | ETA_2 | |
|---|---|---|
| ID | ||
| 1 | -0.043861 | 0.005430 | 
| 2 | -0.166321 | -0.131833 | 
| 3 | 0.095934 | 0.130868 | 
| 4 | -0.009154 | 0.017388 | 
| 5 | 0.102019 | 0.283500 | 
| 6 | -0.019417 | 0.099839 | 
| 7 | 0.045946 | 0.059072 | 
| 8 | -0.024270 | -0.189351 | 
| 9 | -0.248536 | -0.091872 | 
| 10 | 0.009545 | 0.012052 | 
| 11 | 0.066151 | 0.293685 | 
| 12 | -0.030236 | 0.074789 | 
| 13 | -0.094502 | -0.147433 | 
| 14 | 0.076820 | -0.105604 | 
| 15 | 0.020051 | 0.066265 | 
| 16 | -0.086035 | 0.023260 | 
| 17 | -0.067138 | -0.030859 | 
| 18 | 0.337255 | 0.035532 | 
| 19 | 0.032579 | -0.028410 | 
| 20 | 0.003589 | -0.080613 | 
| 21 | -0.060233 | -0.052854 | 
| 22 | -0.004469 | -0.057344 | 
| 23 | 0.051992 | -0.212941 | 
| 24 | 0.137510 | -0.004111 | 
| 25 | 0.023282 | 0.302636 | 
| 26 | -0.039069 | -0.119442 | 
| 27 | -0.044956 | -0.263320 | 
| 28 | 0.000776 | 0.083231 | 
| 29 | 0.003150 | 0.012752 | 
| 30 | 0.049654 | 0.080932 | 
| 31 | -0.000555 | -0.099614 | 
| 32 | 0.061864 | 0.332738 | 
| 33 | -0.038156 | -0.067641 | 
| 34 | -0.038017 | -0.184137 | 
| 35 | -0.156617 | -0.208753 | 
| 36 | 0.114558 | -0.053036 | 
| 37 | -0.008405 | 0.026004 | 
| 38 | 0.144920 | 0.081646 | 
| 39 | 0.083320 | -0.015380 | 
| 40 | 0.000392 | 0.078062 | 
| 41 | 0.018966 | 0.112030 | 
| 42 | 0.112715 | 0.383786 | 
| 43 | -0.001730 | -0.167583 | 
| 44 | 0.042068 | 0.066598 | 
| 45 | 0.012052 | 0.037600 | 
| 46 | 0.000093 | 0.010662 | 
| 47 | -0.009775 | -0.058306 | 
| 48 | -0.229005 | 0.033958 | 
| 49 | 0.008959 | 0.092312 | 
| 50 | -0.050987 | -0.192569 | 
| 51 | -0.002727 | 0.225657 | 
| 52 | 0.115824 | -0.204269 | 
| 53 | -0.054792 | -0.066334 | 
| 54 | -0.123689 | -0.239678 | 
| 55 | 0.047215 | 0.186615 | 
| 56 | -0.000949 | -0.010812 | 
| 57 | 0.015929 | -0.017213 | 
| 58 | -0.005234 | -0.122552 | 
| 59 | -0.076677 | -0.095696 | 
Uncertainty for the individual estimates can be found in individual_estimates_covariance, which is a series of covariance matrices for each individual.
results.individual_estimates_covariance[1]
results$individual_estimates_covariance[2]
| ETA_1 | ETA_2 | |
|---|---|---|
| ETA_1 | 0.024883 | -0.002999 | 
| ETA_2 | -0.002999 | 0.007157 |