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

UseCase4 : Warfarin population pharmacokinetic model for multiple dosing and administration routes

This example script is intended to illustrate how to use the 'ddmore' R package to perform a M&S workflow using the DDMoRe Standalone Execution Environment (SEE).

The following steps are implemented in this workflow:

To run a task, select wiht the coursor any code lines you wish to execute and press CTRL+R+R in your keyboard. An HTML file containing the commands in this file and associated output will be provided to allow the user to compare the results

Initialisation

Clear workspace and set working directory under 'UsesCasesDemo' project

rm(list=ls(all=F))
mydir <- file.path(Sys.getenv("MDLIDE_WORKSPACE_HOME"),"UseCasesDemo")
setwd(mydir)

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

uc<-"UseCase4"
datafile <- "warfarin_infusion_oral.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] "UseCase4.mdl"               "warfarin_infusion_oral.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_IVPO_dat" "warfarin_PK_IVPO_par" "warfarin_PK_IVPO_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 AMT RATE CMT      DV  logtWT MDV
## 1  1  0.0 80.778 100  100   2  0.0000 0.14321   1
## 2  1  0.5 80.778   0    0   0  5.4851 0.14321   0
## 3  1  1.0 80.778   0    0   0 12.1870 0.14321   0
## 4  1  2.0 80.778   0    0   0 11.2920 0.14321   0
## 5  1  3.0 80.778   0    0   0  9.7773 0.14321   0
## 6  1  6.0 80.778   0    0   0  8.7563 0.14321   0

Extract only observation records

myEDAData<-myData[myData$MDV==0,]

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)",scales=list(relation="free"))
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 results to PDF file

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

Model Development

ESTIMATE model parameters using Monolix

There is a bug in the implemention of administration of doses to multiple compartments using ODE models in the current SEE version. Check UC4_1 to see how this can be encoded using COMPARTMENTS

#mlx <- estimate(mdlfile, target="MONOLIX", subfolder="Monolix")
#slotNames(mlx)
# #' The ddmore "LoadSOObj" reads and parsed existing Standardise Output Objects
# #'  mlx <- LoadSOObject("Monolix/UseCase4.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")
#print(parameters_mlx)
#print(getPopulationParameters(mlx, what="precisions"))

#print(getEstimationInfo(mlx))


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

# #' We can then call Xpose functions referencing this mlx.xpdb object as the input. 
# #' Perform some basic goodness of fit
#print(basic.gof(mlx.xpdb))
#print(ind.plots(mlx.xpdb))

# #' Export results to PDF file
#pdf("GOF_MLX.pdf")
#print(basic.gof(mlx.xpdb))
#print(ind.plots(mlx.xpdb))
#dev.off()

SAEM Estimation with NONMEM

NM <- estimate(mdlfile, target="NONMEM", subfolder="NONMEM")
## -- Fri Dec 11 05:21:51 2015
## New
## Submitted
## Job e172655c-1a47-4ebe-adff-6ef184b79d7a progress:
## Running [ ......................................................................................... ]
## Importing Results
## Copying the result data back to the local machine for job ID e172655c-1a47-4ebe-adff-6ef184b79d7a...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd04a26464b to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase4/NONMEM
## Done.
## 
## 
## The following elements were parsed successfully:
##       RawResults
##       TaskInformation
##       Estimation:PopulationEstimates
##       Estimation:IndividualEstimates
##       Estimation:Residuals
##       Estimation:Predictions
##       Estimation:Likelihood
## 
## The following MESSAGEs were raised during the job execution:
##  minimization_successful: 1
##  covariance_step_run: 0
##  rounding_errors: 0
##  estimate_near_boundary: 0
##  s_matrix_singular: 0
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
## 
## Completed
## -- Fri Dec 11 05:51:40 2015

The ddmore “LoadSOObj” reads and parsed existing Standardise Output Objects NM <- LoadSOObject(“NONMEM/UseCase4.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(parameters_nm)
## $MLE
##       POP_CL        POP_V       POP_KA     POP_TLAG    POP_FORAL 
##  1.00234e-01  7.99174e+00  3.64062e-01  1.00621e+00  9.81337e-01 
##     RUV_PROP      RUV_ADD       PPV_CL ETA_CL_ETA_V        PPV_V 
##  1.24260e-01  9.94849e-07  1.23296e-01  3.28797e-02  1.28507e-01 
##       PPV_KA    PPV_FORAL   BETA_CL_WT    BETA_V_WT     PPV_TLAG 
##  6.66224e-02  3.95429e-03  7.50000e-01  1.00000e+00  1.00000e-01
#print(parameters_mlx)

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

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

print(getEstimationInfo(NM))
## $Likelihood
## $Likelihood$Deviance
## [1] 107.8819
## 
## 
## $Messages
## $Messages$Info
## $Messages$Info$minimization_successful
## [1] "1"
## 
## $Messages$Info$covariance_step_run
## [1] "0"
## 
## $Messages$Info$rounding_errors
## [1] "0"
## 
## $Messages$Info$estimate_near_boundary
## [1] "0"
## 
## $Messages$Info$s_matrix_singular
## [1] "0"
## 
## $Messages$Info$nmoutput2so_version
## [1] "This SOBlock was created with nmoutput2so version 4.5.11"

Xpose diagnostics using NONMEM output

Use 'ddmore' function as.xpdb() to create an Xpose database object from the Standardised Output object, regardless of target software used for estimation.

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.

We can then call Xpose functions referencing this mlx.xpdb object as the input. Perform some basic goodness of fit

print(basic.gof(nm.xpdb))

plot of chunk unnamed-chunk-20

print(ind.plots(nm.xpdb))

plot of chunk unnamed-chunk-20 plot of chunk unnamed-chunk-20

print(parm.hist(nm.xpdb))

plot of chunk unnamed-chunk-20 plot of chunk unnamed-chunk-20

Export results to a PDF file

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

Change estimation method to FOCEI (for speed)

MDL Objects can be manipulated from R to change for example the estimation algorithm

myTaskProperties <- getTaskPropertiesObjects(mdlfile)[[1]]
myNewTaskProperties <- myTaskProperties
myNewTaskProperties@ESTIMATE$algo <- "focei"

Assembling the new MOG. Note that we reuse the data and model from the previous run.

myNewerMOG <- createMogObj(dataObj = getDataObjects(mdlfile)[[1]], 
        parObj = getParameterObjects(mdlfile)[[1]], 
        mdlObj = getModelObjects(mdlfile)[[1]], 
        taskObj = myNewTaskProperties)

We can then write the MOG back out to an .mdl file.

mdlfile.FOCEI <- paste0(uc,"_FOCEI.mdl")
writeMogObj(myNewerMOG,mdlfile.FOCEI)

Test estimation using this new MOG.

NM.FOCEI <- estimate(mdlfile.FOCEI, target="PsN", subfolder="NONMEM_FOCEI")
## -- Fri Dec 11 05:52:06 2015
## New
## Submitted
## Job 3d247f04-a4e4-4a09-833e-1273f74dc616 progress:
## Running [ ....... ]
## Importing Results
## Copying the result data back to the local machine for job ID 3d247f04-a4e4-4a09-833e-1273f74dc616...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd01fe12f41 to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase4/NONMEM_FOCEI
## Done.
## 
## 
## The following elements were parsed successfully:
##       RawResults
##       TaskInformation
##       Estimation:PopulationEstimates
##       Estimation:IndividualEstimates
##       Estimation:Residuals
##       Estimation:Predictions
##       Estimation:Likelihood
## 
## The following WARNINGs were raised during the job execution:
##  minimization_successful: 0
## 
## The following MESSAGEs were raised during the job execution:
##  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
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
## 
## Completed
## -- Fri Dec 11 05:54:32 2015

Load previous results NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase4_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    POP_FORAL 
##  9.90568e-02  7.71745e+00  3.45606e-01  9.47287e-01  9.99995e-01 
##     RUV_PROP      RUV_ADD       PPV_CL ETA_CL_ETA_V        PPV_V 
##  1.30662e-01  2.43560e-02  1.25999e-01 -7.76545e-05  1.07264e-01 
##       PPV_KA    PPV_FORAL   BETA_CL_WT    BETA_V_WT     PPV_TLAG 
##  1.09510e-01  1.02725e-01  7.50000e-01  1.00000e+00  1.00000e-01
print(parameters_nm)
## $MLE
##       POP_CL        POP_V       POP_KA     POP_TLAG    POP_FORAL 
##  1.00234e-01  7.99174e+00  3.64062e-01  1.00621e+00  9.81337e-01 
##     RUV_PROP      RUV_ADD       PPV_CL ETA_CL_ETA_V        PPV_V 
##  1.24260e-01  9.94849e-07  1.23296e-01  3.28797e-02  1.28507e-01 
##       PPV_KA    PPV_FORAL   BETA_CL_WT    BETA_V_WT     PPV_TLAG 
##  6.66224e-02  3.95429e-03  7.50000e-01  1.00000e+00  1.00000e-01
#print(parameters_mlx)

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

Export graphs to a PDF file

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

Run the bootstrap using PsN

The ddmore “bootstrap.PsN” function is a wrap up function that calls Bootstrap PsN functionality using as input an MDL file that will be translated to NMTRAN as first step. Additional PsN arguments can be specified under the “bootstrapOptions” attribute. After task execution, the output from PsN is converted to a Standardised Output object which is saved in a .SO.xml file. Translated files and PsN output will be returned in the ./Bootstrap subfolder

bootstrapResults <- bootstrap.PsN(mdlfile.FOCEI, samples=20, seed=123456,
        bootstrapOptions=" -no-skip_minimization_terminated -threads=2",
        subfolder="Bootstrap", plot=TRUE)
## -- Fri Dec 11 05:54:43 2015
## New
## Submitted
## Job ad2aa98b-f901-4902-a3ef-344a56dd942b progress:
## Running [ ................................ ]
## Importing Results
## Copying the result data back to the local machine for job ID ad2aa98b-f901-4902-a3ef-344a56dd942b...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd079b14dd7 to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase4/Bootstrap
## Done.
## 
## 
## The following elements were parsed successfully:
##       RawResults
##       TaskInformation
##       Estimation:PopulationEstimates
##       Estimation:PrecisionPopulationEstimates
##       Estimation:IndividualEstimates
##       Estimation:Residuals
##       Estimation:Predictions
##       Estimation:Likelihood
## 
## The following WARNINGs were raised during the job execution:
##  minimization_successful: 0
##  bootstrap_parameter_scale: The parameters PPV_CL, ETA_CL_ETA_V, PPV_V, PPV_KA, PPV_TLAG and PPV_FORAL 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:
##  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
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
## 
## Completed
## -- Fri Dec 11 06:05:30 2015
## Warning: NAs introduced by coercion
## [[1]]

plot of chunk Bootstrap

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

plot of chunk Bootstrap

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

Load results from a bootstrap previously performed bootstrapResults <- LoadSOObject(“Bootstrap/UseCase4_FOCEI.SO.xml”) Export bootstrap histograms to a pdf

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

Extract parameter estimates and precision from bootstrap results.

print(getPopulationParameters(bootstrapResults, what="estimates"))
## $MLE
##       POP_CL        POP_V       POP_KA     POP_TLAG    POP_FORAL 
##  9.90568e-02  7.71745e+00  3.45606e-01  9.47287e-01  9.99995e-01 
##     RUV_PROP      RUV_ADD       PPV_CL ETA_CL_ETA_V        PPV_V 
##  1.30662e-01  2.43560e-02  1.25999e-01 -7.76545e-05  1.07264e-01 
##       PPV_KA    PPV_FORAL   BETA_CL_WT    BETA_V_WT     PPV_TLAG 
##  1.09510e-01  1.02725e-01  7.50000e-01  1.00000e+00  1.00000e-01 
## 
## $Bootstrap
##                 Parameter         Mean       Median
## POP_CL             POP_CL 0.1002602000 0.0995025000
## POP_V               POP_V 7.9578340000 7.9395400000
## POP_KA             POP_KA 0.3391792000 0.3418165000
## POP_TLAG         POP_TLAG 0.9540551000 0.9577385000
## POP_FORAL       POP_FORAL 0.9999961000 0.9999975000
## RUV_PROP         RUV_PROP 0.1246791000 0.1263550000
## RUV_ADD           RUV_ADD 0.0442236600 0.0377386500
## BETA_CL_WT     BETA_CL_WT 0.7500000000 0.7500000000
## BETA_V_WT       BETA_V_WT 1.0000000000 1.0000000000
## PPV_CL             PPV_CL 0.0107005200 0.0107119500
## ETA_CL_ETA_V ETA_CL_ETA_V 0.0001205959 0.0001047395
## PPV_V               PPV_V 0.0111170100 0.0107729500
## PPV_KA             PPV_KA 0.0120712300 0.0103444500
## PPV_TLAG         PPV_TLAG 0.0100000000 0.0100000000
## PPV_FORAL       PPV_FORAL 0.0094893080 0.0098101300

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 0.7500000000  0.7500000000 0.750000000
## 2     BETA_V_WT 1.0000000000 1.0000000000  1.0000000000 1.000000000
## 3  ETA_CL_ETA_V 0.0001205959 0.0001047395 -0.0012647571 0.001449308
## 4        POP_CL 0.1002602000 0.0995025000  0.0958179500 0.109705400
## 5     POP_FORAL 0.9999961000 0.9999975000  0.9999730000 1.000000000
## 6        POP_KA 0.3391792000 0.3418165000  0.3083741000 0.370490100
## 7      POP_TLAG 0.9540551000 0.9577385000  0.9114062000 0.982826500
## 8         POP_V 7.9578340000 7.9395400000  7.6276560000 8.391824000
## 9        PPV_CL 0.0107005200 0.0107119500  0.0070410750 0.015792820
## 10    PPV_FORAL 0.0094893080 0.0098101300  0.0049547300 0.010562200
## 11       PPV_KA 0.0120712300 0.0103444500  0.0007938965 0.032875190
## 12     PPV_TLAG 0.0100000000 0.0100000000  0.0100000000 0.010000000
## 13        PPV_V 0.0111170100 0.0107729500  0.0081829300 0.016674830
## 14      RUV_ADD 0.0442236600 0.0377386500  0.0065807880 0.100644000
## 15     RUV_PROP 0.1246791000 0.1263550000  0.1125409000 0.134421200

VPC of model

Before running the VPC with PsN we must update the (initial) values in the MDL Parameter Object MLE estimates from previous step can be used

structuralPar <- getPopulationParameters(NM.FOCEI, what="estimates",block='structural')$MLE
variabilityPar <- getPopulationParameters(NM.FOCEI, what="estimates",block='variability')$MLE

In the current version of the SO standard, we need to manually update parameter names for correlation and covariance parameters to match the SO with the MDL. This will not be needed in future releases. The SO object returned from NONMEM has parameter ETA_CL_ETA_V. This needs to be renamed to conform to model Correlation name OMEGA

variabilityNames <- names(myParObj@VARIABILITY)
names(variabilityPar)[names(variabilityPar)=="ETA_CL_ETA_V"] <- grep("OMEGA",variabilityNames,value=T)
names(variabilityPar)
## [1] "PPV_CL"    "OMEGA"     "PPV_V"     "PPV_KA"    "PPV_FORAL" "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.0990568"
## 
## $POP_CL$lo
## [1] "0.001"
## 
## 
## $POP_V
## $POP_V$value
## [1] "7.71745"
## 
## $POP_V$lo
## [1] "0.001"
## 
## 
## $POP_KA
## $POP_KA$value
## [1] "0.345606"
## 
## $POP_KA$lo
## [1] "0.001"
## 
## 
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.947287"
## 
## $POP_TLAG$lo
## [1] "0.001"
## 
## $POP_TLAG$hi
## [1] "10"
## 
## 
## $POP_FORAL
## $POP_FORAL$value
## [1] "0.999995"
## 
## $POP_FORAL$lo
## [1] "0.001"
## 
## 
## $BETA_CL_WT
## $BETA_CL_WT$value
## [1] "0.75"
## 
## $BETA_CL_WT$fix
## [1] "true"
## 
## 
## $BETA_V_WT
## $BETA_V_WT$value
## [1] "1"
## 
## $BETA_V_WT$fix
## [1] "true"
## 
## 
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.130662"
## 
## $RUV_PROP$lo
## [1] "0"
## 
## 
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.024356"
## 
## $RUV_ADD$lo
## [1] "0"
print(myParObjUpdated@VARIABILITY)
## $PPV_CL
## $PPV_CL$value
## [1] "0.125999"
## 
## $PPV_CL$type
## [1] "sd"
## 
## 
## $PPV_V
## $PPV_V$value
## [1] "0.107264"
## 
## $PPV_V$type
## [1] "sd"
## 
## 
## $PPV_KA
## $PPV_KA$value
## [1] "0.10951"
## 
## $PPV_KA$type
## [1] "sd"
## 
## 
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
## 
## $PPV_TLAG$type
## [1] "sd"
## 
## $PPV_TLAG$fix
## [1] "true"
## 
## 
## $PPV_FORAL
## $PPV_FORAL$value
## [1] "0.102725"
## 
## $PPV_FORAL$type
## [1] "sd"
## 
## 
## $OMEGA
## $OMEGA$parameter
## [1] "[ETA_CL,ETA_V]"
## 
## $OMEGA$value
## [1] "-7.76545e-05"
## 
## $OMEGA$type
## [1] "corr"

A bug in the writeMogObj function means that for now, we must manually add the square bracket around the OMEGA value to signify that this is a vector (of length 1).

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

Assembling the new MOG. Note that we reuse the data and model from the previous run.

myVPCMOG <- createMogObj(dataObj = getDataObjects(mdlfile)[[1]], 
        parObj = myParObjUpdated, 
        mdlObj = getModelObjects(mdlfile)[[1]], 
        taskObj = getTaskPropertiesObjects(mdlfile)[[1]])

We can then write the MOG back out to an .mdl file.

mdlfile.VPC <- paste0(uc,"_VPC.mdl")
writeMogObj(myVPCMOG,mdlfile.VPC)

Similarly as above, ddmore “VPC.PsN” function can be used to run a VPC using PsN as target tool

vpcFiles <- VPC.PsN(mdlfile.VPC,samples=20, seed=12345,
        vpcOptions ="-n_simulation=10",
        subfolder="VPC", plot=TRUE) 
## -- Fri Dec 11 06:05:51 2015
## New
## Submitted
## Job e6353ef9-344f-4ff3-9d0b-5e01686d72fe progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID e6353ef9-344f-4ff3-9d0b-5e01686d72fe...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpkfi8Jd\DDMORE.jobfd021297b7c to D:/SEE-1.2-SNAPSHOT-10DEC2015/MDL_IDE/workspace/UseCasesDemo/UseCase4/VPC
## Done.
## 
## 
## The following elements were parsed successfully:
##       RawResults
##       TaskInformation
##       Simulation
## 
## The following MESSAGEs were raised during the job execution:
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.11
## 
## Completed
## -- Fri Dec 11 06:07:18 2015

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

Simulation using simulx

Simulation with simulx is not possible for UseCase4

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

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

#adm <- list(target='GUT', time = 0, 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)

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

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

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

Call simulx

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

Plot of predicted concentrations band defines the percentile bands displayed level = range of values to examine (in %) 100 = full range of values number = number of bins within the level range. Plot of observed concentrations

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

Table of the same information

#print(prctilemlx(res.1000$Y,band=list(number=10, level=100), plot=F)$y)