Guided-demo: Exploring 'ddmore' R functionality with the warfarin model

UseCase9 : ODE model with infusion administration

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

Initialisation

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)

Create a working directory under 'models' folder where results are stored

uc<-"UseCase9"
mdlfile <- paste0(uc,".mdl")
datafile <- "warfarin_infusion.csv"

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] "UseCase9.mdl"          "warfarin_infusion.csv"

Introduction to 'ddmore' R package

View objects within the .mdl file

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_INFUSION_dat" "warfarin_PK_INFUSION_par"
## [3] "warfarin_PK_INFUSION_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]]

Exploratory Data Analysis

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         DV  logtWT
## 1  1  0.0 78.817 100  100  0.0000000 0.11864
## 2  1  0.5 78.817   0    0  0.0018392 0.11864
## 3  1  1.0 78.817   0    0  2.5371000 0.11864
## 4  1  2.0 78.817   0    0 11.8330000 0.11864
## 5  1  3.0 78.817   0    0 12.3150000 0.11864
## 6  1  6.0 78.817   0    0 11.0960000 0.11864

Extract only observation records

myEDAData<-myData[myData$AMT==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)

plot of chunk unnamed-chunk-15

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)

plot of chunk unnamed-chunk-15 plot of chunk unnamed-chunk-15 plot of chunk unnamed-chunk-15

Export the results in a pdf file

pdf(paste0(uc,"_EGA.pdf"))
 print(plot1)
 print(plot2)
dev.off()
## rj.GD 
##     2

Model Development

ESTIMATE model parameters using Monolix

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 02:46:48 2015
## New
## Submitted
## Job 6bbf1ff2-39c7-42b8-8597-ecb740df00b8 progress:
## Running [ ........... ]
## Importing Results
## Copying the result data back to the local machine for job ID 6bbf1ff2-39c7-42b8-8597-ecb740df00b8...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd04c873855 to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase9/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 02:50:34 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/UseCase9.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_CL   BETA_CL_WT        PPV_V 
##      9.42754      1.00000      0.11679      0.75000      0.02887 
##       PPV_CL ETA_V_ETA_CL      RUV_ADD     RUV_PROP 
##      0.03630     -0.41112      0.00000      0.44669
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_V_ETA_CL -0.41112 5.19282 1263.08
## 4       POP_CL  0.11679 0.00309    2.65
## 5        POP_V  9.42754 0.26304    2.79
## 6       PPV_CL  0.03630 0.07996  220.31
## 7        PPV_V  0.02887 0.11193  387.75
## 8      RUV_ADD  0.00000 0.00000   13.14
## 9     RUV_PROP  0.44669 0.01611    3.61
print(getEstimationInfo(mlx))
## $Likelihood
## $Likelihood$LogLikelihood
## [1] -9.85
## 
## $Likelihood$IndividualContribToLL
##    Subject ICtoLL
## 1        1   5.11
## 2        2  -1.38
## 3        3   0.20
## 4        4  -0.82
## 5        5   1.58
## 6        6  -5.63
## 7        7   3.56
## 8        8  -3.44
## 9        9   2.13
## 10      10  -2.14
## 11      11   0.26
## 12      12   1.15
## 13      13  -1.60
## 14      14  -0.34
## 15      15  -3.01
## 16      16  -2.89
## 17      17  -1.64
## 18      18  -0.19
## 19      19   2.52
## 20      20  -0.14
## 21      21  -0.02
## 22      22  -1.70
## 23      23  -2.93
## 24      24  -0.72
## 25      25   2.37
## 26      26  -3.98
## 27      27  -3.17
## 28      28   1.69
## 29      29   0.81
## 30      30   3.94
## 31      31  -2.76
## 32      32   3.33
## 
## $Likelihood$InformationCriteria
## $Likelihood$InformationCriteria$AIC
## [1] 33.7
## 
## $Likelihood$InformationCriteria$BIC
## [1] 43.96
## 
## 
## 
## $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 Standard Output object, regardless of target software used for estimation.

mlx.xpdb<-as.xpdb(mlx,datafile)

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))

plot of chunk unnamed-chunk-19

print(ind.plots(mlx.xpdb))

plot of chunk unnamed-chunk-19 plot of chunk unnamed-chunk-19

Export graphs to a PDF file

pdf("GOF_MLX.pdf")
 print(basic.gof(mlx.xpdb))
 print(ind.plots(mlx.xpdb))
dev.off()
## rj.GD 
##     2

SAEM Estimation with NONMEM

NM <- estimate(mdlfile, target="NONMEM", subfolder="NONMEM")
## -- Fri Dec 11 02:50:53 2015
## New
## Submitted
## Job 18b3642d-6edc-4c97-aeb9-3a2cb59cd30f progress:
## Running [ ............ ]
## Importing Results
## Copying the result data back to the local machine for job ID 18b3642d-6edc-4c97-aeb9-3a2cb59cd30f...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd030983e3a to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase9/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 02:55:00 2015

Load previous results NM <- LoadSOObject(“NONMEM/UseCase9.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     RUV_PROP      RUV_ADD       PPV_CL 
##  1.05056e-01  9.40932e+00  5.60809e-01  0.00000e+00  3.95125e-05 
## ETA_CL_ETA_V        PPV_V   BETA_CL_WT    BETA_V_WT 
## -9.98762e-01  1.15922e-04  7.50000e-01  1.00000e+00
print(parameters_mlx)
##        POP_V    BETA_V_WT       POP_CL   BETA_CL_WT        PPV_V 
##      9.42754      1.00000      0.11679      0.75000      0.02887 
##       PPV_CL ETA_V_ETA_CL      RUV_ADD     RUV_PROP 
##      0.03630     -0.41112      0.00000      0.44669

Covariance step cannot be requested in the current version of the Framework

#print(getPopulationParameters(NM, what="precisions"))

print(getEstimationInfo(NM))
## $Likelihood
## $Likelihood$Deviance
## [1] 138.698
## 
## 
## $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"

Xpose diagnostics using NONMEM output

nm.xpdb<-as.xpdb(NM,datafile)

Perform some basic goodness of fit (graphs are exported to PDF file)

print(basic.gof(nm.xpdb))

plot of chunk unnamed-chunk-23

print(ind.plots(nm.xpdb))

plot of chunk unnamed-chunk-23 plot of chunk unnamed-chunk-23

print(parm.hist(nm.xpdb))

plot of chunk unnamed-chunk-23

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()
## rj.GD 
##     2

Change estimation method to FOCEI (for speed)

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 02:55:26 2015
## New
## Submitted
## Job 6f1c1fcc-6ea5-47e6-900e-769223a6a198 progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 6f1c1fcc-6ea5-47e6-900e-769223a6a198...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd0487f126c to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase9/NONMEM_FOCEI
## Done.
## 
## 
## The following elements were parsed successfully:
##       RawResults
##       TaskInformation
##       Estimation:PopulationEstimates
##       Estimation:IndividualEstimates
##       Estimation:Residuals
##       Estimation:Predictions
##       Estimation:Likelihood
## 
## The following WARNINGs were raised during the job execution:
##  zero_gradients: 5
##  final_zero_gradients: 2
##  estimate_near_boundary: 1
## 
## The following MESSAGEs were raised during the job execution:
##  minimization_successful: 1
##  covariance_step_run: 0
##  rounding_errors: 0
##  hessian_reset: 0
##  s_matrix_singular: 0
##  significant_digits: 3.6
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
## 
## Completed
## -- Fri Dec 11 02:56:52 2015

Load previous results NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase9_FOCEI.SO.xml”)

print(getPopulationParameters(NM.FOCEI,what="estimates"))
## $MLE
##       POP_CL        POP_V     RUV_PROP      RUV_ADD       PPV_CL 
##   0.11441100   9.23932000   0.43837100   0.00100000   0.00114987 
## ETA_CL_ETA_V        PPV_V   BETA_CL_WT    BETA_V_WT 
##  -0.79688500   0.00165519   0.75000000   1.00000000
print(parameters_nm)
## $MLE
##       POP_CL        POP_V     RUV_PROP      RUV_ADD       PPV_CL 
##  1.05056e-01  9.40932e+00  5.60809e-01  0.00000e+00  3.95125e-05 
## ETA_CL_ETA_V        PPV_V   BETA_CL_WT    BETA_V_WT 
## -9.98762e-01  1.15922e-04  7.50000e-01  1.00000e+00

Xpose diagnostics using NONMEM output

nmfocei.xpdb<-as.xpdb(NM.FOCEI,datafile)

Basic diagnostics for NONMEM fit.

print(basic.gof(nmfocei.xpdb))

plot of chunk unnamed-chunk-29

Export graphs to a PDF file

pdf("GOF_NM_FOCEI.pdf")
print(basic.gof(nmfocei.xpdb))
dev.off()
## rj.GD 
##     2

Run the bootstrap using PsN

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 02:57:04 2015
## New
## Submitted
## Job 83b0b1d8-309a-4ca4-bc0e-de2a0e50c7d8 progress:
## Running [ .............. ]
## Importing Results
## Copying the result data back to the local machine for job ID 83b0b1d8-309a-4ca4-bc0e-de2a0e50c7d8...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd0263336d0 to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase9/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:
##  zero_gradients: 5
##  final_zero_gradients: 2
##  estimate_near_boundary: 1
##  bootstrap_parameter_scale: The parameters PPV_CL, ETA_CL_ETA_V and PPV_V 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
##  s_matrix_singular: 0
##  significant_digits: 3.6
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
## 
## Completed
## -- Fri Dec 11 03:01:50 2015
## Warning: NAs introduced by coercion
## [[1]]

plot of chunk Bootstrap

## 
## [[2]]
## NULL
## 
## [[3]]

plot of chunk Bootstrap

## 
## [[4]]
## NULL
## 
## [[5]]
## NULL

Load results from a bootstrap previously performed bootstrapResults <- LoadSOObject(“Bootstrap/UseCase9_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()
## rj.GD 
##     2

Extract parameter estimates and precision from bootstrap results.

print(getPopulationParameters(bootstrapResults, what="estimates"))
## $MLE
##       POP_CL        POP_V     RUV_PROP      RUV_ADD       PPV_CL 
##   0.11441100   9.23932000   0.43837100   0.00100000   0.00114987 
## ETA_CL_ETA_V        PPV_V   BETA_CL_WT    BETA_V_WT 
##  -0.79688500   0.00165519   0.75000000   1.00000000 
## 
## $Bootstrap
##                 Parameter          Mean        Median
## POP_CL             POP_CL  1.143097e-01  1.140505e-01
## POP_V               POP_V  9.237873e+00  9.217350e+00
## RUV_PROP         RUV_PROP  4.362990e-01  4.357305e-01
## RUV_ADD           RUV_ADD  1.000000e-03  1.000000e-03
## BETA_CL_WT     BETA_CL_WT  7.500000e-01  7.500000e-01
## BETA_V_WT       BETA_V_WT  1.000000e+00  1.000000e+00
## PPV_CL             PPV_CL  1.492543e-04  1.000000e-06
## ETA_CL_ETA_V ETA_CL_ETA_V -8.871317e-05 -9.332205e-07
## PPV_V               PPV_V  1.814412e-04  1.874575e-06

Extract the information regarding the precision intervals

print(getPopulationParameters(bootstrapResults, what="intervals")$Bootstrap)
##      Parameter          Mean        Median        Perc_5       Perc_95
## 1   BETA_CL_WT  7.500000e-01  7.500000e-01  7.500000e-01  7.500000e-01
## 2    BETA_V_WT  1.000000e+00  1.000000e+00  1.000000e+00  1.000000e+00
## 3 ETA_CL_ETA_V -8.871317e-05 -9.332205e-07 -8.157958e-04 -1.813408e-07
## 4       POP_CL  1.143097e-01  1.140505e-01  1.120305e-01  1.174091e-01
## 5        POP_V  9.237873e+00  9.217350e+00  8.846467e+00  9.700633e+00
## 6       PPV_CL  1.492543e-04  1.000000e-06  1.000000e-06  1.889993e-03
## 7        PPV_V  1.814412e-04  1.874575e-06  1.034208e-06  2.034626e-03
## 8      RUV_ADD  1.000000e-03  1.000000e-03  1.000000e-03  1.000000e-03
## 9     RUV_PROP  4.362990e-01  4.357305e-01  4.310310e-01  4.416032e-01

VPC of model

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. This will not be needed in future releases. The SO object returned from NONMEM has parameter ETA_CL_ETA_V. This needs to be renamed to conform to model Correlation name OMEGA

variabilityNames <- names(myParObj@VARIABILITY)
names(variabilityPar)[names(variabilityPar)=="ETA_CL_ETA_V"] <- grep("OMEGA",variabilityNames,value=T)
names(variabilityPar)
## [1] "PPV_CL" "OMEGA"  "PPV_V"

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.114411"
## 
## $POP_CL$lo
## [1] "0.001"
## 
## 
## $POP_V
## $POP_V$value
## [1] "9.23932"
## 
## $POP_V$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.438371"
## 
## $RUV_PROP$lo
## [1] "0"
## 
## 
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.001"
## 
## $RUV_ADD$lo
## [1] "0"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.00114987"
## 
## $PPV_CL$type
## [1] "sd"
## 
## 
## $PPV_V
## $PPV_V$value
## [1] "0.00165519"
## 
## $PPV_V$type
## [1] "sd"
## 
## 
## $OMEGA
## $OMEGA$parameter
## [1] "[ETA_CL,ETA_V]"
## 
## $OMEGA$value
## [1] "-0.796885"
## 
## $OMEGA$type
## [1] "corr"

Add square brackets around the correlation parameter

myParObjUpdated@VARIABILITY$OMEGA$value<-paste0("[",myParObjUpdated@VARIABILITY$OMEGA$value,"]")

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 03:02:10 2015
## New
## Submitted
## Job 3614ced1-b7a1-4778-b727-6f45375d7755 progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID 3614ced1-b7a1-4778-b727-6f45375d7755...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd05bdb73dc to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase9/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 03:03:56 2015

plot of chunk VPC

To replay the visualisation using information from the VPC SO file

pdf(paste0(uc,"_VPC.pdf"))
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

Simulation using simulx

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     RUV_PROP      RUV_ADD       PPV_CL 
##   0.11441100   9.23932000   0.43837100   0.00100000   0.00114987 
## ETA_CL_ETA_V        PPV_V   BETA_CL_WT    BETA_V_WT       logtWT 
##  -0.79688500   0.00165519   0.75000000   1.00000000   0.00000000

Simulate for a dose of 100mg given at time 0 into the GUT (oral administration)

adm <- list(target='CENTRAL', time = 0, rate = 100, amount=100)

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=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        CL        V
## 1   1 0.1144521 9.244093
## 2   2 0.1146185 9.263447
## 3   3 0.1146517 9.267313
## 4   4 0.1147414 9.277757
## 5   5 0.1145910 9.260249
## 6   6 0.1145082 9.250624
## 7   7 0.1143555 9.232874
## 8   8 0.1144836 9.247757
## 9   9 0.1142906 9.225330
## 10 10 0.1143898 9.236852
## 11 11 0.1146983 9.272731
## 12 12 0.1144878 9.248246

Plot simulated results 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. Plot of observed concentrations

print(prctilemlx(res.1000$Y,band=list(number=9, level=90)))

plot of chunk unnamed-chunk-51

Table of the same information

print(prctilemlx(res.1000$Y,band=list(number=10, level=100), plot=F)$y)
##    time           0%         10%          20%          30%           40%
## 1   0.0 -0.003475322 -0.00140272 -0.001009373 -0.000573565 -0.0002504379
## 2   0.5  0.096268487  3.34137366  3.893391047  4.337212868  5.1888260324
## 3   1.0  0.173614588  4.53768845  7.092807128  8.223815142  9.3895676306
## 4   2.0 -1.425075143  4.40669548  6.862796746  7.823662407  8.9942327678
## 5   3.0 -1.840641296  3.45647485  6.883475899  8.758909897  9.3918331732
## 6   4.0 -1.665729979  4.38448816  6.041281219  6.978990726  8.5061843544
## 7   6.0  0.294584359  4.90714600  6.780577053  8.153865498  9.4201184106
## 8   8.0 -0.398843853  3.30442347  5.993943248  7.587654795  9.1315655742
## 9  12.0  0.502939273  4.11985651  5.885634700  7.233277062  8.5649017689
## 10 24.0 -0.317790954  3.49586703  5.105417637  5.857554788  6.8835703192
## 11 36.0 -0.241293078  2.47620872  4.126182039  5.386224110  6.0411012136
## 12 48.0 -0.423939052  1.79391342  3.793816731  4.620271261  5.4779920097
##              50%           50%          60%          70%          80%
## 1  -4.157337e-05 -4.157337e-05 1.713958e-04 3.164907e-04 6.437083e-04
## 2   6.034638e+00  6.034638e+00 6.449546e+00 7.040558e+00 7.872260e+00
## 3   1.048708e+01  1.048708e+01 1.118259e+01 1.210803e+01 1.334385e+01
## 4   9.883903e+00  9.883903e+00 1.136855e+01 1.240795e+01 1.415991e+01
## 5   1.022168e+01  1.022168e+01 1.155648e+01 1.282643e+01 1.474859e+01
## 6   9.609336e+00  9.609336e+00 1.076202e+01 1.179212e+01 1.287589e+01
## 7   1.013302e+01  1.013302e+01 1.092672e+01 1.201941e+01 1.384621e+01
## 8   9.717013e+00  9.717013e+00 1.100863e+01 1.223341e+01 1.371074e+01
## 9   1.009828e+01  1.009828e+01 1.069881e+01 1.190402e+01 1.348176e+01
## 10  7.709129e+00  7.709129e+00 9.250791e+00 1.034446e+01 1.160817e+01
## 11  6.543467e+00  6.543467e+00 7.388440e+00 8.377874e+00 9.224383e+00
## 12  5.976580e+00  5.976580e+00 6.658778e+00 7.432007e+00 8.287960e+00
##             90%         100%
## 1   0.001263459  0.002332127
## 2   8.870915957 10.635206983
## 3  14.931668679 20.806686626
## 4  16.555442650 22.218062955
## 5  16.217116825 23.855110007
## 6  14.234099739 20.842829357
## 7  16.154740292 20.372397850
## 8  16.134300140 19.869463709
## 9  15.560553012 20.435009913
## 10 12.890833499 17.999046412
## 11 10.393004774 17.228258199
## 12  9.399478973 13.439704493