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=FALSE))
mydir <- file.path(Sys.getenv("MDLIDE_WORKSPACE_HOME"),"UseCasesDemo")
setwd(mydir)
Create a working directory under 'models' folder where results are stored
uc<-"UseCase4_2"
datafile <- "warfarin_infusion_oral.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)
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] "UseCase4_2.mdl" "warfarin_infusion_oral.csv"
mlx <- estimate(mdlfile, target="MONOLIX", subfolder="Monolix")
## -- Wed Aug 17 18:45:50 2016
## New
## Submitted
## Job 8da60e4c-ed3e-4853-b010-37e4a56a494c progress:
## Running [ ........ ]
## Importing Results
## Copying the result data back to the local machine for job ID 8da60e4c-ed3e-4853-b010-37e4a56a494c...
## From C:\Users\zparra\AppData\Local\Temp\RtmpSKgKTU\DDMORE.job1dec502542b to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase4_2/Monolix
## Done.
##
##
## The following main elements were parsed successfully:
## ToolSettings
## RawResults
## Estimation::PopulationEstimates::MLE
## Estimation::PrecisionPopulationEstimates::MLE
## Estimation::IndividualEstimates::Estimates
## Estimation::IndividualEstimates::RandomEffects
## Estimation::Residuals::ResidualTable
## Estimation::Predictions
## Estimation::OFMeasures::IndividualContribToLL
## Estimation::OFMeasures::InformationCriteria
## Estimation::OFMeasures::LogLikelihood
##
## Completed
## -- Wed Aug 17 18:48:38 2016
slotNames(mlx)
## [1] "ToolSettings" "RawResults" "TaskInformation"
## [4] "Estimation" "ModelDiagnostic" "Simulation"
## [7] "OptimalDesign" ".pathToSourceXML"
The ddmore “LoadSOObj” reads and parsed existing Standardise Output Objects
# mlx <- LoadSOObject("Monolix/UseCase4_2.SO.xml")
The ddmore function “getPopulationParameters” extracts the Population Parameter values from an R object of (S4) class “StandardOutputObject” and returns the estimates. See documentation for getPopulationParameters to see other arguments and settings for this function.
parameters_mlx <- getPopulationParameters(mlx, what="estimates")
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_TLAG
## 7.98883 1.00000 0.35758 0.10082 0.75000 1.00247
## POP_FORAL PPV_V PPV_KA PPV_CL PPV_TLAG PPV_FORAL
## 0.99160 0.12470 0.07619 0.11930 0.10000 0.32991
## CORR_CL_V RUV_ADD RUV_PROP
## 0.03330 0.00000 0.12281
print(getPopulationParameters(mlx, what="precisions"))
## $MLE
## Parameter MLE SE RSE
## 1 BETA_CL_WT 0.75000 0.00000 0.00
## 2 BETA_V_WT 1.00000 0.00000 0.00
## 3 CORR_CL_V 0.03330 0.18907 567.86
## 4 POP_CL 0.10082 0.00222 2.21
## 5 POP_FORAL 0.99160 0.01030 1.04
## 6 POP_KA 0.35758 0.01258 3.52
## 7 POP_TLAG 1.00247 0.02850 2.84
## 8 POP_V 7.98883 0.18518 2.32
## 9 PPV_CL 0.11930 0.01583 13.27
## 10 PPV_FORAL 0.32991 16.10903 4882.78
## 11 PPV_KA 0.07619 0.04729 62.07
## 12 PPV_TLAG 0.10000 0.00000 0.00
## 13 PPV_V 0.12470 0.01684 13.51
## 14 RUV_ADD 0.00000 0.02167 5739954.00
## 15 RUV_PROP 0.12281 0.00458 3.73
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -1336.86
##
##
## $OFMeasures$IndividualContribToLL
## Subject ICtoLL
## 1 1 -34.19
## 2 2 -36.09
## 3 3 -27.25
## 4 4 -46.05
## 5 5 -43.52
## 6 6 -46.11
## 7 7 -37.45
## 8 8 -42.92
## 9 9 -34.60
## 10 10 -59.68
## 11 11 -42.45
## 12 12 -41.58
## 13 13 -49.62
## 14 14 -44.32
## 15 15 -48.82
## 16 16 -42.70
## 17 17 -39.41
## 18 18 -45.19
## 19 19 -41.56
## 20 20 -46.66
## 21 21 -40.62
## 22 22 -36.42
## 23 23 -51.37
## 24 24 -45.40
## 25 25 -43.13
## 26 26 -45.22
## 27 27 -39.98
## 28 28 -37.67
## 29 29 -32.96
## 30 30 -33.57
## 31 31 -45.91
## 32 32 -34.42
##
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 2697.72
##
## $OFMeasures$InformationCriteria$BIC
## [1] 2715.31
##
##
##
## $Messages
## list()
Use 'ddmore' function as.xpdb() to create an Xpose database object from the Standardised Output object, regardless of target software used for estimation.
mlx.xpdb<-as.xpdb(mlx,datafile)
##
## Removed dose rows in rawData slot of SO to enable merge with Predictions data.
We can then call Xpose functions referencing this mlx.xpdb object as the input. Perform some basic goodness of fit
print(basic.gof(mlx.xpdb))
print(ind.plots(mlx.xpdb))
Export results to PDF file
pdf("GOF_MLX.pdf")
print(basic.gof(mlx.xpdb))
print(ind.plots(mlx.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 18:49:02 2016
## New
## Submitted
## Job 65bb9437-f27f-4e93-8368-6e4c36ba08e4 progress:
## Running [ ................. ]
## Importing Results
## Copying the result data back to the local machine for job ID 65bb9437-f27f-4e93-8368-6e4c36ba08e4...
## From C:\Users\zparra\AppData\Local\Temp\RtmpSKgKTU\DDMORE.job1dec586019ac to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase4_2/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 WARNINGs were raised during the job execution:
## estimation_successful: 0
## zero_gradients: 1
## final_zero_gradients: 1
## estimate_near_boundary: 1
##
## The following MESSAGEs were raised during the job execution:
## covariance_step_run: 0
## rounding_errors: 0
## hessian_reset: 0
## s_matrix_singular: 0
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Wed Aug 17 18:54:51 2016
Load previous results
# NM.FOCEI <- LoadSOObject("NONMEM_FOCEI/UseCase4_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 POP_FORAL RUV_PROP
## 0.10009300 7.93231000 0.34186300 0.95012900 0.99999000 0.12169300
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.00109900 0.75000000 1.00000000 0.12223000 0.00838324 0.12313400
## PPV_KA PPV_TLAG PPV_FORAL
## 0.09522580 0.10000000 0.12487700
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_TLAG
## 7.98883 1.00000 0.35758 0.10082 0.75000 1.00247
## POP_FORAL PPV_V PPV_KA PPV_CL PPV_TLAG PPV_FORAL
## 0.99160 0.12470 0.07619 0.11930 0.10000 0.32991
## CORR_CL_V RUV_ADD RUV_PROP
## 0.03330 0.00000 0.12281
Use 'ddmore' function as.xpdb() to create an Xpose database object from the Standard Output object, regardless of target software used for estimation.
nm.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.
We can then call Xpose functions referencing this mlx.xpdb object as the input. Perform some basic goodness of fit
print(basic.gof(nm.xpdb))
print(ind.plots(nm.xpdb))
Export results to PDF file
pdf("GOF_NM.FOCEI.pdf")
print(basic.gof(nm.xpdb))
print(ind.plots(nm.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.100093"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "7.93231"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "0.341863"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.950129"
##
## $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"
##
##
## $POP_FORAL
## $POP_FORAL$value
## [1] "0.99999"
##
## $POP_FORAL$lo
## [1] "0.001"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.12223"
##
##
## $PPV_V
## $PPV_V$value
## [1] "0.123134"
##
##
## $PPV_KA
## $PPV_KA$value
## [1] "0.0952258"
##
##
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
##
## $PPV_TLAG$fix
## [1] "true"
##
##
## $PPV_FORAL
## $PPV_FORAL$value
## [1] "0.124877"
##
##
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "0.00838324"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.121693"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.001099"
##
## $RUV_ADD$lo
## [1] "1.0E-4"
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",
subfolder="VPC", plot=TRUE)
## -- Wed Aug 17 18:55:23 2016
## New
## Submitted
## Job ff0dd2e0-2d7d-47c2-85a3-7b81067e1282 progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID ff0dd2e0-2d7d-47c2-85a3-7b81067e1282...
## From C:\Users\zparra\AppData\Local\Temp\RtmpSKgKTU\DDMORE.job1dec64a12e9c to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase4_2/VPC
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## SimulationSimulationBlock
## SimulationSimulationBlock
##
## The following MESSAGEs were raised during the job execution:
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Wed Aug 17 18:56:49 2016
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"))
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 POP_FORAL RUV_PROP
## 0.10009300 7.93231000 0.34186300 0.95012900 0.99999000 0.12169300
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.00109900 0.75000000 1.00000000 0.12223000 0.00838324 0.12313400
## PPV_KA PPV_TLAG PPV_FORAL logtWT
## 0.09522580 0.10000000 0.12487700 0.00000000
Simulate for a dose of 100mg given at time 0 into the CENTRAL (iv administration) and a dose of 150 mg given to the CENTRAL (iv dose). Note that we are using COMPARMTMENTS for dosing processes, which translate to PK macros, and therefore the type option needs to be used
adm1 <- list(type=2, time = 0, amount=100, rate=100) #iv dose
adm2 <- list(type=1, time = 168, amount=150) #oral dose
Simulate PK parameters for individuals
ind <- list(name = c('CL','V'))
Simulate predicted (CC) and observed concentration values (Y)
f <- list( name = c('CC'), time = seq(0,to=300,by=1))
y <- list( name = c('Y'), time = c(0, 0.5, 1, 4, 8, 12, 24, 36, 48,120,
168,168.5,170,171,174,180,192,216,240,288))
Simulate 12 subjects
g <- list( size = 12, level = 'individual')
Call simulx
res <- simulx(model = myPharmML,
parameter = p,
group = g,
treatment = list(adm1,adm2),
output = list(ind,f,y))
Simulated parameter values for each individual
print(res$parameter)
## id CL V
## 1 1 0.11853300 7.693147
## 2 2 0.10916421 9.813362
## 3 3 0.11118152 7.440567
## 4 4 0.09540063 9.133591
## 5 5 0.09409975 6.327528
## 6 6 0.08808842 8.739982
## 7 7 0.12273784 9.646295
## 8 8 0.10070634 8.396366
## 9 9 0.09241264 9.403188
## 10 10 0.10417163 8.261747
## 11 11 0.11043235 8.509011
## 12 12 0.08736465 9.016890
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')
Call simulx
res.1000 <- simulx(model = myPharmML,
parameter = p,
group = g,
treatment = list(adm1,adm2),
output = list(ind,f,y))
Plot prediction intervals with prctilemlx
. band
defines the percentile bands displayed:
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%
## 1 0.0 -0.002434415 -0.001230859 -0.0006907394 -0.0004200868
## 2 0.5 3.699567360 4.784231583 5.1355278486 5.4656484887
## 3 1.0 8.462059863 10.406529370 10.9088929504 11.4284374639
## 4 4.0 8.026207746 9.575067110 10.4277315079 10.8513311650
## 5 8.0 7.824279559 9.457514508 10.0007730487 10.5010741736
## 6 12.0 6.707232305 8.636643943 9.3234437852 9.8019436809
## 7 24.0 6.760092899 7.730160768 8.1700421459 8.6205323158
## 8 36.0 5.331910727 6.472699351 7.0618593624 7.4557446406
## 9 48.0 4.310573071 5.258459931 5.9069358460 6.2129201131
## 10 120.0 1.547898477 2.073685943 2.2643115922 2.3826372314
## 11 168.0 0.796432423 0.953279896 1.2323513297 1.3593985668
## 12 168.5 0.767094852 0.993310769 1.2002944416 1.3249348729
## 13 170.0 5.042010982 5.562566754 5.9319510059 6.2414841111
## 14 171.0 6.799678398 8.670007058 9.3548631146 9.8382048598
## 15 174.0 8.980946344 13.097397490 14.0512572372 14.8467978707
## 16 180.0 11.553979374 14.690414285 15.2554575662 16.2787899935
## 17 192.0 9.587160280 12.627161548 13.9863829515 14.6720984542
## 18 216.0 7.641433237 9.635061483 10.1512436882 10.6384929135
## 19 240.0 4.859896150 6.940022392 7.2077916567 7.5285414347
## 20 288.0 2.622786107 3.523439683 3.9545377254 4.2374482747
## 40% 50% 50% 60% 70%
## 1 -0.0002055521 -7.926177e-05 -7.926177e-05 1.875618e-04 3.486082e-04
## 2 5.7719594447 5.986546e+00 5.986546e+00 6.247543e+00 6.699697e+00
## 3 11.8659035194 1.243564e+01 1.243564e+01 1.289813e+01 1.336204e+01
## 4 11.3723207559 1.160449e+01 1.160449e+01 1.195840e+01 1.256296e+01
## 5 11.0711281912 1.135717e+01 1.135717e+01 1.177366e+01 1.231765e+01
## 6 10.2622624180 1.079313e+01 1.079313e+01 1.116577e+01 1.154274e+01
## 7 8.9213350902 9.180900e+00 9.180900e+00 9.446969e+00 9.649599e+00
## 8 7.6614303399 7.908182e+00 7.908182e+00 8.205122e+00 8.686644e+00
## 9 6.3658616160 6.738689e+00 6.738689e+00 7.022017e+00 7.322612e+00
## 10 2.6607556809 2.863498e+00 2.863498e+00 2.959787e+00 3.104504e+00
## 11 1.4332180595 1.585081e+00 1.585081e+00 1.666304e+00 1.779183e+00
## 12 1.4340302475 1.493569e+00 1.493569e+00 1.580194e+00 1.687368e+00
## 13 6.6033727749 6.967273e+00 6.967273e+00 7.267045e+00 7.570171e+00
## 14 10.1927343290 1.046221e+01 1.046221e+01 1.098386e+01 1.148128e+01
## 15 15.4502120401 1.590675e+01 1.590675e+01 1.677786e+01 1.758867e+01
## 16 17.0823721805 1.779480e+01 1.779480e+01 1.829466e+01 1.894428e+01
## 17 15.1469564504 1.543846e+01 1.543846e+01 1.586982e+01 1.655826e+01
## 18 11.1503343917 1.148210e+01 1.148210e+01 1.189499e+01 1.251754e+01
## 19 8.0249442868 8.525774e+00 8.525774e+00 8.793255e+00 8.993150e+00
## 20 4.4043229874 4.616958e+00 4.616958e+00 4.890336e+00 5.103552e+00
## 80% 90% 100%
## 1 6.956913e-04 0.001552201 0.002077781
## 2 7.071120e+00 7.626427072 9.808802544
## 3 1.432685e+01 15.214651331 17.533738973
## 4 1.329814e+01 14.231605285 17.246800233
## 5 1.274449e+01 13.257028039 15.272249042
## 6 1.199748e+01 12.739487338 14.849527911
## 7 1.026644e+01 10.924402698 12.362065266
## 8 9.065670e+00 9.444225492 11.789462295
## 9 7.602882e+00 8.066878872 9.142123534
## 10 3.349665e+00 3.613078731 4.442882123
## 11 1.910945e+00 2.290155220 3.012997266
## 12 1.885443e+00 2.120144032 2.680734749
## 13 8.084254e+00 8.475212247 10.111259774
## 14 1.198187e+01 12.884703823 14.789141421
## 15 1.803176e+01 18.739138697 21.665636854
## 16 2.027715e+01 21.416393149 24.859522474
## 17 1.741120e+01 18.135591836 23.290245796
## 18 1.307620e+01 14.077267223 16.458148198
## 19 9.777029e+00 10.450793237 13.218800196
## 20 5.402829e+00 5.997519512 7.805624951