Simulate from ODE-based population PK/PD and QSP models in R
Fortran R C++ Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
R NAMESPACE changes to satisfy CRAN check Apr 27, 2018
data pull all code out of rdev; makescripts in ./inst/maintenance #154 Dec 16, 2016
inst NAMESPACE changes to satisfy CRAN check Apr 27, 2018
man NAMESPACE changes to satisfy CRAN check Apr 27, 2018
src mtime Apr 12, 2018
tests re-build for next release Apr 26, 2018
.Rbuildignore reformat NEWS.md for pkgdown compatibility Feb 17, 2018
.gitignore documentation cleanup and re-org Feb 18, 2018
.travis.yml
DESCRIPTION NAMESPACE changes to satisfy CRAN check Apr 27, 2018
Makefile don't run R CMD check in make travis Mar 8, 2018
NAMESPACE NAMESPACE changes to satisfy CRAN check Apr 27, 2018
NEWS.md re-build for next release Apr 26, 2018
README.Rmd reformat NEWS.md for pkgdown compatibility Feb 17, 2018
README.md reformat NEWS.md for pkgdown compatibility Feb 17, 2018

README.md

mrgsolve

Build Status master CRAN License questions Metrumrg

mrgsolve facilitates simulation in R from hierarchical, ordinary differential equation (ODE) based models typically employed in drug development. See the example below.

Resources

Please see mrgsolve.github.io for additional resources.

Installation

We recommend staying up to date with the development version

devtools::install_github("metrumresearchgroup/mrgsolve")

Otherwise, install the latest release on CRAN

install.packages("mrgsolve", type="source")

Please be sure to see important install-related information here.

Ask a question

Example

library(mrgsolve)
library(dplyr)
library(ggplot2)

The model specification file is similar to other non-linear mixed effects modeling software

code <- '
$GLOBAL
#define CP (CENT/VC)
#define INH (CP/(IC50+CP))

$SET delta=0.1

$PARAM TVCL=1, TVVC=20, KA = 1.3, KIN=100, KOUT=2, IC50=10

$CMT GUT CENT RESP

$MAIN
double CL = exp(log(TVCL) + ETA(1));
double VC = exp(log(TVVC) + ETA(2));

RESP_0 = KIN/KOUT;

$OMEGA 0 0

$ODE
dxdt_GUT = -KA*GUT;
dxdt_CENT = KA*GUT - (CL/VC)*CENT;
dxdt_RESP = KIN*(1-INH) - KOUT*RESP;

$CAPTURE CP
'

The model is parsed, compiled, and dynamically loaded into the R session

  • Information about the model is saved as an R object
  • Important model attributes can be updated in R without recompiling
mod <- mcode("demo", code)

Use mrgsolve as an interactive simulation tool for model exploration and sensitivity analyses

  • Simulated data are returned as R objects
  • Input and output data are kept in memory in the R process; writing or reading to disk is never necessary (unless results are to be saved for later use).
out <- 
  mod %>%
  ev(amt=100, ii=24, addl=2) %>%
  mrgsim(end=120)

out
. Model:  demo 
. Dim:    1202 x 6 
. Time:   0 to 120 
. ID:     1 
.      ID time    GUT  CENT  RESP    CP
. [1,]  1  0.0   0.00  0.00 50.00 0.000
. [2,]  1  0.0 100.00  0.00 50.00 0.000
. [3,]  1  0.1  87.81 12.16 49.72 0.608
. [4,]  1  0.2  77.11 22.78 49.03 1.139
. [5,]  1  0.3  67.71 32.04 48.11 1.602
. [6,]  1  0.4  59.45 40.11 47.06 2.006
. [7,]  1  0.5  52.20 47.14 45.96 2.357
. [8,]  1  0.6  45.84 53.25 44.87 2.663
plot(out, CP+RESP~.)

out <- 
  mod %>% update(end=48) %>%
  ev(amt=100) %>%
  Req(CP,RESP) %>%
  knobs(TVVC=c(10,20,40), TVCL=c(0.5,1.5))
plot(out)

Use mrgsolve for large-scale population simulation

mod <- mod %>% omat(cmat(0.1, 0.67, 0.4))

Flexibility with input data sets

  • Data set format that is likely familiar to modeling and simulation scientists
  • No need to include observation records; mrgsolve will automatically insert
.data <- 
  expand.ev(ID=1:10, amt=c(100,300,1000)) %>%
  mutate(dose=amt)

head(.data)
.   ID amt evid cmt time dose
. 1  1 100    1   1    0  100
. 2  2 100    1   1    0  100
. 3  3 100    1   1    0  100
. 4  4 100    1   1    0  100
. 5  5 100    1   1    0  100
. 6  6 100    1   1    0  100

Input data are passed in as R objects

  • Pass many different data sets or implement different designs in the same model code without recompiling
  • Control simulation output from R to better manage memory
set.seed(1010)
out <- 
  mod %>%
  data_set(.data) %>%
  Req(RESP,CP) %>% obsonly %>%
  carry_out(dose) %>%
  mrgsim(end=48)
plot(out, RESP~time|factor(dose), scales="same")

Pass simulated output to your favorite data summary or visualization routines

Summarise with dplyr

out %>%
  as.tbl %>%
  group_by(dose) %>%
  summarise(rmin = min(RESP), tmim=time[which.min(RESP)])
. # A tibble: 3 x 3
.    dose  rmin  tmim
.   <dbl> <dbl> <dbl>
. 1   100 19.0   2.90
. 2   300 16.1   3.50
. 3  1000  6.20  3.50

Plot with ggplot2

out %>%
  as.tbl %>%
  ggplot(data=.) +
  geom_line(aes(x=time, y=RESP, group=ID, col=factor(dose)))