The R codes and the Mlxtran model files can be found here
In this example,
modeling of simulated joint data (continuous data and repeated events) is performed first with Monolix
,
simulation of joint continuous data and repeated events is then performed with simulx
, using the parameters estimated by Monolix
.
Define the project to be used for the simulations (relative paths)
Simulate a trial with N=200 individuals:
N=200
out <- list(name = c('Cc'), time = seq(0,150,by=0.5))
res <- simulx(project=project.file,
group = list(size = N),
output = out)
Plot the simuated PK data and the predicted concentrations
plot1 <- ggplot() +
geom_line(data=res$Cc, aes(x=time, y=Cc, group=id), colour="black") +
geom_point(data=res$Concentration, aes(x=time, y=Concentration), colour="red") +
theme(legend.position="none") + ylab("concentration (mg/l)")
print(plot1)
Plot the survival functions for the first and second events
library("gridExtra")
plot2a <- kmplotmlx(res$Hemorrhaging) + ylim(c(0,1))
plot2b <- kmplotmlx(res$Hemorrhaging, index=2) + ylim(c(0,1))
grid.arrange(plot2a,plot2b,ncol=2)
Three different doses are administrated in this clinical trial: 0.25g, 0.5 and 1g.
We can therefore add the amount to the simulated data
trt0 <- res$treatment[res$treatment$time==0,c(1,3)]
rh <- merge(res$Hemorrhaging,trt0)
ry <- merge(res$Concentration,trt0)
rc <- merge(res$Cc,trt0)
and distinguish these three treatment groups in the plots:
plot3 <- ggplot() +
geom_line(data=rc, aes(x=time, y=Cc, group=id, colour=factor(amount))) +
geom_point(data=ry, aes(x=time, y=Concentration, colour=factor(amount))) +
theme(legend.position="none") + ylab("concentration (mg/l)")
print(plot3)
plot4a <- kmplotmlx(rh, group="amount", facet=FALSE) + ylab("Survival (first event)") +
scale_colour_discrete(name ="dose")
plot4b <- kmplotmlx(rh, index=2, group="amount", facet=FALSE) + ylab("Survival (second event)") +
scale_colour_discrete(name ="dose")
grid.arrange(plot4a,plot4b,ncol=2)