Calculating ω

16 views
Skip to first unread message

yd li

unread,
May 25, 2019, 11:23:30 AM5/25/19
to brainGraph-help
Hi Cris,

According to the manual of brainGraph 2.7.0, I can calculate small-world σ, however I got following errors when generating random graphs with clustering controlling .

thresholds<-seq(0.05,0.4,0.01)
sub.thresh<-0.6
divisor<-'waytotal'
my.mats<-create_mats(matfiles$A,modality=modality,
                         divisor='none',
                         div.files=matfiles$way,
                         mat.thresh=thresholds,
                         sub.thresh = sub.thresh,
                         threshold.by='density', 
                         inds = inds,
                         algo = 'probabilistic',
                         symm.by='max' 
                         )
A.norm.sub <- my.mats$A.norm.sub
A.norm.mean <- my.mats$A.norm.mean

......

kNumRandClust <- 1e2 # Create 100 graphs per group/density combination
g.rand <- small.clust.dt <- vector('list', length=length(groups))

for (i in seq_along(groups)) {
  g.rand[[i]] <- vector('list', length=length(thresholds))
  for (j in seq_along(thresholds)) {
    g.rand[[i]][[j]] <- sim.rand.graph.par(g[[i]][[j]],
                                           N=kNumRandClust, clustering=T)
  }
  small.clust.dt[[i]] <- small.world(g[[i]], g.rand[[i]])
}
>> Error in sim.rand.graph.par(g[[i]][[j]], N = kNumRandClust, clustering = T) : 
  is_igraph(g) is not TRUE

Can you help me out? 


Chris Watson

unread,
May 25, 2019, 12:53:22 PM5/25/19
to brainGr...@googlegroups.com
I will need more information to determine the cause.

1. What versions of brainGraph and igraph are you using?
2. What are the values of "i" and "j" when the error appears? In the R console, can you then type "is_igraph(g[[i]][[j]])" to see if it is an igraph object?

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-he...@googlegroups.com.
To post to this group, send email to brainGr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/36ca6831-9f66-4713-a2ba-8bd891e56290%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yd li

unread,
May 25, 2019, 8:17:53 PM5/25/19
to brainGraph-help
Hi, Chris,
1. I am using brainGraph 2.7.0 and igraph 1.2.4.1.
2. The values of "i" and "j" are 1 and 1 when the error appears. The result of  "is_igraph(g[[i]][[j]])" is False. However, I got no error messages when i generating random graphs controlling only for degree distribution.

在 2019年5月26日星期日 UTC+8上午12:53:22,Chris Watson写道:
To unsubscribe from this group and stop receiving emails from it, send an email to brainGr...@googlegroups.com.

yd li

unread,
May 25, 2019, 8:26:45 PM5/25/19
to brainGraph-help
Hi,Chris,
The result of "is_igraph(g[[i]][[j]][[1]])" is True.

在 2019年5月26日星期日 UTC+8上午8:17:53,yd li写道:

Chris Watson

unread,
May 25, 2019, 10:00:20 PM5/25/19
to brainGr...@googlegroups.com
I would not think that it should work for degree distribution, either, unless you have another "for" loop. It will be necessary for the code to work, since you have single-subject graphs.
So you will have to add
g.rand[[i]][[j]] <- vector('list', length(g[[i]][[j]])
for (k in seq_along(g[[i]][[j]])) {
  g.rand[[i]][[j]][[k]] <- sim.rand.graph.par(g[[i]][[j]][[k]], ...)
}

You could also just run the "analysis_random_graphs" function, which was made to simplify this. Just be sure to include "clustering=TRUE" in the function call.
Chris

To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.

To post to this group, send email to brainGr...@googlegroups.com.

yd li

unread,
May 26, 2019, 1:39:45 PM5/26/19
to brainGraph-help
Hi,Chris,
I did get no error when i generated random graphs controlling only for degree distribution and i did not add another 'for' loop in the script.

With respect to generating random graphs controlling for degree distribution and clustering. I have changed my code according to your instruction:

kNumRandClust <- 1e2
g.rand <- small.clust.dt <- vector('list', length=length(groups))
for (i in seq_along(groups)) {
  g.rand[[i]] <- vector('list', length=length(thresholds))
  for (j in seq_along(thresholds)) {
    g.rand[[i]][[j]] <- vector('list', length(g[[i]][[j]]))
    for (k in seq_along(g[[i]][[j]])) {
      g.rand[[i]][[j]][[k]] <- sim.rand.graph.par(g[[i]][[j]][[k]],
                                             N=kNumRandClust, clustering=T)
    }
  }
  small.clust.dt[[i]] <- small.world(g[[i]], g.rand[[i]])
}

When the calculation for the first group(i=1, I have 2 groups) finished, I got an error: Error in graph_attr(x, "Lp") : Not a graph object.  
It seems that I missed something is the line: small.clust.dt[[i]] <- small.world(g[[i]], g.rand[[i]]).  Could you find it out?


在 2019年5月26日星期日 UTC+8上午10:00:20,Chris Watson写道:

Chris Watson

unread,
May 26, 2019, 3:14:07 PM5/26/19
to brainGr...@googlegroups.com
I think you have to move the "small.clust.dt" line into the "j" loop. So add the following to the start of the line "g.rand[[i]][[j]] <-"
small.clust.dti[[i]][[j]] <-

And then after the end of the "k" loop, write
small.clust.dt[[i]][[j]] <- small.world(g[[i]][[j]], g.rand[[i]][[j]])

I think this should work. I recommend testing with a smaller number of random graphs; maybe 10 or so. If it works then you can create as many as you'd like.
Chris

To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.

To post to this group, send email to brainGr...@googlegroups.com.

yd li

unread,
May 28, 2019, 11:12:50 AM5/28/19
to brainGraph-help
Hi, Chris,
Thanks a lot for your help! I have one feedback infomation and 2 questions.

1. The following code generated a huge-size list and lead the computer to be unresponsive (46 subjects for each group,2 groups;32 GB RAM)

for (i in seq_along(groups)) {
  g.rand[[i]] <- vector('list', length=length(thresholds))
  for (j in seq_along(thresholds)) {
    small.clust.dt[[i]][[j]]<-g.rand[[i]][[j]] <- vector('list', length(g[[i]][[j]]))
    for (k in seq_along(g[[i]][[j]])) {
      g.rand[[i]][[j]][[k]] <- sim.rand.graph.par(g[[i]][[j]][[k]],
                                             N=kNumRandClust, clustering=T)
    }
    small.clust.dt[[i]][[j]] <- small.world(g[[i]][[j]], g.rand[[i]][[j]])
  }
}

So, I use rand_vars_clust <- analysis_random_graphs(g, kNumRandClust,  savedir=outdir, clustering=T) to generate random graphs controlling for degree distribution and clustering, and this code worked fine.

2. Since I only cared about group-level small-worldness currently, I replaced g with g.group. Is that right?
3. According to the manual, the code to calculate omega is :small.dt[, omega := small.dt[, Lp.rand / Lp] - small.clust.dt[, Cp / Cp.rand]],  why is it not small.dt[, omega := small.clust.dt[, Lp.rand / Lp] - small.clust.dt[, Cp / Cp.rand]] ?

在 2019年5月27日星期一 UTC+8上午3:14:07,Chris Watson写道:

Chris Watson

unread,
May 28, 2019, 1:21:25 PM5/28/19
to brainGr...@googlegroups.com
1. Yes, in "analysis_random_graphs", it saves the random graphs individually, and then combines them later. I had noticed long ago that this resulted in a significant memory improvement; otherwise, as you have discovered, it can be untenable if you have a large number of subjects X thresholds X random graphs.
2. Yes, you should look at the group-level graphs in that case. However, since you do have single-subject graphs, you can get summary statistics by using the individual values.
3. The reason the code is listed as that can be seen by inspecting Equation 4 in Telesford et al. (2011). The "Lp.rand" should come from the "standard" random graphs, while the "Cp.rand" should be from the random graphs controlling for clustering (called "C_latt" in the paper). In fact the code could probably be simplified somewhat further as
small.dt[, omega := (Lp.rand / Lp) - small.clust.dt[, Cp / Cp.rand]]

or perhaps better,
small.dt[, Cp.latt := small.clust.dt$Cp.rand]
small.dt[, omega := (Lp.rand / Lp) - (Cp / Cp.latt)]
although in this case, it would require that the rows in both "small.dt" and "small.clust.dt" are exact matches. The final line of code could also be

Chris

To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.

To post to this group, send email to brainGr...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages