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

getGraph

Get the "graph" Part or Aspect of R Object


Description

Get the graph part or “aspect” of an R object, notably from our pc(), skeleton(), fci(), etc, results.

Usage

getGraph(x)

Arguments

x

potentially any R object which can be interpreted as a graph (with nodes and edges).

Value

a graph object, i.e., one inheriting from (the virtual) class "graph", package graph.

Methods

signature(x = "ANY")

the default method just tries as(x, "graph"), so works when a coerce (S4) method is defined for x.

signature(x = "pcAlgo")

and

signature(x = "fciAlgo")

extract the graph part explicitly.

signature(x = "matrix")

interpret x as adjacency matrix and return the corresponding "graphAM" object.

For sparseMatrix methods, see the ‘Note’.

Note

For large graphs, it may be attractive to work with sparse matrices from the Matrix package. If desired, you can activate this by

require(Matrix)
 setMethod("getGraph", "sparseMatrix", function(x) as(x, "graphNEL"))
 setMethod("getGraph", "Matrix",       function(x) as(x, "graphAM"))

Author(s)

Martin Maechler

See Also

fci, etc. The graph class description in package graph.

Examples

A <- rbind(c(0,1,0,0,1),
           c(0,0,0,1,1),
           c(1,0,0,1,0),
           c(1,0,0,0,1),
           c(0,0,0,1,0))
sum(A) # 9
getGraph(A) ## a graph with 5 nodes and  'sum(A)' edges

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.