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

UseCase5 : Implementation of continous and categorical covariates

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)

Set name of .mdl file and dataset for future tasks

uc<-"UseCase5"
datafile <- "warfarin_conc_sexf.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] "UseCase5.mdl"           "warfarin_conc_sexf.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_covariate_dat" "warfarin_PK_covariate_par"
## [3] "warfarin_PK_covariate_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 Hoover 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 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 SEXF AMT DVID  DV MDV
## 1  1  0.0 66.7  50 male 100    0  NA   1
## 2  1  0.5 66.7  50 male  NA    1 0.0   0
## 3  1  1.0 66.7  50 male  NA    1 1.9   0
## 4  1  2.0 66.7  50 male  NA    1 3.3   0
## 5  1  3.0 66.7  50 male  NA    1 6.6   0
## 6  1  6.0 66.7  50 male  NA    1 9.1   0

Extract only observation records

myEDAData<-myData[is.na(myData$AMT),]

Open an R window to record and access all your plots

windows(record=TRUE) 

Now 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 results to 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 12:41:31 2016
## New
## Submitted
## Job 908f1b6e-5043-4792-a38b-be3a09f88613 progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 908f1b6e-5043-4792-a38b-be3a09f88613...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356474a1bfe to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase5/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 12:42:53 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/UseCase5.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 BETA_CL_AGE 
##     8.06842     1.00000     1.67953     0.14160     0.75000     0.00854 
## POP_FCL_FEM    POP_TLAG       PPV_V      PPV_KA      PPV_CL    PPV_TLAG 
##     0.13702     0.95115     0.12803     1.04272     0.24162     0.10000 
##   CORR_CL_V     RUV_ADD    RUV_PROP 
##     0.18183     0.21156     0.06749
print(getPopulationParameters(mlx, what="precisions"))
## $MLE
##      Parameter     MLE      SE    RSE
## 1  BETA_CL_AGE 0.00854 0.00421  49.30
## 2   BETA_CL_WT 0.75000 0.00000   0.00
## 3    BETA_V_WT 1.00000 0.00000   0.00
## 4    CORR_CL_V 0.18183 0.20386 112.12
## 5       POP_CL 0.14160 0.00884   6.24
## 6  POP_FCL_FEM 0.13702 0.11958  87.27
## 7       POP_KA 1.67953 0.65148  38.79
## 8     POP_TLAG 0.95115 0.05304   5.58
## 9        POP_V 8.06842 0.21243   2.63
## 10      PPV_CL 0.24162 0.03156  13.06
## 11      PPV_KA 1.04272 0.28688  27.51
## 12    PPV_TLAG 0.10000 0.00000   0.00
## 13       PPV_V 0.12803 0.02146  16.77
## 14     RUV_ADD 0.21156 0.04303  20.34
## 15    RUV_PROP 0.06749 0.00907  13.44
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -330.15
## 
## 
## $OFMeasures$IndividualContribToLL
##    Subject ICtoLL
## 1        1 -23.24
## 2        2  -5.64
## 3        3 -12.82
## 4        4 -12.33
## 5        5 -12.46
## 6        6  -7.47
## 7        7 -17.73
## 8        8 -20.95
## 9        9 -30.82
## 10      10  -5.57
## 11      12 -19.57
## 12      13 -19.80
## 13      14 -19.04
## 14      15 -10.61
## 15      16 -14.60
## 16      17  -5.44
## 17      18  -5.06
## 18      19  -6.76
## 19      20  -5.93
## 20      21  -5.62
## 21      22  -6.03
## 22      23  -7.87
## 23      24  -4.62
## 24      25  -7.40
## 25      26  -6.99
## 26      27  -5.00
## 27      28  -6.58
## 28      29  -5.44
## 29      30  -4.63
## 30      31  -4.86
## 31      32  -4.51
## 32      33  -4.75
## 
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 684.3
## 
## $OFMeasures$InformationCriteria$BIC
## [1] 701.89
## 
## 
## 
## $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-21

print(ind.plots(mlx.xpdb))

plot of chunk unnamed-chunk-21 plot of chunk unnamed-chunk-21

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 12:42:58 2016
## New
## Submitted
## Job 5060ad68-955d-4004-b0f3-ae7ab4281d72 progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 5060ad68-955d-4004-b0f3-ae7ab4281d72...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job3564470829c0 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase5/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 12:44:21 2016

Load previous results

NM <- LoadSOObject(“NONMEM/UseCase5.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_nm <- getPopulationParameters(NM, what="estimates")
print(getPopulationParameters(NM, what="estimates",block="structural"))
## $MLE
##      POP_CL       POP_V      POP_KA    POP_TLAG BETA_CL_AGE POP_FCL_FEM 
##  0.14087600  8.09520000  1.67554000  0.92918900  0.00834105  0.13954700 
##  BETA_CL_WT   BETA_V_WT 
##  0.75000000  1.00000000
print(parameters_nm)
## $MLE
##      POP_CL       POP_V      POP_KA    POP_TLAG    RUV_PROP     RUV_ADD 
##  0.14087600  8.09520000  1.67554000  0.92918900  0.07632220  0.16968600 
## BETA_CL_AGE POP_FCL_FEM  BETA_CL_WT   BETA_V_WT      PPV_CL   CORR_CL_V 
##  0.00834105  0.13954700  0.75000000  1.00000000  0.24275000  0.22216900 
##       PPV_V      PPV_KA    PPV_TLAG 
##  0.13633900  0.94410400  0.10000000
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -267.5108
## 
## 
## 
## $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)
## 
## 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-25

print(ind.plots(nm.xpdb))

plot of chunk unnamed-chunk-25 plot of chunk unnamed-chunk-25

print(parm.hist(nm.xpdb))

plot of chunk unnamed-chunk-25

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 Modelling Object Group (MOG). Note that we reuse the data, parameters and model from the MOG.

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 12:44:36 2016
## New
## Submitted
## Job 299f1c43-73f4-4b13-a407-89ef334efaf9 progress:
## Running [ .. ]
## Importing Results
## Copying the result data back to the local machine for job ID 299f1c43-73f4-4b13-a407-89ef334efaf9...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35643009563e to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase5/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.2
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 12:45:19 2016

Load previous results

NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase5_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.1416380   8.1059900   1.5625700   0.9676060   0.0708693   0.1971440 
## BETA_CL_AGE POP_FCL_FEM  BETA_CL_WT   BETA_V_WT      PPV_CL   CORR_CL_V 
##   0.0084406   0.1384690   0.7500000   1.0000000   0.2391590   0.2197880 
##       PPV_V      PPV_KA    PPV_TLAG 
##   0.1347520   0.9333550   0.1000000
print(parameters_nm)
## $MLE
##      POP_CL       POP_V      POP_KA    POP_TLAG    RUV_PROP     RUV_ADD 
##  0.14087600  8.09520000  1.67554000  0.92918900  0.07632220  0.16968600 
## BETA_CL_AGE POP_FCL_FEM  BETA_CL_WT   BETA_V_WT      PPV_CL   CORR_CL_V 
##  0.00834105  0.13954700  0.75000000  1.00000000  0.24275000  0.22216900 
##       PPV_V      PPV_KA    PPV_TLAG 
##  0.13633900  0.94410400  0.10000000

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

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 12:45:22 2016
## New
## Submitted
## Job 2b2f867d-3d34-43fb-8204-e4c223e4cc18 progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID 2b2f867d-3d34-43fb-8204-e4c223e4cc18...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35645a831133 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase5/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.2
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 12:47:04 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/UseCase5_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      POP_KA    POP_TLAG    RUV_PROP     RUV_ADD 
##   0.1416380   8.1059900   1.5625700   0.9676060   0.0708693   0.1971440 
## BETA_CL_AGE POP_FCL_FEM  BETA_CL_WT   BETA_V_WT      PPV_CL   CORR_CL_V 
##   0.0084406   0.1384690   0.7500000   1.0000000   0.2391590   0.2197880 
##       PPV_V      PPV_KA    PPV_TLAG 
##   0.1347520   0.9333550   0.1000000 
## 
## $Bootstrap
##               Parameter        Mean     Median
## BETA_CL_AGE BETA_CL_AGE 0.007395582 0.00610113
## BETA_CL_WT   BETA_CL_WT 0.750000000 0.75000000
## BETA_V_WT     BETA_V_WT 1.000000000 1.00000000
## CORR_CL_V     CORR_CL_V 0.005746716 0.00520061
## POP_CL           POP_CL 0.140022800 0.13875250
## POP_FCL_FEM POP_FCL_FEM 0.202825200 0.16671250
## POP_KA           POP_KA 1.377451000 1.25151000
## POP_TLAG       POP_TLAG 0.924424300 0.92490900
## POP_V             POP_V 8.128746000 8.10086500
## PPV_CL           PPV_CL 0.052005950 0.05808665
## PPV_KA           PPV_KA 0.603459100 0.54871450
## PPV_TLAG       PPV_TLAG 0.010000000 0.01000000
## PPV_V             PPV_V 0.015249290 0.01537295
## RUV_ADD         RUV_ADD 0.100929000 0.00109900
## RUV_PROP       RUV_PROP 0.096397020 0.09835285

Extract the information regarding the precision intervals

print(getPopulationParameters(bootstrapResults, what="intervals")$Bootstrap)
##      Parameter        Mean     Median        Perc_5    Perc_95
## 1  BETA_CL_AGE 0.007395582 0.00610113 -0.0003933975 0.02380566
## 2   BETA_CL_WT 0.750000000 0.75000000  0.7500000000 0.75000000
## 3    BETA_V_WT 1.000000000 1.00000000  1.0000000000 1.00000000
## 4    CORR_CL_V 0.005746716 0.00520061 -0.0020135530 0.01327641
## 5       POP_CL 0.140022800 0.13875250  0.1222508000 0.16438250
## 6  POP_FCL_FEM 0.202825200 0.16671250  0.0100000000 0.63829940
## 7       POP_KA 1.377451000 1.25151000  0.8084377000 2.08947600
## 8     POP_TLAG 0.924424300 0.92490900  0.7721754000 1.03391600
## 9        POP_V 8.128746000 8.10086500  7.6829890000 8.56017400
## 10      PPV_CL 0.052005950 0.05808665  0.0146228900 0.08469345
## 11      PPV_KA 0.603459100 0.54871450  0.0064315750 1.68081400
## 12    PPV_TLAG 0.010000000 0.01000000  0.0100000000 0.01000000
## 13       PPV_V 0.015249290 0.01537295  0.0073927160 0.02853726
## 14     RUV_ADD 0.100929000 0.00109900  0.0010990000 0.32564240
## 15    RUV_PROP 0.096397020 0.09835285  0.0475589900 0.14464240

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.141638"
## 
## $POP_CL$lo
## [1] "0.001"
## 
## 
## $POP_V
## $POP_V$value
## [1] "8.10599"
## 
## $POP_V$lo
## [1] "0.001"
## 
## 
## $POP_KA
## $POP_KA$value
## [1] "1.56257"
## 
## $POP_KA$lo
## [1] "0.001"
## 
## 
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.967606"
## 
## $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"
## 
## 
## $BETA_CL_AGE
## $BETA_CL_AGE$value
## [1] "0.0084406"
## 
## 
## $POP_FCL_FEM
## $POP_FCL_FEM$value
## [1] "0.138469"
## 
## $POP_FCL_FEM$lo
## [1] "0"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.239159"
## 
## 
## $PPV_V
## $PPV_V$value
## [1] "0.134752"
## 
## 
## $PPV_KA
## $PPV_KA$value
## [1] "0.933355"
## 
## 
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
## 
## $PPV_TLAG$fix
## [1] "true"
## 
## 
## $PPV_FORAL
## $PPV_FORAL$value
## [1] "0.1"
## 
## 
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "0.219788"
## 
## 
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0708693"
## 
## $RUV_PROP$lo
## [1] "0"
## 
## 
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.197144"
## 
## $RUV_ADD$lo
## [1] "1.0E-4"

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 12:47:17 2016
## New
## Submitted
## Job b8714b82-244a-480d-ba5e-606b266970d7 progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID b8714b82-244a-480d-ba5e-606b266970d7...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35642ad36ccd to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase5/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 12:48:20 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 in models with categorical covariates.

# #' 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.
# #+ Simulation via simulx
# 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, typical age of 40, and female. 
# p <- c(parValues,WT=70,AGE=40,SEX=1)
# 
# #' Parameter values used in simulation
# print(p) 
# 
# #' Simulate PK parameters for individuals
# ind <- list(name = c('TLAG','KA','CL','V'))
# 
# #' Simulate predicted (CC) and observed concentration values (Y)
# f   <- list( name = c('CC'), time = seq(0,to=50,by=1))
# y   <- list( name = c('Y'), time = c(0, 0.5, 1, 2, 3, 4, 6, 8, 12, 24, 36, 48))
#  
# #' Simulate for a dose of 100mg given at time 0 into the GUT (oral administration)
# adm <- list(time = 0, amount = 100, target="GUT")
# 
# #' 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)
# 
# #' Plot simulated results
# plot(ggplot() + 
#               geom_line(data=res$CC, aes(x=time, y=CC, colour=id)) +
#               geom_line(data=res$Y, aes(x=time, y=Y, colour=id)) +
#               xlab("time (h)") + ylab("concentration") )
# 
# #' Simulate 1000 subjects - with simulx this is a QUICK process!
# #+ VPC with simulx
# 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:
# #' * level = range of values to examine (in %; 100 = full range of values)
# #' * number = number of bins within the level range.
# plot(prctilemlx(res.1000$Y,band=list(number=9, level=90)))
# 
# #' Table of the same information
# print(prctilemlx(res.1000$Y,band=list(number=10, level=100), plot=F)$y)