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 wiht the coursor any code lines you wish to execute and press CTRL+R+R in your keyboard. An HTML file containing the commands in this file and associated output will be provided to allow the user to compare the results
Clear workspace and set working directory under 'UsesCasesDemo' project
rm(list=ls(all=F))
mydir <- file.path(Sys.getenv("MDLIDE_WORKSPACE_HOME"),"UseCasesDemo")
setwd(mydir)
Set name of .mdl file and dataset for future tasks
uc<-"UseCase6"
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)
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] "UseCase6.mdl" "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_ODE_dat" "warfarin_PK_CORR_par" "warfarin_PK_ODE_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 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()
## windows
## 8
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 Standardised Output object which is saved in a .SO.xml file.
Translated files and Monolix output will be returned in the ./Monolix subfolder. The Standardised 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")
## -- Fri Dec 11 09:42:06 2015
## New
## Submitted
## Job ebd0cfd6-9727-4d59-905f-cf2702ee105b progress:
## Running [ .......... ]
## Importing Results
## Copying the result data back to the local machine for job ID ebd0cfd6-9727-4d59-905f-cf2702ee105b...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd017357f9d to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase6/Monolix
## Done.
##
##
## The following elements were parsed successfully:
## ToolSettings
## RawResults
## TaskInformation
## Estimation:PopulationEstimates
## Estimation:PrecisionPopulationEstimates
## Estimation:IndividualEstimates
## Estimation:Residuals
## Estimation:Predictions
## Estimation:Likelihood
##
## Completed
## -- Fri Dec 11 09:45:31 2015
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/UseCase6.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
## 7.90252 1.00000 0.72632 0.13882 0.75000
## POP_TLAG PPV_V PPV_KA PPV_CL PPV_TLAG
## 0.92045 0.14662 0.68166 0.22101 0.01000
## ETA_V_ETA_KA ETA_V_ETA_CL ETA_KA_ETA_CL RUV_ADD RUV_PROP
## -0.36226 0.26523 0.80246 0.96679 -0.00217
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 ETA_KA_ETA_CL 0.80246 0.15442 19.24
## 4 ETA_V_ETA_CL 0.26523 0.22844 86.13
## 5 ETA_V_ETA_KA -0.36226 0.25029 69.09
## 6 POP_CL 0.13882 0.00596 4.29
## 7 POP_KA 0.72632 0.12326 16.97
## 8 POP_TLAG 0.92045 0.01652 1.79
## 9 POP_V 7.90252 0.24951 3.16
## 10 PPV_CL 0.22101 0.03335 15.09
## 11 PPV_KA 0.68166 0.14218 20.86
## 12 PPV_TLAG 0.01000 0.00000 0.00
## 13 PPV_V 0.14662 0.02644 18.03
## 14 RUV_ADD 0.96679 0.09457 9.78
## 15 RUV_PROP -0.00217 0.01328 611.73
print(getEstimationInfo(mlx))
## $Likelihood
## $Likelihood$LogLikelihood
## [1] -404.965
##
## $Likelihood$IndividualContribToLL
## Subject ICtoLL
## 1 1 -26.13
## 2 2 -7.23
## 3 3 -16.53
## 4 4 -14.96
## 5 5 -16.59
## 6 6 -10.76
## 7 7 -17.44
## 8 8 -20.92
## 9 9 -29.32
## 10 10 -7.51
## 11 12 -20.56
## 12 13 -20.06
## 13 14 -19.99
## 14 15 -14.73
## 15 16 -32.90
## 16 17 -7.44
## 17 18 -7.48
## 18 19 -7.45
## 19 20 -8.01
## 20 21 -7.59
## 21 22 -7.52
## 22 23 -8.54
## 23 24 -6.95
## 24 25 -9.20
## 25 26 -8.38
## 26 27 -7.29
## 27 28 -8.13
## 28 29 -7.20
## 29 30 -6.94
## 30 31 -7.14
## 31 32 -6.81
## 32 33 -7.26
##
## $Likelihood$InformationCriteria
## $Likelihood$InformationCriteria$AIC
## [1] 833.93
##
## $Likelihood$InformationCriteria$BIC
## [1] 851.51
##
##
##
## $Messages
## list()
Perform model diagnostics for the base model using Xpose functions 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 (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()
## windows
## 8
NM <- estimate(mdlfile, target="NONMEM", subfolder="NONMEM")
## -- Fri Dec 11 09:45:50 2015
## New
## Submitted
## Job 87513edf-6db9-4a64-ae3d-942af9da0640 progress:
## Running [ ..................................... ]
## Importing Results
## Copying the result data back to the local machine for job ID 87513edf-6db9-4a64-ae3d-942af9da0640...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd029b56d6 to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase6/NONMEM
## Done.
##
##
## The following elements were parsed successfully:
## RawResults
## TaskInformation
## Estimation:PopulationEstimates
## Estimation:IndividualEstimates
## Estimation:Residuals
## Estimation:Predictions
## Estimation:Likelihood
##
## The following MESSAGEs were raised during the job execution:
## minimization_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.11
##
## Completed
## -- Fri Dec 11 09:58:16 2015
Load previous results NM <- LoadSOObject(“NONMEM/UseCase6.SO.xml”)
parameters_nm <- getPopulationParameters(NM, what="estimates")
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP
## 0.1334620 8.0825200 1.9372600 0.9487420 0.0725785
## RUV_ADD PPV_CL ETA_CL_ETA_V PPV_V ETA_CL_ETA_KA
## 0.1863010 0.2701400 0.2244500 0.1377470 -0.2821020
## ETA_V_ETA_KA PPV_KA BETA_CL_WT BETA_V_WT PPV_TLAG
## 0.0316001 0.9431170 0.7500000 1.0000000 0.1000000
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT
## 7.90252 1.00000 0.72632 0.13882 0.75000
## POP_TLAG PPV_V PPV_KA PPV_CL PPV_TLAG
## 0.92045 0.14662 0.68166 0.22101 0.01000
## ETA_V_ETA_KA ETA_V_ETA_CL ETA_KA_ETA_CL RUV_ADD RUV_PROP
## -0.36226 0.26523 0.80246 0.96679 -0.00217
Covariance step cannot be requested in the current version of the Framework
#getPopulationParameters(NM, what="precisions")
print(getEstimationInfo(NM))
## $Likelihood
## $Likelihood$Deviance
## [1] -264.4621
##
##
## $Messages
## $Messages$Info
## $Messages$Info$minimization_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.11"
nm.xpdb<-as.xpdb(NM,datafile)
##
## Removed dose rows in rawData+Predictions slot of SO to enable merge with Residuals data.
##
## Residuals data does not currently contain dose rows in output from Nonmem executions.
Perform some basic goodness of fit (graphs are exported to PDF file)
print(basic.gof(nm.xpdb))
print(ind.plots(nm.xpdb))
print(parm.hist(nm.xpdb))
Export graphs to a PDF file
pdf("GOF_NM.pdf")
print(basic.gof(nm.xpdb))
print(ind.plots(nm.xpdb))
print(parm.hist(nm.xpdb))
dev.off()
## windows
## 8
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")
## -- Fri Dec 11 09:58:46 2015
## New
## Submitted
## Job 2007d932-0fa4-4635-990f-516ea5642293 progress:
## Running [ ............ ]
## Importing Results
## Copying the result data back to the local machine for job ID 2007d932-0fa4-4635-990f-516ea5642293...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd054c53d7 to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase6/NONMEM_FOCEI
## Done.
##
##
## The following elements were parsed successfully:
## RawResults
## TaskInformation
## Estimation:PopulationEstimates
## Estimation:IndividualEstimates
## Estimation:Residuals
## Estimation:Predictions
## Estimation:Likelihood
##
## The following MESSAGEs were raised during the job execution:
## minimization_successful: 1
## covariance_step_run: 0
## rounding_errors: 0
## hessian_reset: 0
## zero_gradients: 0
## final_zero_gradients: 0
## estimate_near_boundary: 0
## s_matrix_singular: 0
## significant_digits: 3.3
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
##
## Completed
## -- Fri Dec 11 10:02:51 2015
Results from NONMEM should be comparable to previous results
getPopulationParameters(NM.FOCEI, what="estimates")
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP
## 0.1344720 8.0356400 1.4624100 0.8619840 0.0632106
## RUV_ADD PPV_CL ETA_CL_ETA_V PPV_V ETA_CL_ETA_KA
## 0.3128270 0.2652360 0.2042010 0.1367230 -0.2024730
## ETA_V_ETA_KA PPV_KA BETA_CL_WT BETA_V_WT PPV_TLAG
## 0.1010170 0.8899120 0.7500000 1.0000000 0.1000000
parameters_nm
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP
## 0.1334620 8.0825200 1.9372600 0.9487420 0.0725785
## RUV_ADD PPV_CL ETA_CL_ETA_V PPV_V ETA_CL_ETA_KA
## 0.1863010 0.2701400 0.2244500 0.1377470 -0.2821020
## ETA_V_ETA_KA PPV_KA BETA_CL_WT BETA_V_WT PPV_TLAG
## 0.0316001 0.9431170 0.7500000 1.0000000 0.1000000
nmfocei.xpdb<-as.xpdb(NM.FOCEI,datafile)
##
## Removed dose rows in rawData+Predictions slot of SO to enable merge with Residuals data.
##
## Residuals data does not currently contain dose rows in output from Nonmem executions.
Basic diagnostics for NONMEM fit.
print(basic.gof(nmfocei.xpdb))
Export graphs to a PDF file
pdf("GOF_NM_FOCEI.pdf")
print(basic.gof(nmfocei.xpdb))
dev.off()
## windows
## 8
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)
## -- Fri Dec 11 10:03:02 2015
## New
## Submitted
## Job 433b9454-f90c-461d-88ee-e035b2f2b23e progress:
## Running [ .............................................................................................................................. ]
## Importing Results
## Copying the result data back to the local machine for job ID 433b9454-f90c-461d-88ee-e035b2f2b23e...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd050e563c5 to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase6/Bootstrap
## Done.
##
##
## The following elements were parsed successfully:
## RawResults
## TaskInformation
## Estimation:PopulationEstimates
## Estimation:PrecisionPopulationEstimates
## Estimation:IndividualEstimates
## Estimation:Residuals
## Estimation:Predictions
## Estimation:Likelihood
##
## The following WARNINGs were raised during the job execution:
## bootstrap_parameter_scale: The parameters PPV_CL, ETA_CL_ETA_V, PPV_V, ETA_CL_ETA_KA, ETA_V_ETA_KA, 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:
## minimization_successful: 1
## covariance_step_run: 0
## rounding_errors: 0
## hessian_reset: 0
## zero_gradients: 0
## final_zero_gradients: 0
## estimate_near_boundary: 0
## s_matrix_singular: 0
## significant_digits: 3.3
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
##
## Completed
## -- Fri Dec 11 10:45:09 2015
## Warning: NAs introduced by coercion
## [[1]]
##
## [[2]]
## NULL
##
## [[3]]
##
## [[4]]
## NULL
##
## [[5]]
## NULL
Load results from a bootstrap previously performed bootstrapResults <- LoadSOObject(“Bootstrap/UseCase6_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()
## windows
## 8
Extract parameter estimates and precision from bootstrap results.
print(getPopulationParameters(bootstrapResults, what="estimates"))
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP
## 0.1344720 8.0356400 1.4624100 0.8619840 0.0632106
## RUV_ADD PPV_CL ETA_CL_ETA_V PPV_V ETA_CL_ETA_KA
## 0.3128270 0.2652360 0.2042010 0.1367230 -0.2024730
## ETA_V_ETA_KA PPV_KA BETA_CL_WT BETA_V_WT PPV_TLAG
## 0.1010170 0.8899120 0.7500000 1.0000000 0.1000000
##
## $Bootstrap
## Parameter Mean Median
## POP_CL POP_CL 0.135510700 0.13686700
## POP_V POP_V 8.028257000 7.96220500
## POP_KA POP_KA 1.609104000 1.54955000
## POP_TLAG POP_TLAG 0.840734500 0.86502000
## RUV_PROP RUV_PROP 0.093167310 0.08340560
## RUV_ADD RUV_ADD 0.189231100 0.20010350
## BETA_CL_WT BETA_CL_WT 0.750000000 0.75000000
## BETA_V_WT BETA_V_WT 1.000000000 1.00000000
## PPV_CL PPV_CL 0.071748940 0.07199260
## ETA_CL_ETA_V ETA_CL_ETA_V 0.005887502 0.00546241
## PPV_V PPV_V 0.014615660 0.01580155
## ETA_CL_ETA_KA ETA_CL_ETA_KA -0.053867173 -0.06664030
## ETA_V_ETA_KA ETA_V_ETA_KA 0.017750080 0.02169305
## PPV_KA PPV_KA 0.814379200 0.84088550
## PPV_TLAG PPV_TLAG 0.010000000 0.01000000
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.750000000 0.75000000
## 2 BETA_V_WT 1.000000000 1.00000000 1.000000000 1.00000000
## 3 ETA_CL_ETA_KA -0.053867173 -0.06664030 -0.181747500 0.09486227
## 4 ETA_CL_ETA_V 0.005887502 0.00546241 -0.006074584 0.01484676
## 5 ETA_V_ETA_KA 0.017750080 0.02169305 -0.052335835 0.11914980
## 6 POP_CL 0.135510700 0.13686700 0.123992200 0.14791840
## 7 POP_KA 1.609104000 1.54955000 0.769585500 2.61488100
## 8 POP_TLAG 0.840734500 0.86502000 0.531418700 0.96308860
## 9 POP_V 8.028257000 7.96220500 7.625156000 8.51895800
## 10 PPV_CL 0.071748940 0.07199260 0.027892830 0.12697600
## 11 PPV_KA 0.814379200 0.84088550 0.151559600 1.87621400
## 12 PPV_TLAG 0.010000000 0.01000000 0.010000000 0.01000000
## 13 PPV_V 0.014615660 0.01580155 0.001842530 0.02537429
## 14 RUV_ADD 0.189231100 0.20010350 0.001000000 0.41717160
## 15 RUV_PROP 0.093167310 0.08340560 0.037561180 0.17099380
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
In the current version of the SO standard, we need to manually update parameter names for correlation and covariance parameters to match the SO with the MDL. The SO object has a parameter “ETA_x_ETA_y” for each of the elements in the correlation. MDL needs them grouped in a vector
corr <- paste(variabilityPar[c("ETA_CL_ETA_V","ETA_CL_ETA_KA","ETA_V_ETA_KA")], collapse=", ")
OMEGA1 <- as.character(paste0("[",corr,"]"))
Remove the parameters for each correlation element, and add the vector
variabilityPar <- variabilityPar[!names(variabilityPar) %in% c("ETA_CL_ETA_V","ETA_CL_ETA_KA","ETA_V_ETA_KA")]
variabilityPar <- c(variabilityPar, OMEGA1=OMEGA1)
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.134472"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "8.03564"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "1.46241"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.861984"
##
## $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"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0632106"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.312827"
##
## $RUV_ADD$lo
## [1] "0"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.265236"
##
## $PPV_CL$type
## [1] "sd"
##
##
## $PPV_V
## $PPV_V$value
## [1] "0.136723"
##
## $PPV_V$type
## [1] "sd"
##
##
## $PPV_KA
## $PPV_KA$value
## [1] "0.889912"
##
## $PPV_KA$type
## [1] "sd"
##
##
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
##
## $PPV_TLAG$type
## [1] "sd"
##
## $PPV_TLAG$fix
## [1] "true"
##
##
## $OMEGA1
## $OMEGA1$type
## [1] "corr"
##
## $OMEGA1$parameter
## [1] "[ETA_CL,ETA_V,ETA_KA]"
##
## $OMEGA1$value
## [1] "[0.204201, -0.202473, 0.101017]"
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)
## -- Fri Dec 11 10:45:26 2015
## New
## Submitted
## Job 16768eb9-68b6-4338-91f4-554c66dd3616 progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID 16768eb9-68b6-4338-91f4-554c66dd3616...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd0444f769f to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase6/VPC
## Done.
##
##
## The following elements were parsed successfully:
## RawResults
## TaskInformation
## Simulation
##
## The following MESSAGEs were raised during the job execution:
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
##
## Completed
## -- Fri Dec 11 10:47:11 2015
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()
## windows
## 8
The mlxR package has been developed to visualize and explore models that are encoded in MLXTRAN or PharmML The ddmore function as.PharmML translates an MDL file (extension .mdl) to its PharmML representation. The output file (extension .xml) is saved in the working directory.
myPharmML <- as.PharmML(mdlfile)
Use parameter values from the FOCEI estimation
parValues <- getPopulationParameters(NM.FOCEI, what="estimates")$MLE
Simulate for the typical weight of 70. Recall that logtWT = log(WT/70).
p <- c(parValues,logtWT=0)
Parameter values used in simulation
print(p)
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP
## 0.1344720 8.0356400 1.4624100 0.8619840 0.0632106
## RUV_ADD PPV_CL ETA_CL_ETA_V PPV_V ETA_CL_ETA_KA
## 0.3128270 0.2652360 0.2042010 0.1367230 -0.2024730
## ETA_V_ETA_KA PPV_KA BETA_CL_WT BETA_V_WT PPV_TLAG
## 0.1010170 0.8899120 0.7500000 1.0000000 0.1000000
## logtWT
## 0.0000000
Simulate for a dose of 100mg given at time 0 into the GUT (oral administration)
adm <- list(target='GUT', time = 0, amount = 100)
Simulate PK parameters for individuals
ind <- list(name = c('TLAG','KA','CL','V'))
Simulate predicted (CC) and observed concentration values (Y)
f <- list( name = c('CC'), time = seq(0,to=50,by=1))
y <- list( name = c('Y'), time = c(0, 0.5, 1, 2, 3, 4, 6, 8, 12, 24, 36, 48))
Simulate 12 subjects
g <- list( size = 12, level = 'individual', treatment = adm)
Call simulx
res <- simulx(model = myPharmML,
parameter = p,
group = g,
output = list(ind,f,y))
Simulated parameter values for each individual
print(res$parameter)
## id TLAG KA CL V
## 1 1 0.8725699 6.1501084 0.2063279 10.019846
## 2 2 1.0093814 2.0556018 0.1488347 8.467178
## 3 3 0.7863776 2.1315846 0.1504535 8.514527
## 4 4 0.6959804 1.3016474 0.1298847 7.893147
## 5 5 0.8728464 1.8116225 0.1433342 8.304404
## 6 6 0.8018132 1.1491938 0.1251508 7.743520
## 7 7 0.8564221 5.2443779 0.1967598 9.777574
## 8 8 0.7669037 0.8906733 0.1159971 7.446201
## 9 9 0.9289887 1.7239815 0.1412314 8.241379
## 10 10 0.8214541 5.5737505 0.2003645 9.869504
## 11 11 0.7226604 2.5693687 0.1590674 8.762421
## 12 12 0.7810802 2.3052303 0.1540067 8.617593
Plot simulated results
plot(ggplot() +
geom_line(data=res$CC, aes(x=time, y=CC, colour=id)) +
geom_point(data=res$Y, aes(x=time, y=Y, colour=id)) +
xlab("time (h)") + ylab("concentration") )
Simulate 1000 subjects - with simulx this is a QUICK process!
g <- list( size = 1000, level = 'individual', treatment = adm)
Call simulx
res.1000 <- simulx(model =myPharmML,
parameter = p,
group = g,
output = list(ind,f,y))
Plot of predicted concentrations band defines the percentile bands displayed level = range of values to examine (in %) 100 = full range of values number = number of bins within the level range.
print(prctilemlx(res.1000$CC,band=list(number=10, level=100)))
Plot of observed concentrations (with residual error)
print(prctilemlx(res.1000$Y,band=list(number=9, level=90)))
Table of the same information
prctilemlx(res.1000$Y,band=list(number=10, level=100), plot=F)$y
## time 0% 10% 20% 30% 40%
## 1 0.0 -0.6829742 -0.38021217 -0.2359907 -0.1425443 -0.07605863
## 2 0.5 -0.6334618 -0.33027277 -0.1829352 -0.1260009 -0.06607485
## 3 1.0 -0.5277959 -0.09701306 0.4730302 0.8648041 1.19534508
## 4 2.0 1.0731371 6.44213760 7.3719805 7.7603021 8.54979075
## 5 3.0 3.7721816 8.77196785 9.4469965 9.8394922 10.30328041
## 6 4.0 4.1517064 8.75798800 9.6274768 10.0786581 10.70030719
## 7 6.0 7.1664119 9.17313105 10.0038856 10.5166303 10.98533917
## 8 8.0 7.1891030 8.68468019 9.3203129 9.8586213 10.64334874
## 9 12.0 6.2362117 7.90750989 8.6665162 9.2506482 10.12847518
## 10 24.0 4.9675515 6.24370791 7.0970877 7.5835051 7.92892870
## 11 36.0 3.9652410 4.91913870 5.4854517 6.0473950 6.38010064
## 12 48.0 2.7747118 4.03801445 4.5214454 4.8301798 5.21956403
## 50% 50% 60% 70% 80% 90%
## 1 -0.00373999 -0.00373999 0.07012821 0.1384662 0.2103261 0.3858571
## 2 -0.01461358 -0.01461358 0.08540660 0.1708657 0.2437862 0.3373467
## 3 1.86687958 1.86687958 2.51239735 3.2871357 4.4114725 5.6109018
## 4 9.15266451 9.15266451 9.82841622 10.1220117 10.4491084 10.7474718
## 5 10.77033902 10.77033902 11.01131898 11.3782027 11.7755977 12.2085953
## 6 11.10842794 11.10842794 11.66068275 11.8706537 12.2229380 12.9144138
## 7 11.44322978 11.44322978 11.79509594 12.2611039 12.8060497 13.7930730
## 8 11.06057960 11.06057960 11.81939194 12.5418007 13.0250191 13.6561918
## 9 10.33821379 10.33821379 10.98852267 11.6228157 12.1350354 13.5372053
## 10 8.72658557 8.72658557 9.22599646 9.7712096 10.3266833 11.2487705
## 11 6.84701103 6.84701103 7.46581096 7.8729424 8.4430852 9.3864117
## 12 5.62658636 5.62658636 6.24844439 6.7669881 7.3328920 8.3647493
## 100%
## 1 0.9422171
## 2 0.7776130
## 3 10.1044776
## 4 12.5919130
## 5 13.4499795
## 6 14.0258679
## 7 15.7764522
## 8 15.5577931
## 9 15.3508765
## 10 15.3348141
## 11 14.0359242
## 12 11.2353166