stefpeschel / NetCoMi

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

Issue with netConstruct with knn algorithm #37

Closed hanghu1024 closed 2 years ago

hanghu1024 commented 2 years ago

Hi!

I am trying to construct the graph with knn algorithm. My data is a pre-computed association matrix, and my parameters are listed below:

net <- netConstruct(data = matrix, 
                    dataType = "correlation", 
                    sparsMethod = "knn",
                    kNeighbor = 10,
                    knnMutual = FALSE)

But I get the error message:

Sparsify associations via 'knn' ... Done.
Error in if (all(x.tmp <= 1)) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In sqrt(0.5 * (1 - xvec)) : NaNs produced

You give an tutorial example for knn using count data, but does it work for association matrix? If so, is there a way to fix this bug? In addition, the default value for kNeighbor is 3L, what's the point for "L" here? I am using version 1.0.2, and I got some success with threshold method for this data.

Many thanks!

Hang

stefpeschel commented 2 years ago

Dear Hang,

The knn algorithm works only for dissimilarities, not for associations. So, your matrix must be a dissimilarity matrix and you have to set the "datatype" argument to "dissimilarity". In the resulting network, nodes will be the samples, not the taxa.

Best, Stefanie

hanghu1024 commented 2 years ago

Hello Stefanie,

Got it, thanks!

Best, Hang