stefpeschel / NetCoMi

Network construction, analysis, and comparison for microbial compositional data
GNU General Public License v3.0
143 stars 24 forks source link

Edges with correlation value == -1 are not displayed in signed mode #104

Closed danpal96 closed 8 months ago

danpal96 commented 8 months ago

When using dissFunc = "signed" the correlation values of -1 are transformed to weight values of 0 in the adjacency matrix and therefore are not been displayed. I don't know if this is the intended behaviour but I would like to visualize in this mode the edges with correlation values of -1

stefpeschel commented 8 months ago

Yes, this is the intended behavior. We follow van Dongen & Enright, who proposed functions to transform correlations into dissimilarities. With "signed", the following function is used:

dissFunc <- function(xvec) {
  sqrt(0.5 * (1-xvec))
}

Using this function, correlations of -1 get the maximum possible distance of 1 and thus a similarity of 0, which is used as edge weight.

If you want to use a different transformation, you can pass your own function to the dissFunc argument of netConstruct.

Reference: van Dongen, S., & Enright, A. J. (2012). Metric distances derived from cosine similarity and Pearson and Spearman correlations. 2, 2–6. http://arxiv.org/abs/1208.3145

danpal96 commented 8 months ago

Thanks for the reply, I think that I will use a slightly modified function, with the default function is ambiguous if no edge means that the correlation is below the cutoff or its value is -1, but probably a correlation of exactly -1 is a very unlikely case

stefpeschel commented 8 months ago

The idea behind this is the following: With the "unsigned" transformation we assume that we are interested in highly correlated taxa, no matter if the correlation is positive or negative. So, the smaller the correlation (in absolute terms) the lower the edge weight, and a correlation of 0 is not shown in the network. With the "unsigned" transformation, on the other hand, we are only interested in highly positive correlated taxa. So, the smaller the correlation, the more "uninteresting" it is. And the most extreme case of -1 is excluded from the network.

And you're right, these extreme values are really unlikely in real cases.

danpal96 commented 8 months ago

Just for clarification, I mainly use the signed transformation to visualize groups of nodes that have positive interactions in the group but negative with others, and since I am interested in this negative interactions between groups it could be a problem that the -1 values are excluded