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

UseCase10 : Use of PK macros to define warfarin population pharmacokinetics

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

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<-"UseCase10"
datafile <- "warfarin_conc_cmt.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] "UseCase10.mdl"         "warfarin_conc_cmt.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_2Compartments_dat" "warfarin_PK_2Compartments_par"
## [3] "warfarin_PK_2Compartments_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 CMT DVID  DV MDV      logtWT
## 1  1  0.0 66.7 100   1    0  NA   1 -0.04829029
## 2  1  0.5 66.7  NA  NA    1 0.0   0 -0.04829029
## 3  1  1.0 66.7  NA  NA    1 1.9   0 -0.04829029
## 4  1  2.0 66.7  NA  NA    1 3.3   0 -0.04829029
## 5  1  3.0 66.7  NA  NA    1 6.6   0 -0.04829029
## 6  1  6.0 66.7  NA  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)

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()
## png 
##   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")
## -- Tue Aug 16 16:01:14 2016
## New
## Submitted
## Job e03f111d-2755-49a9-837b-34c094249f5b progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID e03f111d-2755-49a9-837b-34c094249f5b...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35645a8346e1 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase10/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 16:02:57 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/UseCase10.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
parameters_mlx
##         POP_KA         POP_CL POP_BETA_CL_WT         POP_VP          POP_Q 
##        1.23609        0.09572        0.75000       28.09046        0.03870 
##       POP_TLAG         POP_VC  POP_BETA_V_WT         PPV_KA         PPV_CL 
##        0.89830        7.79291        1.00000        0.76028        0.15932 
##         PPV_VP          PPV_Q       PPV_TLAG         PPV_VC     CORR_CL_VC 
##        1.41437        0.81509        0.10000        0.12994        0.41208 
##        RUV_ADD       RUV_PROP 
##        0.00001        0.11053
getPopulationParameters(mlx, what="precisions")
## $MLE
##         Parameter      MLE       SE   RSE
## 1      CORR_CL_VC  0.41208  0.36065 87.52
## 2  POP_BETA_CL_WT  0.75000  0.00000  0.00
## 3   POP_BETA_V_WT  1.00000  0.00000  0.00
## 4          POP_CL  0.09572  0.01038 10.85
## 5          POP_KA  1.23609  0.33337 26.97
## 6           POP_Q  0.03870  0.01320 34.12
## 7        POP_TLAG  0.89830  0.04905  5.46
## 8          POP_VC  7.79291  0.22577  2.90
## 9          POP_VP 28.09046 19.19084 68.32
## 10         PPV_CL  0.15932  0.07948 49.88
## 11         PPV_KA  0.76028  0.20846 27.42
## 12          PPV_Q  0.81509  0.19837 24.34
## 13       PPV_TLAG  0.10000  0.00000  0.00
## 14         PPV_VC  0.12994  0.02408 18.54
## 15         PPV_VP  1.41437  0.47967 33.91
## 16        RUV_ADD  0.00001  0.00000 35.36
## 17       RUV_PROP  0.11053  0.00618  5.60
getEstimationInfo(mlx)
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -288.735
## 
## 
## $OFMeasures$IndividualContribToLL
##    Subject ICtoLL
## 1        1 -17.02
## 2        2  -5.01
## 3        3  -3.64
## 4        4 -11.61
## 5        5 -12.11
## 6        6  -7.72
## 7        7 -15.08
## 8        8 -18.74
## 9        9 -17.93
## 10      10  -5.80
## 11      12 -17.10
## 12      13 -23.00
## 13      14 -18.22
## 14      15  -3.32
## 15      16 -15.19
## 16      17  -5.44
## 17      18  -4.90
## 18      19  -9.28
## 19      20  -4.85
## 20      21  -6.04
## 21      22  -4.71
## 22      23  -7.81
## 23      24  -4.50
## 24      25  -7.75
## 25      26  -6.87
## 26      27  -5.03
## 27      28  -6.22
## 28      29  -5.36
## 29      30  -4.45
## 30      31  -4.64
## 31      32  -4.31
## 32      33  -5.08
## 
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 605.47
## 
## $OFMeasures$InformationCriteria$BIC
## [1] 625.99
## 
## 
## 
## $Messages
## list()

Perform model diagnostics for the base model using Xpose functions (graphs are exported to PDF)

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)

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

SAEM Estimation with NONMEM

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 16:02:59 2016
## New
## Submitted
## Job 654a24dc-8feb-4b5e-85f1-6fc7effd8063 progress:
## Running [ ......... ]
## Importing Results
## Copying the result data back to the local machine for job ID 654a24dc-8feb-4b5e-85f1-6fc7effd8063...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356452fe2c7b to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase10/NONMEM
## Done.
## 
## 
## The following main elements were parsed successfully:
##   RawResults
##   Estimation::PopulationEstimates::MLE
##   Estimation::OFMeasures::Deviance
## 
## The following ERRORs were raised during the job execution:
##  tables_step_error: 0PROGRAM TERMINATED BY FNLETA
##  ERROR IN CELS   WITH INDIVIDUAL       1   ID= 1.00000000000000E+00
##  SUM OF "SQUARED" WEIGHTED INDIVIDUAL RESIDUALS IS INFINITE
##  MESSAGE ISSUED FROM TABLE STEP
## 
## The following WARNINGs were raised during the job execution:
##  File error: Could not find table .\sdtab. Results from this table could not be added.
##  File error: Could not find table .\patab. Results from this table could not be added.
## 
## 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
## 
## Failed
## -- Tue Aug 16 16:06:01 2016

The ddmore “LoadSOObj” reads and parsed existing Standardise Output Objects

NM <- LoadSOObject(“NONMEM/UseCase10.SO.xml”)

parameters_nm <- getPopulationParameters(NM, what="estimates")$MLE
print(parameters_nm)
##         POP_CL         POP_VC          POP_Q         POP_VP         POP_KA 
##      0.1293350      6.7180400      0.0563586      3.3251500      1.2558300 
##       POP_TLAG       RUV_PROP        RUV_ADD POP_BETA_CL_WT  POP_BETA_V_WT 
##      0.9589270      0.0856707      0.0000000      0.7500000      1.0000000 
##         PPV_CL     CORR_CL_VC         PPV_VC          PPV_Q         PPV_VP 
##      0.5961200     -0.8567570      0.4322400      1.5076900      1.7689800 
##         PPV_KA       PPV_TLAG 
##      0.9499070      0.1000000
print(parameters_mlx)
##         POP_KA         POP_CL POP_BETA_CL_WT         POP_VP          POP_Q 
##        1.23609        0.09572        0.75000       28.09046        0.03870 
##       POP_TLAG         POP_VC  POP_BETA_V_WT         PPV_KA         PPV_CL 
##        0.89830        7.79291        1.00000        0.76028        0.15932 
##         PPV_VP          PPV_Q       PPV_TLAG         PPV_VC     CORR_CL_VC 
##        1.41437        0.81509        0.10000        0.12994        0.41208 
##        RUV_ADD       RUV_PROP 
##        0.00001        0.11053
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -201.0243
## 
## 
## 
## $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"
## 
## 
## $Messages$Errors
## $Messages$Errors$tables_step_error
## [1] "0PROGRAM TERMINATED BY FNLETA\n ERROR IN CELS   WITH INDIVIDUAL       1   ID= 1.00000000000000E+00\n SUM OF \"SQUARED\" WEIGHTED INDIVIDUAL RESIDUALS IS INFINITE\n MESSAGE ISSUED FROM TABLE STEP\n"
## 
## 
## $Messages$Warnings
## $Messages$Warnings$`File error`
## [1] "Could not find table .\\patab. Results from this table could not be added."

Xpose diagnostics using NONMEM output

nm.xpdb<-as.xpdb(NM,datafile)
## Warning in extractIdandIdvNames(SOObject, PredictionsSlotName,
## ResidualsSlotName): No DATA_INPUT_VARIABLES have a 'use' parameter defined
## as 'id' in the StandardOutputObject cannot determine correct column name
## for ID from StandardOutputObject.
## Warning in extractIdandIdvNames(SOObject, PredictionsSlotName,
## ResidualsSlotName): No DATA_INPUT_VARIABLES have a 'use' parameter defined
## as 'idv' in the StandardOutputObject cannot determine correct column name
## for TIME from StandardOutputObject.
## Warning in as.data(SOObject, inputDataPath): ID.colName was character(0),
## setting to 'ID' in as.data
## Warning in as.data(SOObject, inputDataPath): TIME.colName was
## character(0), setting to 'TIME' in as.data
## Warning in as.data(SOObject, inputDataPath): No Estimation::Predictions
## found in the SO; the resulting data frame will not contain these
## Warning in as.data(SOObject, inputDataPath): No Estimation::Residuals
## found in the SO; the resulting data frame will not contain these
## Warning in as.data(SOObject, inputDataPath): No
## Estimation::IndividualEstimates::Estimates::Mean found in the SO; the
## resulting data frame will not contain these
## Warning in as.data(SOObject, inputDataPath): No
## Estimation::IndividualEstimates::RandomEffects::EffectMean found in the
## SO; the resulting data frame will not contain these
## Warning in extractIdandIdvNames(SOObject, PredictionsSlotName,
## ResidualsSlotName): No DATA_INPUT_VARIABLES have a 'use' parameter defined
## as 'id' in the StandardOutputObject cannot determine correct column name
## for ID from StandardOutputObject.
## Warning in extractIdandIdvNames(SOObject, PredictionsSlotName,
## ResidualsSlotName): No DATA_INPUT_VARIABLES have a 'use' parameter defined
## as 'idv' in the StandardOutputObject cannot determine correct column name
## for TIME from StandardOutputObject.

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

print(basic.gof(nm.xpdb))
## Error in print(basic.gof(nm.xpdb)): error in evaluating the argument 'x' in selecting a method for function 'print': Error in `[.data.frame`(data, , xvardef("wres", object)) : 
##   undefined columns selected
print(ind.plots(nm.xpdb))
## Error in print(ind.plots(nm.xpdb)): error in evaluating the argument 'x' in selecting a method for function 'print': Error in `[.data.frame`(data, , xvardef("wres", object)) : 
##   undefined columns selected
print(parm.hist(nm.xpdb))
## Error in plotList[[i]]: subscript out of bounds

Export graphs to a PDF file

pdf("GOF_NM.pdf")
 print(basic.gof(nm.xpdb))
## Error in print(basic.gof(nm.xpdb)): error in evaluating the argument 'x' in selecting a method for function 'print': Error in `[.data.frame`(data, , xvardef("wres", object)) : 
##   undefined columns selected
 print(ind.plots(nm.xpdb))
## Error in print(ind.plots(nm.xpdb)): error in evaluating the argument 'x' in selecting a method for function 'print': Error in `[.data.frame`(data, , xvardef("wres", object)) : 
##   undefined columns selected
 print(parm.hist(nm.xpdb))
## Error in plotList[[i]]: subscript out of bounds
dev.off()
## png 
##   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.

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 16:06:08 2016
## New
## Submitted
## Job 26779e15-9812-441f-91a4-8211081f561a progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID 26779e15-9812-441f-91a4-8211081f561a...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job3564201b7dfb to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase10/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:
##  zero_gradients: 4
##  estimate_near_boundary: 1
## 
## The following MESSAGEs were raised during the job execution:
##  estimation_successful: 1
##  covariance_step_run: 0
##  rounding_errors: 0
##  hessian_reset: 0
##  final_zero_gradients: 0
##  s_matrix_singular: 0
##  significant_digits: 3.3
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 16:07:11 2016

Load previous results

NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase10_FOCEI.SO.xml”)

Results from NONMEM should be comparable to previous results

print(getPopulationParameters(NM.FOCEI,  what="estimates"))
## $MLE
##         POP_CL         POP_VC          POP_Q         POP_VP         POP_KA 
##     0.12112300     8.07758000     0.01032180    24.54910000     1.38255000 
##       POP_TLAG       RUV_PROP        RUV_ADD POP_BETA_CL_WT  POP_BETA_V_WT 
##     0.94063400     0.10711000     0.00100000     0.75000000     1.00000000 
##         PPV_CL     CORR_CL_VC         PPV_VC          PPV_Q         PPV_VP 
##     0.25590500     0.34917800     0.14139100     1.49470000     0.00511166 
##         PPV_KA       PPV_TLAG 
##     0.80050300     0.10000000
print(parameters_nm)
##         POP_CL         POP_VC          POP_Q         POP_VP         POP_KA 
##      0.1293350      6.7180400      0.0563586      3.3251500      1.2558300 
##       POP_TLAG       RUV_PROP        RUV_ADD POP_BETA_CL_WT  POP_BETA_V_WT 
##      0.9589270      0.0856707      0.0000000      0.7500000      1.0000000 
##         PPV_CL     CORR_CL_VC         PPV_VC          PPV_Q         PPV_VP 
##      0.5961200     -0.8567570      0.4322400      1.5076900      1.7689800 
##         PPV_KA       PPV_TLAG 
##      0.9499070      0.1000000
print(parameters_mlx)
##         POP_KA         POP_CL POP_BETA_CL_WT         POP_VP          POP_Q 
##        1.23609        0.09572        0.75000       28.09046        0.03870 
##       POP_TLAG         POP_VC  POP_BETA_V_WT         PPV_KA         PPV_CL 
##        0.89830        7.79291        1.00000        0.76028        0.15932 
##         PPV_VP          PPV_Q       PPV_TLAG         PPV_VC     CORR_CL_VC 
##        1.41437        0.81509        0.10000        0.12994        0.41208 
##        RUV_ADD       RUV_PROP 
##        0.00001        0.11053

Xpose diagnostics using NONMEM output

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

plot of chunk unnamed-chunk-28

Export graphs to a PDF file

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

Run the bootstrap using PsN (takes several hours)

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 16:07:13 2016
## New
## Submitted
## Job 248dfcb7-f6b7-4201-b11f-322bc79d4691 progress:
## Running [ ......... ]
## Importing Results
## Copying the result data back to the local machine for job ID 248dfcb7-f6b7-4201-b11f-322bc79d4691...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35645e361dad to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase10/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:
##  zero_gradients: 4
##  estimate_near_boundary: 1
##  bootstrap_parameter_scale: The parameters PPV_CL, CORR_CL_VC, PPV_VC, PPV_Q, PPV_VP, 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
##  final_zero_gradients: 0
##  s_matrix_singular: 0
##  significant_digits: 3.3
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 16:10:16 2016
## 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/UseCase10_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_VC          POP_Q         POP_VP         POP_KA 
##     0.12112300     8.07758000     0.01032180    24.54910000     1.38255000 
##       POP_TLAG       RUV_PROP        RUV_ADD POP_BETA_CL_WT  POP_BETA_V_WT 
##     0.94063400     0.10711000     0.00100000     0.75000000     1.00000000 
##         PPV_CL     CORR_CL_VC         PPV_VC          PPV_Q         PPV_VP 
##     0.25590500     0.34917800     0.14139100     1.49470000     0.00511166 
##         PPV_KA       PPV_TLAG 
##     0.80050300     0.10000000 
## 
## $Bootstrap
##                     Parameter         Mean      Median
## CORR_CL_VC         CORR_CL_VC 9.410270e-03  0.00497653
## POP_BETA_CL_WT POP_BETA_CL_WT 7.500000e-01  0.75000000
## POP_BETA_V_WT   POP_BETA_V_WT 1.000000e+00  1.00000000
## POP_CL                 POP_CL 9.607122e-02  0.10488650
## POP_KA                 POP_KA 1.237835e+00  1.21059000
## POP_Q                   POP_Q 3.820730e-02  0.02936630
## POP_TLAG             POP_TLAG 8.780453e-01  0.91388750
## POP_VC                 POP_VC 7.892894e+00  7.84509000
## POP_VP                 POP_VP 1.144670e+16 40.12515000
## PPV_CL                 PPV_CL 1.347774e-01  0.07832740
## PPV_KA                 PPV_KA 5.433737e-01  0.52635050
## PPV_Q                   PPV_Q 9.647559e-01  0.43852700
## PPV_TLAG             PPV_TLAG 1.000000e-02  0.01000000
## PPV_VC                 PPV_VC 1.470098e-02  0.01566875
## PPV_VP                 PPV_VP 3.207283e+01  0.01053889
## RUV_ADD               RUV_ADD 3.287678e-02  0.00100000
## RUV_PROP             RUV_PROP 1.091915e-01  0.11379650

Extract the information regarding the precision intervals

print(getPopulationParameters(bootstrapResults, what="intervals")$Bootstrap)
##         Parameter         Mean      Median        Perc_5      Perc_95
## 1      CORR_CL_VC 9.410270e-03  0.00497653 -8.163976e-03 5.025048e-02
## 2  POP_BETA_CL_WT 7.500000e-01  0.75000000  7.500000e-01 7.500000e-01
## 3   POP_BETA_V_WT 1.000000e+00  1.00000000  1.000000e+00 1.000000e+00
## 4          POP_CL 9.607122e-02  0.10488650  3.116189e-02 1.331998e-01
## 5          POP_KA 1.237835e+00  1.21059000  7.633182e-01 2.019202e+00
## 6           POP_Q 3.820730e-02  0.02936630  3.093585e-03 1.082618e-01
## 7        POP_TLAG 8.780453e-01  0.91388750  4.972401e-01 1.001679e+00
## 8          POP_VC 7.892894e+00  7.84509000  7.342630e+00 8.537349e+00
## 9          POP_VP 1.144670e+16 40.12515000  2.824600e-01 2.174873e+17
## 10         PPV_CL 1.347774e-01  0.07832740  2.657045e-06 5.279152e-01
## 11         PPV_KA 5.433737e-01  0.52635050  1.969732e-01 1.358914e+00
## 12          PPV_Q 9.647559e-01  0.43852700  1.000000e-06 3.750616e+00
## 13       PPV_TLAG 1.000000e-02  0.01000000  1.000000e-02 1.000000e-02
## 14         PPV_VC 1.470098e-02  0.01566875  2.183297e-03 2.700240e-02
## 15         PPV_VP 3.207283e+01  0.01053889  1.000000e-06 5.857048e+02
## 16        RUV_ADD 3.287678e-02  0.00100000  1.000000e-03 2.647267e-01
## 17       RUV_PROP 1.091915e-01  0.11379650  4.054552e-02 1.488408e-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] "RUV_PROP"   "RUV_ADD"    "PPV_CL"     "CORR_CL_VC" "PPV_VC"    
## [6] "PPV_Q"      "PPV_VP"     "PPV_KA"     "PPV_TLAG"

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.121123"
## 
## $POP_CL$lo
## [1] "0.001"
## 
## 
## $POP_VC
## $POP_VC$value
## [1] "8.07758"
## 
## $POP_VC$lo
## [1] "0.001"
## 
## 
## $POP_Q
## $POP_Q$value
## [1] "0.0103218"
## 
## $POP_Q$lo
## [1] "0.001"
## 
## 
## $POP_VP
## $POP_VP$value
## [1] "24.5491"
## 
## $POP_VP$lo
## [1] "0.001"
## 
## 
## $POP_KA
## $POP_KA$value
## [1] "1.38255"
## 
## $POP_KA$lo
## [1] "0.001"
## 
## 
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.940634"
## 
## $POP_TLAG$lo
## [1] "0.001"
## 
## 
## $POP_BETA_CL_WT
## $POP_BETA_CL_WT$value
## [1] "0.75"
## 
## $POP_BETA_CL_WT$fix
## [1] "true"
## 
## 
## $POP_BETA_V_WT
## $POP_BETA_V_WT$value
## [1] "1"
## 
## $POP_BETA_V_WT$fix
## [1] "true"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.255905"
## 
## 
## $PPV_VC
## $PPV_VC$value
## [1] "0.141391"
## 
## 
## $CORR_CL_VC
## $CORR_CL_VC$value
## [1] "0.349178"
## 
## 
## $PPV_Q
## $PPV_Q$value
## [1] "1.4947"
## 
## 
## $PPV_VP
## $PPV_VP$value
## [1] "0.00511166"
## 
## 
## $PPV_KA
## $PPV_KA$value
## [1] "0.800503"
## 
## 
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
## 
## $PPV_TLAG$fix
## [1] "true"
## 
## 
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.10711"
## 
## $RUV_PROP$lo
## [1] "0"
## 
## 
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.001"
## 
## $RUV_ADD$lo
## [1] "0"

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 16:10:29 2016
## New
## Submitted
## Job ccae6a94-c36f-4264-a5b4-d1492760ed20 progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID ccae6a94-c36f-4264-a5b4-d1492760ed20...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356468e242e8 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase10/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 16:11:31 2016

plot of chunk VPC

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

Simulation using simulx

Simulation with simulx is not yet possible for UseCase10.

# #' 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_VC          POP_Q         POP_VP         POP_KA 
##     0.12112300     8.07758000     0.01032180    24.54910000     1.38255000 
##       POP_TLAG       RUV_PROP        RUV_ADD POP_BETA_CL_WT  POP_BETA_V_WT 
##     0.94063400     0.10711000     0.00100000     0.75000000     1.00000000 
##         PPV_CL     CORR_CL_VC         PPV_VC          PPV_Q         PPV_VP 
##     0.25590500     0.34917800     0.14139100     1.49470000     0.00511166 
##         PPV_KA       PPV_TLAG         logtWT 
##     0.80050300     0.10000000     0.00000000

Simulate PK parameters for individuals

ind <- list(name = c('TLAG','KA','CL','VC','VP','Q'))

Simulate predicted (CC) and observed concentration values (Y)

f   <- list( name = c('CC'), time = seq(0,to=50,by=1))
y   <- list( name = c('CC_obs'), 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(type=1, 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,f))

Simulated parameter values for each individual

print(res$parameter)
##    id      TLAG         KA         CL       VC       VP           Q
## 1   1 0.9016189  1.6072336 0.13430512 8.136951 24.60867 0.002828005
## 2   2 0.8058047  0.9143504 0.11219353 9.545580 24.60930 0.097482796
## 3   3 0.9526836 18.1600732 0.10376093 8.443931 24.71595 0.018922277
## 4   4 0.9970035  0.5844871 0.10388931 9.364364 24.64213 0.008437209
## 5   5 1.0602636  0.2979917 0.09731895 6.986129 24.37484 0.019489188
## 6   6 1.1291741  1.4305207 0.11071167 8.313857 24.53048 0.015739331
## 7   7 1.1753549  0.2626183 0.07054008 7.691332 24.58076 0.004080262
## 8   8 1.2054030  1.9560224 0.10072847 8.023167 24.54825 0.050897248
## 9   9 0.8358975  1.0326128 0.12680793 7.086816 24.53437 0.001238083
## 10 10 0.8892143  2.2252366 0.12211279 9.825464 24.51852 0.015233286
## 11 11 0.9186413  0.9542631 0.17192062 8.754228 24.66865 0.014476404
## 12 12 0.9737231  0.5587889 0.13903048 7.508329 24.54425 0.008240265

Plot simulated results

plot(ggplot() + 
                geom_line(data=res$CC, aes(x=time, y=CC, colour=id)) +
                geom_point(data=res$CC_obs, aes(x=time, y=CC_obs, colour=id)) +
                xlab("time (h)") + ylab("concentration") )

plot of chunk unnamed-chunk-49

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$CC_obs,band=list(number=9, level=90)))

plot of chunk unnamed-chunk-51

Table of the same information

print(prctilemlx(res.1000$CC_obs,band=list(number=10, level=100), plot=F)$y)
##    time           0%           10%           20%           30%
## 1   0.0 -0.002112602 -0.0012320898 -0.0008767652 -0.0006393598
## 2   0.5 -0.002269515 -0.0010890560 -0.0006230918 -0.0002916925
## 3   1.0 -0.001983997 -0.0001390881  0.0008439022  0.0602498476
## 4   2.0  2.206350791  3.6593473117  6.0426479927  7.1683796873
## 5   3.0  4.489340622  6.0644874720  8.3960964878  9.2493272955
## 6   4.0  5.523740892  7.6854514448  9.1264545440 10.3818795898
## 7   6.0  6.728046685  8.5253146723  9.4348361038 10.0474998231
## 8   8.0  6.070490918  8.3926705924  8.9256625471  9.4896463976
## 9  12.0  5.649764621  8.2775030885  8.9450554001  9.5041710667
## 10 24.0  2.862401078  6.2575260346  6.8243407497  7.3477798617
## 11 36.0  1.835894264  5.1261391053  5.7471487440  6.0658086767
## 12 48.0  1.998084610  3.9870754921  4.5333078746  4.8548165659
##              40%           50%           50%          60%          70%
## 1  -2.698316e-04 -0.0001315084 -0.0001315084 7.941063e-05 3.073447e-04
## 2  -3.287498e-06  0.0001533013  0.0001533013 2.915074e-04 5.587450e-04
## 3   3.777685e-01  0.6905284279  0.6905284279 1.138052e+00 1.380729e+00
## 4   8.096263e+00  9.1575405145  9.1575405145 9.381851e+00 9.981762e+00
## 5   9.727192e+00 10.8188983252 10.8188983252 1.149254e+01 1.190112e+01
## 6   1.074571e+01 11.3228886217 11.3228886217 1.172744e+01 1.221358e+01
## 7   1.043067e+01 10.8366420582 10.8366420582 1.144776e+01 1.224763e+01
## 8   1.030626e+01 10.5918186993 10.5918186993 1.108286e+01 1.152372e+01
## 9   9.856231e+00 10.2619532110 10.2619532110 1.078225e+01 1.141104e+01
## 10  7.759085e+00  8.2211020221  8.2211020221 8.670366e+00 9.052800e+00
## 11  6.344141e+00  6.6838548253  6.6838548253 6.940112e+00 7.407216e+00
## 12  5.242108e+00  5.5632400736  5.5632400736 5.821510e+00 6.196411e+00
##             80%          90%         100%
## 1  5.805933e-04  0.001247095  0.002717010
## 2  9.130513e-04  0.001250981  0.002479131
## 3  2.163432e+00  2.840890264  8.158411653
## 4  1.149452e+01 12.732811912 16.847428873
## 5  1.245717e+01 13.512822509 18.153700996
## 6  1.315873e+01 13.480012825 19.258509497
## 7  1.312723e+01 14.026599190 17.419352935
## 8  1.220904e+01 13.448071154 17.037369618
## 9  1.206229e+01 12.585651183 14.907311156
## 10 9.675012e+00 10.441494926 13.538352063
## 11 8.194985e+00  9.036236639 11.229832569
## 12 6.561852e+00  7.065723551  8.645385557