graph_node_compar: Compare the local properties of the nodes from two graphs

View source: R/graph_node_compar.R

graph_node_comparR Documentation

Compare the local properties of the nodes from two graphs

Description

The function computes a correlation coefficient between the graph-theoretic metric values computed at the node-level in two graphs sharing the same nodes. It allows to assess whether the connectivity properties of the nodes in one graph are similar to that of the same nodes in the other graph. Alternatively, the correlation is computed between a graph-theoretic metric values and the values of an attribute associated to the nodes of a graph.

Usage

graph_node_compar(
  x,
  y,
  metrics = c("siw", "siw"),
  method = "spearman",
  weight = TRUE,
  test = TRUE
)

Arguments

x

An object of class igraph. Its nodes must have the same names as in graph y.

y

An object of class igraph. Its nodes must have the same names as in graph x.

metrics

Two-element character vector specifying the graph-theoretic metrics computed at the node-level in the graphs or the node attribute values to be correlated to these metrics. Graph-theoretic metrics can be:

  • Degree (metrics = c("deg", ...))

  • Closeness centrality index (metrics = c("close",...))

  • Betweenness centrality index (metrics = c("btw",...))

  • Strength (sum of the weights of the links connected to a node) (metrics = c("str",...))

  • Sum of the inverse weights of the links connected to a node (metrics = c("siw", ...), default)

  • Mean of the inverse weights of the links connected to a node (metrics = c("miw", ...))

Node attributes must have the same names as in the igraph object, and must refer to an attribute with numerical values. The vector metrics is composed of two character values. When a node attribute has the same name as a metric computable from the graph, node attributes are given priority.

method

A character string indicating which correlation coefficient is to be computed ("pearson", "kendall" or "spearman" (default)).

weight

Logical which indicates whether the links are weighted during the calculation of the centrality indices betweenness and closeness. (default: weight = TRUE). Link weights are interpreted as distances when computing the shortest paths. They should then be inversely proportional to the strength of the relationship between nodes (e.g. to fluxes).

test

Logical. Should significance testing be performed? (default = TRUE)

Details

The correlation coefficients between the metrics can be computed in different ways, as initial assumptions (e.g. linear relationship) are rarely verified. Pearson's r, Spearman's rho and Kendall's tau can be computed (from function cor). When x is similar to y, then the correlation is computed between two metrics characterizing the nodes of the same graph.

Value

A list summarizing the correlation analysis.

Author(s)

P. Savary

Examples

data(data_ex_genind)
data(pts_pop_ex)
mat_dist <- suppressWarnings(graph4lg::mat_geo_dist(data = pts_pop_ex,
      ID = "ID",
      x = "x",
      y = "y"))
mat_dist <- mat_dist[order(as.character(row.names(mat_dist))),
                      order(as.character(colnames(mat_dist)))]
graph_obs <- gen_graph_thr(mat_w = mat_dist, mat_thr = mat_dist,
                           thr = 9500, mode = "larger")
mat_gen <- mat_gen_dist(x = data_ex_genind, dist = "DPS")
graph_pred <- gen_graph_topo(mat_w = mat_gen, mat_topo = mat_dist,
                            topo = "gabriel")
res_cor <- graph_node_compar(x = graph_obs, y = graph_pred,
                             metrics = c("siw", "siw"), method = "spearman",
                             test = TRUE, weight = TRUE)

graph4lg documentation built on Feb. 16, 2023, 5:43 p.m.