source("global.R") set.seed(20202)
This is a simple vignette to help you get your first simulation done with mrgsolve. Check out https://github.com/metrumresearchgroup/mrgsolve for links to other resources including the user guide, blog, vignettes, pkgdown documentation and more.
After loading the package
library(dplyr) library(mrgsolve)
we'll use the modlib()
function to read, parse, compile and load a model
out of the internal model library. These models are good to try when learning
mrgsolve.
For this first example, we're using a one compartment model (called pk1
in the
model library)
mod <- modlib("pk1")
Once we create the model object (mod
) we can extract certain information
about the model. For example, get an overview
mod
Or look at model parameters and their values
param(mod)
We'll see in the section below how to run a simulation from this model. But first, let's create a dosing intervention to use with this model.
The simplest way to create an intervention is to use an event object. This is just a simple expression of one or more model interventions (most frequently doses)
evnt <- ev(amt = 100, ii = 24, addl = 9)
evnt
We'll see in other vignettes how to create more-complicated events as well as how to create larger data sets with many individuals in them.
For now, the event object is just an intervention that we can combine with a model.
To simulate, use the mrgsim()
function.
out <- mod %>% ev(evnt) %>% mrgsim(end = 480, delta = 0.1)
We use a pipe sequence here (%>%
) to pass the model object (mod)
into the event function (ev()
) where we attach the dosing intervention,
and that result gets passed into the simulation function. The result
of the simulation function is essentially a data frame of simulated values
out
mrgsolve comes with several different functions for processing output. One simple function is a plot method that will generate a plot of what was just simulated
plot(out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.