View source: R/ccdrAlgorithm-mvn.R
generate_mvn_data | R Documentation |
Given a Gaussian DAG, generate data from the underlying distribution. Equivalently, generate data from a multivariate normal distribution given one of its SEM. Can generate both observational and intervention data.
generate_mvn_data(graph, params, n = 1, ivn = NULL, ivn.rand = TRUE)
graph |
DAG in |
params |
Vector of parameters. Last p elements correspond to variances (p = number of nodes in |
n |
Number of samples to draw. |
ivn |
List of interventions (see |
ivn.rand |
If |
If ivn = NULL
, then n
observational samples are drawn. For each
component of ivn
that is not NULL
, interventional samples will
be drawn with the values of each node specified in the component.
### Generate observational data gr <- sparsebnUtils::random.graph(5, 5) # use sparsebnUtils package to generate a random graph gr.params <- runif(10) # there are 5 coefficients + 5 variances data.obs <- ccdrAlgorithm::generate_mvn_data(graph = gr, n = 100, params = gr.params) ### Generate experimental data ivn <- as.list(c(rep("V1", 50), rep("V2", 50))) # 50 interventions on V1, 50 interventions on V2 data.ivn <- ccdrAlgorithm::generate_mvn_data(graph = gr, n = 100, params = gr.params, ivn = ivn) ### Use pre-specified values for interventions ### In this toy example, we assume that all intervened nodes were fixed to ### to the value 1, although this can be any number of course. ivn.vals <- lapply(ivn, function(x) sapply(x, function(x) 1)) # replace all entries with a 1 data.ivn <- ccdrAlgorithm::generate_mvn_data(graph = gr, n = 100, params = gr.params, ivn = ivn.vals, ivn.rand = FALSE) ### If ivn.rand = FALSE, you must specify values ### The code below will fail because ivn does not contain any values ### (compare to ivn.vals above). ## Not run: data.ivn <- ccdrAlgorithm::generate_mvn_data(graph = gr, n = 100, params = gr.params, ivn = ivn, ivn.rand = FALSE) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.