simulate.rma: Simulate Method for 'rma' Objects

View source: R/simulate.rma.r

simulate.rmaR Documentation

Simulate Method for 'rma' Objects

Description

Function to simulate effect sizes or outcomes based on "rma" model objects.

Usage

## S3 method for class 'rma'
simulate(object, nsim=1, seed=NULL, olim, ...)

Arguments

object

an object of class "rma".

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 NULL or an integer that will be used in a call to set.seed before simulating the response vectors. If set, the value is saved as the "seed" attribute of the returned value. The default, NULL will not change the random generator state, and return .Random.seed as the "seed" attribute; see ‘Value’.

olim

optional argument to specify observation/outcome limits for the simulated values. If unspecified, no limits are used.

...

other arguments.

Details

The model specified via object must be a model fitted with either the rma.uni or rma.mv functions.

Value

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()).

Note

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).

Author(s)

Wolfgang Viechtbauer wvb@metafor-project.org https://www.metafor-project.org

References

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⁠

See Also

rma.uni and rma.mv for functions to fit models for which simulated effect sizes or outcomes can be generated.

Examples

### 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

metafor documentation built on May 29, 2024, 7:44 a.m.