Hello,

> ### Which works fine, but for comparing the community structures I use this
> for loop:
>  
> nmi <- rep(NA, 45)
> for (i in 1:10) {for (n in (i+1):10) { for (j in 1:45) {
> nmi[j] <- compare(info[[i]], info[[n]], method="nmi")
> }}}
>  
> which just gives me 1's.
Okay, there's one thing I don't understand here. Why do you have an inner for 
loop for the j variable? This will just run the comparison for the same pair of 
communities 45 times, and fill the result of the nmi vector with this. Then the 
outer two loops will move on to the next community pair, compare the pair 45 
times, and fill the result of the nmi vector. So you are essentially 
overwriting the nmi vector whenever you start to evaluate a new pair. What you 
need is probably this:

j <- 1
for (i in 1:10) {
    for (n in (i+1):10) {
        nmi[j] <- compare(info[[i]], info[[n]], method="nmi")
        j <- j+1  
    }
}

In this case you can still get a vector containing 1's only, but this will only 
indicate that your communities are identical.

For what it's worth, you can get all the possible pairings of the community 
structures with t(combn(info, 2)) -- this gives you a 2D array with two columns 
where each row corresponds to one possible pairing. You can then use apply() to 
apply the comparison function for each row:

pairs <- t(combn(info, 2))
nmi <- apply(pairs, 1, function (row) { compare(row[[1]], row[[2]], 
method="nmi") })

-- 
T.

_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to