Description Usage Arguments Details Value Author(s) See Also Examples
Generate multivariate data with dependency structure specified by a (given) DAG (Directed Acyclic Graph) with nodes corresponding to random variables. The DAG has to be topologically ordered.
1 2 3 4 
n 
number of samples that should be drawn. (integer) 
dag 
a graph object describing the DAG; must contain weights for
all the edges. The nodes must be topologically sorted. (For
topological sorting use 
errDist 
string specifying the distribution of each node.
Currently, the options "normal", "t4", "cauchy", "mix", "mixt3" and
"mixN100" are supported. The first
three generate standard normal, t(df=4) and cauchyrandom
numbers. The options containing the word "mix" create standard
normal random variables with a mix of outliers. The outliers for the
options "mix", "mixt3", "mixN100" are drawn from a standard cauchy,
t(df=3) and N(0,100) distribution, respectively. The fraction of
outliers is determined by the 
mix 
for the 
errMat 
numeric n * p matrix specifiying the error vectors
e_i (see Details), instead of specifying 
back.compatible 
logical indicating if the data generated should
be the same as with pcalg version 1.06 and earlier (where

use.node.names 
logical indicating if the column names of the
result matrix should equal 
Each node is visited in the topological order. For each node i we generate a pdimensional value X_i in the following way: Let X_1,…,X_k denote the values of all neighbours of i with lower order. Let w_1,…,w_k be the weights of the corresponding edges. Furthermore, generate a random vector E_i according to the specified error distribution. Then, the value of X_i is computed as
X_i = w_1*X_1 + … + w_k*X_k + E_i.
If node i has no neighbors with lower order, X_i = E_i is set.
A n*p matrix with the generated data. The p columns correspond to the nodes (i.e., random variables) and each of the n rows correspond to a sample.
Markus Kalisch ([email protected]) and Martin Maechler.
randomDAG
for generating a random DAG;
skeleton
and pc
for estimating the
skeleton and the CPDAG of a DAG that
corresponds to the data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  ## generate random DAG
p < 20
rDAG < randomDAG(p, prob = 0.2, lB=0.1, uB=1)
if (require(Rgraphviz)) {
## plot the DAG
plot(rDAG, main = "randomDAG(20, prob = 0.2, ..)")
}
## generate 1000 samples of DAG using standard normal error distribution
n < 1000
d.normMat < rmvDAG(n, rDAG, errDist="normal")
## generate 1000 samples of DAG using standard t(df=4) error distribution
d.t4Mat < rmvDAG(n, rDAG, errDist="t4")
## generate 1000 samples of DAG using standard normal with a cauchy
## mixture of 30 percent
d.mixMat < rmvDAG(n, rDAG, errDist="mix",mix=0.3)
require(MASS) ## for mvrnorm()
Sigma < toeplitz(ARMAacf(0.2, lag.max = p  1))
dim(Sigma)# p x p
## *Correlated* normal error matrix "e_i" (against model assumption)
eMat < mvrnorm(n, mu = rep(0, p), Sigma = Sigma)
d.CnormMat < rmvDAG(n, rDAG, errMat = eMat)

Loading required package: Rgraphviz
Loading required package: graph
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, sd, var, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colMeans, colSums, colnames, do.call,
duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
lapply, lengths, mapply, match, mget, order, paste, pmax, pmax.int,
pmin, pmin.int, rank, rbind, rowMeans, rowSums, rownames, sapply,
setdiff, sort, table, tapply, union, unique, unsplit, which,
which.max, which.min
Loading required package: grid
Loading required package: MASS
[1] 20 20
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.