Learn R Programming

NMproject

Script based ‘NONMEM’ model development in RStudio intended for intermediate to advanced R users.

  • NONMEM code library
  • End-to-end script based model development workflows
  • Scale to groups of runs and complex workflows
  • 100% flexibility through tracked manual edits to model files
  • Customisable to multiple infrastructure types

Prerequisites

  • PsN >= 4.4.8
  • NONMEM installed with valid license
  • RStudio

Installation

You can install the released version of NMproject from CRAN with:

install.packages("NMproject")

To install the latest version of NMproject from GitHub:

if(!require("devtools")) install.packages("devtools")
devtools::install_github("tsahota/NMproject")

To install a specific release (e.g. v0.5.1) on GitHub use the following command:

devtools::install_github("tsahota/NMproject@v0.5.1")

Load the package with

library(NMproject)

Getting started with NMproject

Two options:

  1. Running the demo is easiest way to familiarise your with NMproject.
  2. Reading the website vignette.

Code snippets

Use of pipes, %>%, make it easy to code sequences of operations to model objects.

Following snippet adds covariates to model object, m2:

  • create a separate child control file
  • add a covariate relationship to it (using PsN SCM syntax)
  • run
m2WT <- m2 %>% child(run_id = "m2WT") %>%
  add_cov(param = "CL", cov = "WT", state = "power") %>%
  run_nm()

Graphical RStudio ‘Addins’ exist for reviewing the changes that functions like add_cov() make before execution and performing nm_tran() checks.

For more complex operations use fully tracked manual edits.

Apply fully customisable diagnostic reports to one or multiple objects with nm_render() like so:

c(m1, m2) %>% nm_render("Scripts/basic_gof.Rmd")
## Saves html diagnostic reports in "Results" directory

The template Scripts/basic_gof.Rmd can also be run as an R notebook for interactively customising to your specific model evaluation criteria.

Here’s a snippet for producing PPCs and VPCs:

  • create a new (child) control stream
  • updating initial estimates to final estimates
  • convert it to a simulation control file
  • run
  • generate customised PPCs and VPCs from the outputs
m2s <- m2 %>% child(run_id = "m2s") %>%
  update_parameters(m2) %>%
  convert_to_simulation(subpr = 50) %>%
  run_nm()

m2s %>% nm_render("Scripts/basic_vpc.Rmd")
m2s %>% nm_render("Scripts/basic_ppc.Rmd")

Advanced functionality enables groups of runs to be handled with the same concise syntax (no loops). For example:

  • create 5 child runs
  • Randomly perturb the initial estimates of $THETA and $OMEGA
  • run them all in their own subdirectory for tidiness.
m1rep <- m1 %>% child(run_id = 1:5) %>% 
  init_theta(init = rnorm(init, mean = init, sd = 0.3)) %>%
  init_omega(init = runif(init, min = init/2, max = init*2)) %>%
  run_in("Models/m1_perturb_inits") %>%
  run_nm()

See the website vignette for more examples

Copy Link

Version

Install

install.packages('NMproject')

Monthly Downloads

49

Version

0.6.9

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Tarj Sahota

Last Published

September 29th, 2022

Functions in NMproject (0.6.9)

as_nm_generic

Convert nm object to nm_generic
based_on

Use file to set control file contents in nm object
bind_covariate_results

Add run results into a covariate tibble
NMproject-package

NMproject: Script Based 'NONMEM' Model Development
as_nm_list

Coerce object into nm_list
add_mixed_param

Add a mixed effect parameter to $PK (or $PRED)
append_nonmem_var

Include NONMEM variables in output table
completed_nm

Create an nm object from an already completed PsN run
NONMEM_version

NONMEM version info
cond_num

Condition number of run
block-omega-sigma

Create or remove $OMEGA/$SIGMA BLOCKs
add_remove_covs

Add/remove a covariate to a NONMEM model
boot_to_csv

Save bootstrap datasets to disk
exclude_rows

Exclude rows of NONMEM dataset
apply_manual_edit

Apply a manual edit patch
child

Make child nm object from parent
cov_forest_data

Produce dataset for covariate forest plotting
change_parent

Change parent object
fill_input

Fill $INPUT
find_nonmem

Find location of NONMEM installation
coef_widelong

Extract parameter values
convert_to_simulation

Convert a NONMEM run to a simulation
code_library

Code Library
cov_cov_plot

Plot correlation between two covariates
check_installation

Check NMproject installation
cov_forest_plot

Plot covariate forest plots
gen_sim_path

Generate paths for simulation runs
comment_lines

Comment and uncomment lines of control file
covariance_matrix

Get covariance matrix
is_nmproject_dir

Is the directory an NMproject directory
is_nm

Test if object is an nm coercible object
ctl_contents

Get/set control file contents
covariance_plot

Plot $COV matrix
ctl_list

Constructor/converter to ctl_list
data_filter_char

Get filter statement
ctl_path

Get and set path to NONMEM control file
data_ignore_char

Get ignore statement
decision

Make decision point
data_path

Get/set path to dataset
delete_dollar

Delete a NONMEM subroutine from control file contents
covariate_step_tibble

Prepare forward covariate step
is_rstudio

Logical flag for detecting if R session is on RStudio
ignore

Get/set ignore statement from control file contents
ctl_character

Constructor/converter to ctl_character
is_successful

Test if NONMEM ran without errors
import

Import staged files into project
nm_diff

Compute diff between two NONMEM runs
%f>%

Function pipe for nm objects
git_hooks

Git hooks
git_cmd_available

Check if git is available on command line
make_boot_datasets

Prepare a bootstrap tibble
ls_scripts

List scripts
nm_dir

Get a directory name
make_xv_datasets

Write (bootstrap) cross validation datasets
make_OCC_every_dose

Make an OCC column for NONMEM IOV use
gsub_ctl

Pattern replacement for control file contents
nm_getsetters

Functions to access and modify fields of nm objects
nm_read_table

Fast read of NONMEM output table
nm_output_path

Find an output file associated with a run
nm_list_gather

Get all nm_list objects
nm_getsetters_execution

Execution related functions to access and modify fields of nm objects
job_info

Get job information (if it exists)
dollar_subroutine

Get/set $SUBROUTINE values in control file
dollar

Get/set existing subroutine
output_table

Reads all $TABLE outputs and merge with input dataset
job_stats

Get job stats for a completed NONMEM run
map_nm

A purrr-like looping function over nm objects
overwrite_behaviour

Overwrite behaviour of NMproject
is_full_path

Test if full path
is_finished

Tests if job is finished
new_nm

Create a new (parent) nm object
nm_output

Get NONMEM output tables
info_scripts

List information about scripts
init_theta

Get/set initial parameters
input_data

Read input dataset of an nm object
nm_default_dirs

Setup analysis subdirectories
insert_dollar

Insert a new subroutine into control file_contents
nm_default_fields

Setup default nm object fields
plot_iter_dygraph

Plot iterations vs parameters/OBJ with dygraphs
job_time_spacing

Setup default job_time_spacing option
nm_render

Create run reports
plot_iter_ggplot

Plot iterations vs parameters/OBJ (ggplot2)
kill_job

Kill cluster job
nmsave

Save plots in results_dir
nonmem_code_to_r

Convert NONMEM code to R ready
ofv

Get Objective Function Value (OFV)
omega_matrix

Get OMEGA matrix from run
nm

Create core NM object
nm_summary

Generate a summary of NONMEM results
nm_row

Convert nm objects to a row-wise tibble/data.frame
nm_tran

Run NMTRAN step of a NONMEM job
parallel_execute

Generic execute command for parallelised runs
param_cov_diag

Plot relationship between a parameter and covariate
sge_parallel_execute

Generic execute command for SGE grids
shiny_nm

Run monitor & summary app
ls_code_library

List files in code library
list_dirs

List directories
ppc_data

PPC functions: process data from simulation and plot
psn_available

Test if psn is available locally
rename_parameter

Rename a parameter in NONMEM control stream
nm_create_analysis_project

Create analysis project
system_cmd

System/shell command wrapper
run_nm_single

Run NONMEM jobs (single job)
nm_tree

Make data.tree object
nm_tran_command

Get/set nm_tran_command
%>%

Pipe operator
parent_run

Get parent object of nm object
search_raw

Search for files matching raw text search
system_nm

System command for NONMEM execution
show_ctl

Show an uneditable version of the control file
plot_iter

Plot iterations vs parameters/OBJ
wipe_run

Wipe previous run files
plot_iter_data

Get data for iterations vs parameters/OBJ plots
show_out

Show an uneditable version of the lst file
rmd_to_vignettes

Convert R markdown scripts to vignettes
write_derived_data

Write derived data file
psn_check

Tests if psn is accessible
write_ctl

Write control file to disk
relative_path

Compute path relative to reference
remove_parameter

Remove parameter from NONMEM control file
psn_style_scm

PsN style stepwise covariate method
read_derived_data

Read derived data
setup_code_completion

Set up code completion for NMproject
run_dir_path

Get path to run_dir
start_manual_edit

Start manual edit
reexports

Objects exported from other packages
rr

Run record
run_all_scripts

Run all project scripts sequentially
target

Target part of control object for further modification
run_nm

Run NONMEM jobs
temp_files

Remove temporary NONMEM files
status

Get status of NONMEM runs
setup_nm_demo

Setup demo in current directory
stage

Stage files in project staging area ready for import
simple_field

Interface for getting and setting your own simple fields in nm objects
system_nm_intern

Diagnostic test for system_nm
tail_lst

Tail of lst file
wait_finish

Wait for runs to finish
system_nm_available

Test integrity of system_nm
system_nm_default

Default system_nm function
view_patch

View a patch
valid_package_name

Package name validator from usethis
wait_for

Wait for statement to be TRUE
status_table

Get status of multiple runs in form of table
subroutine

Subroutine
update_parameters

Update initial estimates to final estimates
test_relations

Generate tibble of covariate relations to test