View source: R/as.data.frame.R
as.data.frame.dcm | R Documentation |
This function extracts a model run from an object of class
dcm
into a data frame using the generic
as.data.frame
function.
## S3 method for class 'dcm'
as.data.frame(x, row.names = NULL, optional = FALSE, run, ...)
x |
An |
row.names |
See |
optional |
See |
run |
Run number for model; used for multiple-run sensitivity models. If not specified, will output data from all runs in a stacked data frame. |
... |
See |
Model output from dcm
simulations are available as a data
frame with this helper function. The output data frame will include
columns for time, the size of each compartment, the overall population
size (the sum of compartment sizes), and the size of each flow.
For models with multiple runs (i.e., varying parameters - see example below),
the default with the run
parameter not specified will output all runs
in a single stacked data frame.
A data frame containing the data from x
.
## Example 1: One-group SIS model with varying act.rate
param <- param.dcm(inf.prob = 0.2, act.rate = seq(0.05, 0.5, 0.05),
rec.rate = 1/50)
init <- init.dcm(s.num = 500, i.num = 1)
control <- control.dcm(type = "SIS", nsteps = 10)
mod1 <- dcm(param, init, control)
as.data.frame(mod1)
as.data.frame(mod1, run = 1)
as.data.frame(mod1, run = 10)
## Example 2: Two-group SIR model with vital dynamics
param <- param.dcm(inf.prob = 0.2, inf.prob.g2 = 0.1,
act.rate = 3, balance = "g1",
rec.rate = 1/50, rec.rate.g2 = 1/50,
a.rate = 1/100, a.rate.g2 = NA,
ds.rate = 1/100, ds.rate.g2 = 1/100,
di.rate = 1/90, di.rate.g2 = 1/90,
dr.rate = 1/100, dr.rate.g2 = 1/100)
init <- init.dcm(s.num = 500, i.num = 1, r.num = 0,
s.num.g2 = 500, i.num.g2 = 1, r.num.g2 = 0)
control <- control.dcm(type = "SIR", nsteps = 10)
mod2 <- dcm(param, init, control)
as.data.frame(mod2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.