Adjacency matrix - does it need to be all positive values

290 views
Skip to first unread message

Sean Ma

unread,
Jan 4, 2018, 6:33:25 PM1/4/18
to brainGraph-help
Hi Chris, 

I was trying to replicate your code in 6.3 `Graph creation` with my correlation matrix that contains positive and negative correlation values. 

Error in { : 
  task 1 failed - "At community.c:2693 : weights must be positive, Invalid value"

Do I need to factor the negative correlation values into a different factor (such as what `igraph` has suggested with edge.color)? And will your `set_brainGraph_attr` be able to handle it?

Thanks for your help!

Sean 

Chris Watson

unread,
Jan 5, 2018, 12:44:59 AM1/5/18
to brainGr...@googlegroups.com
Hi, that is correct, the Louvain clustering algorithm won't work if there are negative edge weights. Unfortunately this means that `set_brainGraph_attr` will fail. I will definitely add a check in the function for negative weights, and I think I will use one of the solutions in this post: https://stats.stackexchange.com/questions/177507/graph-clustering-algorithms-which-consider-negative-weights

As one of the comments states, if the weights have range [-1, 1], then mapping to `abs(x)` might be the best bet. This is also appropriate if *all* weights are negative. Alternatively, I might just switch it to use the "spinglass" method instead of trying to think of every edge case.

Chris

--
You received this message because you are subscribed to the Google Groups "brainGraph-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-help+unsubscribe@googlegroups.com.
To post to this group, send email to brainGraph-help@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/d1a3f3a3-c686-47bb-a70a-849a7524fe46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sean Ma

unread,
Jan 22, 2018, 12:55:13 PM1/22/18
to brainGraph-help
Hi Chris, 

I would like to follow up on this topic and the error I got after applying the abs() approach on my negative correlation matrices for `brainGraph`. 

There are 2 main issues I'd like to report:

1. As the nature of these negative correlation matrices are sparser than the positive ones, I've notice `set_brainGraph_attr` will crash if certain threshold levels have all zero matrices within the `A.norm.sub` variable. 

2. After removing the all zero matrices for the specific threshold levels, I've encountered an error below at line 135, 
`      V(g)$GC.wt <- gateway_coeff(g, V(g)$comm.wt)`   within the `set_brainGraph_attr` function.

The error is:
Error in colSums(Kis[which(memb == x), 1:M]) : 
  'x' must be an array of at least two dimensions

I'm trying to trace the function `gateway_coeff` but the source code is not in your Github repo. Can you briefly explain what that function is doing and if sparse matrix will cause it to collapse?

Let me know if you need me to upload my `A.norm.sub` variable to help reproduce this error. 

Thanks for your help!

Sean

Chris Watson

unread,
Jan 22, 2018, 2:01:04 PM1/22/18
to brainGr...@googlegroups.com
1) Thanks, I will look into that. I think I'll just end up writing a solution that will allow you to keep the negative edge weights, as these can be important in some cases.

2) Ah, I thought I had fixed that bug. Yes, I remember in the past that the function would throw an error with sparser matrices; I will fix it.
The function is in the file "vertex_roles.R": https://github.com/cwatson/brainGraph/blob/681fec00e7c6e704373ac7a0e8d6a872546260f5/R/vertex_roles.R
It is extremely similar to the participation coefficient; you can read the reference here: https://link.springer.com/article/10.1140/epjb/e2014-40800-7


--
You received this message because you are subscribed to the Google Groups "brainGraph-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-help+unsubscribe@googlegroups.com.
To post to this group, send email to brainGraph-help@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages