LAPKB / Pmetrics

https://lapkb.github.io/Pmetrics/
21 stars 8 forks source link

How to create single individual PK profiles vs observed Conc #194

Closed ChrisKonig closed 8 months ago

ChrisKonig commented 8 months ago

I haven't used PMetrics for quite some time and still getting used to the new coding and systematics. Appreciate the new design of the plots and the way to handle the single runs though. Right now, I would like to plot single individual predicted PK profiles vs. the observed conc of these individuals. I would be very happy to get some help in coding.

Thanks, CK

Siel commented 8 months ago

Hi @ChrisKonig Thanks for your message, there is a tutorial inside the package that covers all the new functionality and methods in the package, you can launch it by calling the PM_tutorial() function. This said, all the old functions in Pmetrics still work so in theory you should be able to plot like you were used to.

Answering your question and assuming you're using the new R6 interface, it would be something like:

res <- PM_load(1) #assuming 1 is the name of the latest run
res$op$plot() #this way you can do a regular op plot

If you want to look further into the options provided by that method call ?plot.PM_op

mhovd commented 8 months ago

The easiest way is just like @Siel writes, using NPex$op$plot(). However, if you prefer to use ggplot2, you can do like this.

library(Pmetrics)
library(tidyverse)

# The `NPex` object is an example output from `PM_load`, containing valid `PM_reslt` object

# The data for the op-plot is contained in NPex$op$data
op = NPex$op$data

head(op, n = 2)
#>   id time   obs     pred pred.type icen outeq block    obsSD         d       ds
#> 1  1  120 10.44 3.663302       pop mean     1     1 1.256535 -6.776698 45.92364
#> 2  1  121 12.89 3.479807       pop mean     1     1 1.524818 -9.410193 88.55173
#>          wd      wds
#> 1 -5.393163 29.08621
#> 2 -6.171354 38.08562

# Here is a basic OP-plot with some styling
op %>% 
  filter(icen == "mean") %>% # Use icen == mean
  filter(pred.type == "post") %>%  # Posterior predictions
  ggplot(aes(x = pred, y = obs)) +
  geom_abline(slope = 1, intercept = 0, lty = "dashed", alpha = 0.5) +
  geom_point() +
  theme_classic() +
  labs(x = "Predicted concentration", y = "Observed concentration")

Created on 2024-02-04 with reprex v2.0.2