pharmpy / pharmpy

A library and toolkit for pharmacometrics
https://pharmpy.github.io
GNU General Public License v3.0
48 stars 14 forks source link

Having $TABLE property #1683

Open OmarAshkar opened 1 year ago

OmarAshkar commented 1 year ago

Feature request

Hello,

Thank you for this awesome work. I am wondering if it is possible to also parse/add $TABLE fields to model object. The idea is to provide checking for all data headers and parameters to make it easier to add new tables. So object of type table could be add to the corresponding property of the model.

Thank you!

rikardn commented 1 year ago

I agree that we should have this.

There is some support in the EstimationStep class for special output variables, but this isn't handled when reading or writing NONMEM models yet.

king-of-poppk commented 4 months ago

Hi!

I see there is functionality for more generically available variables:

Where are those extracted from when working on a NONMEM model?

I am also wondering if there is a generic way to retrieve information about tabulated values such as CL, THETA_1, etc.

rikardn commented 4 months ago

Predictions and residuals are extracted from table files. Pharmpy go through all $TABLE records to find variables of interest. The index of the results.predictions and results.residuals tables are the integer index of the input dataset. For residuals none will exist where DVs are missing (e.g. dosing records) so there will be gaps left for these. The index makes it possible to join these together or back with the dataset.

Individual estimates comes from the phi-file. For this parsing the case of having PHI instead of ETA in the phi file is handled by always converting from PHI to ETA in Pharmpy.

The code for all of the above is in pharmpy/tools/external/nonmem/results.py

There is no generic way of retrieving tabulated values currently. I can see two ways of implementing this:

  1. Simply add a way to table any symbol from the model similar to EstimationStep.predictions etc.

  2. Calculate these in Pharmpy.

$TABLE in NONMEM can handle many different things.

a) Variables calculated after estimation: predictions, residuals, final ETAs, final population parameter estimates b) individual predictions of any variable in the model given the final pop parameter estimates and the final etas

The cases in b) could be calculated by Pharmpy (easily if in $PK or $PRED). Then also other variables that weren't even in the model could be calculated. We already do something similar in the calculate_individual_parameter_statistics, but there we calculate summatory statistics for a variable or expression representing a distribution (so etas are not replaced with their individual estimates, but kept as a distribution).

Option 1 is of course the safer route, but 2 is more flexible and doesn't force you to rerun NONMEM if you missed to add a variable in $TABLE.