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.
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)
Set name of .mdl file and dataset for future tasks
uc <- "UseCase2"
datafile <- "warfarin_conc.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):
## 'C:\SEE\MDL_IDE\workspace\UseCasesDemo\UseCase2' 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] "Bootstrap" "GOF_MLX.pdf"
## [3] "GOF_NM.pdf" "GOF_NM_FOCEI.pdf"
## [5] "Monolix" "NONMEM"
## [7] "NONMEM_FOCEI" "UseCase2.mdl"
## [9] "UseCase2.xml" "UseCase2_Bootstrap.pdf"
## [11] "UseCase2_EGA.pdf" "UseCase2_FOCEI.mdl"
## [13] "UseCase2_tr.txt" "UseCase2_VPC.mdl"
## [15] "UseCase2_VPC.pdf" "VPC"
## [17] "warfarin_conc.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_ANALYTIC_dat" "warfarin_PK_ODE_par"
## [3] "warfarin_PK_ANALYTIC_mdl" "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 DVID DV MDV logtWT
## 1 1 0.0 66.7 100 0 NA 1 -0.04829029
## 2 1 0.5 66.7 NA 1 0.0 0 -0.04829029
## 3 1 1.0 66.7 NA 1 1.9 0 -0.04829029
## 4 1 2.0 66.7 NA 1 3.3 0 -0.04829029
## 5 1 3.0 66.7 NA 1 6.6 0 -0.04829029
## 6 1 6.0 66.7 NA 1 9.1 0 -0.04829029
Extract only observation records
myEDAData<-myData[myData$MDV==0,]
Open an R window to record and access all your plots
windows(record=TRUE)
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)")
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 the results in a pdf file
pdf(paste0(uc,"_EGA.pdf"))
print(plot1)
print(plot2)
dev.off()
## png
## 2
The ddmore “estimate” function translates the contents of the .mdl file to a target language and then estimates parameters using the target software. After estimation, the output is converted to a Standard Output object which is saved in a .SO.xml file.
Translated files and Monolix output will be returned in the ./Monolix subfolder. The Standard Output object (.SO.xml) is read and parsed into an R object called “mlx” of (S4) class “StandardOutputObject”.
mlx <- estimate(mdlfile, target="MONOLIX", subfolder="Monolix")
## -- Tue Aug 16 08:44:23 2016
## New
## Submitted
## Job 747c8f84-4a74-4d4d-93ac-e447247e7f32 progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID 747c8f84-4a74-4d4d-93ac-e447247e7f32...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356454bd641f to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase2/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 08:46:12 2016
slotNames(mlx)
## [1] "ToolSettings" "RawResults" "TaskInformation"
## [4] "Estimation" "ModelDiagnostic" "Simulation"
## [7] "OptimalDesign" ".pathToSourceXML"
The ddmore “LoadSOObj” function reads and parses existing Standard Output Objects
mlx <- LoadSOObject(“Monolix/UseCase2.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")$MLE
print(parameters_mlx)
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_TLAG
## 8.08758 1.00000 1.67019 0.13438 0.75000 0.97399
## PPV_V PPV_KA PPV_CL PPV_TLAG CORR_CL_V RUV_ADD
## 0.13357 1.12170 0.26583 0.10000 0.19380 0.22733
## RUV_PROP
## 0.06484
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.19380 0.20050 103.46
## 4 POP_CL 0.13438 0.00644 4.80
## 5 POP_KA 1.67019 0.67645 40.50
## 6 POP_TLAG 0.97399 0.05459 5.60
## 7 POP_V 8.08758 0.22016 2.72
## 8 PPV_CL 0.26583 0.03450 12.98
## 9 PPV_KA 1.12170 0.29706 26.48
## 10 PPV_TLAG 0.10000 0.00000 0.00
## 11 PPV_V 0.13357 0.02198 16.46
## 12 RUV_ADD 0.22733 0.04455 19.60
## 13 RUV_PROP 0.06484 0.00919 14.18
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -332.895
##
##
## $OFMeasures$IndividualContribToLL
## Subject ICtoLL
## 1 1 -24.46
## 2 2 -5.22
## 3 3 -13.08
## 4 4 -12.17
## 5 5 -11.05
## 6 6 -7.51
## 7 7 -18.58
## 8 8 -20.94
## 9 9 -30.99
## 10 10 -5.77
## 11 12 -19.83
## 12 13 -19.28
## 13 14 -19.29
## 14 15 -11.46
## 15 16 -14.38
## 16 17 -5.69
## 17 18 -5.13
## 18 19 -6.62
## 19 20 -5.18
## 20 21 -5.95
## 21 22 -5.87
## 22 23 -8.12
## 23 24 -4.86
## 24 25 -7.16
## 25 26 -7.25
## 26 27 -5.29
## 27 28 -6.82
## 28 29 -5.58
## 29 30 -4.57
## 30 31 -5.03
## 31 32 -4.71
## 32 33 -5.07
##
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 685.79
##
## $OFMeasures$InformationCriteria$BIC
## [1] 700.44
##
##
##
## $Messages
## list()
Use 'ddmore' function as.xpdb() to create an Xpose database object from the Standard 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 (graphs are exported to PDF file)
print(basic.gof(mlx.xpdb))
print(ind.plots(mlx.xpdb))
Export graphs to a 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 08:46:24 2016
## New
## Submitted
## Job f929c3ec-5d98-4d86-97c7-3ca3df167f9c progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID f929c3ec-5d98-4d86-97c7-3ca3df167f9c...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356429dd571 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase2/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 08:48:07 2016
Load previous results:
NM <- LoadSOObject(“NONMEM/UseCase2.SO.xml”)
Results from NONMEM should be comparable with results from MONOLIX
parameters_nm <- getPopulationParameters(NM, what="estimates")
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.132954000 8.173140000 1.749320000 0.945971000 0.108251000 0.000100001
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.750000000 1.000000000 0.263455000 0.277717000 0.136488000 0.947330000
## PPV_TLAG
## 0.100000000
print(parameters_mlx)
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_TLAG
## 8.08758 1.00000 1.67019 0.13438 0.75000 0.97399
## PPV_V PPV_KA PPV_CL PPV_TLAG CORR_CL_V RUV_ADD
## 0.13357 1.12170 0.26583 0.10000 0.19380 0.22733
## RUV_PROP
## 0.06484
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -310.3207
##
##
##
## $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"
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
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()
## 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 Modelling Object Group (MOG). Note that we reuse the data, parameters and model from the MOG.
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 in NONMEM via PsN
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 08:48:22 2016
## New
## Submitted
## Job bfdfe184-c615-46c6-8705-c7de9fe90f0d progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID bfdfe184-c615-46c6-8705-c7de9fe90f0d...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35642c2935ef to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase2/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.4
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 08:49:25 2016
Load previous results:
NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase2_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.1341370 8.1009300 1.5616700 0.9677510 0.0715972 0.1932710
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.7500000 1.0000000 0.2637800 0.2425230 0.1348360 0.9360700
## PPV_TLAG
## 0.1000000
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.132954000 8.173140000 1.749320000 0.945971000 0.108251000 0.000100001
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.750000000 1.000000000 0.263455000 0.277717000 0.136488000 0.947330000
## PPV_TLAG
## 0.100000000
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 Standard 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 08:49:28 2016
## New
## Submitted
## Job 706cfe09-c756-4fe2-b157-1e0a23aa20e3 progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID 706cfe09-c756-4fe2-b157-1e0a23aa20e3...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35645c9a56ad to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase2/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:
## bootstrap_parameter_scale: The parameters PPV_CL, CORR_CL_V, PPV_V, PPV_KA and PPV_TLAG 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:
## 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.4
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 08:51:10 2016
## Warning: NAs introduced by coercion
## [[1]]
##
## [[2]]
## NULL
##
## [[3]]
##
## [[4]]
## NULL
##
## [[5]]
## NULL
Load results from a bootstrap previously performed:
bootstrapResults <- LoadSOObject(“Bootstrap/UseCase2_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 RUV_PROP RUV_ADD
## 0.1341370 8.1009300 1.5616700 0.9677510 0.0715972 0.1932710
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.7500000 1.0000000 0.2637800 0.2425230 0.1348360 0.9360700
## PPV_TLAG
## 0.1000000
##
## $Bootstrap
## Parameter Mean Median
## BETA_CL_WT BETA_CL_WT 0.750000000 0.75000000
## BETA_V_WT BETA_V_WT 1.000000000 1.00000000
## CORR_CL_V CORR_CL_V 0.005615584 0.00564982
## POP_CL POP_CL 0.134651000 0.13647200
## POP_KA POP_KA 1.494715000 1.41805000
## POP_TLAG POP_TLAG 0.927304500 0.93550300
## POP_V POP_V 8.102665000 8.01352500
## PPV_CL PPV_CL 0.070545630 0.06764735
## PPV_KA PPV_KA 0.585871500 0.54814450
## PPV_TLAG PPV_TLAG 0.010000000 0.01000000
## PPV_V PPV_V 0.014731550 0.01407660
## RUV_ADD RUV_ADD 0.127911900 0.12632150
## RUV_PROP RUV_PROP 0.089430860 0.09400740
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.750000000 0.75000000 0.7500000000 0.75000000
## 2 BETA_V_WT 1.000000000 1.00000000 1.0000000000 1.00000000
## 3 CORR_CL_V 0.005615584 0.00564982 -0.0041056180 0.01428605
## 4 POP_CL 0.134651000 0.13647200 0.1129103000 0.14789560
## 5 POP_KA 1.494715000 1.41805000 0.8082667000 3.04457600
## 6 POP_TLAG 0.927304500 0.93550300 0.7726211000 1.00539500
## 7 POP_V 8.102665000 8.01352500 7.6731430000 8.59367300
## 8 PPV_CL 0.070545630 0.06764735 0.0241234900 0.12475530
## 9 PPV_KA 0.585871500 0.54814450 0.0005247876 1.67861400
## 10 PPV_TLAG 0.010000000 0.01000000 0.0100000000 0.01000000
## 11 PPV_V 0.014731550 0.01407660 0.0071630180 0.02859239
## 12 RUV_ADD 0.127911900 0.12632150 0.0010990000 0.32237270
## 13 RUV_PROP 0.089430860 0.09400740 0.0482136900 0.13384490
When basing VPC on estimation from a target software other than NONMEM we must update the parameter values.
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.134137"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "8.10093"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "1.56167"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.967751"
##
## $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.26378"
##
##
## $PPV_V
## $PPV_V$value
## [1] "0.134836"
##
##
## $PPV_KA
## $PPV_KA$value
## [1] "0.93607"
##
##
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
##
## $PPV_TLAG$fix
## [1] "true"
##
##
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "0.242523"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0715972"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.193271"
##
## $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 -auto_bin=10",
subfolder="VPC", plot=TRUE)
## -- Tue Aug 16 08:51:23 2016
## New
## Submitted
## Job 73bfae99-9650-4c54-9d0a-6f72ffdf0b11 progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID 73bfae99-9650-4c54-9d0a-6f72ffdf0b11...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356416c4713d to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase2/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 08:52:26 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,WT=70)
Parameter values used in simulation
print(p)
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.1341370 8.1009300 1.5616700 0.9677510 0.0715972 0.1932710
## BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V PPV_KA
## 0.7500000 1.0000000 0.2637800 0.2425230 0.1348360 0.9360700
## PPV_TLAG WT
## 0.1000000 70.0000000
Simulate PK parameters for individuals
ind <- list(name = c('TLAG','KA','CL','V'))
Simulate predicted (CC) and observed concentration values (Y)
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 into the GUT (oral administration)
adm <- list(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,y))
Simulated parameter values for each individual
print(res$parameter)
## id TLAG KA CL V
## 1 1 1.1246196 0.9629657 0.12395565 6.552275
## 2 2 1.0077985 31.7274974 0.11436367 8.075694
## 3 3 0.9547855 0.5706391 0.11450953 8.571977
## 4 4 1.0097909 0.2595632 0.10705206 9.213065
## 5 5 0.9954566 1.6252165 0.12226839 10.170268
## 6 6 0.9094885 0.2239083 0.07683033 10.117872
## 7 7 1.0767710 2.3431626 0.11092005 10.944621
## 8 8 0.8397414 1.1101499 0.14063110 6.982595
## 9 9 0.9932825 2.7245133 0.13526701 7.534425
## 10 10 0.9899016 1.0122987 0.19245561 8.213548
## 11 11 0.9532780 0.5414114 0.15462325 8.626368
## 12 12 0.9441759 0.6527124 0.10967060 7.173718
Plot simulated results
plot(ggplot() +
geom_line(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 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.4083047 -0.2381272 -0.16945328 -0.12356970 -0.0470093024
## 2 0.5 -0.4386314 -0.2104829 -0.12042557 -0.05637570 -0.0006353781
## 3 1.0 -0.3834491 -0.0921631 -0.01922129 0.06958312 0.1159509276
## 4 2.0 1.6328325 3.9270485 5.86095652 7.04191577 8.0152289408
## 5 3.0 3.3401532 6.4699405 8.42844493 9.33992386 10.1346350080
## 6 4.0 4.0649851 8.2400047 9.38246940 10.14468101 10.7644919782
## 7 6.0 5.8634289 8.7931947 9.58749249 10.11042226 10.4962888313
## 8 8.0 6.1029314 8.5136919 9.25262180 9.84148768 10.2968694962
## 9 12.0 7.1647720 8.7429102 9.11072690 9.48500918 9.7913820045
## 10 24.0 5.2988727 6.8828360 7.40696392 7.72446064 8.0184188684
## 11 36.0 3.8335248 5.3762640 6.02115225 6.24828697 6.6730935275
## 12 48.0 2.3495185 4.3237814 4.82128737 5.18832356 5.4774577290
## 50% 50% 60% 70% 80% 90%
## 1 -0.02336252 -0.02336252 0.02927932 0.06377744 0.1146831 0.2410273
## 2 0.02823376 0.02823376 0.05304906 0.10677943 0.1733844 0.2341191
## 3 0.21824936 0.21824936 0.36861791 1.12522101 1.6120907 2.6094018
## 4 8.99703313 8.99703313 9.51275009 10.27607001 11.5575986 13.2428249
## 5 10.88699595 10.88699595 11.45878205 12.14648728 12.5935066 13.1539971
## 6 11.42447319 11.42447319 11.78728633 12.17948306 12.7264649 13.7923893
## 7 10.95409814 10.95409814 11.35416694 12.18678216 12.9327009 13.9405068
## 8 10.71878696 10.71878696 11.19828288 11.78454321 12.3973503 12.9303204
## 9 10.18221209 10.18221209 10.94885544 11.41285539 11.7302831 12.1524911
## 10 8.38459583 8.38459583 8.69765336 9.24808506 9.6278421 10.0390231
## 11 6.93696534 6.93696534 7.40146940 7.76982487 8.3553115 9.1357757
## 12 5.83651360 5.83651360 6.16755959 6.45549901 6.8037293 7.2270444
## 100%
## 1 0.5251191
## 2 0.4791442
## 3 6.1520140
## 4 17.1403393
## 5 19.6492198
## 6 18.0272392
## 7 15.6959000
## 8 15.3821749
## 9 15.5373923
## 10 12.6137885
## 11 10.2735912
## 12 8.2076503