Skip to content

Instantly share code, notes, and snippets.

@dpastoor
Created May 9, 2017 19:26
Show Gist options
  • Save dpastoor/8926e7928cdf8a79fd654e7aaa43900a to your computer and use it in GitHub Desktop.
Save dpastoor/8926e7928cdf8a79fd654e7aaa43900a to your computer and use it in GitHub Desktop.
model blueprints
## Create a model blueprint, using a consistent API across modeling platforms.
```{r}
blueprint <- make_blueprint("nonmem")
```
```{r}
one_cmt <- blueprint %>%
ode_model(cmt = 1, depot = 1) %>%
parameterize("CL") %>%
params(CL = 1.6, V = 14.3, KA = 0.8)
```
```{r}
one_cmt_block <- one_cmt %>%
heirarchy(block(CL = 0.1, V = 0.04, CL_V = 0.01), KA = 0.1) # add a block omega for Cl/V and a separate omega for KA
one_cmt_diag <- one_cmt %>%
heirarchy(CL = 0.1, V = 0.04, KA = 0.1) # add diagonal matrix for Cl, V, KA
```
At this point, we may want to try different residual error structures
```{r}
one_cmt_block_combined <- one_cmt_block %>% residual_error(add = 1, prop=0.04)
one_cmt_block_prop <- one_cmt_block %>% residual_error(prop=0.04)
```
Or both can apply something to multiple models
```{r}
model_list <- c(one_cmt_block, one_cmt_diag)
map(model_list, function(model) {
model %>% residual_error(prop=0.04)
})
```
This iterative construction is the same as:
```{r}
make_blueprint("mrgsolve") %>%
ode_model(cmt = 1, depot = 1) %>%
parameterize("CL") %>%
params(CL = 1.6, V = 14.3, KA = 0.8) %>%
heirarchy(block(CL = 0.1, V = 0.04, CL_V = 0.01), KA = 0.1) %>%
residual_error(prop=0.04)
```
As the arguments can be chained, the later steps can be created as a functional blueprint
```{r}
one_cmt_creator <- . %>%
ode_model(cmt = 1, depot = 1) %>%
parameterize("CL") %>%
params(CL = 1.6, V = 14.3, KA = 0.8) %>%
heirarchy(block(CL = 0.1, V = 0.04, CL_V = 0.01), KA = 0.1) %>%
residual_error(prop=0.04)
```
```{r}
make_blueprint("mrgsolve") %>% one_cmt_creator()
make_blueprint("nonmem") %>% one_cmt_creator()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment