Hi Philipp,
I think the easiest way would be to adapt the code from the "small.world"
function. So something like the following, assuming that "g" is a *list* of graphs for each
subject, and "rand" is a *list of lists* of the N random graphs for that subject.
E.global.wt <- sapply(g, efficiency, 'global')
E.glob.rand <- colMeans(sapply(rand, sapply, efficiency, 'global'))
E.glob.norm <- E.global.wt / E.glob.rand
Let me know if that works, or if that is even what you are looking for.
Chris
On Fri, Aug 02, 2019 at 03:31 PM, Philipp Riedel <philipp.ri...@gmail.com> wrote:
> from: Philipp Riedel <philipp.ri...@gmail.com>
> date: Fri, Aug 02 01:31 PM -07:00 2019
> to: brainGraph-help <brainGr...@googlegroups.com>
> reply-to: brainGr...@googlegroups.com
> subject: [brainGraph-help] Normalization of Graph Indices
>
> Hi everybody,
>
> I was wondering what would be the correct way to compute normalized graph
> measures. Â Chapter 12.1. in the brainGraph User Guide explains how to get
> Lp.norm and Cp.norm. Â However, how do I compute E.global.norm and mod.norm
> in an identical fashion given their random indices in 'rand.dt' (I just
> picked the name based on the code in 12.1.1)?
>
> I thought about taking the mean and standard deviation of the 'E.global' in
> rand.dt ("E.global.rand") regardless of Subject.ID and regardless of Group
> but with regard to density threshold and just normalize by computing:
> E.global.norm <- (E.global.subj - mean(E.global.rand))/sd(E.global.rand).
>
> But I'm not sure if there is any reason as to why analysis_random_graphs()
> computes a kNumRand number of random graphs for each density threshhold *separately
> for each Subject.ID* and if I should take that into account? Â The subject's
> specific matrix shouldn't affect the random graph generation [in the case
> that threshold.by = 'density' was used in create.mats()], should it? Â
>
> Thanks,
> Philipp
>
> --
> 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 brainGr...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/5257fa0e-bb21-4383-8e42-381fc8ebb21e%40googlegroups.com. See
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/5257fa0e-bb21-4383-8e42-381fc8ebb21e%40googlegroups.com. See
rand.dt[, kruskal.test(E.global ~ as.numeric(Group))$p.value, by=threshold]
rand_vars <- analysis_random_graphs(g, 20, savedir = outdirA, clustering = FALSE)
rand.dt <- rand_vars$rand
##########################
#  Graph Creation   #
##########################
## STEP 1 ##
setwd(savedir)
g.group <- g <- fnames <- vector('list', length=length(groups))
for (i in seq_along(groups)) {
for (j in seq_along(thresholds)) {
  print(paste0('Threshold ', j, '/', length(thresholds), '; group ', i, '; ', format(Sys.time(), '%H:%M:%S')))
for (k in seq_along(inds[[i]])) {
g.tmp <- graph_from_adjacency_matrix(A.norm.sub[[j]][, , inds[[i]][k]], mode = 'undirected', diag = F, weighted = T)
   g.tmp <- set_brainGraph_attr(g.tmp, atlas = atlas, modality = modality, weighting = 'pearson', threshold = thresholds[j], subject = covars[groups[i], Study.ID[k]], group = groups[i], use.parallel=FALSE, A = A.norm.sub[[j]][, , inds[[i]][k]])
   saveRDS(g.tmp, file = paste0(savedir, sprintf('g%i_thr%02i_subj%03i%s', i, j, k, '.rds')))
}
}
}
## STEP 2 ##
for (i in seq_along(groups)) {
g[[i]] <- fnames[[i]] <- vector('list', length = length(thresholds))
for (j in seq_along(thresholds)) {
  fnames[[i]][[j]] <- list.files(savedir, sprintf('g%i_thr%02i.*', i, j), full.names=T)
  g[[i]][[j]] <- lapply(fnames[[i]][[j]], readRDS)
  }
x <- all.equal(sapply(g[[i]][[1]], graph_attr, 'name'), covars[groups[i], Study.ID])
if (isTRUE(x)) lapply(fnames[[i]], file.remove)
}
saveRDS(g, file = paste0(savedir, 'g.rds'))
I think there may be a significant difference because you created only
20. It depends "how significant" the difference is. What statistical
test are you using to determine significance? What is the code you
used? Did you make sure to calculate means and get the correct values
per group and density? e.g., you could do something like
rand.dt[, kruskal.wallis(E.global ~ as.numeric(Group))$p.value, by=density]
Furthermore, the *pattern* of connections contributes to the metrics.
Granted, it is reasonable to expect that any differences would
"average out" with multiple random graphs, but I would have to see the
data to know more.
I looked at the data. It looks like the mean values for those
variables per group are very close to one another. They are
*statistically* significantly different, but they are likely not of
*practical/clinical* significance. For example, I ran
rand.dt[threshold == 1, summary(lm(E.global ~ Group))]
The parameter estimates are all very small (< 0.01), and the r-squared
is extremely small (~0.06). They are indeed statistically significant,
but then again this is technically repeated measures data (i.e., there
are 20 data points per subject & threshold) so the model is not exact.
Another thing to consider is only creating 20 per subject; I recall
reading that 100 is the minimum for stable estimates, but I do not
remember which paper it was.
Either way, the between--group differences are very small and of the
same order of magnitude as (or smaller than) the observed
between-group differences.
RE the runtime: yes, "analysis_random_graphs" runs every step from
random graph generation to small-world calculations to rich-club
calculations to simple calculation of some popular graph metrics (such
as modularity). So it is a huge convenience for the user who would be
running all those commands anyway, but the runtime increases quite a
bit. The solution to this issue, specifically, is to run on a computer
with more cores and/or higher CPU clock speeds, and necessarily more
RAM.
> To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/181a4d2d-8f1e-4bdb-bc85-c082adb1a218%40googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/181a4d2d-8f1e-4bdb-bc85-c082adb1a218%40googlegroups.com.