list_compar: Graph Pairwise Comparison on Common Elements

Description Usage Arguments Details Value See Also Examples

View source: R/list_compar.R

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

1
2
3
4
5
6
nds_compar(grphs, nd.var = "type")

eds_compar(grphs, nd.var = "type")

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

Arguments

grphs

A list of two graphs (pair of graphs) to be compared.

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

 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
27
28
29
30
31
32
33
# Read data
imgs <- read.table(system.file("extdata", "imgs.tsv", package = "iconr"),
                   sep="\t",stringsAsFactors = FALSE)
nodes <- read.table(system.file("extdata", "nodes.tsv", package = "iconr"),
                    sep="\t",stringsAsFactors = FALSE)
edges <- read.table(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]])
## Edges of the second decoration graph

iconr documentation built on Feb. 16, 2021, 5:06 p.m.