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"
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.mdl" "warfarin_infusion_oral.csv"
Use 'ddmore' function getMDLObjects() to retrieve model object(s) from an existing .mdl file. This function reads the MDL in an .mdl file and parses the MDL code for each MDL Object into an R list of objects of appropriate types with names corresponding to the MDL Object names given in the file.
myMDLObj <- getMDLObjects(mdlfile)
length(myMDLObj)
## [1] 4
names(myMDLObj)
## [1] "warfarin_PK_IVPO_dat" "warfarin_PK_IVPO_par" "warfarin_PK_IVPO_mdl"
## [4] "warfarin_PK_ODE_task"
Use 'ddmore' function getDataObjects() to retrieve only data object(s) from an existing .mdl file. This function returns a list of Parameter Object(s) from which we select the first element. Hover over the variable name to see its structure
myDataObj <- getDataObjects(mdlfile)[[1]]
Use 'ddmore' function getParameterObjects() to retrieve only parameter object(s) from an existing .mdl file
myParObj <- getParameterObjects(mdlfile)[[1]]
Use 'ddmore' function getModelObjects() to retrieve only model object(s) from an existing .mdl file.
myModObj <- getModelObjects(mdlfile)[[1]]
Use 'ddmore' function getTaskPropertiesObjects() to retrieve only task properties object(s) from an existing .mdl file
myTaskObj <- getTaskPropertiesObjects(mdlfile)[[1]]
Recall that getDataObjects only reads the MDL code from the .mdl file. Use 'ddmore' function readDataObj() to create an R object from the MDL data object.
myData <- readDataObj(myDataObj)
Let's look at the first 6 lines of the data set
head(myData)
## ID TIME WT AMT RATE CMT DV logtWT MDV
## 1 1 0.0 80.778 100 100 2 0.0000 0.14321 1
## 2 1 0.5 80.778 0 0 0 5.4851 0.14321 0
## 3 1 1.0 80.778 0 0 0 12.1870 0.14321 0
## 4 1 2.0 80.778 0 0 0 11.2920 0.14321 0
## 5 1 3.0 80.778 0 0 0 9.7773 0.14321 0
## 6 1 6.0 80.778 0 0 0 8.7563 0.14321 0
Extract only observation records
myEDAData<-myData[myData$MDV==0,]
Open an R window to record and access all your plots
windows(record=TRUE)
Now plot the data using xyplot from the lattice library
plot1 <- xyplot(DV~TIME, groups=ID,data=myEDAData,type="b",ylab="Conc. (mg/L)",xlab="Time (h)",scales=list(relation="free"))
print(plot1)
plot2 <- xyplot(DV~TIME|ID,data=myEDAData,type="b",layout=c(3,4),ylab="Conc. (mg/L)",xlab="Time (h)",scales=list(relation="free"))
print(plot2)
Export results to PDF file
pdf(paste0(uc,"_EGA.pdf"))
print(plot1)
print(plot2)
dev.off()
## png
## 2
mlx <- estimate(mdlfile, target="MONOLIX", subfolder="Monolix")
## -- Tue Aug 16 11:39:39 2016
## New
## Submitted
## Job 557e4051-20cf-4bd2-bb39-4a652b06b38a progress:
## Running [ ...... ]
## Importing Results
## Copying the result data back to the local machine for job ID 557e4051-20cf-4bd2-bb39-4a652b06b38a...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356427ff2e9d to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase4/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
## -- Tue Aug 16 11:41:42 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.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.97902 1.00000 0.36489 0.10026 0.75000 1.00668
## POP_FORAL PPV_V PPV_KA PPV_CL PPV_TLAG PPV_FORAL
## 0.98055 0.12687 0.07830 0.12072 0.10000 0.15467
## CORR_CL_V RUV_ADD RUV_PROP
## 0.02400 0.00000 0.12351
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.02400 0.18868 786.26
## 4 POP_CL 0.10026 0.00224 2.23
## 5 POP_FORAL 0.98055 0.01006 1.03
## 6 POP_KA 0.36489 0.01039 2.85
## 7 POP_TLAG 1.00668 0.10067 10.00
## 8 POP_V 7.97902 0.18758 2.35
## 9 PPV_CL 0.12072 0.01600 13.25
## 10 PPV_FORAL 0.15467 6.36772 4116.96
## 11 PPV_KA 0.07830 0.03718 47.49
## 12 PPV_TLAG 0.10000 0.00000 0.00
## 13 PPV_V 0.12687 0.01706 13.45
## 14 RUV_ADD 0.00000 0.02120 1413307.23
## 15 RUV_PROP 0.12351 0.00457 3.70
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -1325.145
##
##
## $OFMeasures$IndividualContribToLL
## Subject ICtoLL
## 1 1 -32.97
## 2 2 -35.00
## 3 3 -26.83
## 4 4 -45.84
## 5 5 -42.14
## 6 6 -45.14
## 7 7 -37.12
## 8 8 -48.06
## 9 9 -33.42
## 10 10 -59.24
## 11 11 -42.66
## 12 12 -41.64
## 13 13 -48.83
## 14 14 -44.53
## 15 15 -47.39
## 16 16 -42.37
## 17 17 -39.54
## 18 18 -43.28
## 19 19 -40.79
## 20 20 -46.51
## 21 21 -40.69
## 22 22 -36.61
## 23 23 -49.56
## 24 24 -44.01
## 25 25 -42.71
## 26 26 -44.67
## 27 27 -39.76
## 28 28 -36.59
## 29 29 -33.21
## 30 30 -33.54
## 31 31 -46.04
## 32 32 -34.45
##
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 2674.29
##
## $OFMeasures$InformationCriteria$BIC
## [1] 2691.88
##
##
##
## $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()
## png
## 2
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")
## -- Tue Aug 16 11:41:48 2016
## New
## Submitted
## Job 0dfc15d1-7a5a-46ae-971f-37fa7cdc9232 progress:
## Running [ .......................................................................... ]
## Importing Results
## Copying the result data back to the local machine for job ID 0dfc15d1-7a5a-46ae-971f-37fa7cdc9232...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356460ec2a61 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase4/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 MESSAGEs were raised during the job execution:
## estimation_successful: 1
## 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
## -- Tue Aug 16 12:06:34 2016
The ddmore “LoadSOObj” reads and parsed existing Standardise Output Objects
NM <- LoadSOObject(“NONMEM/UseCase4.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_nm <- getPopulationParameters(NM, what="estimates")
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG POP_FORAL RUV_PROP
## 0.100776000 8.029460000 0.361668000 1.004260000 0.988334000 0.135529000
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.000100001 0.750000000 1.000000000 0.122742000 0.035191100 0.126857000
## PPV_KA PPV_TLAG PPV_FORAL
## 0.001113570 0.100000000 0.010208600
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_TLAG
## 7.97902 1.00000 0.36489 0.10026 0.75000 1.00668
## POP_FORAL PPV_V PPV_KA PPV_CL PPV_TLAG PPV_FORAL
## 0.98055 0.12687 0.07830 0.12072 0.10000 0.15467
## CORR_CL_V RUV_ADD RUV_PROP
## 0.02400 0.00000 0.12351
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -65.74766
##
##
##
## $Messages
## $Messages$Info
## $Messages$Info$estimation_successful
## [1] "1"
##
## $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"
Use 'ddmore' function as.xpdb() to create an Xpose database object from the Standardised Output object, regardless of target software used for estimation.
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.
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))
print(parm.hist(nm.xpdb))
Export results 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()
## png
## 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.
By default, a covariance step is not run when estimating in PsN. To see how it can be requested, see UseCase1_1.mdl
NM.FOCEI <- estimate(mdlfile.FOCEI, target="PsN", subfolder="NONMEM_FOCEI")
## -- Tue Aug 16 12:06:51 2016
## New
## Submitted
## Job 0eb147b8-5900-4dfc-b2a1-2449bb329818 progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 0eb147b8-5900-4dfc-b2a1-2449bb329818...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35643d2d2f30 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase4/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
## -- Tue Aug 16 12:08:14 2016
Load previous results
NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase4_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.1040870 8.2015700 0.3287240 0.9365240 0.9999900 0.1318750
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.0394124 0.7500000 1.0000000 0.1087070 0.0100140 0.1010400
## PPV_KA PPV_TLAG PPV_FORAL
## 0.1126570 0.1000000 0.1027870
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG POP_FORAL RUV_PROP
## 0.100776000 8.029460000 0.361668000 1.004260000 0.988334000 0.135529000
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.000100001 0.750000000 1.000000000 0.122742000 0.035191100 0.126857000
## PPV_KA PPV_TLAG PPV_FORAL
## 0.001113570 0.100000000 0.010208600
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_TLAG
## 7.97902 1.00000 0.36489 0.10026 0.75000 1.00668
## POP_FORAL PPV_V PPV_KA PPV_CL PPV_TLAG PPV_FORAL
## 0.98055 0.12687 0.07830 0.12072 0.10000 0.15467
## CORR_CL_V RUV_ADD RUV_PROP
## 0.02400 0.00000 0.12351
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()
## png
## 2
The ddmore “bootstrap.PsN” function is a wrap up function that calls Bootstrap PsN functionality using as input an MDL file that will be translated to NMTRAN as first step. Additional PsN arguments can be specified under the “bootstrapOptions” attribute. After task execution, the output from PsN is converted to a Standardised Output object which is saved in a .SO.xml file.
Translated files and PsN output will be returned in the ./Bootstrap subfolder
bootstrapResults <- bootstrap.PsN(mdlfile.FOCEI, samples=20, seed=123456,
bootstrapOptions=" -no-skip_minimization_terminated -threads=2",
subfolder="Bootstrap", plot=TRUE)
## -- Tue Aug 16 12:08:19 2016
## New
## Submitted
## Job 1aff9b76-24b4-493d-9e18-0d928552a5b6 progress:
## Running [ .............................. ]
## Importing Results
## Copying the result data back to the local machine for job ID 1aff9b76-24b4-493d-9e18-0d928552a5b6...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job3564a39667c to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase4/Bootstrap
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## Estimation::PopulationEstimates::MLE
## Estimation::PopulationEstimates::OtherMethodBootstrap
## Estimation::PrecisionPopulationEstimates::OtherMethodBootstrap
## 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
## bootstrap_parameter_scale: The parameters PPV_CL, CORR_CL_V, PPV_V, PPV_KA, PPV_TLAG and PPV_FORAL were requested on the sd/corr scale but are given on the var/cov scale in all bootstrap results.
##
## 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
## -- Tue Aug 16 12:18:23 2016
## Warning: NAs introduced by coercion
## [[1]]
##
## [[2]]
## NULL
##
## [[3]]
##
## [[4]]
## NULL
##
## [[5]]
## NULL
Load results from a bootstrap previously performed
bootstrapResults <- LoadSOObject(“Bootstrap/UseCase4_FOCEI.SO.xml”)
Export bootstrap histograms to a pdf
pdf(paste0(uc,"_Bootstrap.pdf"))
print(boot.hist(results.file = file.path("Bootstrap",paste0("raw_results_",uc,"_FOCEI.csv")),
incl.ids.file = file.path("Bootstrap","included_individuals1.csv")))
## [[1]]
##
## [[2]]
## NULL
##
## [[3]]
##
## [[4]]
## NULL
##
## [[5]]
## NULL
dev.off()
## png
## 2
Extract parameter estimates and precision from bootstrap results.
print(getPopulationParameters(bootstrapResults, what="estimates"))
## $MLE
## POP_CL POP_V POP_KA POP_TLAG POP_FORAL RUV_PROP
## 0.1040870 8.2015700 0.3287240 0.9365240 0.9999900 0.1318750
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.0394124 0.7500000 1.0000000 0.1087070 0.0100140 0.1010400
## PPV_KA PPV_TLAG PPV_FORAL
## 0.1126570 0.1000000 0.1027870
##
## $Bootstrap
## Parameter Mean Median
## BETA_CL_WT BETA_CL_WT 0.7500000000 0.750000000
## BETA_V_WT BETA_V_WT 1.0000000000 1.000000000
## CORR_CL_V CORR_CL_V 0.0001169085 0.000100695
## POP_CL POP_CL 0.1009160000 0.101747000
## POP_FORAL POP_FORAL 0.9999968000 0.999997500
## POP_KA POP_KA 0.3402635000 0.342084500
## POP_TLAG POP_TLAG 0.9540283000 0.953221000
## POP_V POP_V 8.0372880000 8.075620000
## PPV_CL PPV_CL 0.0104772900 0.010455300
## PPV_FORAL PPV_FORAL 0.0094609030 0.009855945
## PPV_KA PPV_KA 0.0114620500 0.010502650
## PPV_TLAG PPV_TLAG 0.0100000000 0.010000000
## PPV_V PPV_V 0.0111995300 0.010087400
## RUV_ADD RUV_ADD 0.0471771800 0.044289050
## RUV_PROP RUV_PROP 0.1263722000 0.126814500
Extract the information regarding the precision intervals
print(getPopulationParameters(bootstrapResults, what="intervals")$Bootstrap)
## Parameter Mean Median Perc_5 Perc_95
## 1 BETA_CL_WT 0.7500000000 0.750000000 0.750000000 0.7500000000
## 2 BETA_V_WT 1.0000000000 1.000000000 1.000000000 1.0000000000
## 3 CORR_CL_V 0.0001169085 0.000100695 -0.000387686 0.0009281199
## 4 POP_CL 0.1009160000 0.101747000 0.094895100 0.1056106000
## 5 POP_FORAL 0.9999968000 0.999997500 0.999991000 1.0000000000
## 6 POP_KA 0.3402635000 0.342084500 0.310096900 0.3643845000
## 7 POP_TLAG 0.9540283000 0.953221000 0.900000900 0.9846822000
## 8 POP_V 8.0372880000 8.075620000 7.625235000 8.6869540000
## 9 PPV_CL 0.0104772900 0.010455300 0.007874106 0.0142786900
## 10 PPV_FORAL 0.0094609030 0.009855945 0.006094529 0.0109278400
## 11 PPV_KA 0.0114620500 0.010502650 0.003680951 0.0267904800
## 12 PPV_TLAG 0.0100000000 0.010000000 0.010000000 0.0100000000
## 13 PPV_V 0.0111995300 0.010087400 0.006527319 0.0230601300
## 14 RUV_ADD 0.0471771800 0.044289050 0.013513400 0.0990131900
## 15 RUV_PROP 0.1263722000 0.126814500 0.109273700 0.1386731000
Before running the VPC with PsN we must update the (initial) values in the MDL Parameter Object. MLE estimates from a 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.104087"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "8.20157"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "0.328724"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.936524"
##
## $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.108707"
##
##
## $PPV_V
## $PPV_V$value
## [1] "0.10104"
##
##
## $PPV_KA
## $PPV_KA$value
## [1] "0.112657"
##
##
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
##
## $PPV_TLAG$fix
## [1] "true"
##
##
## $PPV_FORAL
## $PPV_FORAL$value
## [1] "0.102787"
##
##
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "0.010014"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.131875"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.0394124"
##
## $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)
## -- Tue Aug 16 12:18:36 2016
## New
## Submitted
## Job 9db94e7f-4e6c-47c8-9c9d-5ece1958b689 progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID 9db94e7f-4e6c-47c8-9c9d-5ece1958b689...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35647c0d41d4 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase4/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
## -- Tue Aug 16 12:19:39 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()
## png
## 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.1040870 8.2015700 0.3287240 0.9365240 0.9999900 0.1318750
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 0.0394124 0.7500000 1.0000000 0.1087070 0.0100140 0.1010400
## PPV_KA PPV_TLAG PPV_FORAL logtWT
## 0.1126570 0.1000000 0.1027870 0.0000000
Simulate for a dose of 100mg given at time 0 into the GUT (oral administration)
adm1 <- list(target='GUT', time = 0, amount=100,rate=100)
adm2 <- list(target='CENTRAL', time = 168, amount=150)
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, 2, 3, 4, 6, 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.10875652 8.126415
## 2 2 0.10075540 9.418060
## 3 3 0.09746605 8.673744
## 4 4 0.09751726 9.384153
## 5 5 0.09484810 7.575749
## 6 6 0.10018793 8.492464
## 7 7 0.08272919 8.536578
## 8 8 0.09624570 8.377655
## 9 9 0.10613492 7.374078
## 10 10 0.10444747 9.511846
## 11 11 0.12078369 8.293980
## 12 12 0.11036583 7.605382
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% 40%
## 1 0.0 -0.08326272 -0.048559614 -0.03455542 -0.02519870 -0.0106347121
## 2 0.5 -0.08944703 -0.042922309 -0.02455754 -0.01149630 -0.0001295682
## 3 1.0 -0.07819408 -0.004725428 0.01703224 0.08994823 0.2357543166
## 4 2.0 4.60622703 5.373857947 6.02346076 6.41541007 6.7672676537
## 5 3.0 7.34736469 9.279371204 10.30075284 10.66275249 11.1525657809
## 6 4.0 9.52944961 12.195366514 13.33932032 14.41803881 14.8698718343
## 7 6.0 12.55649538 15.236311928 16.68691194 17.45798786 18.1060668612
## 8 8.0 10.97800770 16.435999802 17.09216889 18.30301076 19.2991073863
## 9 12.0 12.62737787 17.572490793 19.12177518 19.85240839 20.6108595375
## 10 24.0 13.00478807 14.567642625 15.87272985 16.54855950 17.2911758434
## 11 36.0 10.29010559 12.836481167 13.98279732 14.87948563 15.4714800951
## 12 48.0 9.43428772 11.571652030 12.17812887 12.83041548 13.3714148597
## 13 120.0 3.16577507 4.144210351 4.59458329 5.01647649 5.4385310814
## 14 168.0 25.12250594 33.718791150 34.83340329 36.78514815 38.0181355074
## 15 168.5 26.90151104 33.267453912 35.06791682 36.61477058 38.2104544721
## 16 170.0 25.62793586 31.387506469 33.40741349 35.88133168 37.2990628552
## 17 171.0 26.52405165 31.744173406 33.69135181 34.99610590 36.3981822237
## 18 174.0 23.61750913 30.730073437 32.51151257 34.54004484 35.5482847622
## 19 180.0 23.85905694 27.127305683 29.12514135 30.69816131 32.7404536996
## 20 192.0 17.65129246 23.619974124 25.61651770 27.50776663 28.4523184769
## 21 216.0 13.27953803 17.155683062 18.87872129 19.85520241 20.5845263588
## 22 240.0 9.92358155 13.376723403 14.18361087 15.07331739 15.4282450465
## 23 288.0 4.82841822 6.316166635 6.83399431 7.61297093 8.2827375396
## 50% 50% 60% 70% 80%
## 1 -0.005183063 -0.005183063 0.003129764 0.01211319 0.02288258
## 2 0.006041972 0.006041972 0.011489008 0.02202148 0.03598554
## 3 0.466608396 0.466608396 0.551048808 0.75834579 1.03047691
## 4 7.085705447 7.085705447 7.268723080 8.13302189 8.45614698
## 5 11.650940318 11.650940318 12.237548761 12.62502002 13.75865955
## 6 15.306169237 15.306169237 15.887623977 16.41840686 17.20004098
## 7 18.723535016 18.723535016 19.304075639 20.34848307 21.78388592
## 8 20.438984876 20.438984876 20.726546213 21.70610537 22.72479964
## 9 21.618694523 21.618694523 22.403224263 23.41631462 24.42093110
## 10 18.335920504 18.335920504 19.352609163 20.46489417 21.58774884
## 11 16.289635279 16.289635279 16.957257996 17.93261440 18.66449592
## 12 13.757534290 13.757534290 14.668707563 15.24857914 16.09737024
## 13 5.754570187 5.754570187 6.010608727 6.24868873 6.59352876
## 14 39.724120328 39.724120328 40.807111235 41.85468263 43.83814748
## 15 39.041447894 39.041447894 41.021757733 42.98438717 44.42086363
## 16 38.286325581 38.286325581 39.523316361 41.17273541 42.32438211
## 17 37.620235277 37.620235277 39.226276727 40.94131704 43.24691486
## 18 37.244824328 37.244824328 38.519574336 39.46128891 40.74952147
## 19 33.447489978 33.447489978 34.692117855 36.40383975 38.53008434
## 20 29.839648327 29.839648327 31.007078095 31.91602375 33.40934371
## 21 21.176974425 21.176974425 22.324754239 23.43863553 24.50221771
## 22 16.073599564 16.073599564 16.758570710 17.18130597 17.95694229
## 23 8.757402061 8.757402061 9.258859524 9.42678183 10.06816919
## 90% 100%
## 1 0.04915100 0.10708387
## 2 0.04930418 0.09770852
## 3 1.36502721 2.09810307
## 4 9.25916192 11.65921360
## 5 14.85792246 18.96509940
## 6 18.60838756 23.24791428
## 7 23.75192488 26.19203623
## 8 23.91476851 28.58140950
## 9 25.76678735 28.06419969
## 10 22.45626132 30.45538094
## 11 19.76487622 24.33133402
## 12 16.92706606 18.45167505
## 13 7.16340664 8.64237156
## 14 46.58809263 55.71946070
## 15 47.25696173 55.74224769
## 16 44.23906657 59.69781702
## 17 45.99175074 54.70415635
## 18 43.21695901 55.75925396
## 19 41.06122577 49.25792871
## 20 35.69684328 43.10834038
## 21 25.88005545 30.08729830
## 22 19.43213633 23.00349745
## 23 10.65993711 14.17504112