simulate.rma | R Documentation |
Function to simulate effect sizes or outcomes based on "rma"
model objects.
## S3 method for class 'rma'
simulate(object, nsim=1, seed=NULL, olim, ...)
object |
an object of class |
nsim |
number of response vectors to simulate (defaults to 1). |
seed |
an object to specify if and how the random number generator should be initialized (‘seeded’). Either |
olim |
optional argument to specify observation/outcome limits for the simulated values. If unspecified, no limits are used. |
... |
other arguments. |
The model specified via object
must be a model fitted with either the rma.uni
or rma.mv
functions.
A data frame with nsim
columns with the simulated effect sizes or outcomes.
The data frame comes with an attribute "seed"
. If argument seed
is NULL
, the attribute is the value of .Random.seed
before the simulation was started; otherwise it is the value of the seed
argument with a "kind"
attribute with value as.list(RNGkind())
.
If the outcome measure used for the analysis is bounded (e.g., correlations are bounded between -1 and +1, proportions are bounded between 0 and 1), one can use the olim
argument to enforce those observation/outcome limits when simulating values (simulated values cannot exceed those bounds then).
Wolfgang Viechtbauer wvb@metafor-project.org https://www.metafor-project.org
Viechtbauer, W. (2010). Conducting meta-analyses in R with the metafor package. Journal of Statistical Software, 36(3), 1–48. https://doi.org/10.18637/jss.v036.i03
rma.uni
and rma.mv
for functions to fit models for which simulated effect sizes or outcomes can be generated.
### copy BCG vaccine data into 'dat'
dat <- dat.bcg
### calculate log risk ratios and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat)
dat
### fit random-effects model
res <- rma(yi, vi, data=dat)
res
### simulate 5 sets of new outcomes based on the fitted model
newdat <- simulate(res, nsim=5, seed=1234)
newdat
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.