View source: R/graph_topo_compar.R
graph_topo_compar | R Documentation |
The function computes several indices in order to compare two graph topologies. One of the graph has the "true" topology the other is supposed to reproduce. The indices are then a way to assess the reliability of the latter graph. Both graphs must have the same number of nodes, but not necessarily the same number of links. They must also have the same node names and in the same order.
graph_topo_compar(obs_graph, pred_graph, mode = "mcc", directed = FALSE)
obs_graph |
A graph object of class |
pred_graph |
A graph object of class |
mode |
A character string specifying which index to compute in order to compare the topologies of the graphs.
|
directed |
Logical (TRUE or FALSE) specifying whether both graphs are directed or not. |
The indices are calculated from a confusion matrix counting the number of links that are in the "observed" graph ("true") and also in the "predicted" graph (true positives : TP), that are in the "observed" graph but not in the "predicted" graph (false negatives : FN), that are not in the "observed" graph but in the "predicted" graph (false positives : FP) and that are not in the "observed" graph and not in the "predicted" graph neither (true negatives: TN). K is the total number of links in the graphs. K is equal to n\times(n-1) if the graphs are directed and to \frac{n\times(n-1)}{2} if they are not directed, with n the number of nodes. OP = TP + FN, ON = TN + FP, PP = TP + FP and PN = FN + TN.
The Matthews Correlation Coefficient (MCC) is computed as follows: MCC = \frac{TP\times TN-FP\times FN}{√{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}
The Kappa index is computed as follows: Kappa = \frac{K\times (TP + TN) - (ON \times PN) - (OP \times PP)}{K^{2} - (ON \times PN) - (OP \times PP)}
The False Discovery Rate (FDR) is calculated as follows: FDR = \frac{FP}{TP+FP}
The Accuracy is calculated as follows: Acc = \frac{TP + TN}{K}
The Sensitivity is calculated as follows: Sens = \frac{TP}{TP+FN}
The Specificity is calculated as follows: Spec = \frac{TN}{TN+FP}
The Precision is calculated as follows: Prec = \frac{TP}{TP+FP}
Self loops are not taken into account.
The value of the index computed
P. Savary
dyer2004populationgraph4lg \insertRefbaldi2000assessinggraph4lg \insertRefmatthews1975comparisongraph4lg
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 = 15000, 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") graph_topo_compar(obs_graph = graph_obs, pred_graph = graph_pred, mode = "mcc", directed = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.