devtools::load_all(pkg = ".") file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), "warfarin_conc_pca.csv"), to = getwd(), overwrite = T ) file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), "warfarin.ctl"), to = getwd(), overwrite = T ) file.rename(from = "warfarin.ctl", "run0.ctl")
In this notebook we will look at running NONMEM and PsN from R using the R
package rspeaksnonmem
.
This demo will show the following steps:
First, let's run a model and knit the results back into this notebook. Note
that in the command
argument to the function we specify the complete path to the
NONMEM executable .bat file. This allows you to be very precise about which
version of NONMEM you use. If the clean
argument is non-zero it cleans up the
working directory deleting all of the temporary NONMEM files, leaving only the
output.
estimate_NM(command = "c:/nm72/run/nmfe72.bat", modelFile = "run0.ctl", clean = 1)
We can now use PsN command sumo
to summarise the output. Note that here we
are not using the command
argument, but instead we specify the installation
directory for Perl / PsN and which PsN version we are using. rspeaksnonmem
will then create a command based on the directory, sumo
and version information.
sumo_PsN(installPath = "c:/strawberry/perl", version = "4.7.0", lstFile = "run0.lst")
Next, we might want to produce some model diagnostics using the R package
xpose4
. To do this, we need to create an Xpose database object and then
create the diagnostic plots. Xpose needs the run number in order to pick up
the $TABLE file outputs from NONMEM.
runno <- as.numeric(gsub("[a-z]", "", list.files(pattern = "^sdtab")[1])) ## ----createXpdb---------------------------------------------------------- xpdb <- xpose4::xpose.data(runno, quiet = T) # save(base.xpdb, file='Xpose database.RData')
print(xpose4::dv.vs.pred.ipred(xpdb))
print(xpose4::pred.vs.idv(xpdb))
print(xpose4::ipred.vs.idv(xpdb))
print(xpose4::wres.vs.idv(xpdb))
print(xpose4::wres.vs.pred(xpdb))
print(xpose4::ranpar.hist(xpdb))
print(xpose4::ind.plots(xpdb, layout = c(4, 4)))
We may also want to investigate simulation-based diagnostics using the PsN
routine VPC. In the call to VPC_PsN
we have specified the required arguments
for VPC (samples, seed) but you can also pass additional arguments to the VPC
routine by passing a name-value list to the argument psnOpts
. rspeaksnonmem
will check these arguments against the options for VPC and let you know if any
are mis-specified. Here the argument min_points_per_bin
is not a valid option
for VPC. (The correct option is min_points_**in**_bin
.)
VPC_PsN( modelFile='run0.ctl', installPath = "c:/strawberry/perl", version = "4.7.0", working.dir='Run1_VPC', samples=100, seed='54321', psnOpts=list(lst='run0.lst', auto_bin = '5', min_points_per_bin = '2'))
and then use the Xpose function xpose_vpc to plot the result:
vpcdir <- "Run1_VPC" vpctab <- file.path(vpcdir,"vpctab") vpcinfo <- file.path(vpcdir,"vpc_results.csv") xpose4::xpose.VPC(vpc.info=vpcinfo, vpctab=vpctab)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.