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)
Set name of .mdl file and dataset for future tasks
uc<-"UseCase6"
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] "UseCase6.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_COV_par" "warfarin_PK_VCOV_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]]
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 12:49:36 2016
## New
## Submitted
## Job 1d2c327f-b57b-4b79-b0c7-c3abeeacaf0b progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 1d2c327f-b57b-4b79-b0c7-c3abeeacaf0b...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35644f4612ef to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase6/Monolix
## Done.
##
##
## The following main elements were parsed successfully:
## ToolSettings
## RawResults
## Estimation::PopulationEstimates::MLE
## Estimation::PrecisionPopulationEstimates::MLE
## Estimation::IndividualEstimates::Estimates
## Estimation::IndividualEstimates::RandomEffects
## Estimation::Residuals::ResidualTable
## Estimation::Predictions
## Estimation::OFMeasures::IndividualContribToLL
## Estimation::OFMeasures::InformationCriteria
## Estimation::OFMeasures::LogLikelihood
##
## Completed
## -- Tue Aug 16 12:50:59 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/UseCase6.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 POP_TLAG
## 8.08521 1.00000 1.49922 0.13283 0.75000 0.84769
## PPV_V PPV_KA PPV_CL PPV_TLAG COV_V_KA COV_CL_V
## 0.01680 0.50577 0.06995 0.10000 -0.25559 0.23523
## COV_CL_KA RUV_ADD RUV_PROP
## -0.32752 0.14046 0.08026
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 COV_CL_KA -0.32752 0.35741 109.13
## 4 COV_CL_V 0.23523 0.19874 84.49
## 5 COV_V_KA -0.25559 0.40507 158.49
## 6 POP_CL 0.13283 0.00632 4.76
## 7 POP_KA 1.49922 0.42163 28.12
## 8 POP_TLAG 0.84769 0.12035 14.20
## 9 POP_V 8.08521 0.21572 2.67
## 10 PPV_CL 0.06995 0.01810 25.88
## 11 PPV_KA 0.50577 0.32413 64.09
## 12 PPV_TLAG 0.10000 0.00000 0.00
## 13 PPV_V 0.01680 0.00565 33.66
## 14 RUV_ADD 0.14046 0.03490 24.85
## 15 RUV_PROP 0.08026 0.00843 10.51
print(getEstimationInfo(mlx))
## $OFMeasures
## $OFMeasures$LogLikelihood
## $OFMeasures$LogLikelihood[[1]]
## [1] -319.985
##
##
## $OFMeasures$IndividualContribToLL
## Subject ICtoLL
## 1 1 -18.79
## 2 2 -5.11
## 3 3 -12.21
## 4 4 -12.01
## 5 5 -10.93
## 6 6 -7.36
## 7 7 -21.17
## 8 8 -21.49
## 9 9 -30.55
## 10 10 -5.72
## 11 12 -18.92
## 12 13 -14.90
## 13 14 -16.61
## 14 15 -12.33
## 15 16 -13.40
## 16 17 -5.60
## 17 18 -4.98
## 18 19 -7.07
## 19 20 -5.07
## 20 21 -5.92
## 21 22 -6.00
## 22 23 -8.00
## 23 24 -4.75
## 24 25 -7.30
## 25 26 -7.25
## 26 27 -5.23
## 27 28 -6.78
## 28 29 -5.51
## 29 30 -4.46
## 30 31 -4.95
## 31 32 -4.63
## 32 33 -4.97
##
## $OFMeasures$InformationCriteria
## $OFMeasures$InformationCriteria$AIC
## [1] 663.97
##
## $OFMeasures$InformationCriteria$BIC
## [1] 681.56
##
##
##
## $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)
print(basic.gof(mlx.xpdb))
print(ind.plots(mlx.xpdb))
Export graphs to a 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 12:51:04 2016
## New
## Submitted
## Job 1fa33f48-4900-406e-a0ed-bd63fc1d4fcc progress:
## Running [ .... ]
## Importing Results
## Copying the result data back to the local machine for job ID 1fa33f48-4900-406e-a0ed-bd63fc1d4fcc...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356437e52eaa to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase6/NONMEM
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## Estimation::PopulationEstimates::MLE
## Estimation::IndividualEstimates::Estimates
## Estimation::IndividualEstimates::RandomEffects
## Estimation::Residuals::ResidualTable
## Estimation::Predictions
## Estimation::OFMeasures::Deviance
##
## The following MESSAGEs were raised during the job execution:
## estimation_successful: 1
## covariance_step_run: 0
## rounding_errors: 0
## estimate_near_boundary: 0
## s_matrix_singular: 0
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 12:52:26 2016
Load previous results
NM <- LoadSOObject(“NONMEM/UseCase6.SO.xml”)
parameters_nm <- getPopulationParameters(NM, what="estimates")
print(parameters_nm)
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP
## 1.32208e-01 8.14851e+00 1.33317e+00 7.49357e-01 1.12517e-01
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL COV_CL_V
## 2.01662e-09 7.50000e-01 1.00000e+00 6.68421e-02 9.75709e-03
## PPV_V COV_CL_KA COV_V_KA PPV_KA PPV_TLAG
## 1.69028e-02 -6.19098e-02 -3.27767e-02 4.32279e-01 1.00000e-01
print(parameters_mlx)
## $MLE
## POP_V BETA_V_WT POP_KA POP_CL BETA_CL_WT POP_TLAG
## 8.08521 1.00000 1.49922 0.13283 0.75000 0.84769
## PPV_V PPV_KA PPV_CL PPV_TLAG COV_V_KA COV_CL_V
## 0.01680 0.50577 0.06995 0.10000 -0.25559 0.23523
## COV_CL_KA RUV_ADD RUV_PROP
## -0.32752 0.14046 0.08026
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] -437.0003
##
##
##
## $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 12:52:41 2016
## New
## Submitted
## Job 035942f6-319c-4fb9-9555-b1d8322917d6 progress:
## Running [ .. ]
## Importing Results
## Copying the result data back to the local machine for job ID 035942f6-319c-4fb9-9555-b1d8322917d6...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job35645efe6c13 to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase6/NONMEM_FOCEI
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## Estimation::PopulationEstimates::MLE
## Estimation::IndividualEstimates::Estimates
## Estimation::IndividualEstimates::RandomEffects
## Estimation::Residuals::ResidualTable
## Estimation::Predictions
## Estimation::OFMeasures::Deviance
##
## The following MESSAGEs were raised during the job execution:
## estimation_successful: 1
## covariance_step_run: 0
## rounding_errors: 0
## hessian_reset: 0
## zero_gradients: 0
## final_zero_gradients: 0
## estimate_near_boundary: 0
## s_matrix_singular: 0
## significant_digits: 3.2
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 12:53:23 2016
Load previous results
NM.FOCEI <- LoadSOObject(“NONMEM_FOCEI/UseCase6_FOCEI.SO.xml”)
Results from NONMEM should be comparable to previous results
getPopulationParameters(NM.FOCEI, what="estimates")
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP RUV_ADD
## 0.13330800 8.09650000 2.42977000 0.87078700 0.08588440 0.10681000
## BETA_CL_WT BETA_V_WT PPV_CL COV_CL_V PPV_V COV_CL_KA
## 0.75000000 1.00000000 0.06944200 0.00785012 0.01748590 -0.10244000
## COV_V_KA PPV_KA PPV_TLAG
## 0.03209470 1.26856000 0.10000000
parameters_nm
## $MLE
## POP_CL POP_V POP_KA POP_TLAG RUV_PROP
## 1.32208e-01 8.14851e+00 1.33317e+00 7.49357e-01 1.12517e-01
## RUV_ADD BETA_CL_WT BETA_V_WT PPV_CL COV_CL_V
## 2.01662e-09 7.50000e-01 1.00000e+00 6.68421e-02 9.75709e-03
## PPV_V COV_CL_KA COV_V_KA PPV_KA PPV_TLAG
## 1.69028e-02 -6.19098e-02 -3.27767e-02 4.32279e-01 1.00000e-01
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 12:53:26 2016
## New
## Submitted
## Job 7121a2c6-591d-441c-a59d-db3b6e74c7ce progress:
## Running [ ........ ]
## Importing Results
## Copying the result data back to the local machine for job ID 7121a2c6-591d-441c-a59d-db3b6e74c7ce...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356421c95e9a to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase6/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 MESSAGEs were raised during the job execution:
## estimation_successful: 1
## covariance_step_run: 0
## rounding_errors: 0
## hessian_reset: 0
## zero_gradients: 0
## final_zero_gradients: 0
## estimate_near_boundary: 0
## s_matrix_singular: 0
## significant_digits: 3.2
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 12:56:10 2016
## Warning: NAs introduced by coercion
## [[1]]
##
## [[2]]
## NULL
##
## [[3]]
##
## [[4]]
## NULL
##
## [[5]]
## NULL
Load results from a bootstrap previously performed
bootstrapResults <- LoadSOObject(“Bootstrap/UseCase6_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.13330800 8.09650000 2.42977000 0.87078700 0.08588440 0.10681000
## BETA_CL_WT BETA_V_WT PPV_CL COV_CL_V PPV_V COV_CL_KA
## 0.75000000 1.00000000 0.06944200 0.00785012 0.01748590 -0.10244000
## COV_V_KA PPV_KA PPV_TLAG
## 0.03209470 1.26856000 0.10000000
##
## $Bootstrap
## Parameter Mean Median
## BETA_CL_WT BETA_CL_WT 0.750000000 0.750000000
## BETA_V_WT BETA_V_WT 1.000000000 1.000000000
## COV_CL_KA COV_CL_KA -0.055342372 -0.061038850
## COV_CL_V COV_CL_V 0.005459428 0.004788685
## COV_V_KA COV_V_KA 0.025764330 0.023972250
## POP_CL POP_CL 0.134930900 0.136003000
## POP_KA POP_KA 1.826123000 1.599315000
## POP_TLAG POP_TLAG 0.860107900 0.846569500
## POP_V POP_V 8.061713000 7.998770000
## PPV_CL PPV_CL 0.073844440 0.079305700
## PPV_KA PPV_KA 0.720084800 0.652388000
## PPV_TLAG PPV_TLAG 0.100000000 0.100000000
## PPV_V PPV_V 0.015463340 0.015415500
## RUV_ADD RUV_ADD 0.103770200 0.127975500
## RUV_PROP RUV_PROP 0.090400720 0.087055850
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 0.750000000 0.75000000
## 2 BETA_V_WT 1.000000000 1.000000000 1.000000000 1.00000000
## 3 COV_CL_KA -0.055342372 -0.061038850 -0.276082850 0.08568050
## 4 COV_CL_V 0.005459428 0.004788685 -0.004479309 0.01480269
## 5 COV_V_KA 0.025764330 0.023972250 -0.069446230 0.13410720
## 6 POP_CL 0.134930900 0.136003000 0.124275900 0.14685000
## 7 POP_KA 1.826123000 1.599315000 0.867710300 4.01230900
## 8 POP_TLAG 0.860107900 0.846569500 0.720892900 1.00746700
## 9 POP_V 8.061713000 7.998770000 7.694330000 8.53056800
## 10 PPV_CL 0.073844440 0.079305700 0.029616610 0.12524730
## 11 PPV_KA 0.720084800 0.652388000 0.187502800 1.44519200
## 12 PPV_TLAG 0.100000000 0.100000000 0.100000000 0.10000000
## 13 PPV_V 0.015463340 0.015415500 0.008167550 0.02678049
## 14 RUV_ADD 0.103770200 0.127975500 0.001000000 0.26657310
## 15 RUV_PROP 0.090400720 0.087055850 0.058423380 0.13516620
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.133308"
##
## $POP_CL$lo
## [1] "0.001"
##
##
## $POP_V
## $POP_V$value
## [1] "8.0965"
##
## $POP_V$lo
## [1] "0.001"
##
##
## $POP_KA
## $POP_KA$value
## [1] "2.42977"
##
## $POP_KA$lo
## [1] "0.001"
##
##
## $POP_TLAG
## $POP_TLAG$value
## [1] "0.870787"
##
## $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.069442"
##
##
## $PPV_V
## $PPV_V$value
## [1] "0.0174859"
##
##
## $PPV_KA
## $PPV_KA$value
## [1] "1.26856"
##
##
## $PPV_TLAG
## $PPV_TLAG$value
## [1] "0.1"
##
## $PPV_TLAG$fix
## [1] "true"
##
##
## $COV_CL_V
## $COV_CL_V$value
## [1] "0.00785012"
##
##
## $COV_CL_KA
## $COV_CL_KA$value
## [1] "-0.10244"
##
##
## $COV_V_KA
## $COV_V_KA$value
## [1] "0.0320947"
##
##
## $RUV_PROP
## $RUV_PROP$value
## [1] "0.0858844"
##
## $RUV_PROP$lo
## [1] "0"
##
##
## $RUV_ADD
## $RUV_ADD$value
## [1] "0.10681"
##
## $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",
subfolder="VPC", plot=TRUE)
## -- Tue Aug 16 12:56:21 2016
## New
## Submitted
## Job e14f9c34-8259-4df5-b11a-19987c045372 progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID e14f9c34-8259-4df5-b11a-19987c045372...
## From C:\Users\smith_mk\AppData\Local\Temp\4\RtmpYF4SFO\DDMORE.job356413f7692c to C:/SEE/MDL_IDE/workspace/UseCasesDemo/UseCase6/VPC
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## SimulationSimulationBlock
## SimulationSimulationBlock
##
## The following MESSAGEs were raised during the job execution:
## nmoutput2so_version: This SOBlock was created with nmoutput2so version 4.5.27
##
## Completed
## -- Tue Aug 16 12:57:24 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.13330800 8.09650000 2.42977000 0.87078700 0.08588440 0.10681000
## BETA_CL_WT BETA_V_WT PPV_CL COV_CL_V PPV_V COV_CL_KA
## 0.75000000 1.00000000 0.06944200 0.00785012 0.01748590 -0.10244000
## COV_V_KA PPV_KA PPV_TLAG logtWT
## 0.03209470 1.26856000 0.10000000 0.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('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 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)
## id TLAG KA CL V
## 1 1 0.6621457 2.5337911 0.14827127 7.842324
## 2 2 1.4003137 1.5811096 0.12319921 6.503757
## 3 3 0.9899196 92.1657397 0.11367485 9.224591
## 4 4 0.8344262 0.9841584 0.11381968 8.167405
## 5 5 0.9961214 0.4464952 0.10641424 8.438860
## 6 6 0.9520886 2.9135404 0.12152391 10.030840
## 7 7 0.7155444 0.6161061 0.07639769 9.157918
## 8 8 1.2204339 5.0839285 0.11025531 10.919296
## 9 9 0.5559791 1.5414754 0.13975542 6.942445
## 10 10 0.9455286 4.4992913 0.13442991 7.755041
## 11 11 0.9353887 0.8747598 0.19119774 8.038124
## 12 12 0.8302670 0.5957391 0.15364599 8.190014
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 prediction intervals with prctilemlx
. band
defines the percentile bands displayed:
print(prctilemlx(res.1000$CC,band=list(number=10, level=100)))
Plot of observed concentrations (with residual error)
print(prctilemlx(res.1000$Y,band=list(number=9, level=90)))
Table of the same information
prctilemlx(res.1000$Y,band=list(number=10, level=100), plot=F)$y
## time 0% 10% 20% 30% 40%
## 1 0.0 -0.2256470 -0.13159951 -0.093647288 -0.06829002 -0.028820716
## 2 0.5 -0.2424069 -0.11632207 -0.062097853 -0.02772178 0.003150656
## 3 1.0 -0.2119107 -0.04433479 -0.004253361 0.09734471 0.412134400
## 4 2.0 2.0159184 4.42603243 6.740490545 8.55001243 9.445620815
## 5 3.0 4.1244757 7.50562059 9.262435997 9.99395562 10.715040238
## 6 4.0 4.5577413 9.07240187 9.863678890 10.30557787 11.095077276
## 7 6.0 6.7795443 8.97745151 9.752382357 10.01874601 10.494306232
## 8 8.0 6.8851238 8.79986155 9.417065333 9.82250231 10.299517337
## 9 12.0 7.2330724 8.77570039 9.418782379 9.64336299 9.907050773
## 10 24.0 5.4330543 6.92414065 7.528376882 7.79329141 7.935608942
## 11 36.0 3.9758516 5.35726544 6.080274191 6.24896542 6.696433002
## 12 48.0 2.5216985 4.37791186 4.857501171 5.20154397 5.477645204
## 50% 50% 60% 70% 80% 90%
## 1 -0.01404642 -0.01404642 0.00848185 0.03282749 0.06201317 0.1332022
## 2 0.01757170 0.01757170 0.04240292 0.06877119 0.10782657 0.1524774
## 3 0.96294909 0.96294909 2.08865215 4.69199013 6.07504750 9.4316502
## 4 10.36904340 10.36904340 10.95811945 11.36252148 12.03918758 13.4247926
## 5 11.32247005 11.32247005 11.84495245 12.37712008 12.91786323 13.7973035
## 6 11.41485788 11.41485788 11.98341622 12.27754952 13.02976315 13.8307028
## 7 11.04616564 11.04616564 11.73835513 12.36834065 13.19768046 14.0895574
## 8 10.75752318 10.75752318 11.23879625 11.77174418 12.22186683 12.7527160
## 9 10.25564662 10.25564662 11.01328786 11.38102453 11.81121097 12.4055270
## 10 8.36160658 8.36160658 8.66446943 9.17932599 9.64929903 10.0992910
## 11 6.93470174 6.93470174 7.30385439 7.83449599 8.22882864 9.2161280
## 12 5.80713747 5.80713747 6.12145226 6.42040626 6.87337403 7.2333707
## 100%
## 1 0.2902038
## 2 3.0705034
## 3 13.3925594
## 4 17.0051562
## 5 18.8070194
## 6 17.2683970
## 7 16.0918247
## 8 14.6069312
## 9 15.4452127
## 10 12.6878997
## 11 10.3956880
## 12 8.1542338