list_compar: Graph Pairwise Comparison on Common Elements

View source: R/list_compar.R

list_comparR Documentation

Graph Pairwise Comparison on Common Elements

Description

nds_compar identifies common nodes in a pair of graphs. eds_compar identifies common edges in a pair of graphs. Given a list of graphs, list_compar extract all combinations of graph pairs and compare them on common elements (nodes and edges).

Usage

list_compar(lgrph, nd.var = "type", verbose = FALSE)

Arguments

lgrph

a list of any number of graphs to be pairwise compared. The list can be typically obtained with the function list_dec.

nd.var

an attribute of the graph nodes containing the node variable (ie, field) on which the comparison will be done. By default nd.var = "type".

verbose

logical. If TRUE, the names of each graph pair combination are listed on the screen. By default verbose = FALSE.

Details

list_compar() calls the functions: nds_compar() and eds_compar() which return respectively the common nodes and the common edges of a graph pairwise. Nodes are common when they have the same value for a given variable, for example horse, sword, etc., for the variable type (nd.var = "type"). Edges are common when they have the same value for starting and ending nodes (horse, sword, etc.) and the same type of edge ('=', '+', etc.). For example, a -=- b in graph 1 is equal to a -=- b in graph 2, but not equal to a -+- b. Edges of type = (normal edges) are undirected, so that a -=- b is equal to b -=- a. But edges of types + (attribute edges) or > (diachronic edges) are directed, so: a ->- b is not equal to b ->- a. If any of the graphs has multiple nodes/edges with the same value, it is considered to count for as many coincidences as the smaller multiplicity. For instance, if there are 2 nodes with value epee in graph 1, and 3 nodes with value epee in graph 2, their number of common nodes is min(2, 3) = 2.

Value

nds_compar() returns the input pair of graphs, each complemented with a new node attribute named comm with value 1 for common nodes and 0 for non-common nodes. eds_compar() returns the input pair of graphs, each complemented with a new edge attribute named comm with value 1 for common edges and 0 for non-common edges. list_compar() returns a list of all combinations of graph pairs. For each pair, both graphs are complemented with the node attribute (comm) identifying common nodes and the edge attribute (comm) identifying common edges. Each pair is also complemented with an attribute named nd.var recording the compared node variable.

See Also

list_dec, plot_compar, same_elements.

Examples


# Read data
imgs <- read.csv2(system.file("extdata", "imgs.tsv", package = "iconr"),
                  sep="\t", stringsAsFactors = FALSE)
nodes <- read.csv2(system.file("extdata", "nodes.tsv", package = "iconr"),
                   sep="\t", stringsAsFactors = FALSE)
edges <- read.csv2(system.file("extdata", "edges.tsv", package = "iconr"),
                   sep="\t", stringsAsFactors = FALSE)
# Generate list of graphs from the three data.frames
lgrph <- list_dec(imgs, nodes, edges)

# Generate list of all graph comparisons depending on the node "type" variable
g.compar <- list_compar(lgrph, nd.var = "type")

length(g.compar)
## Ten pairwise comparisons

# Inspect the second pairwise comparison of the list
g.compar[[2]]
## The two compared graphs with the name of the comparison variable

# Inspecting nodes:
igraph::as_data_frame(g.compar[[2]][[1]], "vertices")
## Vertices from the first decoration graph

igraph::as_data_frame(g.compar[[2]][[2]], "vertices")
## Vertices from the second decoration graph

# Inspecting edges:
igraph::as_data_frame(g.compar[[2]][[1]])
## Edges of the first decoration graph

igraph::as_data_frame(g.compar[[2]][[2]])


zoometh/iconr documentation built on Nov. 9, 2023, 10:01 a.m.