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

UseCase17 : Steady-state model

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=FALSE))
mydir <- file.path(Sys.getenv("MDLIDE_WORKSPACE_HOME"),"UseCasesDemo")
setwd(mydir)

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

uc<-"UseCase17"
datafile <- "warfarin_conc_SS.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] "UseCase17.mdl"        "warfarin_conc_SS.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_SS_dat"   "warfarin_PK_par"      "warfarin_PK_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]]

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 AGE  SEX AMT SS II DVID     DV MDV      logtWT
## 1  1  0.0 66.7  50 male   5  1 24    0 0.0000   1 -0.04829029
## 2  1  0.5 66.7  50 male   0  0  0    1 1.6404   0 -0.04829029
## 3  1  1.0 66.7  50 male   0  0  0    1 2.0318   0 -0.04829029
## 4  1  2.0 66.7  50 male   0  0  0    1 1.7198   0 -0.04829029
## 5  1  3.0 66.7  50 male   0  0  0    1 2.4068   0 -0.04829029
## 6  1  6.0 66.7  50 male   0  0  0    1 2.4318   0 -0.04829029

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

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-16 plot of chunk unnamed-chunk-16 plot of chunk unnamed-chunk-16

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")
## -- Wed Aug 17 15:24:35 2016
## New
## Submitted
## Job 2b93da20-fa63-4c6f-aebe-91c541746e3e progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 2b93da20-fa63-4c6f-aebe-91c541746e3e...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpojERtE\DDMORE.job4acc5114186 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase17/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
## -- Wed Aug 17 15:26:01 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/UseCase17.SO.xml”)

The ddmore function “getPopulationParameters” extracts the Population Parameter values from an R object of (S4) class “StandardOutputObject” and returns the estimates. See documentation for getPopulationParameters to see other arguments and settings for this function.

parameters_mlx <- getPopulationParameters(mlx, what="estimates")$MLE
print(parameters_mlx)
##      POP_V  BETA_V_WT     POP_KA     POP_CL BETA_CL_WT   POP_TLAG 
##    4.63696    1.00000    0.27348    0.09028    0.75000    1.02063 
##      PPV_V     PPV_KA     PPV_CL   PPV_TLAG  CORR_CL_V    RUV_ADD 
##    0.07960    0.48234    0.10469    0.10000   -0.29456    0.07869 
##   RUV_PROP 
##    0.08206
print(getPopulationParameters(mlx, what="precisions"))
## $MLE
##     Parameter      MLE      SE    RSE
## 1  BETA_CL_WT  0.75000 0.00000   0.00
## 2   BETA_V_WT  1.00000 0.00000   0.00
## 3   CORR_CL_V -0.29456 0.75578 256.58
## 4      POP_CL  0.09028 0.00241   2.67
## 5      POP_KA  0.27348 0.08134  29.74
## 6    POP_TLAG  1.02063 0.29506  28.91
## 7       POP_V  4.63696 0.37865   8.17
## 8      PPV_CL  0.10469 0.01788  17.08
## 9      PPV_KA  0.48234 0.26642  55.23
## 10   PPV_TLAG  0.10000 0.00000   0.00
## 11      PPV_V  0.07960 0.16907 212.41
## 12    RUV_ADD  0.07869 0.08534 108.46
## 13   RUV_PROP  0.08206 0.04416  53.82
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -29.23
## 
## 
## $OFMeasures$IndividualContribToLL
##    Subject ICtoLL
## 1        1   0.22
## 2        2  -3.54
## 3        3  -0.57
## 4        4  -0.50
## 5        5  -1.26
## 6        6   0.73
## 7        7  -3.17
## 8        8  -2.40
## 9        9  -7.35
## 10      10  -0.17
## 11      12   0.40
## 12      13   0.94
## 13      14  -3.27
## 14      15  -4.72
## 15      16   0.85
## 16      17  -2.33
## 17      18  -0.51
## 18      19  -0.35
## 19      20   0.84
## 20      21   1.39
## 21      22  -5.26
## 22      23   0.56
## 23      24   0.18
## 24      25   1.73
## 25      26   0.94
## 26      27   0.05
## 27      28   0.84
## 28      29  -0.07
## 29      30  -3.01
## 30      31   1.33
## 31      32  -2.90
## 32      33   1.14
## 
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 78.46
## 
## $OFMeasures$InformationCriteria$BIC
## [1] 93.12
## 
## 
## 
## $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)

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()
## 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")
## -- Wed Aug 17 15:26:06 2016
## New
## Submitted
## Job 79f0efb4-058f-4d82-8a34-8d08669c6909 progress:
## Running [ ............... ]
## Importing Results
## Copying the result data back to the local machine for job ID 79f0efb4-058f-4d82-8a34-8d08669c6909...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpojERtE\DDMORE.job4acc62d3287 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase17/NONMEM
## Done.
## 
## 
## The following main elements were parsed successfully:
##   RawResults
##   Estimation::PopulationEstimates::MLE
##   Estimation::IndividualEstimates::Estimates
##   Estimation::IndividualEstimates::RandomEffects
##   Estimation::Residuals::ResidualTable
##   Estimation::Predictions
##   Estimation::OFMeasures::Deviance
## 
## The following WARNINGs were raised during the job execution:
##  estimation_successful: 0
## 
## The following MESSAGEs were raised during the job execution:
##  covariance_step_run: 0
##  rounding_errors: 0
##  estimate_near_boundary: 0
##  s_matrix_singular: 0
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Wed Aug 17 15:31:09 2016

Load previous results

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

Results from NONMEM should be comparable with results from MONOLIX

parameters_nm <- getPopulationParameters(NM, what="estimates")
print(parameters_nm)
## $MLE
##     POP_CL      POP_V     POP_KA   POP_TLAG   RUV_PROP    RUV_ADD 
##  0.0976672  7.2068600  1.4571700  1.9550300  0.0000000  0.1011270 
## BETA_CL_WT  BETA_V_WT     PPV_CL  CORR_CL_V      PPV_V     PPV_KA 
##  0.7500000  1.0000000  0.1012920 -0.0193799  0.4599980  1.9930500 
##   PPV_TLAG 
##  0.1000000
print(parameters_mlx)
##      POP_V  BETA_V_WT     POP_KA     POP_CL BETA_CL_WT   POP_TLAG 
##    4.63696    1.00000    0.27348    0.09028    0.75000    1.02063 
##      PPV_V     PPV_KA     PPV_CL   PPV_TLAG  CORR_CL_V    RUV_ADD 
##    0.07960    0.48234    0.10469    0.10000   -0.29456    0.07869 
##   RUV_PROP 
##    0.08206
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -347.9066
## 
## 
## 
## $Messages
## $Messages$Info
## $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$Warnings
## $Messages$Warnings$estimation_successful
## [1] "0"

Xpose diagnostics using NONMEM output

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

plot of chunk unnamed-chunk-22

print(ind.plots(nm.xpdb))

plot of chunk unnamed-chunk-22 plot of chunk unnamed-chunk-22

print(parm.hist(nm.xpdb))

plot of chunk unnamed-chunk-22

Export graphs to a PDF file

pdf("GOF_NM.pdf")
 print(basic.gof(nm.xpdb))
 print(ind.plots(nm.xpdb))
 print(parm.hist(nm.xpdb))
dev.off()
## png 
##   2

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")
## -- Wed Aug 17 15:31:24 2016
## New
## Submitted
## Job 102a9928-587f-4db1-82ee-907a8f66e246 progress:
## Running [ .. ]
## Importing Results
## Copying the result data back to the local machine for job ID 102a9928-587f-4db1-82ee-907a8f66e246...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpojERtE\DDMORE.job4acc2eb38d0 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase17/NONMEM_FOCEI
## Done.
## 
## 
## The following main elements were parsed successfully:
##   RawResults
##   Estimation::PopulationEstimates::MLE
##   Estimation::IndividualEstimates::Estimates
##   Estimation::IndividualEstimates::RandomEffects
##   Estimation::Residuals::ResidualTable
##   Estimation::Predictions
##   Estimation::OFMeasures::Deviance
## 
## The following MESSAGEs were raised during the job execution:
##  estimation_successful: 1
##  covariance_step_run: 0
##  rounding_errors: 0
##  hessian_reset: 0
##  zero_gradients: 0
##  final_zero_gradients: 0
##  estimate_near_boundary: 0
##  s_matrix_singular: 0
##  significant_digits: 3.3
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Wed Aug 17 15:32:06 2016

Load previous results

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

Results from NONMEM should be comparable to previous results

print(getPopulationParameters(NM.FOCEI,  what="estimates"))
## $MLE
##      POP_CL       POP_V      POP_KA    POP_TLAG    RUV_PROP     RUV_ADD 
##  0.09879320  7.15015000  0.27571300  0.68584400  0.06416210  0.10363900 
##  BETA_CL_WT   BETA_V_WT      PPV_CL   CORR_CL_V       PPV_V      PPV_KA 
##  0.75000000  1.00000000  0.08882460 -0.99982200  0.14035300  0.00449273 
##    PPV_TLAG 
##  0.10000000
print(parameters_nm)
## $MLE
##     POP_CL      POP_V     POP_KA   POP_TLAG   RUV_PROP    RUV_ADD 
##  0.0976672  7.2068600  1.4571700  1.9550300  0.0000000  0.1011270 
## BETA_CL_WT  BETA_V_WT     PPV_CL  CORR_CL_V      PPV_V     PPV_KA 
##  0.7500000  1.0000000  0.1012920 -0.0193799  0.4599980  1.9930500 
##   PPV_TLAG 
##  0.1000000

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

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

# Bootstrap
bootstrapResults <- bootstrap.PsN(mdlfile.FOCEI, samples=20, seed=123456,
        bootstrapOptions=" -no-skip_minimization_terminated -threads=2",
        subfolder="Bootstrap", plot=TRUE)
## -- Wed Aug 17 15:32:09 2016
## New
## Submitted
## Job a91c746e-32c4-47c8-9792-916b507d89ef progress:
## Running [ ...... ]
## Importing Results
## Copying the result data back to the local machine for job ID a91c746e-32c4-47c8-9792-916b507d89ef...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpojERtE\DDMORE.job4acc41c36613 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase17/Bootstrap
## Done.
## 
## 
## The following main elements were parsed successfully:
##   RawResults
##   Estimation::PopulationEstimates::MLE
##   Estimation::PopulationEstimates::OtherMethodBootstrap
##   Estimation::PrecisionPopulationEstimates::OtherMethodBootstrap
##   Estimation::IndividualEstimates::Estimates
##   Estimation::IndividualEstimates::RandomEffects
##   Estimation::Residuals::ResidualTable
##   Estimation::Predictions
##   Estimation::OFMeasures::Deviance
## 
## The following WARNINGs were raised during the job execution:
##  bootstrap_parameter_scale: The parameters PPV_CL, CORR_CL_V, PPV_V, PPV_KA and PPV_TLAG were requested on the sd/corr scale but are given on the var/cov scale in all bootstrap results.
## 
## The following MESSAGEs were raised during the job execution:
##  estimation_successful: 1
##  covariance_step_run: 0
##  rounding_errors: 0
##  hessian_reset: 0
##  zero_gradients: 0
##  final_zero_gradients: 0
##  estimate_near_boundary: 0
##  s_matrix_singular: 0
##  significant_digits: 3.3
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Wed Aug 17 15:34:12 2016
## Warning: NAs introduced by coercion
## [[1]]

plot of chunk unnamed-chunk-30

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

plot of chunk unnamed-chunk-30

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

Export bootstrap histograms to a pdf

pdf(paste0(uc,"_Bootstrap.pdf"))
print(boot.hist(results.file = file.path("Bootstrap",paste0("raw_results_",uc,"_FOCEI.csv")),
                incl.ids.file = file.path("Bootstrap","included_individuals1.csv")))
## [[1]]
## 
## [[2]]
## NULL
## 
## [[3]]
## 
## [[4]]
## NULL
## 
## [[5]]
## NULL
dev.off()
## png 
##   2

Extract parameter estimates and precision from bootstrap results.

print(getPopulationParameters(bootstrapResults, what="estimates"))
## $MLE
##      POP_CL       POP_V      POP_KA    POP_TLAG    RUV_PROP     RUV_ADD 
##  0.09879320  7.15015000  0.27571300  0.68584400  0.06416210  0.10363900 
##  BETA_CL_WT   BETA_V_WT      PPV_CL   CORR_CL_V       PPV_V      PPV_KA 
##  0.75000000  1.00000000  0.08882460 -0.99982200  0.14035300  0.00449273 
##    PPV_TLAG 
##  0.10000000 
## 
## $Bootstrap
##             Parameter         Mean       Median
## BETA_CL_WT BETA_CL_WT  0.750000000  0.750000000
## BETA_V_WT   BETA_V_WT  1.000000000  1.000000000
## CORR_CL_V   CORR_CL_V -0.007670445 -0.007627565
## POP_CL         POP_CL  0.098865480  0.098495500
## POP_KA         POP_KA  0.481610200  0.362457000
## POP_TLAG     POP_TLAG  1.009923000  0.837897000
## POP_V           POP_V  7.715473000  7.934850000
## PPV_CL         PPV_CL  0.007128181  0.006968355
## PPV_KA         PPV_KA  0.096032680  0.000001000
## PPV_TLAG     PPV_TLAG  0.010000000  0.010000000
## PPV_V           PPV_V  0.031255990  0.024593900
## RUV_ADD       RUV_ADD  0.127831600  0.143197000
## RUV_PROP     RUV_PROP  0.051458580  0.047279750

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.750000000  0.750000000 0.75000000
## 2   BETA_V_WT  1.000000000  1.000000000  1.000000000 1.00000000
## 3   CORR_CL_V -0.007670445 -0.007627565 -0.024965710 0.01194158
## 4      POP_CL  0.098865480  0.098495500  0.096095770 0.10270070
## 5      POP_KA  0.481610200  0.362457000  0.058137610 1.56234300
## 6    POP_TLAG  1.009923000  0.837897000  0.010990000 2.01794600
## 7       POP_V  7.715473000  7.934850000  2.563191000 9.56454700
## 8      PPV_CL  0.007128181  0.006968355  0.000910871 0.01511646
## 9      PPV_KA  0.096032680  0.000001000  0.000001000 1.18770200
## 10   PPV_TLAG  0.010000000  0.010000000  0.010000000 0.01000000
## 11      PPV_V  0.031255990  0.024593900  0.000822953 0.11472510
## 12    RUV_ADD  0.127831600  0.143197000  0.001000000 0.22394340
## 13   RUV_PROP  0.051458580  0.047279750  0.001000000 0.12333480

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

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.0987932"
## 
## $POP_CL$lo
## [1] "0.001"
## 
## 
## $POP_V
## $POP_V$value
## [1] "7.15015"
## 
## $POP_V$lo
## [1] "0.001"
## 
## 
## $POP_KA
## $POP_KA$value
## [1] "0.275713"
## 
## $POP_KA$lo
## [1] "0.001"
## 
## 
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.685844"
## 
## $POP_TLAG$lo
## [1] "0.001"
## 
## 
## $BETA_CL_WT
## $BETA_CL_WT$value
## [1] "0.75"
## 
## $BETA_CL_WT$fix
## [1] "true"
## 
## 
## $BETA_V_WT
## $BETA_V_WT$value
## [1] "1"
## 
## $BETA_V_WT$fix
## [1] "true"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.0888246"
## 
## 
## $PPV_V
## $PPV_V$value
## [1] "0.140353"
## 
## 
## $PPV_KA
## $PPV_KA$value
## [1] "0.00449273"
## 
## 
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
## 
## $PPV_TLAG$fix
## [1] "true"
## 
## 
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "-0.999822"
## 
## 
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0641621"
## 
## $RUV_PROP$lo
## [1] "0"
## 
## 
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.103639"
## 
## $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) 
## -- Wed Aug 17 15:34:25 2016
## New
## Submitted
## Job 096a426f-0e27-493a-ba50-b2c109de25ee progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID 096a426f-0e27-493a-ba50-b2c109de25ee...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpojERtE\DDMORE.job4acc74744a62 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase17/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
## -- Wed Aug 17 15:35:27 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

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     RUV_ADD 
##  0.09879320  7.15015000  0.27571300  0.68584400  0.06416210  0.10363900 
##  BETA_CL_WT   BETA_V_WT      PPV_CL   CORR_CL_V       PPV_V      PPV_KA 
##  0.75000000  1.00000000  0.08882460 -0.99982200  0.14035300  0.00449273 
##    PPV_TLAG      logtWT 
##  0.10000000  0.00000000

Simulate PK parameters for individuals

ind <- list(name = c('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 for a dose of 100mg given at time 0 (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,f,y))

Simulated parameter values for each individual

print(res$parameter)
##    id        KA         CL         V
## 1   1 0.2745083 0.09104592  8.126897
## 2   2 0.2760055 0.11976654  5.274942
## 3   3 0.2756346 0.08488366  9.128687
## 4   4 0.2735771 0.07967355 10.004706
## 5   5 0.2761952 0.08404899  9.254171
## 6   6 0.2758070 0.09037394  8.249083
## 7   7 0.2761954 0.10134203  6.893232
## 8   8 0.2756682 0.09124829  8.111998
## 9   9 0.2747381 0.09914561  7.115646
## 10 10 0.2758613 0.10690204  6.328127
## 11 11 0.2745305 0.09299946  7.881197
## 12 12 0.2773312 0.10062267  6.916892

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

plot of chunk unnamed-chunk-48

Simulate 1000 subjects - with simulx this is a QUICK process!

g <- list( size = 1000, level = 'individual',  treatment = adm)

Call simulx

res.1000  <- simulx(model =myPharmML,
                    parameter = p,
                    group = g,
                    output = list(ind,y))

Plot prediction intervals with prctilemlx. band defines the percentile bands displayed:

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

plot of chunk unnamed-chunk-50

Table of the same information

print(prctilemlx(res.1000$Y,band=list(number=10, level=100), plot=FALSE)$y)
##    time         0%        10%         20%         30%         40%
## 1   0.0 -0.3510862 -0.1662344 -0.11548344 -0.07138429 -0.04497340
## 2   0.5 -0.2217009 -0.1086707 -0.07096727 -0.05287230 -0.01944711
## 3   1.0  0.2534866  0.6500279  0.83079579  0.91276690  1.02333705
## 4   2.0  2.3266266  3.0208137  3.45063734  3.69547814  3.92650791
## 5   3.0  3.5204056  5.2182636  5.62126766  5.86246726  6.05847247
## 6   4.0  4.5292627  6.2786790  6.72182623  7.14285061  7.54803353
## 7   6.0  6.7779527  8.1488973  8.74378084  9.18295608  9.73796481
## 8   8.0  6.7053427  8.9641837  9.48577420 10.25980102 10.78745411
## 9  12.0  7.6328794  9.3528537  9.96717848 10.55787555 11.13449938
## 10 24.0  7.2334771  8.6180030  9.41597478  9.68850174 10.22959473
## 11 36.0  6.6132020  7.8223748  8.14936768  8.41594846  8.68575976
## 12 48.0  6.0208910  6.8797041  7.19454887  7.27864153  7.42681552
##             50%          50%          60%         70%         80%
## 1  -0.011077845 -0.011077845  0.008280259  0.03630707  0.08202727
## 2   0.006682938  0.006682938  0.026605347  0.05652719  0.09513356
## 3   1.087899104  1.087899104  1.158131056  1.25535660  1.34929155
## 4   4.062603318  4.062603318  4.272029087  4.54968532  4.70133814
## 5   6.235602835  6.235602835  6.539137240  6.80049403  7.44908323
## 6   7.853467821  7.853467821  8.157561488  8.48281444  8.93970890
## 7   9.993238120  9.993238120 10.464812395 10.87654267 11.34976517
## 8  11.113431513 11.113431513 11.329818509 11.75588367 12.19670159
## 9  11.579432943 11.579432943 11.951336813 12.51053210 12.91833861
## 10 10.454293417 10.454293417 10.569380424 10.89889995 11.26441875
## 11  8.864958139  8.864958139  9.107215398  9.40945271  9.70090605
## 12  7.537403761  7.537403761  7.682608963  7.77784854  8.10926793
##           90%       100%
## 1   0.1079472  0.3402929
## 2   0.1402397  0.3207307
## 3   1.5132458  2.2387765
## 4   5.1557472  5.9254697
## 5   8.1777895 10.2670781
## 6   9.4824707 13.2973427
## 7  12.2636423 14.5597784
## 8  12.9956009 17.8631613
## 9  13.6420703 19.2942657
## 10 11.7481415 13.1248200
## 11  9.9802790 11.8099638
## 12  8.2866418  9.1146681