View source: R/as.data.frame.R
as.data.frame.icm | R Documentation |
This function extracts model simulations for objects of classes
icm
and netsim
into a data frame using
the generic as.data.frame
function.
## S3 method for class 'icm'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
out = "vals",
sim = NULL,
qval = NULL,
...
)
## S3 method for class 'netsim'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
out = "vals",
sim = NULL,
...
)
x |
An |
row.names |
See |
optional |
See |
out |
Data output to data frame: |
sim |
If |
qval |
Quantile value required when |
... |
See |
These methods work for both icm
and netsim
class models. The
available output includes time-specific means, standard deviations,
quantiles, and simulation values (compartment and flow sizes) from these
stochastic model classes. Means, standard deviations, and quantiles are
calculated by taking the row summary (i.e., each row of data is corresponds
to a time step) across all simulations in the model output.
A data frame containing the data from x
.
## Stochastic ICM SIS model
param <- param.icm(inf.prob = 0.8, act.rate = 2, rec.rate = 0.1)
init <- init.icm(s.num = 500, i.num = 1)
control <- control.icm(type = "SIS", nsteps = 10,
nsims = 3, verbose = FALSE)
mod <- icm(param, init, control)
# Default output all simulation runs, default to all in stacked data.frame
as.data.frame(mod)
as.data.frame(mod, sim = 2)
# Time-specific means across simulations
as.data.frame(mod, out = "mean")
# Time-specific standard deviations across simulations
as.data.frame(mod, out = "sd")
# Time-specific quantile values across simulations
as.data.frame(mod, out = "qnt", qval = 0.25)
as.data.frame(mod, out = "qnt", qval = 0.75)
## Not run:
## Stochastic SI Network Model
nw <- network_initialize(n = 100)
formation <- ~edges
target.stats <- 50
coef.diss <- dissolution_coefs(dissolution = ~offset(edges), duration = 20)
est <- netest(nw, formation, target.stats, coef.diss, verbose = FALSE)
param <- param.net(inf.prob = 0.5)
init <- init.net(i.num = 10)
control <- control.net(type = "SI", nsteps = 10, nsims = 3, verbose = FALSE)
mod <- netsim(est, param, init, control)
# Same data extraction methods as with ICMs
as.data.frame(mod)
as.data.frame(mod, sim = 2)
as.data.frame(mod, out = "mean")
as.data.frame(mod, out = "sd")
as.data.frame(mod, out = "qnt", qval = 0.25)
as.data.frame(mod, out = "qnt", qval = 0.75)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.