UUPharmacometrics / xpose

Graphical diagnostics for pharmacometric models
https://uupharmacometrics.github.io/xpose
GNU Lesser General Public License v3.0
55 stars 29 forks source link

Lines showing the percentiles for both the observations and the predictions #206

Open pmpharm opened 1 year ago

pmpharm commented 1 year ago

According to the recommendations of the Model Evaluation Group of the International Society of Pharmacometrics (ISoP) Best Practice Committee (https://pubmed.ncbi.nlm.nih.gov/27884052/ ), it is suggested that a VPC should have lines showing the percentiles of both observations and predictions. This is important so the percentiles can be compared visually in order to compare the distribution of observed and predicted values. There is an illustration in the Figure S8 of the supplemental material.

If I checked correctly this is not possible yet in the package. My guess so far is that this functionality is available only in Monolix. Would it be possible to implement such functionality?

andrewhooker commented 1 year ago

Hi,

I believe that all of the plots in Figure S8 of the paper you reference can be created by xpose, which uses the VPC package. Please see: https://uupharmacometrics.github.io/xpose/articles/vpc.html http://vpc.ronkeizer.com/appearance.html

Best regards, Andy

smouksassi commented 1 year ago

I was a co-author on the MOEV paper and at the time the code of the paper was in the supplemental materials available online (pure from the ground up ggplot2 nothing special, I take good care of informative legends)

later on I co-wrote tidyvpc https://github.com/certara/tidyvpc (where all computation are efficiently done using data.table) I support observation level LLOQ (e.g. different loq by study) and flexible by strata binning method etc. the package has a plot method for automatic plotting but you can write any ggplot2 code that you would like to use.

tidyvpc is software agnostic just need an obstable and a simulation table

bguiastr commented 1 year ago

Hi,

Appologies for the delay in my response. The representation of the medians for the percentiles of the simulations is not yet implemented in xpose but given the flexibility of offered by the package it is quite easy to add this layer yourself. I have generated a small example for you. I hope it helps.

library(xpose)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'xpose'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

## Compute the vpc data
xpdb_vpc <- vpc_data(xpdb_ex_pk, stratify = 'SEX', opt = vpc_opt(n_bins = 7, lloq = 0.1))
#> 
#> VPC continuous --------------------
#> 1. Gathering data & settings
#> Using xpdb simulation problem 2 and observation problem 1.
#> Setting stratifying variable to SEX
#> Setting lloq to 0.1.
#> 
#> 2. Computing VPC data
#> Configuring and initializing...
#> Stratifying oberved data...
#> Parsing observed data...
#> Filtering rows where EVID not 0
#> Parsing simulated data...
#> Filtering rows where EVID not 0
#> Binning: 0 0.66667 1.25 1.8 3 5 7 9
#> Calculating statistics for simulated data...
#> Calculating statistics for observed data...
#> 
#> VPC done

## Extract the vpc data for use outside of the "conventional way"
special_df <- get_special(xpdb_vpc)
#> Returning vpc continuous data from $prob no.3

## Call the VPC function
vpc(xpdb_vpc) + 

  ## Add your layer
  geom_line(
  data = special_df$vpc_dat, 
  aes(x = bin_mid, y = med, color = Simulations)) + 

  ## Ensure consistent color scale
  scale_color_manual(values = c('steelblue3', 'grey60', 'steelblue3'))
#> Warning: Removed 4 rows containing missing values (`geom_line()`).
#> Warning: Removed 25 rows containing missing values (`geom_point()`).

Created on 2022-10-21 with reprex v2.0.2