Skip to contents

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()
#> # A tibble: 500 × 3
#>           x       y       z
#>       <dbl>   <dbl>   <dbl>
#>  1  0.358   -1.54    2.49  
#>  2 -0.975    0.204  -0.0999
#>  3  1.88    -0.704  -0.0611
#>  4  0.0579   1.12   -1.42  
#>  5 -1.46    -0.349  -0.0291
#>  6  0.152   -0.141  -0.422 
#>  7  0.00618  2.29   -0.692 
#>  8  0.400    0.748  -0.123 
#>  9  1.29    -1.28    0.128 
#> 10  0.517   -0.0827 -0.464 
#> # ℹ 490 more rows