Learn R Programming

pcalg (version 2.0-3)

wgtMatrix: Compute weight matrix of simulated DAG.

Description

Transform a DAG that was generated by randomDAG to a weight matrix.

Usage

wgtMatrix(g, transpose = TRUE)

Arguments

g
Graph object containing the DAG.
transpose
Transpose weight matrix (see details).

Value

  • Weight matrix.

Details

When generating a DAG (e.g. using randomDAG), a graph object is usually generated and edge weights are usually specified. This function extracts the edge weights and arranges them in a matrix M.

If transpose is TRUE (default), M[i,j] is the weight of the edge from j to i. If transpose is FALSE (default), M[i,j] is the weight of the edge from i to j.

See Also

randomDAG for generating a random DAG; rmvDAG for simulating data from a generated DAG.

Examples

Run this code
set.seed(123)
g <- randomDAG(n = 5, prob = 0.3) ## generate random DAG
if(require(Rgraphviz)) {
plot(g)
}

## edge weights as matrix
wgtMatrix(g)

## for comparison: edge weights in graph object
g@edgeData@data

Run the code above in your browser using DataLab