knitr::opts_chunk$set(comment = '.', message=FALSE, warning = FALSE, fig.path="man/figures/README-")
local sensitivity analysis in R with mrgsolve
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
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)
Use vera::lsa(). We pick the parameters that we want to fiddle with
(par):
Kpli liver partition coefficientKpmu muscle partition coefficientKpad adipose tissue partition coefficientBW body weight Also specify the output that we want to look at (var):
Cp - venous concentrationAmu - amount in the muscle compartmentd gets passed through to the function as dose.
out <- lsa(mod, fun, par = "Kpli,Kpmu,Kpad,BW", var = "Cp,Amu", dose = d)
The output is long and ready to send in to ggplot2.
head(out)
There is a default plotting method as well.
plot(out)
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)
See inst/doc/about.md (on GitHub only) for more details.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.