-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
100 lines (74 loc) · 2.02 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
title: ""
output: github_document
---
```{r,setup,include=FALSE}
knitr::opts_chunk$set(comment = '.', message=FALSE, warning = FALSE,
fig.path="man/figures/README-")
```
# vera
<!-- badges: start -->
[](https://travis-ci.org/kylebaron/vera)
<!-- badges: end -->
## 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.
```{r,message=FALSE}
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.
```{r}
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`):
- `Kpli` liver partition coefficient
- `Kpmu` muscle partition coefficient
- `Kpad` adipose tissue partition coefficient
- `BW` body weight
Also specify the __output__ that we want to look at (`var`):
- `Cp` - venous concentration
- `Amu` - amount in the muscle compartment
`d` gets passed through to the function as `dose`.
```{r}
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`.
```{r}
head(out)
```
There is a default plotting method as well.
```{r}
plot(out)
```
## Plot with ggplot2
```{r}
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)
```
<hr>
## More info
See [inst/doc/about.md (on GitHub only)](inst/doc/about.md) for more details.