knitr::opts_chunk$set(comment = '.', message=FALSE, warning = FALSE, 
                      fig.path="man/figures/README-")

vera

Travis build status

Overview

local sensitivity analysis in R with mrgsolve

Model

Load the vera package and a PBPK model from the mrgsolve package. We decrease the tolerance a bit as well as the maximum step size.

library(vera)

mod <- modlib(
  "pbpk", 
  end = 12,     delta = 0.1, 
  atol = 1E-20, rtol  = 1E-12, hmax = 0.5
) %>% obsonly

Scenario

Create a function that uses the model to simulate a certain scenario. For now, we just simulate a single dose.

fun <- function(p,dose) {
  mod %>% 
    param(p) %>% 
    ev(dose) %>% 
    mrgsim()
}

d <- ev(amt = 100)

fun(param(mod),d) %>% plot(Cp+Amu~time)

Sensitivity analysis

Use vera::lsa(). We pick the parameters that we want to fiddle with (par):

Also specify the output that we want to look at (var):

d gets passed through to the function as dose.

out <- lsa(mod, fun, par = "Kpli,Kpmu,Kpad,BW", var = "Cp,Amu", dose = d)

Ouput

The output is long and ready to send in to ggplot2.

head(out)

There is a default plotting method as well.

plot(out)

Plot with ggplot2

library(ggplot2)

filter(out, par=="Kpmu") %>% 
  ggplot(aes(time,sens,col=var)) + 
  geom_line(lwd=1) + theme_bw() + 
  scale_color_brewer(palette="Set2") + 
  theme(legend.position="top") + 
  facet_wrap(~par) + geom_hline(yintercept=0,lty=2)

More info

See inst/doc/about.md (on GitHub only) for more details.



kylebaron/vera documentation built on July 6, 2020, 12:51 p.m.