Graph-level Attributes

31 views
Skip to first unread message

Onur Ugurlu

unread,
Oct 28, 2016, 5:47:28 AM10/28/16
to brainGraph-help

Hi Chris,

 

I am trying to investigate group difference in graph level as in the 'brainGraph_UserGuide'. I can calculate the ‘Lp’, ‘Cp’, E.global’, ‘modality’, ‘assortativity’ and ‘assortativity.lobe’. However, I got following errors for some parameters (max.comp, clique.num, num.tri, diameter, transitivity, asymm, num.hubs, E.local, vulnerability). I am using the following procedure:

 
____________________________________
 
exclude.subs <- NULL
use.mean <- FALSE 
 
init.vars <- brainGraph_init(atlas='destrieux', densities=seq(0.05, 0.5, 0.01),
                datadir=datadir, modality='thickness',
                       exclude.subs=exclude.subs, use.mean=use.mean)
 
lapply(seq_along(init.vars), function(x)
       assign(names(init.vars)[x], eval(init.vars[[x]]), envir=.GlobalEnv))
               
N <- which(abs(densities - 0.3) < 0.001)
 
all.dat.resids <- get.resid(all.dat.tidy, covars, exclude='Group')
resids.all <- all.dat.resids$resids.all
formulas <- all.dat.resids$formulas
resids.all <- all.dat.resids$resids.all
 
corrs <- lapply(groups, function(x)
                    lapply(densities, function(y)
                           corr.matrix(resids.all[x], density=y)))
                               
g <- lapply(corrs, lapply, function(x)
        graph_from_adjacency_matrix(x$r.thresh, mode='undirected', diag=F))
                       
g <- Map(function(x, y) llply(x, set.brainGraph.attributes, atlas=atlas,
                       modality=modality, group=y, .progress='text'),
                               g, as.list(groups))
kNumPerms <- 1e4
 
myPerms <- permute::shuffleSet(n=nrow(resids.all), nset=kNumPerms)
 
perms.all <- plyr::adply(densities, .margins=1, function(x)
               permute.group(myPerms, x, resids.all, 'graph', atlas),
                       .progress='text',.id=NULL)
 
setDT(perms.all)
dim(perms.all)
 
permPlot <- plot_perm_diffs(g[[1]], g[[2]], perms.all, 'num.hubs', level='graph',
               groups=groups, alternative='less',
               ylabel='Number of Hubs')
 
>>Error in plot_perm_diffs(g[[1]], g[[2]], perms.all, "num.hubs", level = "graph",  : 
  Measure "num.hubs" is not valid!
 
________________________________

Is there a problem about the procedure? 
 
Thanks in advance.
Onur
ss.png

Chris Watson

unread,
Oct 28, 2016, 12:12:29 PM10/28/16
to brainGr...@googlegroups.com
Hi Onur,
For permutation testing, "num.hubs" isn't one of the defaults that is calculated.
In the User Guide in Chapter 5.2.4 there is an example custom function. You can paste that code into R, run the example, and then add "num.hubs" to the "perms.all" data.table:
perms.all$num.hubs <- perms.hub.diffs$num.hubs

And then your code should work. You may want to test it out with a low number of permutations first to see that it runs without error.
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/ca76b4e8-437d-410e-990e-833d690c1b3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Onur Ugurlu

unread,
Oct 29, 2016, 7:39:23 AM10/29/16
to brainGraph-help
Hi Cris,
Thank you so much for your answer. It works! 
It seems I have to create custom functions for the parameters which aren’t in defaults.
I suppose, for permutation testing, - in vertex-level -,  betweenness centrality ,degree, k-nearest, neighbor degree, nodal efficiency, transitivity, and vulnerability are the defaults parameters. 
However when I try to calculate eigenvector centrality, I get some results. Are all vertex attributes hard-coded in permutation testing ? 

perms.btwn <- adply(densities[N:(N+1)], .margins=1, function(x)
     permute.group(myPerms[1:1e3, ], x, resids.all, 'vertex'),
    .id=NULL)
setDT(perms.btwn)
setnames(perms.btwn, 2:(kNumVertices+1), V(g[[1]][[N]])$name)

p.perm.btwn <- plot_perm_diffs(g[[1]], g[[2]], perms.btwn, 'btwn.cent',
                               level='vertex', groups=groups)
p.perm.btwn$dt[p < 0.05, .SD[1], by=.(density, region)]

   density region    N  perm.diff obs.diff           p     p.fdr
1:    0.10   lLOG 1000 -147.72866 185.5327 0.024975025 0.8378288
2:    0.10  lrACC 1000    0.00000 -49.0000 0.036963037 0.8378288
3:    0.10   lINS 1000    0.00000 218.9444 0.007992008 0.5434565
4:    0.11  lrACC 1000    0.00000 -50.0000 0.041958042 0.8491508
5:    0.11   lINS 1000  -53.95476 219.4584 0.008991009 0.6113886 

p.perm.btwn <- plot_perm_diffs(g[[1]], g[[2]], perms.btwn, 'ev.cent',
                               level='vertex', groups=groups)
p.perm.btwn$dt[p < 0.05, .SD[1], by=.(density, region)]

   density region    N perm.diff      obs.diff          p p.fdr
1:     0.1  rrACC 1000         0 -1.404391e-17 0.04695305     1

Thank you for your help,
Onur

Chris Watson

unread,
Oct 29, 2016, 12:16:32 PM10/29/16
to brainGr...@googlegroups.com
No, sorry that is a "bug". In the sense that, there is no way for the code to look at the vertex measure that was used in the data.table "perms.btwn" (because the column names represent the brain regions). So while your function call does not throw any errors, what you are seeing in the plot is the comparison of the *permuted betweenness centrality differences* and the *observed eigenvector centrality differences*.

To get permutation differences in vertex eigenvector centrality, you can pass this function; please let me know if there is an error as I have not tested it.

evcent.diffs.perm <- function(g1, g2, density) {
  ev.diff <- centr_eigen(g1)$vector - centr_eigen(g2)$vector
  tmp <- as.data.table(cbind(density, t(ev.diff)))
}

The current default (hard-coded) vertex-level measures in "permute.group" are: btwn.cent, vulnerability, degree, E.nodal, knn, transitivity
I would like to ultimately either include more, or write the code in such a way that it can handle multiple options, but that would be tricky. The former solution is simpler but I will not get to it for several days. The temp function above will work just the same.

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.

Onur Ugurlu

unread,
Oct 29, 2016, 2:12:28 PM10/29/16
to brainGraph-help
Hi again,

I create the function but I am getting the following error when I call it. 

> evcent.diffs.perm <- function(g1, g2, density) {
+     ev.diff <- centr_eigen(g1)$vector - centr_eigen(g2)$vector
+     tmp <- as.data.table(cbind(density, t(ev.diff)))
+ }
> ev.diffs <- plyr::adply(densities, .margins=1, function(x)
+     permute.group(myPerms[1:1e2, ], x,
+                   resids.all, 'other',
+                   .function=evcent.diffs.perm),
+     .progress='text', .id=NULL)
  |                                                                                                |   0%
Error in { : task 1 failed - "could not find function "as.data.table""
Called from: e$fun(obj, substitute(ex), parent.frame(), e$data)
Browse[1]> 

Finally, is there a way to calculate permuted 'cloness centrality' differences ? I didn't see anything about 'cloness centrality' on UserGuied, can we create a function to calculate it ? 

Thanks for all the help,
Onur  

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.

Chris Watson

unread,
Oct 29, 2016, 3:16:19 PM10/29/16
to brainGr...@googlegroups.com
1. You need to load the "data.table" package: library(data.table) Alternatively, just change to "data.table::as.data.table"
2. The code would be almost the same for closeness, but instead use:
cent.diff <- centr_clo(g1)$res - centr_clo(g2)$res

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/d34b2ed8-77e3-4366-82da-3996f9fcb510%40googlegroups.com.

Onur Ugurlu

unread,
Oct 31, 2016, 2:32:56 PM10/31/16
to brainGraph-help
Hi Cris, 

I created a function for cloness cent. What should I type to see the difference after permutation ? 

close.diffs.perm <- function(g1, g2, density) {
  clo.diff <- centr_clo(g1)$res - centr_clo(g2)$res
  tmp <- data.table(cbind(density, t(clo.diff)))
}

clnss.diffs <- plyr::adply(densities[N], .margins=1, function(x)
permute.group(myPerms[1:1e4, ], x,
resids.all, 'other',
.function=close.diffs.perm),
.progress='text', .id=NULL)

setDT(clnss.diffs)

p.cloness <- plot_perm_diffs(g[[1]], g[[2]], clnss.diffs, '???',
                              level='vertex', groups=groups)

Thanks in advance,
Onur

Chris Watson

unread,
Oct 31, 2016, 2:49:50 PM10/31/16
to brainGr...@googlegroups.com
Hi Onur, you will have to assign that attribute to your "observed" graphs, i.e. the actual data. So something like the following:

for (i in 1:length(groups)) {
  for (j in 1:length(densities)) {
    V(g[[i]][[j]])$clo.cent <- centr_clo(g[[i]][[j]])$res
  }
}

And then in the function call, you would type 'clo.cent' for the 4th argument (or whatever name you choose to call that variable).

Chris

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/f46ae429-1d07-436c-995a-33517b6cc8ed%40googlegroups.com.

özgün özalay

unread,
Sep 6, 2017, 7:28:33 AM9/6/17
to brainGraph-help, cwa...@alum.mit.edu
Hi Chris, i am trying to calculate "EigenVector Cent" and "Closeness" as it is above (with data.table library loaded). These codes worked before updating to v1.0 but after i get the same error again :
 
Error in { : task 1 failed - "Not a graph object"

 I've tried to figure out but i couldn't. Can you suggest any changes to this code for v1.6.0 ?

Best,
Özgün



Vertex Level 

kNumPerms <- 1e3



myPerms
<- permute::shuffleSet(n=nrow(resids.all), nset=kNumPerms)



perms
.btwn <- adply(densities[N:(N+1)], .margins=1, function(x)

 permute
.group(myPerms[1:1e3, ], x, resids.all, 'vertex'),

 
.progress='text',.id=NULL)



setDT
(perms.btwn)


setnames
(perms.btwn, 2:(kNumVertices+1), V(g[[1]][[N]])$name)



EigenVector Cent


evcent.diffs.perm <- function(g1, g2, density) {
  ev
.diff <- centr_eigen(g1)$vector - centr_eigen(g2)
$vector
  tmp
<- data.table(cbind(density, t(ev.diff)))
}


ev
.diffs <- plyr::adply(densities[N], .margins=1, function(x)
permute
.group(myPerms[1:1e3, ], x,
resids
.all, 'other',
.function=evcent.diffs.perm),
.progress='text', .id=NULL)


setDT
(ev.diffs)


p
.perm.btwn <- plot_perm_diffs(g[[1]], g[[2]], ev.diffs, 'ev.cent',

Chris Watson

unread,
Sep 6, 2017, 9:48:35 AM9/6/17
to brainGr...@googlegroups.com
Hi Ozgun, I am sorry you are seeing errors since v1.0.0.
It would probably be easiest if you sent me the data objects needed to reproduce the error ("resids.all" and "densities", I think are the only ones). If you choose to send to me, please send as a single ".rda" file (i.e., using the "save" command in R). You may email off-list if you prefer.

Otherwise, could you type "traceback()" at the console? The error message looks like it was printed by "foreach". Are you seeing the error for betweenness, or eigenvector centrality, or both?

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/199b9502-5539-4a8b-8337-72af31925d5e%40googlegroups.com.

Chris Watson

unread,
Sep 7, 2017, 5:08:05 PM9/7/17
to brainGr...@googlegroups.com
Hi Ozgun et al., I have figured out the problem.

Since v1.0.0, I combined "permute.group" and "permute.group.auc". This requires a change to the structure of custom functions. I forgot to update the User Guide accordingly. For EV and closeness centralities, the code would be:

evcent.diffs.perm <- function(g, densities) {
  meas.list <- lapply(g, function(x) t(sapply(x, function(y) centr_eigen(y)$vector)))
  my.diff <- sapply(seq_along(V(g[[1]][[1]])), function(x)
      brainGraph:::auc_diff(densities, cbind(meas.list[[1]][, x], meas.list[[2]][, x])))
  tmp <- as.data.table(t(my.diff))
  setnames(tmp, 1:ncol(tmp), V(g[[1]][[1]])$name)
  return(tmp)
}

For closeness, replace "centr_eigen(y)$vector" with "centr_clo(y)$res" in the function (and be sure to change the function name, accordingly).

In the future I will likely make this a much easier process. And probably I will add these 2 measures to the hard-coded version, so then you can just type measure="ev.cent", for example.

Chris

özgün özalay

unread,
Sep 9, 2017, 4:19:03 PM9/9/17
to brainGr...@googlegroups.com
Hi Chris;

Now I am using version 1.6.0 and these functions work very well. 

Thank you so much, now i have required data.

Best,
Özgün

You received this message because you are subscribed to a topic in the Google Groups "brainGraph-help" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brainGraph-help/pF2-4BIQeug/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brainGraph-help+unsubscribe@googlegroups.com.

To post to this group, send email to brainGraph-help@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Department of Neuroscience
Institute of Health Sciences
Ege University, Izmir, Turkey

Department of Psychiatry
Ege University Hospital, Izmir, Turkey
Reply all
Reply to author
Forward
0 new messages