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 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<-"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()
## 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 15:39:04 2016
## New
## Submitted
## Job ed311e51-f939-4b04-82f5-34c069d19545 progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID ed311e51-f939-4b04-82f5-34c069d19545...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job3564b967b87 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase9/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 15:40:27 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/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     PPV_CL 
##    9.33375    1.00000    0.11644    0.75000    0.05258    0.04282 
##  CORR_CL_V    RUV_ADD   RUV_PROP 
##   -0.71903    0.00000    0.44199
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.71903 2.85595 397.20
## 4     POP_CL  0.11644 0.00308   2.65
## 5      POP_V  9.33375 0.26797   2.87
## 6     PPV_CL  0.04282 0.06757 157.80
## 7      PPV_V  0.05258 0.06475 123.14
## 8    RUV_ADD  0.00000 0.00000  13.14
## 9   RUV_PROP  0.44199 0.01594   3.61
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -7.855
## 
## 
## $OFMeasures$IndividualContribToLL
##    Subject ICtoLL
## 1        1   5.06
## 2        2  -1.33
## 3        3   0.42
## 4        4  -0.54
## 5        5   1.64
## 6        6  -5.63
## 7        7   3.59
## 8        8  -3.46
## 9        9   2.14
## 10      10  -2.14
## 11      11   0.33
## 12      12   1.24
## 13      13  -1.26
## 14      14  -0.24
## 15      15  -2.97
## 16      16  -2.54
## 17      17  -1.68
## 18      18  -0.16
## 19      19   2.58
## 20      20  -0.07
## 21      21   0.04
## 22      22  -1.69
## 23      23  -2.69
## 24      24  -0.58
## 25      25   2.51
## 26      26  -3.98
## 27      27  -3.25
## 28      28   1.65
## 29      29   0.69
## 30      30   3.93
## 31      31  -2.73
## 32      32   3.26
## 
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 29.71
## 
## $OFMeasures$InformationCriteria$BIC
## [1] 39.97
## 
## 
## 
## $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()
## 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 15:40:32 2016
## New
## Submitted
## Job 18057bd0-4b84-4467-8d0f-1e1061c45a88 progress:
## Running [ ....... ]
## Importing Results
## Copying the result data back to the local machine for job ID 18057bd0-4b84-4467-8d0f-1e1061c45a88...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35646b615898 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase9/NONMEM
## Done.
## 
## 
## The following main elements were parsed successfully:
##   RawResults
##   Estimation::PopulationEstimates::MLE
##   Estimation::IndividualEstimates::Estimates
##   Estimation::IndividualEstimates::RandomEffects
##   Estimation::Residuals::ResidualTable
##   Estimation::Predictions
##   Estimation::OFMeasures::Deviance
## 
## The following MESSAGEs were raised during the job execution:
##  estimation_successful: 1
##  covariance_step_run: 0
##  rounding_errors: 0
##  estimate_near_boundary: 0
##  s_matrix_singular: 0
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 15:42:55 2016

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   BETA_CL_WT 
##  0.107081000  9.032190000  0.510490000  0.000000000  0.750000000 
##    BETA_V_WT       PPV_CL    CORR_CL_V        PPV_V 
##  1.000000000  0.000527268 -0.999943000  0.001072270
print(parameters_mlx)
##      POP_V  BETA_V_WT     POP_CL BETA_CL_WT      PPV_V     PPV_CL 
##    9.33375    1.00000    0.11644    0.75000    0.05258    0.04282 
##  CORR_CL_V    RUV_ADD   RUV_PROP 
##   -0.71903    0.00000    0.44199
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] 316.1013
## 
## 
## 
## $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"

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-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")
## -- Tue Aug 16 15:43:08 2016
## New
## Submitted
## Job c3a4bd4c-69b8-4e58-b36c-020431ecf9cc progress:
## Running [ .. ]
## Importing Results
## Copying the result data back to the local machine for job ID c3a4bd4c-69b8-4e58-b36c-020431ecf9cc...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35645129115e to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase9/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: 9
##  final_zero_gradients: 2
##  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
##  s_matrix_singular: 0
##  significant_digits: 3.5
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 15:43:51 2016

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 BETA_CL_WT  BETA_V_WT 
##  0.1146060  9.2334000  0.4378270  0.0010000  0.7500000  1.0000000 
##     PPV_CL  CORR_CL_V      PPV_V 
##  0.0168234 -0.9974850  0.0141093
print(parameters_nm)
## $MLE
##       POP_CL        POP_V     RUV_PROP      RUV_ADD   BETA_CL_WT 
##  0.107081000  9.032190000  0.510490000  0.000000000  0.750000000 
##    BETA_V_WT       PPV_CL    CORR_CL_V        PPV_V 
##  1.000000000  0.000527268 -0.999943000  0.001072270
print(parameters_mlx)
##      POP_V  BETA_V_WT     POP_CL BETA_CL_WT      PPV_V     PPV_CL 
##    9.33375    1.00000    0.11644    0.75000    0.05258    0.04282 
##  CORR_CL_V    RUV_ADD   RUV_PROP 
##   -0.71903    0.00000    0.44199

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

bootstrapResults <- bootstrap.PsN(mdlfile.FOCEI, samples=20, seed=123456,
        bootstrapOptions=" -no-skip_minimization_terminated -threads=2 ",
        subfolder="Bootstrap", plot=TRUE)
## -- Tue Aug 16 15:43:54 2016
## New
## Submitted
## Job 1be81dce-3924-4333-b533-49d318a8c7ac progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 1be81dce-3924-4333-b533-49d318a8c7ac...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job3564f1d5f29 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase9/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: 9
##  final_zero_gradients: 2
##  estimate_near_boundary: 1
##  bootstrap_parameter_scale: The parameters PPV_CL, CORR_CL_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:
##  estimation_successful: 1
##  covariance_step_run: 0
##  rounding_errors: 0
##  hessian_reset: 0
##  s_matrix_singular: 0
##  significant_digits: 3.5
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 15:45:17 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/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()
## png 
##   2

Extract parameter estimates and precision from bootstrap results.

print(getPopulationParameters(bootstrapResults, what="estimates"))
## $MLE
##     POP_CL      POP_V   RUV_PROP    RUV_ADD BETA_CL_WT  BETA_V_WT 
##  0.1146060  9.2334000  0.4378270  0.0010000  0.7500000  1.0000000 
##     PPV_CL  CORR_CL_V      PPV_V 
##  0.0168234 -0.9974850  0.0141093 
## 
## $Bootstrap
##             Parameter          Mean        Median
## BETA_CL_WT BETA_CL_WT  0.7500000000  7.500000e-01
## BETA_V_WT   BETA_V_WT  1.0000000000  1.000000e+00
## CORR_CL_V   CORR_CL_V -0.0000917941 -1.211066e-06
## POP_CL         POP_CL  0.1143132000  1.140635e-01
## POP_V           POP_V  9.2378770000  9.217365e+00
## PPV_CL         PPV_CL  0.0001530302  1.000000e-06
## PPV_V           PPV_V  0.0001840294  1.874220e-06
## RUV_ADD       RUV_ADD  0.0010000000  1.000000e-03
## RUV_PROP     RUV_PROP  0.4363049000  4.357305e-01

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.7500000000  7.500000e-01  7.500000e-01  7.500000e-01
## 2  BETA_V_WT  1.0000000000  1.000000e+00  1.000000e+00  1.000000e+00
## 3  CORR_CL_V -0.0000917941 -1.211066e-06 -8.164428e-04 -1.813202e-07
## 4     POP_CL  0.1143132000  1.140635e-01  1.120305e-01  1.174091e-01
## 5      POP_V  9.2378770000  9.217365e+00  8.846469e+00  9.700644e+00
## 6     PPV_CL  0.0001530302  1.000000e-06  1.000000e-06  1.892524e-03
## 7      PPV_V  0.0001840294  1.874220e-06  1.034191e-06  2.035241e-03
## 8    RUV_ADD  0.0010000000  1.000000e-03  1.000000e-03  1.000000e-03
## 9   RUV_PROP  0.4363049000  4.357305e-01  4.310272e-01  4.416005e-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

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.114606"
## 
## $POP_CL$lo
## [1] "0.001"
## 
## 
## $POP_V
## $POP_V$value
## [1] "9.2334"
## 
## $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"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.0168234"
## 
## 
## $PPV_V
## $PPV_V$value
## [1] "0.0141093"
## 
## 
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "-0.997485"
## 
## 
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.437827"
## 
## $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 15:45:29 2016
## New
## Submitted
## Job 8d1d6115-9bf3-4f2a-88dc-abe99e291c3a progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID 8d1d6115-9bf3-4f2a-88dc-abe99e291c3a...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job3564402830 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase9/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 15:46:31 2016

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()
## 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   RUV_PROP    RUV_ADD BETA_CL_WT  BETA_V_WT 
##  0.1146060  9.2334000  0.4378270  0.0010000  0.7500000  1.0000000 
##     PPV_CL  CORR_CL_V      PPV_V     logtWT 
##  0.0168234 -0.9974850  0.0141093  0.0000000

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

adm <- list(type=1, 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.1153870 9.182816
## 2   2 0.1140305 9.267582
## 3   3 0.1134462 9.342309
## 4   4 0.1134554 9.301658
## 5   5 0.1129692 9.327286
## 6   6 0.1139308 9.279548
## 7   7 0.1106043 9.492336
## 8   8 0.1132252 9.331548
## 9   9 0.1149521 9.206781
## 10 10 0.1146673 9.234757
## 11 11 0.1172753 9.053062
## 12 12 0.1156496 9.153281

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

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

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.002112602 -0.00123209 -0.0008767652 -0.0006393598 -0.0002698316
## 2   0.5  0.032057797  2.83584377  3.9012187890  4.8283003179  5.4326132846
## 3   1.0 -0.175527977  5.32656788  7.0484126691  8.8619899415  9.9829721017
## 4   2.0  2.230885933  5.47434327  6.9831493069  8.5642994166  9.9038677698
## 5   3.0 -5.015997756  5.55114923  6.7564839057  7.8135013105  8.4997542919
## 6   4.0 -1.285555200  5.38062607  7.2370374703  8.4112798030  9.5911078229
## 7   6.0  1.034520643  4.19024242  6.2199657931  7.2919639010  8.1946196390
## 8   8.0 -2.905034449  4.00025033  5.3110530422  6.5808067290  7.3464665288
## 9  12.0 -2.592934025  4.93294078  6.2859026836  7.4275719680  8.2342716139
## 10 24.0 -0.285439972  2.89995713  4.2646146099  5.1977583271  6.4506248057
## 11 36.0 -0.131941621  2.82124611  4.1855554833  5.3895389515  6.1234596114
## 12 48.0  0.172169829  2.32730135  3.6636330892  4.4024939983  5.3824012053
##              50%           50%          60%          70%          80%
## 1  -0.0001315084 -0.0001315084 7.941063e-05 3.073447e-04 5.805933e-04
## 2   5.7202753296  5.7202753296 6.126612e+00 6.726158e+00 7.622908e+00
## 3  10.5934995802 10.5934995802 1.137234e+01 1.270305e+01 1.471368e+01
## 4  10.7124566377 10.7124566377 1.162581e+01 1.249479e+01 1.319716e+01
## 5   9.9666986743  9.9666986743 1.084191e+01 1.268828e+01 1.370994e+01
## 6  10.3843597383 10.3843597383 1.127267e+01 1.262092e+01 1.364887e+01
## 7   9.3740790419  9.3740790419 1.093020e+01 1.198467e+01 1.334302e+01
## 8   8.2793495588  8.2793495588 9.391334e+00 1.060196e+01 1.177413e+01
## 9   9.1836242351  9.1836242351 1.019837e+01 1.149526e+01 1.285481e+01
## 10  7.3504736929  7.3504736929 8.217296e+00 9.428455e+00 1.032326e+01
## 11  7.3701675095  7.3701675095 7.867995e+00 8.637793e+00 9.741337e+00
## 12  6.1506192640  6.1506192640 6.868121e+00 7.812511e+00 8.570312e+00
##             90%        100%
## 1   0.001247095  0.00271701
## 2   8.402320308 10.95882869
## 3  16.676500132 19.32999551
## 4  14.961276777 18.64677354
## 5  15.843652823 23.28586863
## 6  14.790091934 25.41049849
## 7  16.012808814 20.97393891
## 8  13.630975642 18.42265217
## 9  14.720396604 21.18029958
## 10 11.885205595 20.37123670
## 11 11.577251066 14.38516191
## 12  9.722163730 12.55084839