-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquick.qmd
More file actions
128 lines (90 loc) · 2.2 KB
/
quick.qmd
File metadata and controls
128 lines (90 loc) · 2.2 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
---
title: "Quick hit demos"
---
```{r, include=FALSE}
options(mrgsolve.soloc = "build")
```
These are all miscellaneous features that may be difficult to find in other
documentation.
```{r,message=FALSE}
#| message: false
#| warning: false
library(mrgsolve)
library(dplyr)
```
# `$` operator for model object gets the parameter value
If our model parameters are
```{r}
mod <- mrgsolve:::house()
param(mod)
```
we can pick a parameter value with
```{r}
mod$CL
mod$WT
```
Or slice off multiple parameters
```{r}
i_want <- c("CL", "WT")
mod[i_want]
```
# Model names
For programming with a model object, we can extract the names
```{r}
names(mod)
```
or get all of the model elements in a list (output not shown)
```{r}
my_model <- as.list(mod)
```
# Zero all random effect variances on the fly
If your model has random effects, you can easily and temporarily zero them out.
```{r}
mod <- modlib("popex") %>% update(end=96) %>% Req(DV,CL,V)
omat(mod)
```
It is easy to simulate either with or without the random effects in the
simulation: this change can be made on the fly.
Use `zero_re` to make all random effect variances zero
```{r}
mod %>% zero_re %>% omat
```
By default, both `OMEGA` and `SIGMA` are zeroed. Check the arguments for
`zero_re` to see how to selectively zero `OMEGA` or `SIGMA`.
Compare the population output
```{r}
mod %>% ev(amt=100) %>% mrgsim(nid=20) %>% plot
```
with
```{r}
mod %>% ev(amt=100) %>% zero_re %>% mrgsim(nid=20) %>% plot
```
# Plot formulae
We commonly plot simulated output with a special plot method. By default, you
get all compartments and output variables in the plot.
```{r}
mod <- mrgsolve:::house() %>% ev(amt=100)
mod %>% mrgsim %>% plot
```
The plot can be customized with a formula selecting variables to plot. Other
arguments
to `lattice::xyplot` can be passed as well.
```{r}
mod %>% mrgsim %>% plot(CP+RESP ~ time, lty=2, col="firebrick")
```
# Get a data frame of simulated data
By default mrgsolve returns an object of simulated data (and other stuff)
```{r}
out <- mrgsim(mod)
class(out)
```
But you can get a data frame with
```{r}
out <- mrgsim_df(mod)
class(out)
```
or
```{r}
out <- mrgsim(mod,output="df")
out <- mrgsim(mod) %>% as_tibble()
```