Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

wgtMatrix

Weight Matrix of a Graph, e.g., a simulated DAG


Description

Given a graph object g, as generated e.g., by randomDAG, return the matrix of its edge weights, the “weight matrix”.

Usage

wgtMatrix(g, transpose = TRUE)

Arguments

g

graph object (package graph) of, say, p nodes, e.g. containing a DAG.

transpose

logical indicating if the weight matrix should be transposed (t(.), see details).

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, M[i,j] is the weight of the edge from i to j.

Nowadays, this is a trivial wrapper around as(g, "matrix") using the (coerce) method provided by the graph package.

Value

The p * p weight matrix M.

Note

This function can not be used to estimate the edge weights in an estimated DAG / CPDAG.

Author(s)

Markus Kalisch

See Also

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

Examples

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

pcalg

Methods for Graphical Models and Causal Inference

v2.7-2
GPL (>= 2)
Authors
Markus Kalisch [aut, cre], Alain Hauser [aut], Martin Maechler [aut], Diego Colombo [ctb], Doris Entner [ctb], Patrik Hoyer [ctb], Antti Hyttinen [ctb], Jonas Peters [ctb], Nicoletta Andri [ctb], Emilija Perkovic [ctb], Preetam Nandy [ctb], Philipp Ruetimann [ctb], Daniel Stekhoven [ctb], Manuel Schuerch [ctb], Marco Eigenmann [ctb], Leonard Henckel [ctb], Joris Mooij [ctb]
Initial release
2021-4-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.