Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Negative modularity when species cannot interact with themselves #161

Closed
clementviolet opened this issue May 13, 2020 · 3 comments
Closed

Comments

@clementviolet
Copy link

Hi! Thanks for your package!

When I have a probabilistic network where species cannot interact with themselves, I've got a negative modularity value. I thought modularity should be between [0;1], right?

Here a small reprex.

using Random, EcologicalNetworks, LinearAlgebra

Random.seed!(42);

net = rand(10, 10);

net_diag = copy(net);
net_diag[diagind(net_diag)] .= 0;

net = UnipartiteProbabilisticNetwork(net);
net_diag = UnipartiteProbabilisticNetwork(net_diag);

Q(net, each_species_its_module(net)[2])
Q(net_diag, each_species_its_module(net)[2])

I'm using Julia v1.2.0 and EcologicalNetworks v0.2.2

@tpoisot
Copy link
Member

tpoisot commented May 17, 2020

Hi Clement,

Modularity as measured here is the number of links within modules compared to how many there would be under the null assumption (it's in Newman's paper). So when there are fewer such links than expected, the modularity can be negative. If you want to try something, look at a very small network (4 species) with two "perfect" modules, the value of Q should be about 1/2.

You can use Qr (realized modularity) if you want something strictly between 0 and 1.

I'll mark this one as solved as this is not a bug (simply normal behavior of the measure, although a rare one).

@tpoisot tpoisot closed this as completed May 17, 2020
@clementviolet
Copy link
Author

Hi Tim!

Thanks for you quick answer, I 've just look at your paper about Qr() and that exactly what I was looking for. However, I still have negative value with Qr() with both simulated data like above and real one. I think I'm missing something...

Here is the updated reprex.

using Random, EcologicalNetworks, LinearAlgebra

Random.seed!(42);

net = rand(10, 10);

net_diag = copy(net);
net_diag[diagind(net_diag)] .= 0;

net = UnipartiteProbabilisticNetwork(net);
net_diag = UnipartiteProbabilisticNetwork(net_diag);

Qr(net, each_species_its_module(net)[2])

Qr(net_diag, each_species_its_module(net_diag)[2])

Should I reopen this issue or open a new one (or is it the normal behavior)?

@tpoisot
Copy link
Member

tpoisot commented May 18, 2020

Also normal behavior - the network you have here is anti-modular, so this is not unexpected to find negative values (there's a discussion of this in the Qr paper, I think)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants