Learn R Programming

dagitty (version 0.1-9)

simulateSEM: Simulate Data from Structural Equation Model

Description

Interprets the input graph as a structural equation model, generates random path coefficients, and simulates data from the model. This is just a dumb frontend to lavaan's simulateData function and probably not very useful except for quick validation purposes (e.g. checking that an implied vanishing tetrad truly vanishes in simulated data). For more elaborate simulation studies, please use the lavaan package or similar facilities in other packages.

Usage

simulateSEM(x, b.lower = -0.6, b.upper = 0.6, eps = 1, N = 500,
  standardized = TRUE)

Arguments

x
the input graph, a DAG (which may contain bidirected edges).
b.lower
lower bound for path coefficients.
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).

If standardized=TRUE, all path coefficients are interpreted as standardized coefficients. But not all standardized coefficients are compatible with all graph structure

Value

  • Returns a data frame containing N values for each variable in x.

Details

Data are generated in the following manner. Each directed arrow is assigned a path coefficient chosen uniformly at random from the interval given by b.lower and b.upper (inclusive; set both parameters to the same value for constant path coefficients). Each bidirected arrow a <-> b is replaced by a substructure a <- L -> b, where L is an exogenous latent variable. Path coefficients on such substructures are set to sqrt(x), where x is again chosen at random from the given interval; if x is negative, one path coefficient is set to -sqrt(x) and the other to sqrt(x). All residual variances are set to eps.

Examples

Run this code
## Simulate data with pre-defined path coefficients of -.6
g <- dagitty('dag{z -> x <- y}')
x <- simulateSEM( g, .707, .707 ) # sqrt(2)/2 is largest possible
cov(x)

Run the code above in your browser using DataLab