UseCase2_1 : Warfarin population pharmacokinetics model with analytical solutions

Variant on UseCase2 - Using DATA_DERIVED_VARIABLES to calculate dose time

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.

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)

Set name of .mdl file and dataset for future tasks

uc <- "UseCase2_1"
datafile <- "warfarin_conc.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)) 
cache.path <- file.path(mydir,uc, 'cache')
dir.create(cache.path)
opts_chunk$set(cache.path=cache.path)
figure.path <- file.path(mydir,uc, 'figure')
dir.create(figure.path)
opts_chunk$set(figure.path=figure.path)

List files available in working directory

list.files()
## [1] "cache"             "figure"            "UseCase2_1.mdl"   
## [4] "warfarin_conc.csv"

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 Standard Output object which is saved in a .SO.xml file.

Translated files and Monolix output will be returned in the ./Monolix subfolder. The Standard 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 17:21:56 2016
## New
## Submitted
## Job 8ba7f3c9-367c-41f5-b511-751bbe5a7ec8 progress:
## Running [ ......... ]
## Importing Results
## Copying the result data back to the local machine for job ID 8ba7f3c9-367c-41f5-b511-751bbe5a7ec8...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpk5tG0t\DDMORE.job1c842cf91dc5 to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase2_1/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 17:25:02 2016
slotNames(mlx)
## [1] "ToolSettings"     "RawResults"       "TaskInformation" 
## [4] "Estimation"       "ModelDiagnostic"  "Simulation"      
## [7] "OptimalDesign"    ".pathToSourceXML"

The ddmore “LoadSOObj” function reads and parses existing Standard Output Objects

mlx <- LoadSOObject(“Monolix/UseCase2_1.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 
##    8.08758    1.00000    1.67019    0.13438    0.75000    0.97399 
##      PPV_V     PPV_KA     PPV_CL   PPV_TLAG  CORR_CL_V    RUV_ADD 
##    0.13357    1.12170    0.26583    0.10000    0.19380    0.22733 
##   RUV_PROP 
##    0.06484
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.19380 0.20050 103.46
## 4      POP_CL 0.13438 0.00644   4.80
## 5      POP_KA 1.67019 0.67645  40.50
## 6    POP_TLAG 0.97399 0.05459   5.60
## 7       POP_V 8.08758 0.22016   2.72
## 8      PPV_CL 0.26583 0.03450  12.98
## 9      PPV_KA 1.12170 0.29706  26.48
## 10   PPV_TLAG 0.10000 0.00000   0.00
## 11      PPV_V 0.13357 0.02198  16.46
## 12    RUV_ADD 0.22733 0.04455  19.60
## 13   RUV_PROP 0.06484 0.00919  14.18
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -332.895
## 
## 
## $OFMeasures$IndividualContribToLL
##    Subject ICtoLL
## 1        1 -24.46
## 2        2  -5.22
## 3        3 -13.08
## 4        4 -12.17
## 5        5 -11.05
## 6        6  -7.51
## 7        7 -18.58
## 8        8 -20.94
## 9        9 -30.99
## 10      10  -5.77
## 11      12 -19.83
## 12      13 -19.28
## 13      14 -19.29
## 14      15 -11.46
## 15      16 -14.38
## 16      17  -5.69
## 17      18  -5.13
## 18      19  -6.62
## 19      20  -5.18
## 20      21  -5.95
## 21      22  -5.87
## 22      23  -8.12
## 23      24  -4.86
## 24      25  -7.16
## 25      26  -7.25
## 26      27  -5.29
## 27      28  -6.82
## 28      29  -5.58
## 29      30  -4.57
## 30      31  -5.03
## 31      32  -4.71
## 32      33  -5.07
## 
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 685.79
## 
## $OFMeasures$InformationCriteria$BIC
## [1] 700.44
## 
## 
## 
## $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)
## 
## 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-9

print(ind.plots(mlx.xpdb))

plot of chunk unnamed-chunk-9 plot of chunk unnamed-chunk-9

Export graphs to a PDF file

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

Change estimation method to FOCEI

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 in NONMEM via PsN

NM.FOCEI <- estimate(mdlfile.FOCEI, target="PsN", subfolder="NONMEM_FOCEI")
## -- Tue Aug 16 17:25:26 2016
## New
## Submitted
## Job 97c72270-6917-4a48-ab36-70a6f35039bd progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 97c72270-6917-4a48-ab36-70a6f35039bd...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpk5tG0t\DDMORE.job1c8465f526b to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase2_1/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.4
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 17:26:52 2016

Load previous results

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

Results from NONMEM should be comparable with results from MONOLIX

print(getPopulationParameters(NM.FOCEI,  what="estimates"))
## $MLE
##     POP_CL      POP_V     POP_KA   POP_TLAG   RUV_PROP    RUV_ADD 
##  0.1341370  8.1009300  1.5616700  0.9677510  0.0715972  0.1932710 
## BETA_CL_WT  BETA_V_WT     PPV_CL  CORR_CL_V      PPV_V     PPV_KA 
##  0.7500000  1.0000000  0.2637800  0.2425230  0.1348360  0.9360700 
##   PPV_TLAG 
##  0.1000000
print(parameters_mlx)
##      POP_V  BETA_V_WT     POP_KA     POP_CL BETA_CL_WT   POP_TLAG 
##    8.08758    1.00000    1.67019    0.13438    0.75000    0.97399 
##      PPV_V     PPV_KA     PPV_CL   PPV_TLAG  CORR_CL_V    RUV_ADD 
##    0.13357    1.12170    0.26583    0.10000    0.19380    0.22733 
##   RUV_PROP 
##    0.06484

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

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 Standard 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 17:26:57 2016
## New
## Submitted
## Job 91770c49-045a-431f-97ac-ff9ba4de4dc5 progress:
## Running [ ........ ]
## Importing Results
## Copying the result data back to the local machine for job ID 91770c49-045a-431f-97ac-ff9ba4de4dc5...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpk5tG0t\DDMORE.job1c8458977bb3 to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase2_1/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.4
##  nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
## 
## Completed
## -- Tue Aug 16 17:29:43 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/UseCase2_1_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.1341370  8.1009300  1.5616700  0.9677510  0.0715972  0.1932710 
## BETA_CL_WT  BETA_V_WT     PPV_CL  CORR_CL_V      PPV_V     PPV_KA 
##  0.7500000  1.0000000  0.2637800  0.2425230  0.1348360  0.9360700 
##   PPV_TLAG 
##  0.1000000 
## 
## $Bootstrap
##             Parameter        Mean     Median
## 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.005615584 0.00564982
## POP_CL         POP_CL 0.134651000 0.13647200
## POP_KA         POP_KA 1.494715000 1.41805000
## POP_TLAG     POP_TLAG 0.927304500 0.93550300
## POP_V           POP_V 8.102665000 8.01352500
## PPV_CL         PPV_CL 0.070545630 0.06764735
## PPV_KA         PPV_KA 0.585871500 0.54814450
## PPV_TLAG     PPV_TLAG 0.010000000 0.01000000
## PPV_V           PPV_V 0.014731550 0.01407660
## RUV_ADD       RUV_ADD 0.127911900 0.12632150
## RUV_PROP     RUV_PROP 0.089430860 0.09400740

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.75000000  0.7500000000 0.75000000
## 2   BETA_V_WT 1.000000000 1.00000000  1.0000000000 1.00000000
## 3   CORR_CL_V 0.005615584 0.00564982 -0.0041056180 0.01428605
## 4      POP_CL 0.134651000 0.13647200  0.1129103000 0.14789560
## 5      POP_KA 1.494715000 1.41805000  0.8082667000 3.04457600
## 6    POP_TLAG 0.927304500 0.93550300  0.7726211000 1.00539500
## 7       POP_V 8.102665000 8.01352500  7.6731430000 8.59367300
## 8      PPV_CL 0.070545630 0.06764735  0.0241234900 0.12475530
## 9      PPV_KA 0.585871500 0.54814450  0.0005247876 1.67861400
## 10   PPV_TLAG 0.010000000 0.01000000  0.0100000000 0.01000000
## 11      PPV_V 0.014731550 0.01407660  0.0071630180 0.02859239
## 12    RUV_ADD 0.127911900 0.12632150  0.0010990000 0.32237270
## 13   RUV_PROP 0.089430860 0.09400740  0.0482136900 0.13384490

VPC of model

When basing VPC on estimation from a target software other than NONMEM we must update the parameter values.

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.134137"
## 
## $POP_CL$lo
## [1] "0.001"
## 
## 
## $POP_V
## $POP_V$value
## [1] "8.10093"
## 
## $POP_V$lo
## [1] "0.001"
## 
## 
## $POP_KA
## $POP_KA$value
## [1] "1.56167"
## 
## $POP_KA$lo
## [1] "0.001"
## 
## 
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.967751"
## 
## $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.26378"
## 
## 
## $PPV_V
## $PPV_V$value
## [1] "0.134836"
## 
## 
## $PPV_KA
## $PPV_KA$value
## [1] "0.93607"
## 
## 
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
## 
## $PPV_TLAG$fix
## [1] "true"
## 
## 
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "0.242523"
## 
## 
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0715972"
## 
## $RUV_PROP$lo
## [1] "0"
## 
## 
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.193271"
## 
## $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 17:30:05 2016
## New
## Submitted
## Job 74fb94aa-c0c0-4b55-8ba8-edac90e9dcb7 progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID 74fb94aa-c0c0-4b55-8ba8-edac90e9dcb7...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpk5tG0t\DDMORE.job1c8473735f17 to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase2_1/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 17:31:51 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,WT=70)

Parameter values used in simulation

print(p)
##     POP_CL      POP_V     POP_KA   POP_TLAG   RUV_PROP    RUV_ADD 
##  0.1341370  8.1009300  1.5616700  0.9677510  0.0715972  0.1932710 
## BETA_CL_WT  BETA_V_WT     PPV_CL  CORR_CL_V      PPV_V     PPV_KA 
##  0.7500000  1.0000000  0.2637800  0.2425230  0.1348360  0.9360700 
##   PPV_TLAG         WT 
##  0.1000000 70.0000000

Simulate PK parameters for individuals

ind <- list(name = c('TLAG','KA','CL','V'))

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

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)

Simulate 12 subjects

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

Call simulx

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

Simulated parameter values for each individual

print(res$parameter)
##    id      TLAG         KA         CL         V
## 1   1 0.9356991  0.6451603 0.18197004  8.799385
## 2   2 0.9701049  1.4413486 0.11884158  7.472905
## 3   3 0.9040290  0.5245994 0.15667812  8.135486
## 4   4 0.9903576  4.8557236 0.10518889  9.309277
## 5   5 1.0400338  1.8950829 0.08414157  8.149115
## 6   6 0.9774555  2.2098309 0.10300150  7.718688
## 7   7 0.9947456  1.6160268 0.19504485  9.360923
## 8   8 0.9704490  3.1210042 0.18149423 10.150364
## 9   9 1.0801702 10.7717417 0.11256108  8.772852
## 10 10 1.0333402  3.1836053 0.16201977  9.016313
## 11 11 0.9818043  0.9391970 0.11919284  6.899420
## 12 12 1.0836423  1.2955816 0.11878371  6.617072

Plot simulated results

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

plot of chunk unnamed-chunk-34

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

Table of the same information

print(prctilemlx(res.1000$Y,band=list(number=10, level=100), plot=F)$y)
##    time         0%         10%         20%         30%         40%
## 1   0.0 -0.3758358 -0.26117065 -0.19238219 -0.10861112 -0.06110563
## 2   0.5 -0.3707545 -0.25542917 -0.17250066 -0.09984208 -0.02972206
## 3   1.0 -0.2917819 -0.07360796  0.01107256  0.12793157  0.24061401
## 4   2.0  2.0817124  5.31409858  6.44885304  7.50259050  8.67040472
## 5   3.0  2.8379570  7.47317965  8.91630019  9.58488134 10.23391430
## 6   4.0  4.4295668  8.82257270  9.15798520 10.03206701 10.59968421
## 7   6.0  4.9096332  9.26098486  9.86172813 10.21071081 10.60438595
## 8   8.0  5.3947117  9.03924840  9.46242042 10.18148915 10.49977622
## 9  12.0  7.3718761  8.61507428  8.98636445  9.27224851  9.77122838
## 10 24.0  5.6026342  6.76010954  7.24387870  7.64214409  7.82740525
## 11 36.0  4.1297424  5.44229478  5.89751148  6.22012839  6.65229239
## 12 48.0  2.5820822  4.23115442  4.69203653  4.98872150  5.38558336
##            50%         50%         60%         70%        80%        90%
## 1  -0.01178155 -0.01178155  0.04038836  0.09075748  0.1368034  0.2039337
## 2   0.02593830  0.02593830  0.05137345  0.08735097  0.1304384  0.2201818
## 3   0.38843366  0.38843366  0.82244176  1.28844393  2.0983389  3.5835727
## 4   9.46981674  9.46981674 10.16811617 10.77089908 11.8481710 13.1585525
## 5  10.93244125 10.93244125 11.53325500 12.11838388 12.9632829 13.4533614
## 6  11.15042097 11.15042097 11.65045839 12.14240130 12.9010252 13.8902817
## 7  11.08353942 11.08353942 11.65486331 12.27143740 12.6509468 13.3813790
## 8  10.73804021 10.73804021 11.42920230 11.90925398 12.6439562 13.3513828
## 9  10.38024278 10.38024278 10.84879883 11.12705011 11.7228526 12.1837462
## 10  8.23922142  8.23922142  8.80853967  9.17716149  9.8259243 10.1931253
## 11  7.10506838  7.10506838  7.40505534  7.81431780  8.0483621  8.6788794
## 12  5.65042520  5.65042520  5.92258779  6.48640420  6.9631836  7.3880954
##          100%
## 1   0.3798155
## 2   0.4195191
## 3  12.8919112
## 4  16.0372175
## 5  18.6037559
## 6  16.5212412
## 7  17.5137131
## 8  16.1524200
## 9  14.8241400
## 10 11.9059802
## 11 10.7187331
## 12  9.2190681