This example script is intended to illustrate how to use the 'ddmore' R package to perform a M&S workflow using the DDMoRe Standalone Execution Environment (SEE).
The following steps are implemented in this workflow:
To run a task, select with the cursor any code lines you wish to execute and press CTRL+R+R in your keyboard. An HTML file containing the commands in this file and associated output will be provided to allow the user to compare the results
Clear workspace and set working directory under 'UsesCasesDemo' project
rm(list=ls(all=F))
mydir <- file.path(Sys.getenv("MDLIDE_WORKSPACE_HOME"),"UseCasesDemo")
setwd(mydir)
Create a working directory under 'models' folder where results are stored
uc<-"UseCase17_1"
datafile <- "warfarin_conc_SSADDL.csv"
mdlfile <- paste0(uc,".mdl")
Create a new folder to be used as working directory and where results will be stored
wd <- file.path(mydir,uc)
dir.create(wd)
## Warning in dir.create(wd):
## 'D:\SEE-Prod5_RC4\MDL_IDE\workspace\UseCasesDemo\UseCase17_1' already
## exists
Copy the dataset and the .mdl file available under “models” into the working directory
file.copy(file.path(mydir,"models", datafile),wd)
## [1] TRUE
file.copy(file.path(mydir,"models",mdlfile),wd)
## [1] TRUE
Set the working directory.
setwd(file.path(mydir,uc))
The working directory needs to be set differently when knitr R package is used to spin the file
library(knitr)
opts_knit$set(root.dir = file.path(mydir,uc))
List files available in working directory
list.files()
## [1] "GOF_NM.pdf" "GOF_NM_FOCEI.pdf"
## [3] "NONMEM" "UseCase17_1.mdl"
## [5] "UseCase17_1.xml" "UseCase17_1_FOCEI.mdl"
## [7] "UseCase17_1_tr.txt" "UseCase17_1_VPC.pdf"
## [9] "warfarin_conc_SSADDL.csv"
The version of Monolix used in the SEE (4.3.2) does not support a combination of steady-state dosing (SS) and additional dosing records (ADDL). Therefore, this Use Case will not be converted to MLXTRAN.
By default, a covariance step is not run when estimating in NONMEM. To see how it can be requested, see UseCase1_1.mdl
NM <- estimate(mdlfile, target="NONMEM", subfolder="NONMEM")
## -- Wed Aug 17 14:56:24 2016
## New
## Submitted
## Job 8d15bb0f-a687-459f-a3ff-1e41b0debfd5 progress:
## Running [ ..................... ]
## Importing Results
## Copying the result data back to the local machine for job ID 8d15bb0f-a687-459f-a3ff-1e41b0debfd5...
## From C:\Users\zparra\AppData\Local\Temp\RtmpSKgKTU\DDMORE.job1dec481255bc to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase17_1/NONMEM
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## Estimation::PopulationEstimates::MLE
## Estimation::IndividualEstimates::Estimates
## Estimation::IndividualEstimates::RandomEffects
## Estimation::Residuals::ResidualTable
## Estimation::Predictions
## Estimation::OFMeasures::Deviance
##
## The following WARNINGs were raised during the job execution:
## estimation_successful: 0
##
## The following MESSAGEs were raised during the job execution:
## covariance_step_run: 0
## rounding_errors: 0
## estimate_near_boundary: 0
## s_matrix_singular: 0
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Wed Aug 17 15:03:30 2016
Load previous results
NM <- LoadSOObject(“NONMEM/UseCase17_1.SO.xml”)
Results from NONMEM
parameters_nm <- getPopulationParameters(NM, what="estimates")
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.0976672 7.2068600 1.4571700 1.9550300 0.0000000 0.1011270
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.7500000 1.0000000 0.1012920 -0.0193799 0.4599980 1.9930500
## PPV_TLAG
## 0.1000000
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -347.9066
##
##
##
## $Messages
## $Messages$Info
## $Messages$Info$covariance_step_run
## [1] "0"
##
## $Messages$Info$rounding_errors
## [1] "0"
##
## $Messages$Info$estimate_near_boundary
## [1] "0"
##
## $Messages$Info$s_matrix_singular
## [1] "0"
##
## $Messages$Info$nmoutput2so_version
## [1] "This SOBlock was created with nmoutput2so version 4.5.27"
##
##
## $Messages$Warnings
## $Messages$Warnings$estimation_successful
## [1] "0"
nm.xpdb<-as.xpdb(NM,datafile)
##
## Removed dose rows in rawData+Predictions slot of SO to enable merge with Residuals data.
##
## Residuals data does not currently contain dose rows in output from Nonmem executions.
Perform some basic goodness of fit (graphs are exported to PDF file)
print(basic.gof(nm.xpdb))
print(ind.plots(nm.xpdb))
print(parm.hist(nm.xpdb))
Export graphs to a PDF file
pdf("GOF_NM.pdf")
print(basic.gof(nm.xpdb))
print(ind.plots(nm.xpdb))
print(parm.hist(nm.xpdb))
dev.off()
## rj.GD
## 2
MDL Objects can be manipulated from R to change for example the estimation algorithm
myTaskProperties <- getTaskPropertiesObjects(mdlfile)[[1]]
myNewTaskProperties <- myTaskProperties
myNewTaskProperties@ESTIMATE$algo <- "focei"
Assembling the new MOG. Note that we reuse the data and model from the previous run.
myNewerMOG <- createMogObj(dataObj = getDataObjects(mdlfile)[[1]],
parObj = getParameterObjects(mdlfile)[[1]],
mdlObj = getModelObjects(mdlfile)[[1]],
taskObj = myNewTaskProperties)
We can then write the MOG back out to an .mdl file.
mdlfile.FOCEI <- paste0(uc,"_FOCEI.mdl")
writeMogObj(myNewerMOG,mdlfile.FOCEI)
Test estimation using this new MOG.
NM.FOCEI <- estimate(mdlfile.FOCEI, target="PsN", subfolder="NONMEM_FOCEI")
## -- Wed Aug 17 15:04:11 2016
## New
## Submitted
## Job f4b65d59-b645-4401-af31-fcb2683f6458 progress:
## Running [ .. ]
## Importing Results
## Copying the result data back to the local machine for job ID f4b65d59-b645-4401-af31-fcb2683f6458...
## From C:\Users\zparra\AppData\Local\Temp\RtmpSKgKTU\DDMORE.job1dec1ae72df1 to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase17_1/NONMEM_FOCEI
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## Estimation::PopulationEstimates::MLE
## Estimation::IndividualEstimates::Estimates
## Estimation::IndividualEstimates::RandomEffects
## Estimation::Residuals::ResidualTable
## Estimation::Predictions
## Estimation::OFMeasures::Deviance
##
## The following MESSAGEs were raised during the job execution:
## estimation_successful: 1
## covariance_step_run: 0
## rounding_errors: 0
## hessian_reset: 0
## zero_gradients: 0
## final_zero_gradients: 0
## estimate_near_boundary: 0
## s_matrix_singular: 0
## significant_digits: 3.3
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Wed Aug 17 15:04:55 2016
Load previous results
#NM.FOCEI <- LoadSOObject("NONMEM_FOCEI/UseCase17_1_FOCEI.SO.xml")
Results from NONMEM should be comparable to previous results
print(getPopulationParameters(NM.FOCEI, what="estimates"))
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.09879320 7.15015000 0.27571300 0.68584100 0.06416220 0.10363800
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.75000000 1.00000000 0.08882460 -0.99982200 0.14035300 0.00449274
## PPV_TLAG
## 0.10000000
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.0976672 7.2068600 1.4571700 1.9550300 0.0000000 0.1011270
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.7500000 1.0000000 0.1012920 -0.0193799 0.4599980 1.9930500
## PPV_TLAG
## 0.1000000
nmfocei.xpdb<-as.xpdb(NM.FOCEI,datafile)
##
## Removed dose rows in rawData+Predictions slot of SO to enable merge with Residuals data.
##
## Residuals data does not currently contain dose rows in output from Nonmem executions.
Basic diagnostics for NONMEM fit.
print(basic.gof(nmfocei.xpdb))
Export graphs to a PDF file
pdf("GOF_NM_FOCEI.pdf")
print(basic.gof(nmfocei.xpdb))
dev.off()
## rj.GD
## 2
Before running the VPC with PsN we must update the (initial) values in the MDL Parameter Object MLE estimates from previous step can be used
structuralPar <- getPopulationParameters(NM.FOCEI, what="estimates",block='structural')$MLE
variabilityPar <- getPopulationParameters(NM.FOCEI, what="estimates",block='variability')$MLE
Update the parameter object using the ddmore “updateParObj” function. This function updates an R object of (S4) class “parObj”. The user chooses which block to update, what items within that block, and what to replace those items with. NOTE: that updateParObj can only update attributes which ALREADY EXIST in the MDL Parameter Object for that item. This ensures that valid MDL is preserved.
myParObj <- getParameterObjects(mdlfile)[[1]]
myParObjUpdated <- updateParObj(myParObj,block="STRUCTURAL",
item=names(structuralPar),
with=list(value=structuralPar))
myParObjUpdated <- updateParObj(myParObjUpdated,block="VARIABILITY",
item=names(variabilityPar),
with=list(value=variabilityPar))
Check that the appropriate initial values have been updated to the MLE values from the previous fit.
print(myParObjUpdated@STRUCTURAL)
## $POP_CL
## $POP_CL$value
## [1] "0.0987932"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "7.15015"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "0.275713"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.685841"
##
## $POP_TLAG$lo
## [1] "0.001"
##
##
## $BETA_CL_WT
## $BETA_CL_WT$value
## [1] "0.75"
##
## $BETA_CL_WT$fix
## [1] "true"
##
##
## $BETA_V_WT
## $BETA_V_WT$value
## [1] "1"
##
## $BETA_V_WT$fix
## [1] "true"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.0888246"
##
##
## $PPV_V
## $PPV_V$value
## [1] "0.140353"
##
##
## $PPV_KA
## $PPV_KA$value
## [1] "0.00449274"
##
##
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
##
## $PPV_TLAG$fix
## [1] "true"
##
##
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "-0.999822"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0641622"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.103638"
##
## $RUV_ADD$lo
## [1] "0"
Assembling the new MOG. Note that we reuse the data and model from the previous run.
myVPCMOG <- createMogObj(dataObj = getDataObjects(mdlfile)[[1]],
parObj = myParObjUpdated,
mdlObj = getModelObjects(mdlfile)[[1]],
taskObj = getTaskPropertiesObjects(mdlfile)[[1]])
We can then write the MOG back out to an .mdl file.
mdlfile.VPC <- paste0(uc,"_VPC.mdl")
writeMogObj(myVPCMOG,mdlfile.VPC)
Similarly as above, ddmore “VPC.PsN” function can be used to run a VPC using PsN as target tool
vpcFiles <- VPC.PsN(mdlfile.VPC,samples=20, seed=12345,
vpcOptions ="-n_simulation=10 -auto_bin=10",
subfolder="VPC", plot=TRUE)
## Warning in normalizePath(path.expand(path), winslash, mustWork):
## path[1]="UseCase17_1_VPC.mdl": The system cannot find the file specified
## Error in execute(model, target = "PsNgeneric", addargs = vpccommand, subfolder = subfolder, : Illegal Argument: file UseCase17_1_VPC.mdl does not exist.
To replay the visualisation using information from the VPC SO file
pdf(paste0(uc,"_VPC.pdf"))
print(xpose.VPC(vpc.info= file.path("./VPC",vpcFiles@RawResults@DataFiles$PsN_VPC_results$path),
vpctab= file.path("./VPC",vpcFiles@RawResults@DataFiles$PsN_VPC_vpctab$path),
main="VPC warfarin"))
## Error in print(xpose.VPC(vpc.info = file.path("./VPC", vpcFiles@RawResults@DataFiles$PsN_VPC_results$path), : error in evaluating the argument 'x' in selecting a method for function 'print': Error in file.path("./VPC", vpcFiles@RawResults@DataFiles$PsN_VPC_vpctab$path) :
## object 'vpcFiles' not found
dev.off()
## rj.GD
## 2
The mlxR package has been developed to visualize and explore models that are encoded in MLXTRAN or PharmML The ddmore function as.PharmML translates an MDL file (extension .mdl) to its PharmML representation. The output file (extension .xml) is saved in the working directory.
myPharmML <- as.PharmML(mdlfile)
Use parameter values from the FOCEI estimation
parValues <- getPopulationParameters(NM.FOCEI, what="estimates")$MLE
Simulate for the typical weight of 70. Recall that logtWT = log(WT/70).
p <- c(parValues,logtWT=0)
Parameter values used in simulation
print(p)
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.09879320 7.15015000 0.27571300 0.68584100 0.06416220 0.10363800
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.75000000 1.00000000 0.08882460 -0.99982200 0.14035300 0.00449274
## PPV_TLAG logtWT
## 0.10000000 0.00000000
Simulate PK parameters for individuals
ind <- list(name = c('KA','CL','V'))
Simulate predicted (CC) and observed concentration values (Y)
f <- list( name = c('CC'), time = seq(0,to=50,by=1))
y <- list( name = c('Y'), time = c(0, 0.5, 1, 2, 3, 4, 6, 8, 12, 24, 36, 48))
Simulate for a dose of 100mg given at time 0 (oral administration)
adm <- list(type = 1, time = 0, amount = 100)
Simulate 12 subjects
g <- list( size = 12, level = 'individual', treatment=adm)
Call simulx
res <- simulx(model =myPharmML,
parameter = p,
group = g,
output = list(ind,f,y))
Simulated parameter values for each individual
print(res$parameter)
## id KA CL V
## 1 1 0.2750176 0.11171017 5.883309
## 2 2 0.2743409 0.10522202 6.464947
## 3 3 0.2750484 0.10663152 6.337212
## 4 4 0.2745251 0.09540554 7.572675
## 5 5 0.2760815 0.09445836 7.706056
## 6 6 0.2744796 0.09003392 8.272071
## 7 7 0.2746429 0.11457619 5.656550
## 8 8 0.2769550 0.09923276 7.101504
## 9 9 0.2744158 0.09322463 7.842699
## 10 10 0.2742974 0.10170264 6.841684
## 11 11 0.2771707 0.10610890 6.380153
## 12 12 0.2785074 0.08949573 8.343967
Plot simulated results
plot(ggplot() +
geom_line(data=res$CC, aes(x=time, y=CC, colour=id)) +
geom_point(data=res$Y, aes(x=time, y=Y, colour=id)) +
xlab("time (h)") + ylab("concentration") )
Simulate 1000 subjects - with simulx this is a QUICK process!
g <- list( size = 1000, level = 'individual', treatment = adm)
Call simulx
res.1000 <- simulx(model =myPharmML,
parameter = p,
group = g,
output = list(ind,y))
Plot of observed concentrations (with residual error) band defines the percentile bands displayed level = range of values to examine (in %) 100 = full range of values number = number of bins within the level range.
print(prctilemlx(res.1000$Y,band=list(number=9, level=90)))
Table of the same information
print(prctilemlx(res.1000$Y,band=list(number=10, level=100), plot=FALSE)$y)
## time 0% 10% 20% 30% 40%
## 1 0.0 -0.2295704 -0.1160725 -0.06513817 -0.03961506 -0.01938399
## 2 0.5 -0.3233166 -0.1637855 -0.12369232 -0.06072311 -0.02693879
## 3 1.0 0.2431164 0.7392224 0.94106240 1.05215459 1.09264818
## 4 2.0 2.6387713 3.4491070 3.66768284 3.86133056 3.99759784
## 5 3.0 4.1461970 5.3466905 5.82222993 6.05167366 6.26024680
## 6 4.0 4.8923867 6.6681346 7.38761717 7.67438323 7.90181178
## 7 6.0 7.1115159 8.4436749 9.28419828 9.55405800 9.76295716
## 8 8.0 7.4138563 9.5197570 10.07145929 10.66452338 11.25326838
## 9 12.0 8.5188843 9.9242600 10.41815974 10.97218698 11.36729374
## 10 24.0 7.9361090 9.2917645 9.58719470 10.12568276 10.43795382
## 11 36.0 7.6240228 8.1454065 8.30913780 8.73150964 8.91573237
## 12 48.0 6.0133161 6.8119309 7.00853491 7.28504014 7.37444232
## 50% 50% 60% 70% 80% 90%
## 1 -0.00747455 -0.00747455 0.01768747 0.03287448 0.06560514 0.1463758
## 2 -0.01792781 -0.01792781 0.01005285 0.03899852 0.07366971 0.1204672
## 3 1.18258123 1.18258123 1.28843163 1.39104015 1.53162652 1.7157404
## 4 4.17647120 4.17647120 4.37057221 4.50879532 4.77874329 5.1400852
## 5 6.47201539 6.47201539 6.69567855 7.02056718 7.39034939 7.8028402
## 6 8.11085115 8.11085115 8.37403454 8.72919308 9.01542654 9.5130016
## 7 10.27242820 10.27242820 10.55600999 10.84927282 11.44789871 12.5023608
## 8 11.49776590 11.49776590 11.76225718 12.24576780 12.64731805 13.3961598
## 9 11.76824359 11.76824359 12.33946926 12.65090459 13.03415462 13.8244864
## 10 10.68233001 10.68233001 11.00959632 11.29328013 11.55430298 11.8557899
## 11 9.11259645 9.11259645 9.23350886 9.52520878 9.68214138 10.0350103
## 12 7.52060096 7.52060096 7.59455261 7.77249141 7.94811313 8.3115450
## 100%
## 1 0.1959391
## 2 0.2999353
## 3 2.0520979
## 4 6.1444236
## 5 9.1507518
## 6 11.2539038
## 7 14.7368337
## 8 16.4738547
## 9 16.8025650
## 10 12.9116710
## 11 10.8381089
## 12 9.4179157