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<-"UseCase7"
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))
List files available in working directory
list.files()
## [1] "UseCase7.mdl" "warfarin_conc.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_dat" "warfarin_PK_Compartments_par"
## [3] "warfarin_PK_Compartments_mdl" "warfarin_PK_ODE_task"
Use 'ddmore' function getDataObjects() to retrieve only data object(s) from an existing .mdl file. This function returns a list of Parameter Object(s) from which we select the first element. Hover over the variable name to see its structure
myDataObj <- getDataObjects(mdlfile)[[1]]
Use 'ddmore' function getParameterObjects() to retrieve only parameter object(s) from an existing .mdl file
myParObj <- getParameterObjects(mdlfile)[[1]]
Use 'ddmore' function getModelObjects() to retrieve only model object(s) from an existing .mdl file.
myModObj <- getModelObjects(mdlfile)[[1]]
Use 'ddmore' function getTaskPropertiesObjects() to retrieve only task properties object(s) from an existing .mdl file
myTaskObj <- getTaskPropertiesObjects(mdlfile)[[1]]
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 DVID DV MDV logtWT
## 1 1 0.0 66.7 100 0 NA 1 -0.04829029
## 2 1 0.5 66.7 NA 1 0.0 0 -0.04829029
## 3 1 1.0 66.7 NA 1 1.9 0 -0.04829029
## 4 1 2.0 66.7 NA 1 3.3 0 -0.04829029
## 5 1 3.0 66.7 NA 1 6.6 0 -0.04829029
## 6 1 6.0 66.7 NA 1 9.1 0 -0.04829029
Extract only observation records
myEDAData<-myData[myData$MDV==0,]
Open an R window to record and access all your plots
windows(record=TRUE)
Plot the data using xyplot from the lattice library
plot1 <- xyplot(DV~TIME,groups=ID,data=myEDAData,type="b",ylab="Conc. (mg/L)",xlab="Time (h)")
print(plot1)
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 the results in a pdf file
pdf(paste0(uc,"_EGA.pdf"))
print(plot1)
print(plot2)
dev.off()
## png
## 2
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 13:03:16 2016
## New
## Submitted
## Job c1333b22-a68a-494d-a83d-5fc05afe5520 progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID c1333b22-a68a-494d-a83d-5fc05afe5520...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35645cad18c8 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase7/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 13:04:38 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/UseCase7.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
parameters_mlx
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_F1
## 8.10773 1.00000 2.47110 0.13382 0.75000 1.00000
## POP_TLAG PPV_V PPV_KA PPV_CL PPV_TLAG CORR_CL_V
## 1.00232 0.13771 1.38800 0.26414 0.10000 0.24097
## RUV_ADD RUV_PROP
## 0.21480 0.06816
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.24097 0.19588 81.29
## 4 POP_CL 0.13382 0.00637 4.76
## 5 POP_F1 1.00000 0.00000 0.00
## 6 POP_KA 2.47110 1.33897 54.18
## 7 POP_TLAG 1.00232 0.05617 5.60
## 8 POP_V 8.10773 0.22635 2.79
## 9 PPV_CL 0.26414 0.03429 12.98
## 10 PPV_KA 1.38800 0.38918 28.04
## 11 PPV_TLAG 0.10000 0.00000 0.00
## 12 PPV_V 0.13771 0.02246 16.31
## 13 RUV_ADD 0.21480 0.04371 20.35
## 14 RUV_PROP 0.06816 0.00916 13.44
getEstimationInfo(mlx)
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -334.635
##
##
## $OFMeasures$IndividualContribToLL
## Subject ICtoLL
## 1 1 -25.73
## 2 2 -5.25
## 3 3 -13.35
## 4 4 -12.42
## 5 5 -11.11
## 6 6 -7.29
## 7 7 -18.95
## 8 8 -20.86
## 9 9 -31.76
## 10 10 -5.77
## 11 12 -19.75
## 12 13 -18.63
## 13 14 -18.82
## 14 15 -11.58
## 15 16 -14.49
## 16 17 -5.73
## 17 18 -5.04
## 18 19 -6.69
## 19 20 -5.05
## 20 21 -5.97
## 21 22 -5.79
## 22 23 -8.07
## 23 24 -4.89
## 24 25 -7.20
## 25 26 -7.21
## 26 27 -5.35
## 27 28 -6.83
## 28 29 -5.62
## 29 30 -4.55
## 30 31 -5.04
## 31 32 -4.74
## 32 33 -5.10
##
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 689.27
##
## $OFMeasures$InformationCriteria$BIC
## [1] 703.93
##
##
##
## $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.
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)
pdf("GOF_MLX.pdf")
basic.gof(mlx.xpdb)
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 13:04:40 2016
## New
## Submitted
## Job a9a33dff-e8ca-4249-9f5b-8ad3aaed082e progress:
## Running [ ..... ]
## Importing Results
## Copying the result data back to the local machine for job ID a9a33dff-e8ca-4249-9f5b-8ad3aaed082e...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35646b07249 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase7/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 13:06:23 2016
The ddmore “LoadSOObj” reads and parsed existing Standardise Output Objects
NM <- LoadSOObject(“NONMEM/UseCase7.SO.xml”)
parameters_nm <- getPopulationParameters(NM,what="estimates")$MLE
print(parameters_nm)
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.132954000 8.173140000 1.749320000 0.945971000 0.108251000 0.000100001
## POP_F1 BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 1.000000000 0.750000000 1.000000000 0.263455000 0.277717000 0.136488000
## PPV_KA PPV_TLAG
## 0.947330000 0.100000000
print(parameters_mlx)
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_F1
## 8.10773 1.00000 2.47110 0.13382 0.75000 1.00000
## POP_TLAG PPV_V PPV_KA PPV_CL PPV_TLAG CORR_CL_V
## 1.00232 0.13771 1.38800 0.26414 0.10000 0.24097
## RUV_ADD RUV_PROP
## 0.21480 0.06816
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -310.3207
##
##
##
## $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"
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))
print(ind.plots(nm.xpdb))
print(parm.hist(nm.xpdb))
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
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 13:06:41 2016
## New
## Submitted
## Job ba4e4ab6-b24e-4f56-bc41-7eea90f8feff progress:
## Running [ .. ]
## Importing Results
## Copying the result data back to the local machine for job ID ba4e4ab6-b24e-4f56-bc41-7eea90f8feff...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35645f537153 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase7/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: 4.2
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 13:07:23 2016
Load previous results
NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase7_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.1341360 8.1009100 1.5617100 0.9677450 0.0716038 0.1932260
## POP_F1 BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 1.0000000 0.7500000 1.0000000 0.2637860 0.2425380 0.1348310
## PPV_KA PPV_TLAG
## 0.9360370 0.1000000
print(parameters_nm)
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.132954000 8.173140000 1.749320000 0.945971000 0.108251000 0.000100001
## POP_F1 BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 1.000000000 0.750000000 1.000000000 0.263455000 0.277717000 0.136488000
## PPV_KA PPV_TLAG
## 0.947330000 0.100000000
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))
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 13:07:27 2016
## New
## Submitted
## Job 271b67ac-89fc-4d7b-921f-d3544a2686cf progress:
## Running [ ....... ]
## Importing Results
## Copying the result data back to the local machine for job ID 271b67ac-89fc-4d7b-921f-d3544a2686cf...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356466917354 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase7/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: 4.2
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 13:09:50 2016
## Warning: NAs introduced by coercion
## [[1]]
##
## [[2]]
## NULL
##
## [[3]]
##
## [[4]]
## NULL
##
## [[5]]
## NULL
Load results from a bootstrap previously performed
bootstrapResults <- LoadSOObject(“Bootstrap/UseCase7_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.1341360 8.1009100 1.5617100 0.9677450 0.0716038 0.1932260
## POP_F1 BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 1.0000000 0.7500000 1.0000000 0.2637860 0.2425380 0.1348310
## PPV_KA PPV_TLAG
## 0.9360370 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.005750799 0.00564692
## POP_CL POP_CL 0.134616500 0.13647200
## POP_F1 POP_F1 1.000000000 1.00000000
## POP_KA POP_KA 1.505258000 1.41767500
## POP_TLAG POP_TLAG 0.929751300 0.93550350
## POP_V POP_V 8.112643000 8.03167000
## PPV_CL PPV_CL 0.070234170 0.06764700
## PPV_KA PPV_KA 0.584371900 0.54790300
## PPV_TLAG PPV_TLAG 0.010000000 0.01000000
## PPV_V PPV_V 0.014625210 0.01407655
## RUV_ADD RUV_ADD 0.113435900 0.07271430
## RUV_PROP RUV_PROP 0.093185120 0.09585170
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.005750799 0.00564692 -0.0041095320 0.01431807
## 4 POP_CL 0.134616500 0.13647200 0.1129542000 0.14712140
## 5 POP_F1 1.000000000 1.00000000 1.0000000000 1.00000000
## 6 POP_KA 1.505258000 1.41767500 0.8082667000 3.04456700
## 7 POP_TLAG 0.929751300 0.93550350 0.7726145000 1.00541500
## 8 POP_V 8.112643000 8.03167000 7.6788860000 8.59129700
## 9 PPV_CL 0.070234170 0.06764700 0.0241277000 0.12453910
## 10 PPV_KA 0.584371900 0.54790300 0.0005248084 1.67861400
## 11 PPV_TLAG 0.010000000 0.01000000 0.0100000000 0.01000000
## 12 PPV_V 0.014625210 0.01407655 0.0071648030 0.02859239
## 13 RUV_ADD 0.113435900 0.07271430 0.0010990000 0.32173970
## 14 RUV_PROP 0.093185120 0.09585170 0.0482136000 0.14126890
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.134136"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "8.10091"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "1.56171"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.967745"
##
## $POP_TLAG$lo
## [1] "0.001"
##
##
## $POP_F1
## $POP_F1$value
## [1] "1"
##
## $POP_F1$fix
## [1] "true"
##
##
## $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.263786"
##
##
## $PPV_V
## $PPV_V$value
## [1] "0.134831"
##
##
## $PPV_KA
## $PPV_KA$value
## [1] "0.936037"
##
##
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
##
## $PPV_TLAG$fix
## [1] "true"
##
##
## $CORR_CL_V
## $CORR_CL_V$value
## [1] "0.242538"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0716038"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.193226"
##
## $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 13:10:03 2016
## New
## Submitted
## Job 0045baf2-e656-4fcb-be92-f043a53e98a4 progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID 0045baf2-e656-4fcb-be92-f043a53e98a4...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35641d4960ef to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase7/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 13:11:05 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,logtWT=0)
Parameter values used in simulation
print(p)
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.1341360 8.1009100 1.5617100 0.9677450 0.0716038 0.1932260
## POP_F1 BETA_CL_WT BETA_V_WT PPV_CL CORR_CL_V PPV_V
## 1.0000000 0.7500000 1.0000000 0.2637860 0.2425380 0.1348310
## PPV_KA PPV_TLAG logtWT
## 0.9360370 0.1000000 0.0000000
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(type=1, 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,f))
Simulated parameter values for each individual
print(res$parameter)
## id TLAG KA CL V
## 1 1 0.9861218 1.4286223 0.11784582 8.886080
## 2 2 0.9190286 5.6400807 0.09214690 6.255916
## 3 3 1.3349890 2.6380193 0.13988075 7.733947
## 4 4 0.8690646 5.4701217 0.15587915 8.450390
## 5 5 0.7989207 0.7546081 0.18540489 8.077224
## 6 6 0.9718773 2.1640347 0.21814055 8.451690
## 7 7 0.7864084 2.3082393 0.23786147 9.650570
## 8 8 1.0106150 1.9142694 0.26330568 7.862231
## 9 9 0.9330995 0.5820375 0.09547058 9.231371
## 10 10 1.0270264 6.1631955 0.11633405 7.648809
## 11 11 0.9239469 1.7104466 0.12664233 7.790393
## 12 12 0.8641969 0.7722433 0.14644074 8.381979
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,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.4082097 -0.23807178 -0.16941383 -0.12354093 -0.0521384864
## 2 0.5 -0.4385293 -0.21043393 -0.12039753 -0.05636257 -0.0006352302
## 3 1.0 -0.4483055 -0.08173416 0.01545145 0.17644583 0.3945920942
## 4 2.0 1.7626055 4.70969568 6.60006873 8.14554916 9.0233426056
## 5 3.0 3.1906167 7.64388817 9.00825258 10.07995360 10.6581730746
## 6 4.0 5.9875491 9.08682835 9.79127423 10.41408318 10.7013207127
## 7 6.0 6.7385865 9.28328476 9.96915402 10.47738527 10.8322507287
## 8 8.0 7.0981753 8.91956526 9.60067915 9.97200076 10.4654226104
## 9 12.0 6.7208196 8.75034987 9.32405535 9.69521944 10.1068798162
## 10 24.0 4.9833753 6.66078449 7.37601106 7.59110380 8.0580755042
## 11 36.0 3.6227165 5.30493767 5.82907396 6.20056107 6.5735509557
## 12 48.0 2.4960288 4.01401757 4.67675014 5.11665442 5.3291945824
## 50% 50% 60% 70% 80% 90%
## 1 -0.02541085 -0.02541085 0.01534420 0.05938699 0.1121857 0.2409712
## 2 0.02962179 0.02962179 0.05632682 0.10796407 0.1764253 0.2417221
## 3 0.70309779 0.70309779 0.98651866 1.35306045 2.3800631 4.4976771
## 4 9.87323346 9.87323346 10.26263289 10.69957039 11.2171608 12.4155361
## 5 11.15072915 11.15072915 11.68625041 12.05954226 12.4433313 13.4505346
## 6 11.18710215 11.18710215 11.97243992 12.72223918 13.0732758 13.3815267
## 7 11.27516150 11.27516150 11.88760972 12.24949226 12.5944127 13.7529080
## 8 10.73853468 10.73853468 11.18444468 11.85425754 12.2803888 13.0106827
## 9 10.42749881 10.42749881 10.93552300 11.25362287 11.7935899 12.6484881
## 10 8.33671298 8.33671298 8.70536841 8.96546426 9.4811594 10.4515332
## 11 6.91228323 6.91228323 7.28009238 7.58347041 8.0655068 8.9144817
## 12 5.56339616 5.56339616 5.96448961 6.39165624 6.6521519 7.4024209
## 100%
## 1 0.5249969
## 2 0.4790326
## 3 7.3451095
## 4 16.3646369
## 5 16.3121626
## 6 16.2005168
## 7 16.2408663
## 8 14.9011574
## 9 14.5173087
## 10 12.6104656
## 11 11.9198117
## 12 10.3258922