ggPMXdevelopment / ggPMX

ggPMX R package
37 stars 13 forks source link

When creating a controller ggPMX is dropping large portion of the data: ggPMX 1.2.8 (but also earlier versions) #262

Closed biencan1 closed 2 years ago

biencan1 commented 2 years ago

Example 1: ER model, only response variable fitted. DV values contain zero

1) plot generated using ggPMX function: ctr %>% pmx_plot_npde_time

image

2) plot recreated by reading in data from controller

dat2plot<-ctr$data$predictions

ggplot(dat2plot,aes(x=TIME,y=NPDE)) +
  geom_point()+
  geom_smooth(se = FALSE,color="red")+
  theme_bw()

image

3) plot recreated by reading in directly Monolix outputs plot source data:

ordat2plot<-read.csv(
  file.path(model.dir,model,'ChartsData/ScatterPlotOfTheResiduals/LIDV_residuals.txt'),sep=','
)

ggplot(ordat2plot,aes(x=time,y=npde)) +
  geom_point()+
  geom_smooth(se = FALSE,color="red")+
  theme_bw()

image

Example 2: PopPK model, dataset contains censored values

1) plot generated using ggPMX function:

ctr %>% pmx_plot_npde_time

image

2) plot recreated by reading in data from controller

dat2plot<-ctr$data$predictions

ggplot(dat2plot,aes(x=TIME,y=NPDE)) +
  geom_point()+
  geom_smooth(se = FALSE,color="red")+
  theme_bw()

image

3) plot recreated by reading in directly Monolix outputs plot source data

ordat2plot<-read.csv(file.path(model.dir,model,'ChartsData/ScatterPlotOfTheResiduals/LIDV_residuals.txt'),sep=',')

ggplot(ordat2plot,aes(x=time,y=npde)) +
  geom_point()+
  geom_smooth(se = FALSE,color="red")+
  theme_bw()

image

Dropping of zero or BLOQ values doesn’t seem to be the source of the problem: different fill for BLOQ data

ggplot(ordat2plot,aes(x=time,y=npde)) +
  geom_point(aes(color=factor(censored)))+
  scale_colour_manual(values = c("0"="black","1"="blue"))+
  geom_smooth(se = FALSE,color="red")+
  theme_bw()

image

filter out censored data

ggplot(filter(ordat2plot,censored==0),aes(x=time,y=npde)) +
  geom_point()+
  geom_smooth(se = FALSE,color="red")+
  theme_bw()

image

replot using simulated BLOQ

ggplot(ordat2plot,aes(x=time,y=npde_simBlq)) +
  geom_point(aes(color=factor(censored)))+
  scale_colour_manual(values = c("0"="black","1"="blue"))+
  geom_smooth(se = FALSE,color="red")+
  theme_bw()

image

biencan1 commented 2 years ago

Feedback from Lixoft: rounding all columns of the dataset to 6 significant digits before using it in Monolix will solve the issue. In the next version, we will increase the number of significant digits in the output to resolve this problem.

biencan1 commented 2 years ago

After testing the work around of rounding to 6th significant digit seems to have resolved the issue. See snapshot below as example.

Original dataset: image

ctr$data$predictions created from this model fit (some time points dropped): image

ctr$data$predictions created from a run with a modified data set where rounding was applied to time variable using mutate(TIME=signif(TIME,6)) image

tynsci commented 2 years ago

@biencan1