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_1"
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)
## Warning in dir.create(wd):
## 'D:\SEE-Prod5_RC4\MDL_IDE\workspace\UseCasesDemo\UseCase4_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] "UseCase4_1.mdl" "warfarin_infusion_oral.csv"
mlx <- estimate(mdlfile, target="MONOLIX", subfolder="Monolix")
## -- Wed Aug 17 18:37:03 2016
## New
## Submitted
## Job b394f4c7-fa5c-4054-bf0b-b4ff08a3c0ed progress:
## Running [ .......... ]
## Importing Results
## Copying the result data back to the local machine for job ID b394f4c7-fa5c-4054-bf0b-b4ff08a3c0ed...
## From C:\Users\zparra\AppData\Local\Temp\RtmpSKgKTU\DDMORE.job1dec334ee8d to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase4_1/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:40:32 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_1.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.96620 1.00000 0.35710 0.10026 0.75000 1.00150
## POP_FORAL PPV_V PPV_KA PPV_CL PPV_TLAG PPV_FORAL
## 0.98421 0.12539 0.06625 0.12171 0.10000 0.41025
## CORR_CL_V RUV_ADD RUV_PROP
## 0.02292 0.00000 0.12309
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.02292 0.18890 824.17
## 4 POP_CL 0.10026 0.00225 2.25
## 5 POP_FORAL 0.98421 0.01043 1.06
## 6 POP_KA 0.35710 0.01291 3.61
## 7 POP_TLAG 1.00150 0.03110 3.11
## 8 POP_V 7.96620 0.18562 2.33
## 9 PPV_CL 0.12171 0.01611 13.24
## 10 PPV_FORAL 0.41025 3.75141 914.42
## 11 PPV_KA 0.06625 0.05279 79.69
## 12 PPV_TLAG 0.10000 0.00000 0.00
## 13 PPV_V 0.12539 0.01692 13.49
## 14 RUV_ADD 0.00000 0.02155 1554819.49
## 15 RUV_PROP 0.12309 0.00458 3.72
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -1337.88
##
##
## $OFMeasures$IndividualContribToLL
## Subject ICtoLL
## 1 1 -34.25
## 2 2 -36.07
## 3 3 -27.39
## 4 4 -46.31
## 5 5 -43.62
## 6 6 -46.02
## 7 7 -37.17
## 8 8 -43.31
## 9 9 -34.61
## 10 10 -59.79
## 11 11 -42.53
## 12 12 -41.62
## 13 13 -49.72
## 14 14 -44.59
## 15 15 -48.87
## 16 16 -42.59
## 17 17 -39.70
## 18 18 -45.33
## 19 19 -40.84
## 20 20 -46.72
## 21 21 -40.62
## 22 22 -36.46
## 23 23 -51.25
## 24 24 -45.10
## 25 25 -43.12
## 26 26 -44.94
## 27 27 -40.12
## 28 28 -37.96
## 29 29 -33.18
## 30 30 -33.74
## 31 31 -45.96
## 32 32 -34.40
##
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 2699.76
##
## $OFMeasures$InformationCriteria$BIC
## [1] 2717.35
##
##
##
## $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:42:03 2016
## New
## Submitted
## Job 8df22d6b-1cfe-4dff-bf91-ec9cad24fe1c progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 8df22d6b-1cfe-4dff-bf91-ec9cad24fe1c...
## From C:\Users\zparra\AppData\Local\Temp\RtmpSKgKTU\DDMORE.job1dec533c4eb1 to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase4_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 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
## hessian_reset: 0
## zero_gradients: 0
## final_zero_gradients: 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 18:43:32 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.1001090 8.0906700 0.3771930 1.1207400 0.9999930 0.1300870
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.0191873 0.7500000 1.0000000 0.1319380 0.0113956 0.1197450
## PPV_KA PPV_TLAG PPV_FORAL
## 0.0350171 0.1000000 0.1011060
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_TLAG
## 7.96620 1.00000 0.35710 0.10026 0.75000 1.00150
## POP_FORAL PPV_V PPV_KA PPV_CL PPV_TLAG PPV_FORAL
## 0.98421 0.12539 0.06625 0.12171 0.10000 0.41025
## CORR_CL_V RUV_ADD RUV_PROP
## 0.02292 0.00000 0.12309
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.100109"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "8.09067"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "0.377193"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "1.12074"
##
## $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.999993"
##
## $POP_FORAL$lo
## [1] "0.001"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.131938"
##
##
## $PPV_V
## $PPV_V$value
## [1] "0.119745"
##
##
## $PPV_KA
## $PPV_KA$value
## [1] "0.0350171"
##
##
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
##
## $PPV_TLAG$fix
## [1] "true"
##
##
## $PPV_FORAL
## $PPV_FORAL$value
## [1] "0.101106"
##
##
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "0.0113956"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.130087"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.0191873"
##
## $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:43:48 2016
## New
## Submitted
## Job ffa479ab-148a-4c08-89bd-dfc0125a2290 progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID ffa479ab-148a-4c08-89bd-dfc0125a2290...
## From C:\Users\zparra\AppData\Local\Temp\RtmpSKgKTU\DDMORE.job1dec4c0a6c5 to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase4_1/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:45:35 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.1001090 8.0906700 0.3771930 1.1207400 0.9999930 0.1300870
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.0191873 0.7500000 1.0000000 0.1319380 0.0113956 0.1197450
## PPV_KA PPV_TLAG PPV_FORAL logtWT
## 0.0350171 0.1000000 0.1011060 0.0000000
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, 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 (CONC) and observed concentration values (Y)
f <- list( name = c('CONC'), 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.12015483 7.857274
## 2 2 0.10993655 9.953310
## 3 3 0.11213109 7.604861
## 4 4 0.09505271 9.278494
## 5 5 0.09365439 6.492985
## 6 6 0.08721304 8.887331
## 7 7 0.12476215 9.791877
## 8 8 0.10077132 8.550740
## 9 9 0.09184319 9.543819
## 10 10 0.10451931 8.418234
## 11 11 0.11131573 8.664632
## 12 12 0.08643979 9.160808
Plot simulated results
plot(ggplot() +
geom_line(data=res$CONC, aes(x=time, y=CONC, 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% 40%
## 1 0.0 -0.04250214 -0.0214894 -0.01205953 -0.007334241 -0.003588708
## 2 0.5 3.45658478 4.5928096 4.96053979 5.375915594 5.617766642
## 3 1.0 8.13273464 10.1160323 10.71280121 11.118709044 11.608872919
## 4 4.0 7.76795223 9.3814666 10.25757792 10.619837653 11.099371981
## 5 8.0 7.58396685 9.1939082 9.76168375 10.301531371 10.859190923
## 6 12.0 6.41657444 8.3821669 9.14008881 9.516837941 10.040150210
## 7 24.0 6.56708633 7.5726987 7.93899750 8.473413943 8.783496184
## 8 36.0 5.06547333 6.3247464 6.95721820 7.343613967 7.560217130
## 9 48.0 4.06691053 5.0977205 5.79851816 6.103610306 6.314033604
## 10 120.0 1.41476758 2.0538022 2.21436078 2.389640975 2.656988092
## 11 168.0 0.79806050 0.9534254 1.23424933 1.371211220 1.460617041
## 12 168.5 0.76305786 0.9925449 1.18908523 1.326614754 1.452759845
## 13 170.0 4.47187982 5.1638308 5.51804862 5.848663634 6.229930178
## 14 171.0 6.60132336 8.6620018 9.20458206 9.844003692 10.204282703
## 15 174.0 9.12585203 13.1524954 14.21175593 15.054218435 15.637885742
## 16 180.0 11.10045309 14.4411164 15.08506737 16.166610591 16.885898936
## 17 192.0 9.03859184 12.3639475 13.75531721 14.498626976 14.918112816
## 18 216.0 7.32080496 9.4262119 9.93510227 10.483802212 11.010911050
## 19 240.0 4.57663723 6.8208800 7.11578286 7.434450762 7.961191078
## 20 288.0 2.50389135 3.4898613 3.95353595 4.224350545 4.464408512
## 50% 50% 60% 70% 80%
## 1 -0.001383821 -0.001383821 0.003274618 0.006086306 0.01214598
## 2 5.875382617 5.875382617 6.113136350 6.572341863 6.95496915
## 3 12.222760808 12.222760808 12.703412299 13.079425300 14.10999083
## 4 11.430317847 11.430317847 11.688034221 12.339419305 13.09266285
## 5 11.243483470 11.243483470 11.578293795 12.120804079 12.46764701
## 6 10.598746060 10.598746060 11.037085213 11.480117689 11.83416698
## 7 9.056183297 9.056183297 9.306928797 9.581069929 10.14503300
## 8 7.812607636 7.812607636 8.162125170 8.633432235 9.02913318
## 9 6.687683638 6.687683638 6.985837460 7.286619361 7.65221006
## 10 2.886398188 2.886398188 2.991237750 3.185885315 3.41723779
## 11 1.624727805 1.624727805 1.698117627 1.833057810 1.96672351
## 12 1.538191009 1.538191009 1.625924068 1.731828740 1.92382845
## 13 6.508340387 6.508340387 6.729499398 7.143008812 7.68539598
## 14 10.636268514 10.636268514 10.964340502 11.286458961 12.06295321
## 15 16.211919320 16.211919320 16.950453799 17.685471515 18.22459712
## 16 17.715475460 17.715475460 18.131207903 18.869008072 20.23348295
## 17 15.218370877 15.218370877 15.654460392 16.218587052 17.35070931
## 18 11.399055974 11.399055974 11.868962995 12.537849592 13.05348113
## 19 8.466998008 8.466998008 8.789664745 9.016811333 9.88939064
## 20 4.678355503 4.678355503 4.944535859 5.187530239 5.54355470
## 90% 100%
## 1 0.02709967 0.0362757
## 2 7.53863254 9.8121637
## 3 15.02200955 17.4222949
## 4 14.14538728 17.1762858
## 5 13.11002937 14.9513483
## 6 12.63641439 14.6670366
## 7 10.86130713 12.4234564
## 8 9.42862106 11.8810324
## 9 8.09348330 9.2101867
## 10 3.73882855 4.6292115
## 11 2.36743710 3.1396415
## 12 2.16646542 2.7571297
## 13 8.21016126 9.5130197
## 14 12.80749907 14.4194950
## 15 19.37675160 22.3810395
## 16 21.38023288 25.1724714
## 17 18.03688079 23.4713964
## 18 14.18492279 16.7574227
## 19 10.55146404 13.5408111
## 20 6.11301564 8.1673443