Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

simulate_data

Simulate Data from Structural Equation Model


Description

This is a thin wrapper for the simulateSEM()function in dagitty that works with tidied dagitty objects. It treats the input DAG as a structural equation model, generating random path coefficients and simulating corresponding data. See dagitty::simulateSEM() for details.

Usage

simulate_data(
  .tdy_dag,
  b.default = NULL,
  b.lower = -0.6,
  b.upper = 0.6,
  eps = 1,
  N = 500,
  standardized = TRUE
)

Arguments

.tdy_dag

the input DAG, which can be a tidy_dagitty or dagitty object.

b.default

default path coefficient applied to arrows for which no coefficient is defined in the model syntax.

b.lower

lower bound for random path coefficients, applied if b.default = NULL.

b.upper

upper bound for path coefficients.

eps

residual variance (only meaningful if standardized=FALSE).

N

number of samples to generate.

standardized

whether a standardized output is desired (all variables have variance 1).

Value

a tblwith N values for each variable in .tdy_dag

Examples

dagify(y ~ z, x ~ z) %>%
  tidy_dagitty() %>%
  simulate_data()

ggdag

Analyze and Create Elegant Directed Acyclic Graphs

v0.2.3
MIT + file LICENSE
Authors
Malcolm Barrett [aut, cre] (<https://orcid.org/0000-0003-0299-5825>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.