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<-"UseCase14_2"
datafile <- "warfarin_TTE_exact.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] "UseCase14_2.mdl" "warfarin_TTE_exact.csv"
Monolix estimation is not possible for this use case. In the current version of the framework, there is no place to define initial conditions for an ODE which are not structural parameters so that the model runs interoperably. See UC14_1 for an alternative implementation that can be used with Monolix.
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 18:21:12 2016
## New
## Submitted
## Job bada9f90-f4ed-4dc9-bc83-22f9b48c2224 progress:
## Running [ ...... ]
## Importing Results
## Copying the result data back to the local machine for job ID bada9f90-f4ed-4dc9-bc83-22f9b48c2224...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpk5tG0t\DDMORE.job1c846eb37a11 to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase14_2/NONMEM
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## Estimation::PopulationEstimates::MLE
## 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 18:23:15 2016
Load previous results
NM <- LoadSOObject(“NONMEM/UseCase14_2.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.
Results from NONMEM should be comparable with results from MONOLIX
parameters_nm <- getPopulationParameters(NM, what="estimates")
print(parameters_nm)
## $MLE
## POP_HBASE POP_BTATRT
## 9.8717300 0.0305249
print(getEstimationInfo(NM))
## $OFMeasures
## $OFMeasures$Deviance
## $OFMeasures$Deviance[[1]]
## [1] 510.33
##
##
##
## $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"
MDL Objects can be manipulated from R to change for example the estimation algorithm
myTaskProperties <- getTaskPropertiesObjects(mdlfile)[[1]]
myNewTaskProperties <- myTaskProperties
myNewTaskProperties@ESTIMATE$algo <- "foce"
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.FOCE <- paste0(uc,"_FOCE.mdl")
writeMogObj(myNewerMOG,mdlfile.FOCE)
Test estimation using this new MOG in NONMEM via PsN
By default, a covariance step is not run when estimating in PsN. To see how it can be requested, see UseCase1_1.mdl
NM.FOCE <- estimate(mdlfile.FOCE, target="PsN", subfolder="NONMEM_FOCE")
## -- Tue Aug 16 18:23:25 2016
## New
## Submitted
## Job 20a49881-76c8-45e8-9782-fc7af9bf6360 progress:
## Running [ ... ]
## Importing Results
## Copying the result data back to the local machine for job ID 20a49881-76c8-45e8-9782-fc7af9bf6360...
## From C:\Users\zparra\AppData\Local\Temp\Rtmpk5tG0t\DDMORE.job1c84372d46a4 to D:/SEE-Prod5_RC4/MDL_IDE/workspace/UseCasesDemo/UseCase14_2/NONMEM_FOCE
## Done.
##
##
## The following main elements were parsed successfully:
## RawResults
## Estimation::PopulationEstimates::MLE
## 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 18:24:29 2016
The ddmore “LoadSOObj” reads and parsed existing Standardise Output Objects
NM.FOCE <- LoadSOObject(“NONMEM_FOCE/UseCase14_2_FOCE.SO.xml”)
Results from NONMEM should be comparable to previous results
print(getPopulationParameters(NM.FOCE, what="estimates")$MLE)
## POP_HBASE POP_BTATRT
## 9.8839000 0.0300856
print(parameters_nm)
## $MLE
## POP_HBASE POP_BTATRT
## 9.8717300 0.0305249