Access the xpdb data

Benjamin Guiastrennec

14 November, 2017

The xpose package was designed as a standardized interface between model outputs and R. Hence model output files can easily be imported in R and used to summarize data or create plots.

Glimpse at the xpdb

The files attached to an xpdb object can be displayed to the console simply by writing the xpdb name to the console or by using the print() function. Any of these files can be accessed from the xpdb using one of the functions listed below.

xpdb # or print(xpdb)
run001.lst overview: 
 - Software: nonmem 7.3.0 
 - Attached files (memory usage 1.3 Mb): 
   + obs tabs: $prob no.1: catab001.csv, cotab001, patab001, sdtab001 
   + sim tabs: $prob no.2: simtab001.zip 
   + output files: run001.cor, run001.cov, run001.ext, run001.grd, run001.phi, run001.shk 
   + special: <none> 
 - gg_theme: theme_readable 
 - xp_theme: theme_xp_default 
 - Options: dir = analysis/models/pk/, quiet = FALSE, manual_import = NULL

Access the model code

The get_code() function can be used to access the parsed model code from the xpdb. This code was used to create the summary and find table names. The parsed code can be used to get additional information about the run. If the argument .problem is specified a subset of the code can be returned based on $PROBLEM.

Note that general code warnings and PsN outputs appended are listed as problem 0.

code <- get_code(xpdb)
code
# A tibble: 764 x 5
   problem level subroutine                                                   code
 *   <int> <int>      <chr>                                                  <chr>
 1       0     0        oth                          Mon Oct 16 13:34:28 CEST 2017
 2       0     0        oth                                                       
 3       0     0        oth                                                       
 4       0     0        oth                                                       
 5       1     1        pro                                   Parameter estimation
 6       1     2        inp ID DOSE DV SCR AGE SEX CLASS WT ACE MED1 MED2 TAD TIME
 7       1     2        inp                                    CLCR AMT SS II EVID
 8       1     3        dat                              ../../mx19_2.csv IGNORE=@
 9       1     4        abb                                              DERIV2=NO
10       1     5        sub                                          ADVAN2 TRANS1
# ... with 754 more rows, and 1 more variables: comment <chr>

Access the output data

The get_data() function can be used to access the imported table files. Tables can be accessed by table name or by .problem. In the latter a single dataset containing all aggregated tables is returned. If more than one table name or .problem number is provided a named list is returned.

Note when providing a table name it is not guaranteed that the table will be identical to its file (i.e. the order of the columns may have been changed and tables with FIRSTONLY will no longer be deduplicated).

data <- get_data(xpdb, table = 'cotab001')
data
# A tibble: 550 x 4
       ID  CLCR   AGE    WT
   <fctr> <dbl> <dbl> <dbl>
 1    110    66    68   105
 2    110    66    68   105
 3    110    66    68   105
 4    110    66    68   105
 5    110    66    68   105
 6    110    66    68   105
 7    110    66    68   105
 8    112    47    73    80
 9    112    47    73    80
10    112    47    73    80
# ... with 540 more rows

Access the run files

The get_file() function can be used to access the imported output files. Files can be accessed by file name, by .problem, .subprob and/or .method. If more than one file name, .problem, .subprob, or .method is provided a named list is returned.

file <- get_file(xpdb, file = 'run001.ext')
file
# A tibble: 28 x 16
   ITERATION  THETA1  THETA2  THETA3   THETA4   THETA5     THETA6     THETA7 `SIGMA(1,1)`
       <dbl>   <dbl>   <dbl>   <dbl>    <dbl>    <dbl>      <dbl>      <dbl>        <dbl>
 1         0 25.3535 1.46525 7.45219 0.214386 0.200119 0.00982739 0.00600636            1
 2         1 26.3257 1.26115 7.34822 0.218727 0.217040 0.00988562 0.00602074            1
 3         2 25.6334 1.46525 7.29462 0.215628 0.212214 0.00987192 0.00602702            1
 4         3 26.7952 1.48967 5.76180 0.213014 0.213097 0.00978966 0.00628043            1
 5         4 26.6949 1.48849 5.69320 0.213037 0.212436 0.00978746 0.00629408            1
 6         5 26.7278 1.48841 5.66352 0.213025 0.211937 0.00979166 0.00630166            1
 7         6 26.6462 1.49205 5.02679 0.209907 0.217267 0.01000230 0.00651552            1
 8         7 26.6205 1.48806 4.92877 0.205327 0.217191 0.01000980 0.00657615            1
 9         8 26.5629 1.47648 4.62271 0.210903 0.216647 0.00951367 0.00735274            1
10         9 26.5577 1.45700 4.41353 0.209440 0.216923 0.00903287 0.00873910            1
# ... with 18 more rows, and 7 more variables: `OMEGA(1,1)` <dbl>, `OMEGA(2,1)` <dbl>,
#   `OMEGA(2,2)` <dbl>, `OMEGA(3,1)` <dbl>, `OMEGA(3,2)` <dbl>, `OMEGA(3,3)` <dbl>, OBJ <dbl>

Access the parameter estimates

The get_prm() function can be used to access the parameter estimates. To get a nice parameter table printed to the console use the function prm_table() instead. The arguments .problem, .subprob and .method can be used to select the parameter estimates to output.

# Raw output for editing
prm <- get_prm(xpdb, digits = 4)
prm
# A tibble: 11 x 10
    type       name      label     value       se     rse fixed diagonal     m     n
 * <chr>      <chr>      <chr>     <dbl>    <dbl>   <dbl> <lgl>    <lgl> <dbl> <dbl>
 1   the     THETA1       TVCL 26.290000 0.891500 0.03391 FALSE       NA     1    NA
 2   the     THETA2        TVV  1.348000 0.043810 0.03250 FALSE       NA     2    NA
 3   the     THETA3       TVKA  4.204000 0.809100 0.19250 FALSE       NA     3    NA
 4   the     THETA4        LAG  0.208000 0.015710 0.07554 FALSE       NA     4    NA
 5   the     THETA5  Prop. Err  0.204600 0.022440 0.10970 FALSE       NA     5    NA
 6   the     THETA6   Add. Err  0.010550 0.003658 0.34660 FALSE       NA     6    NA
 7   the     THETA7 CRCL on CL  0.007172 0.001697 0.23660 FALSE       NA     7    NA
 8   ome OMEGA(1,1)     IIV CL  0.270100 0.023270 0.08616 FALSE     TRUE     1     1
 9   ome OMEGA(2,2)      IIV V  0.195000 0.032040 0.16430 FALSE     TRUE     2     2
10   ome OMEGA(3,3)     IIV KA  1.381000 0.202100 0.14630 FALSE     TRUE     3     3
11   sig SIGMA(1,1)             1.000000       NA      NA  TRUE     TRUE     1     1
# Nicely formated table
prm_table(xpdb, digits = 4)

The relative standard errors for omega and sigma are reported on the approximate
standard deviation scale (SE/variance estimate)/2.

Estimates for $prob no.1, subprob no.0, method foce
 Parameter  Label      Value        RSE
 THETA1     TVCL       26.29        0.03391
 THETA2     TVV        1.348        0.0325
 THETA3     TVKA       4.204        0.1925
 THETA4     LAG        0.208        0.07554
 THETA5     Prop. Err  0.2046       0.1097
 THETA6     Add. Err   0.01055      0.3466
 THETA7     CRCL on CL 0.007172     0.2366
 OMEGA(1,1) IIV CL     0.2701       0.08616
 OMEGA(2,2) IIV V      0.195        0.1643
 OMEGA(3,3) IIV KA     1.381        0.1463
 SIGMA(1,1)            1        fix  - 

Access the run summary

The get_summary() function can be used to access the generated run summary from which the template_titles. If the argument .problem is specified a subset of the summary can be returned based on $PROBLEM.

Note that general summary information are listed as problem 0.

run_sum <- get_summary(xpdb, .problem = 0)
run_sum
# A tibble: 12 x 5
   problem subprob               descr       label                         value
     <dbl>   <dbl>               <chr>       <chr>                         <chr>
 1       0       0     Run description       descr   NONMEM PK example for xpose
 2       0       0       Run directory         dir           analysis/models/pk/
 3       0       0          Run errors      errors                            na
 4       0       0 ESAMPLE seed number esampleseed                            na
 5       0       0            Run file        file                    run001.lst
 6       0       0   Number of ESAMPLE    nesample                            na
 7       0       0     Reference model         ref                           000
 8       0       0          Run number         run                        run001
 9       0       0            Software    software                        nonmem
10       0       0      Run start time   timestart Mon Oct 16 13:34:28 CEST 2017
11       0       0       Run stop time    timestop Mon Oct 16 13:34:35 CEST 2017
12       0       0    Software version     version                         7.3.0