Giter Club home page Giter Club logo

Comments (1)

stefpeschel avatar stefpeschel commented on August 14, 2024

Hey,

please excuse my late response. I just had a closer look into this issue and the way the edgeFilter works is indeed not nice.

Some background on what happens within netConstruct() if the network is based on correlations:
First, correlations are estimated. These are transformed into dissimilarities (according to how dissFunc is set) and the dissimilarities, in turn, are transformed into similarities, which are finally used as adjacency matrix in a weighted network. This transformation approach is necessary because correlations range from -1 to 1 but we need values in [0,1] for the edge weights. Further details on the available transformation methods can be found in our manuscript as well as in the package docu.

At the moment, there are three possible options for when to do the edge filter step:

1) During network construction
The threshold is applied to the estimated associations and transformation comes afterwards. In this case, all further steps (network analysis and plotting) is applied to the filtered network.

2) Using edgeFilter and edgeFilterPar when plotting the network
Threshold is applied to the adjacency matrix, which contains the edge weights. The difference to the former method is that network analysis is applied to the unfiltered network and edges are only filtered in the plot. Here, edges are filtered before the layout is computed.

3) Using edgeInvisFilter and edgeInvisPar when plotting the network
Same as before but edges are filter after the layout is computed. This filter is useful to just hide some edges without changing the layout and can be applied in addition to the other filters.

Now, the problem is that in the latter two methods, the threshold is applied to the transformed edge weights so that - in the current NetCoMi version - the threshold has to be transformed as well. I see that it's not solved nicely and will fix this in a future update. For now, I can only provide an example on how to use the filter options properly:

Example:
In this example, edges corresponding to an absolute correlation |r| < 0.3 are filtered out.

For a better understanding what happens within netConstruct, here is the code of the two functions for transforming associations into dissimilarities, which are used if disFunc = "signed" and disFunc = "unsigned" is chosen:

signed <- function(x){
  sqrt(0.5 * (1-x))
}

unsigned <- function(x){
  sqrt(1 - x^2)
}

Note: In the current version, the edgeFilter cannot be used properly if disFunc = "signed" because we would have to filter out edges with weights between 1 - signed(-0.3) and 1 - signed(0.3), but edgeFilterPar accepts only one value. With the "signed" transformation, we would filter out all negative correlations, which happened in your case.
Thus, we have to use the "unsigned" transformation:

library(NetCoMi)
data("amgut2.filt.phy")

amgut_net1 <- netConstruct(amgut2.filt.phy, 
                           measure = "pearson",
                           zeroMethod = "multRepl",
                           normMethod = "clr",
                           sparsMethod = "none",
                           dissFunc = "unsigned")

amgut_props1 <- netAnalyze(amgut_net1, clustMethod = "cluster_fast_greedy",
                           weightDeg = TRUE, normDeg = FALSE)

thresh <- 1 - unsigned(0.3)

plot(amgut_props1,
     edgeFilter = "threshold",
     edgeFilterPar = thresh)

And here is also an example for the first method, which leads to the same plot, except for node colors. These represent the cluster assignment, which is computed for the filtered network with the first method and for the unfiltered network with method two and three.


amgut_net1 <- netConstruct(amgut2.filt.phy, 
                           measure = "pearson",
                           zeroMethod = "multRepl",
                           normMethod = "clr",
                           dissFunc = "unsigned",
                           sparsMethod = "thresh",
                           thresh = 0.3)

amgut_props1 <- netAnalyze(amgut_net1, clustMethod = "cluster_fast_greedy")

plot(amgut_props1)

I hope that clarifies how the threshold filter works at the moment. And I'll have to implement a better solution asap.

Best,
Stefanie

from netcomi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.