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
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<-"UseCase8"
datafile <- "warfarin_conc_bov_P4_sort.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] "UseCase8.mdl" "warfarin_conc_bov_P4_sort.csv"
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_BOV_dat" "warfarin_PK_BOV_par" "warfarin_PK_BOV_mdl"
## [4] "warfarin_PK_BOV_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]]
Recall that getDataObjects only reads the MDL code from the .mdl file. Use 'ddmore' function readDataObj() to create an R object from the MDL data object.
myData <- readDataObj(myDataObj)
Let's look at the first 6 lines of the data set
head(myData)
## ID TIME WT AGE SEX AMT OCC DV MDV
## 1 1 0.0 66.7 50 female 100 1 0.00000 1
## 2 1 0.5 66.7 50 female 0 1 -0.23526 0
## 3 1 1.0 66.7 50 female 0 1 5.68580 0
## 4 1 2.0 66.7 50 female 0 1 14.87200 0
## 5 1 3.0 66.7 50 female 0 1 12.81900 0
## 6 1 6.0 66.7 50 female 0 1 12.75200 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|OCC,groups=ID,data=myEDAData,type="b",ylab="Conc. (mg/L)",xlab="Time (h)",scales=list(relation="free"))
print(plot1)
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)
Export results to PDF file
pdf(paste0(uc,"_EGA.pdf"))
print(plot1)
print(plot2)
dev.off()
## png
## 2
mlx <- estimate(mdlfile, target="MONOLIX", subfolder="Monolix")
## -- Tue Aug 16 15:03:59 2016
## New
## Submitted
## Job de2733a5-f8ef-4cdf-bd02-191afe25f3c3 progress:
## Running [ ............... ]
## Importing Results
## Copying the result data back to the local machine for job ID de2733a5-f8ef-4cdf-bd02-191afe25f3c3...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356424da32da to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase8/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:09:06 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/UseCase8.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)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT
## 8.59584 1.00000 7.48435 0.10833 0.75000
## POP_TLAG BSV_V BSV_KA BSV_CL BSV_TLAG
## 1.12123 0.00005 2.06309 0.00050 0.01000
## COV_BSV_CL_V BOV_V BOV_CL RUV_ADD RUV_PROP
## -0.19056 0.16628 0.17703 0.31489 0.08215
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 BOV_CL 0.17703 0.05113 28.88
## 4 BOV_V 0.16628 0.04804 28.89
## 5 BSV_CL 0.00050 0.03666 7377.59
## 6 BSV_KA 2.06309 0.06872 3.33
## 7 BSV_TLAG 0.01000 0.00000 0.00
## 8 BSV_V 0.00005 0.03394 72148.31
## 9 COV_BSV_CL_V -0.19056 134.11375 70377.34
## 10 POP_CL 0.10833 0.00641 5.92
## 11 POP_KA 7.48435 2.98977 39.95
## 12 POP_TLAG 1.12123 0.03814 3.40
## 13 POP_V 8.59584 0.48671 5.66
## 14 RUV_ADD 0.31489 0.04375 13.89
## 15 RUV_PROP 0.08215 0.00800 9.74
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -800.295
##
##
## $OFMeasures$IndividualContribToLL
## Subject ICtoLL
## 1 1 -44.99
## 2 2 -17.20
## 3 3 -37.08
## 4 4 -46.24
## 5 5 -27.14
## 6 6 -26.98
## 7 7 -31.72
## 8 8 -33.04
## 9 9 -55.05
## 10 10 -28.10
## 11 12 -30.02
## 12 13 -45.01
## 13 14 -59.88
## 14 15 -45.74
## 15 16 -27.04
## 16 17 -20.45
## 17 18 -18.17
## 18 19 -17.68
## 19 20 -19.15
## 20 22 -16.87
## 21 23 -16.26
## 22 24 -21.42
## 23 25 -19.98
## 24 26 -20.26
## 25 28 -19.96
## 26 30 -16.64
## 27 32 -19.05
## 28 33 -19.18
##
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 1624.59
##
## $OFMeasures$InformationCriteria$BIC
## [1] 1648.9
##
##
##
## $Messages
## list()
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.
## Warning in mergeCheckColumnNames(df1, df2, ID.colName = ID.colName, TIME.colName = TIME.colName): The following duplicate column names were detected and will be dropped from the output:
## OCC
## Warning in mergeCheckColumnNames(df1, df2, ID.colName = ID.colName, TIME.colName = TIME.colName): The following duplicate column names were detected and will be dropped from the output:
## OCC
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()
## png
## 2
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:09:27 2016
## New
## Submitted
## Job 7c11b510-a3b5-46f6-acbc-fa4a3895e34b progress:
## Running [ ....................... ]
## Importing Results
## Copying the result data back to the local machine for job ID 7c11b510-a3b5-46f6-acbc-fa4a3895e34b...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35646a581c4 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase8/NONMEM
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## Estimation::PopulationEstimates::MLE
## Estimation::IndividualEstimates::Estimates
## Estimation::IndividualEstimates::RandomEffects
## Estimation::Residuals::ResidualTable
## Estimation::Predictions
## Estimation::OFMeasures::Deviance
##
## The following WARNINGs were raised during the job execution:
## Name change: Parameter label "OMEGA(6,6)" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_6_6_
## Name change: Parameter label "OMEGA(8,8)" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_8_8_
##
## 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:17:13 2016
The ddmore “LoadSOObj” reads and parsed existing Standardise Output Objects
NM <- LoadSOObject(“NONMEM/UseCase8.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 RUV_PROP
## 0.10749700 8.41037000 1.73247000 0.87796800 0.09654270
## RUV_ADD BETA_CL_WT BETA_V_WT BSV_CL COV_BSV_CL_V
## 0.31577000 0.75000000 1.00000000 0.01713800 0.01112120
## BSV_V BSV_KA BSV_TLAG BOV_CL OMEGA_6_6_
## 0.00721707 0.09996940 0.01000000 0.14436300 0.14436300
## BOV_V OMEGA_8_8_
## 0.18440600 0.18440600
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT
## 8.59584 1.00000 7.48435 0.10833 0.75000
## POP_TLAG BSV_V BSV_KA BSV_CL BSV_TLAG
## 1.12123 0.00005 2.06309 0.00050 0.01000
## COV_BSV_CL_V BOV_V BOV_CL RUV_ADD RUV_PROP
## -0.19056 0.16628 0.17703 0.31489 0.08215
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -375.6158
##
##
##
## $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"
##
##
## $Messages$Warnings
## $Messages$Warnings$`Name change`
## [1] "Parameter label \"OMEGA(8,8)\" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_8_8_"
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.
## Warning in mergeCheckColumnNames(df1, df2, ID.colName = ID.colName, TIME.colName = TIME.colName): The following duplicate column names were detected and will be dropped from the output:
## OCC
## Warning in mergeCheckColumnNames(df1, df2, ID.colName = ID.colName, TIME.colName = TIME.colName): The following duplicate column names were detected and will be dropped from the output:
## OCC
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))
print(basic.gof(nm.xpdb, by="OCC"))
print(ind.plots(nm.xpdb))
print(parm.hist(nm.xpdb))
Export results to a PDF file
pdf("GOF_NM.pdf")
print(basic.gof(nm.xpdb))
print(basic.gof(nm.xpdb, by="OCC"))
print(ind.plots(nm.xpdb))
print(parm.hist(nm.xpdb))
dev.off()
## png
## 2
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:17:40 2016
## New
## Submitted
## Job b72ea0c8-a430-4c3a-8e2a-ea3d121e4d74 progress:
## Running [ ....... ]
## Importing Results
## Copying the result data back to the local machine for job ID b72ea0c8-a430-4c3a-8e2a-ea3d121e4d74...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356475594ddf to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase8/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:
## estimation_successful: 0
## rounding_errors: 1
## hessian_reset: 6
## zero_gradients: 16
## final_zero_gradients: 1
## estimate_near_boundary: 1
## Name change: Parameter label "OMEGA(6,6)" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_6_6_
## Name change: Parameter label "OMEGA(8,8)" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_8_8_
##
## The following MESSAGEs were raised during the job execution:
## covariance_step_run: 0
## s_matrix_singular: 0
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 15:20:03 2016
Load previous results
NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase8_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
## 0.10765400 8.49874000 1.60377000 0.86818700 0.09694860
## RUV_ADD BETA_CL_WT BETA_V_WT BSV_CL COV_BSV_CL_V
## 0.31600700 0.75000000 1.00000000 0.01161790 0.00573471
## BSV_V BSV_KA BSV_TLAG BOV_CL OMEGA_6_6_
## 0.00284061 0.08430700 0.01000000 0.13599200 0.13599200
## BOV_V OMEGA_8_8_
## 0.18079900 0.18079900
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP
## 0.10749700 8.41037000 1.73247000 0.87796800 0.09654270
## RUV_ADD BETA_CL_WT BETA_V_WT BSV_CL COV_BSV_CL_V
## 0.31577000 0.75000000 1.00000000 0.01713800 0.01112120
## BSV_V BSV_KA BSV_TLAG BOV_CL OMEGA_6_6_
## 0.00721707 0.09996940 0.01000000 0.14436300 0.14436300
## BOV_V OMEGA_8_8_
## 0.18440600 0.18440600
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT
## 8.59584 1.00000 7.48435 0.10833 0.75000
## POP_TLAG BSV_V BSV_KA BSV_CL BSV_TLAG
## 1.12123 0.00005 2.06309 0.00050 0.01000
## COV_BSV_CL_V BOV_V BOV_CL RUV_ADD RUV_PROP
## -0.19056 0.16628 0.17703 0.31489 0.08215
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.
## Warning in mergeCheckColumnNames(df1, df2, ID.colName = ID.colName, TIME.colName = TIME.colName): The following duplicate column names were detected and will be dropped from the output:
## OCC
## Warning in mergeCheckColumnNames(df1, df2, ID.colName = ID.colName, TIME.colName = TIME.colName): The following duplicate column names were detected and will be dropped from the output:
## OCC
Basic diagnostics for NONMEM fit.
print(basic.gof(nmfocei.xpdb))
Export graphs to a PDF file
pdf("GOF_NM_FOCEI.pdf")
print(basic.gof(nmfocei.xpdb))
dev.off()
## png
## 2
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:20:10 2016
## New
## Submitted
## Job 930426a6-fe4a-4bde-9feb-e8bb0ad51fb5 progress:
## Running [ ..................................... ]
## Importing Results
## Copying the result data back to the local machine for job ID 930426a6-fe4a-4bde-9feb-e8bb0ad51fb5...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356479275ef to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase8/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:
## estimation_successful: 0
## rounding_errors: 1
## hessian_reset: 6
## zero_gradients: 16
## final_zero_gradients: 1
## estimate_near_boundary: 1
## Name change: Parameter label "OMEGA(6,6)" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_6_6_
## Name change: Parameter label "OMEGA(8,8)" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_8_8_
##
## The following MESSAGEs were raised during the job execution:
## covariance_step_run: 0
## s_matrix_singular: 0
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 15:32:34 2016
## Warning: NAs introduced by coercion
## [[1]]
##
## [[2]]
## NULL
##
## [[3]]
##
## [[4]]
## NULL
##
## [[5]]
## NULL
Load results from a bootstrap previously performed
bootstrapResults <- LoadSOObject(“Bootstrap/UseCase8_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
## 0.10765400 8.49874000 1.60377000 0.86818700 0.09694860
## RUV_ADD BETA_CL_WT BETA_V_WT BSV_CL COV_BSV_CL_V
## 0.31600700 0.75000000 1.00000000 0.01161790 0.00573471
## BSV_V BSV_KA BSV_TLAG BOV_CL OMEGA_6_6_
## 0.00284061 0.08430700 0.01000000 0.13599200 0.13599200
## BOV_V OMEGA_8_8_
## 0.18079900 0.18079900
##
## $Bootstrap
## Parameter Mean Median
## BETA_CL_WT BETA_CL_WT 0.750000000 0.750000000
## BETA_V_WT BETA_V_WT 1.000000000 1.000000000
## BOV_CL BOV_CL 0.125021900 0.125004000
## BOV_V BOV_V 0.167257000 0.176528500
## BSV_CL BSV_CL 0.020738130 0.013904600
## BSV_KA BSV_KA 0.051870250 0.072451550
## BSV_TLAG BSV_TLAG 0.010000000 0.010000000
## BSV_V BSV_V 0.004629412 0.002615225
## COV_BSV_CL_V COV_BSV_CL_V 0.004299062 0.002215090
## OMEGA_6_6_ OMEGA_6_6_ 0.125021900 0.125004000
## OMEGA_8_8_ OMEGA_8_8_ 0.167257000 0.176528500
## POP_CL POP_CL 0.107126600 0.107725000
## POP_KA POP_KA 1.566207000 1.544185000
## POP_TLAG POP_TLAG 0.824302300 0.841148500
## POP_V POP_V 8.291708000 8.305800000
## RUV_ADD RUV_ADD 0.362512000 0.357364000
## RUV_PROP RUV_PROP 0.094574080 0.092000100
Extract the information regarding the precision intervals
print(getPopulationParameters(bootstrapResults, what="intervals")$Bootstrap)
## Parameter Mean Median Perc_5 Perc_95
## 1 BETA_CL_WT 0.750000000 0.750000000 7.500000e-01 0.75000000
## 2 BETA_V_WT 1.000000000 1.000000000 1.000000e+00 1.00000000
## 3 BOV_CL 0.125021900 0.125004000 8.304487e-02 0.17199000
## 4 BOV_V 0.167257000 0.176528500 8.167527e-02 0.21465980
## 5 BSV_CL 0.020738130 0.013904600 1.000000e-05 0.06753287
## 6 BSV_KA 0.051870250 0.072451550 1.000000e-05 0.13108320
## 7 BSV_TLAG 0.010000000 0.010000000 1.000000e-02 0.01000000
## 8 BSV_V 0.004629412 0.002615225 9.931232e-06 0.01932321
## 9 COV_BSV_CL_V 0.004299062 0.002215090 -7.531800e-03 0.01899782
## 10 OMEGA_6_6_ 0.125021900 0.125004000 8.304487e-02 0.17199000
## 11 OMEGA_8_8_ 0.167257000 0.176528500 8.167527e-02 0.21465980
## 12 POP_CL 0.107126600 0.107725000 9.175291e-02 0.11957350
## 13 POP_KA 1.566207000 1.544185000 1.217220e+00 1.90200400
## 14 POP_TLAG 0.824302300 0.841148500 5.077280e-01 0.99684000
## 15 POP_V 8.291708000 8.305800000 7.421821e+00 9.22034800
## 16 RUV_ADD 0.362512000 0.357364000 1.182200e-01 0.57709280
## 17 RUV_PROP 0.094574080 0.092000100 6.085998e-02 0.13466380
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, a between occassion variability parameter is recorded for each OCC when MDL only specifies one. 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 has parameter BOV_CL_BOV_V. This needs to be renamed to conform to model Correlation name OMEGA
variabilityNames <- names(myParObj@VARIABILITY)
variabilityPar <- variabilityPar[variabilityNames]
variabilityPar
## BSV_CL BSV_V COV_BSV_CL_V BOV_CL BOV_V
## 0.01161790 0.00284061 0.00573471 0.13599200 0.18079900
## BSV_KA BSV_TLAG RUV_PROP RUV_ADD
## 0.08430700 0.01000000 0.09694860 0.31600700
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.107654"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "8.49874"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "1.60377"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.868187"
##
## $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)
## $BSV_CL
## $BSV_CL$value
## [1] "0.0116179"
##
##
## $BSV_V
## $BSV_V$value
## [1] "0.00284061"
##
##
## $COV_BSV_CL_V
## $COV_BSV_CL_V$value
## [1] "0.00573471"
##
##
## $BOV_CL
## $BOV_CL$value
## [1] "0.135992"
##
##
## $BOV_V
## $BOV_V$value
## [1] "0.180799"
##
##
## $BSV_KA
## $BSV_KA$value
## [1] "0.084307"
##
##
## $BSV_TLAG
## $BSV_TLAG$value
## [1] "0.01"
##
## $BSV_TLAG$fix
## [1] "true"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0969486"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.316007"
##
## $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 -stratify_on=OCC",
subfolder="VPC", plot=TRUE)
## -- Tue Aug 16 15:32:48 2016
## New
## Submitted
## Job 4cb7c83f-634c-44e5-ab0f-ffefd71d5542 progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 4cb7c83f-634c-44e5-ab0f-ffefd71d5542...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job3564279b5bba to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase8/VPC
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## SimulationSimulationBlock
## SimulationSimulationBlock
##
## The following WARNINGs were raised during the job execution:
## Name change: Parameter label "OMEGA(6,6)" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_6_6_
## Name change: Parameter label "OMEGA(8,8)" not specified or not a legal symbolIdType. Setting/changing it to: OMEGA_8_8_
##
## 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:34:11 2016
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
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
## 0.10765400 8.49874000 1.60377000 0.86818700 0.09694860
## RUV_ADD BETA_CL_WT BETA_V_WT BSV_CL COV_BSV_CL_V
## 0.31600700 0.75000000 1.00000000 0.01161790 0.00573471
## BSV_V BSV_KA BSV_TLAG BOV_CL OMEGA_6_6_
## 0.00284061 0.08430700 0.01000000 0.13599200 0.13599200
## BOV_V OMEGA_8_8_ WT
## 0.18079900 0.18079900 70.00000000
Simulate for a dose of 100mg given at time 0 into the GUT (oral administration)
adm <- list(type=1, 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))
Define a varlevel (ID, OCC)
vl <- list(time=c(0,20), name = 'occ')
Simulate 12 subjects
g <- list( size = 12, level = 'individual', treatment = adm)
Call simulx
res <- simulx(model = myPharmML,
varlevel = vl,
parameter = p,
group = g,
output = list(ind,f,y))
Simulated parameter values for each individual
print(res$parameter)
## id time occ CL V
## 1 1 0 1 0.10244221 7.596627
## 2 1 20 2 0.10542580 10.350770
## 3 2 0 1 0.12017490 7.253387
## 4 2 20 2 0.12989547 20.485263
## 5 3 0 1 0.10032233 7.000948
## 6 3 20 2 0.10719447 4.855010
## 7 4 0 1 0.06975548 6.032570
## 8 4 20 2 0.17417837 8.962542
## 9 5 0 1 0.09826270 6.383978
## 10 5 20 2 0.08530869 18.833919
## 11 6 0 1 0.08139053 8.875907
## 12 6 20 2 0.22647883 5.122665
## 13 7 0 1 0.09996817 5.561151
## 14 7 20 2 0.09092070 3.658492
## 15 8 0 1 0.12048452 15.258213
## 16 8 20 2 0.06167403 6.596337
## 17 9 0 1 0.08841777 14.990048
## 18 9 20 2 0.11606069 7.029747
## 19 10 0 1 0.17552216 6.469904
## 20 10 20 2 0.16037116 8.896697
## 21 11 0 1 0.17292700 13.041433
## 22 11 20 2 0.18204104 18.545997
## 23 12 0 1 0.05089589 4.600040
## 24 12 20 2 0.09578542 9.445735
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,
varlevel = vl,
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)))
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.6675970 -0.3893490 -0.2770639 -0.20204216 -0.076862378
## 2 0.5 -0.7171826 -0.3441493 -0.1969014 -0.09217686 -0.001038873
## 3 1.0 -0.4845512 0.3292093 0.6690394 0.92511222 1.186947741
## 4 2.0 3.2453886 5.0569583 6.2181194 7.22560506 7.919226614
## 5 3.0 4.3105118 5.8143015 7.1276934 8.06603820 8.675571085
## 6 4.0 3.5282202 6.5380003 7.6958544 8.43404829 9.250557498
## 7 6.0 3.6636547 6.1142584 7.1151334 8.56539332 9.526902067
## 8 8.0 3.0396481 5.7593859 6.9853183 8.03557329 9.109451886
## 9 12.0 3.4134747 5.9532848 6.8558701 8.21395952 9.069037316
## 10 24.0 2.4485005 4.8335180 5.6900931 6.28071585 7.135451470
## 11 36.0 1.6224182 4.0266771 4.7126886 5.73054560 6.310645792
## 12 48.0 1.1921365 2.6650093 3.5743182 4.60443760 5.479547526
## 50% 50% 60% 70% 80% 90%
## 1 -0.03819879 -0.03819879 0.04787303 0.1042791 0.1875122 0.3940907
## 2 0.04616350 0.04616350 0.08673767 0.1745893 0.2834916 0.3827955
## 3 1.67025051 1.67025051 1.92045266 2.5731564 3.1121236 3.8247268
## 4 8.88545951 8.88545951 10.07577343 11.9564795 13.0355463 15.6260955
## 5 10.68692744 10.68692744 12.32518386 13.3944069 14.9967849 19.8530378
## 6 10.84837431 10.84837431 11.99109645 13.4530370 15.6604290 19.7125022
## 7 10.77033328 10.77033328 12.24275198 13.2984038 14.9832177 19.1532520
## 8 9.77051534 9.77051534 11.21094337 12.4230094 14.5679518 18.8604898
## 9 10.05997184 10.05997184 10.89377747 12.0101220 13.5822036 17.1077248
## 10 7.92299038 7.92299038 8.91152009 10.4600606 12.5890867 15.7225529
## 11 7.10917068 7.10917068 7.70551864 8.8801954 10.9846403 13.9558678
## 12 6.32913599 6.32913599 7.23652849 8.7438275 10.0544032 12.6511396
## 100%
## 1 0.8585940
## 2 0.7834229
## 3 9.6110400
## 4 26.9686242
## 5 37.1569185
## 6 42.0421803
## 7 28.4475086
## 8 26.9473581
## 9 24.0993872
## 10 29.6514373
## 11 25.2577511
## 12 18.3750044