Same graph metrics across subjects within the same group, Why?

45 views
Skip to first unread message

Goku Sun

unread,
Jun 12, 2020, 5:57:36 AM6/12/20
to brainGraph-help
Hi, Chris.

I am doing analysis of tractography networks of 3 groups, each group have about 20 subjects.
Follow your code example in user guide 7.2.3 to create matrix, and 7.3 to create graphs, 7.4 to calculate graph measures.
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')))
    foreach(k = seq_along(inds[[i]])) %dopar% {
      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, modality = 'dti',
                                   weighting = 'sld', threshold = thresholds[j],
                                   subject = covars_dti[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')))
    }
  }
  # Group mean weighted graphs
  print(paste0('Group', i, '; ', format(Sys.time(), '%H:%M:%S')))
  g.group[[i]] <- lapply(seq_along(thresholds), function(x)
    graph_from_adjacency_matrix(A.norm.mean[[x]][[i]],
                                mode = 'undirected', diag = F,
                                weighted = T))
  g.group[[i]] <-
    llply(seq_along(thresholds), function(x)
      brainGraph::set_brainGraph_attr(g.group[[i]][[x]], atlas,
                                      modality = 'dti', weighting = 'sld',
                                      threshold = thresholds[x], group = groups[i],
                                      A = A.norm.mean[[x]][[i]], use.parallel = FALSE),
      .parallel = TRUE)
}

## check data
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_dti[groups[i], Study.ID])
  if (isTRUE(x)) lapply(fnames[[i]], file.remove)
}
saveRDS(g, file = paste0(savedir, '/', 'g.rds'))
saveRDS(g.group, file = paste0(savedir, '/', 'g.group.rds'))

## Graph and Vertex measurements
# GROUP-LEVEL
#===============================================================================
dt.V.group <- rbindlist(lapply(g.group, function(x)
  rbindlist(lapply(x, vertex_attr_dt))))
dt.G.group <- rbindlist(Map(graph_attr_dt, g.group, as.list(groups)))
# SUBJECT-LEVEL
#===============================================================================
dt.V <- vector('list', length = length(groups))
for (i in seq_along(groups)) {
  dt.V[[i]] <- lapply(g[[i]], llply, vertex_attr_dt, groups[i])
  dt.V[[i]] <- rbindlist(lapply(dt.V[[i]], rbindlist))
}
dt.V <- rbindlist(dt.V)
dt.G <- rbindlist(Map(function(x, y)
  rbindlist(lapply(x, graph_attr_dt, y)),
  g, as.list(groups)))
dt.V.group$sub.thresh <- dt.G.group$sub.thresh <- dt.G$sub.thresh <-
  dt.V$sub.thresh <- sub.thresh
setorderv(dt.V, 'threshold', -1)
setorderv(dt.G, 'threshold', -1)
setcolorder(dt.V.group, c('modality', 'atlas', 'weighting', 'sub.thresh',
                          'threshold', 'Group', names(dt.V.group)[1:33]))
setcolorder(dt.G.group, c('modality', 'atlas', 'weighting', 'sub.thresh','threshold', 'Group', names(dt.G.group)[c(1:4, 6:23)]))
setcolorder(dt.G, c('modality', 'atlas', 'weighting', 'sub.thresh', 'threshold', 'Group', 'Study.ID', names(dt.G)[c(1:4, 6:23)]))
setcolorder(dt.V, c('modality', 'atlas', 'weighting', 'sub.thresh', 'threshold',
                    'Group', 'Study.ID', names(dt.V)[1:33]))
dt.G.group.tidy <- melt(dt.G.group, names(dt.G)[1:6])
dt.G.tidy <- melt(dt.G, c(names(dt.G)[1:7], 'density'))

red lines I actually commented out, because they always gave errors:
Error in colnamesInt(x, neworder, check_dups = TRUE) : 
  argument specifying columns specify duplicated column(s)

There is warning message in the R console:
Warning message:
In melt.data.table(dt.G.group, names(dt.G)[1:6]) :
  'measure.vars' [num.tri, diameter, transitivity, assortativity, ...] are not all of the same type. By order of hierarchy, the molten data value column will be of type 'character'. All measure variables not of type 'character' will be coerced too. Check DETAILS in ?melt.data.table for more on coercion.

and the yellow line gives duplicate density, maybe because I commented out the red lines?

Then, I found a lot of graph metrics always the same in one group, they are:
"Cp"                      "Lp"                      "E.global"                "mod"                    
"density"                 "num.tri"                 "diameter"                "threshold"
"transitivity"            "assortativity"           "assortativity.lobe"      "assortativity.lobe.hemi"
"asymm"                   "spatial.dist"            "num.hubs"                "E.local"                
"vulnerability"

while other graph metrics seems normal, different for each subject in one group:               
"strength" "mod.wt"
"E.local.wt"              "E.global.wt"             "diameter.wt"             "Lp.wt"                  
"num.hubs.wt"  

I can't figure out why. Please help !

The environment is brainGraph v2.7.3,Ubuntu 18.04, Rstudio 1.2.5033, and R version 3.6.3 (2020-02-29) -- "Holding the Windsock"

Chris Watson

unread,
Jun 12, 2020, 10:47:32 AM6/12/20
to brainGr...@googlegroups.com
It looks like the non-weighted metrics are the same across subjects. This means that each subject within a group has the same topology. I suspect it depends on the "sub.thresh" value you used (the closer to 1, the more likely it is that they will have the same edges), but I didn't see you mention it in the email. It is not necessarily a problem or issue, though.

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 view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/275fff89-9b7f-4cd1-a313-821524ebb119o%40googlegroups.com.

Goku Sun

unread,
Jun 12, 2020, 1:03:36 PM6/12/20
to brainGraph-help
Hi, Chris,

Sorry I did not mention these arguments.

sub.thresh = 0.5 , as your example codes in the user guide.
thresholds <- rev(seq(0.001, 0.01, 0.001))
sub.thresh <- 0.5
divisor <- 'waytotal'
my.mats <- create_mats(matfiles$A, modality=modality, divisor=divisor,
                       div.files=matfiles$way,  threshold.by = "consensus", mat.thresh=thresholds,
                       sub.thresh=sub.thresh, inds=inds)

I do checked the raw fdt_matrix, they were not the same across subjects.
I plotted some matrix in A.norm.sub to compare, and looks like the topology maybe the same, if turned into binary network. Only the weights differs.

At this point, what is your advice for me to  do analysis correctly? 
Should I change some parameter when create_mats? Change "threshold.by" or sub.thresh, or something else?

Chris Watson

unread,
Jun 12, 2020, 3:54:16 PM6/12/20
to brainGr...@googlegroups.com
I wouldn't say there is one way or another that is "correct". It is not wrong for all subjects to have the same topology. What that means, though, is that you can only perform inference on weighted graph metrics. If you would like to learn more, you will have to read the literature

--
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.

Goku Sun

unread,
Jun 12, 2020, 11:48:25 PM6/12/20
to brainGraph-help
Thank you, Chris. 
Now I get the point that it is not wrong to have the same topology in the same group. 
Your answers helped me a lot, thank you.

Oh, by the way, I have an other question to ask. I compared the 3 group weighted graph metrics, but I could not get the glm plots.
I have 3 group subjects, GroupA, GroupB, GroupC, and the GLM design was like this:
X <- brainGraph_GLM_design(covars_use, coding = "cell.means")
conmat <- matrix(c(-1,1,0, -1,0,1, 0,-1,1), nrow = 3)
conmat <- t(conmat)
rownames(conmat) <- c("B-A", "C-A", "C-B")
g.glm <- do.call(Map, c(c, g))[[6]]
glm.res <- brainGraph_GLM(g.list = g.glm, covars = covars_use,  measure = "strength", X = X, con.mat = conmat, level = "graph")
summary(glm.res)
plot(glm.res)

the console output was:
brainGraph GLM results
---------------------------------------------------------------
Level:  graph 
Graph metric of interest:  strength 

Contrast type:  T contrast 
Alternative hypothesis:  C != 0 
Contrast matrix:  
      GroupA GroupB GroupC
B-A      -1       1       0
C-A      -1       0       1
C-B       0      -1       1

Statistics
-------------------------------
B-A
   Region Estimate 95% CI low 95% CI high Std. error t value   p-value p-value (FDR)
1:  graph  0.11905   0.046618     0.19149   0.036224  3.2866 0.0016847     0.0016847

C-A
	No signficant results!

C-B
	No signficant results!


`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
TableGrob (4 x 2) "arrange": 6 grobs
  z     cells    name                 grob
1 1 (2-2,1-1) arrange       gtable[layout]
2 2 (2-2,2-2) arrange       gtable[layout]
3 3 (3-3,1-1) arrange       gtable[layout]
4 4 (3-3,2-2) arrange       gtable[layout]
5 5 (1-1,1-2) arrange text[GRID.text.4511]
6 6 (4-4,1-2) arrange text[GRID.text.4512]
There were 12 warnings (use warnings() to see them)
> warnings()
1: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  pseudoinverse used at 2.4124
2: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  neighborhood radius 0.11965
3: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  reciprocal condition number  3.5405e-16
4: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  There are other near singularities as well. 0.014315
5: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  pseudoinverse used at 2.4124
6: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  neighborhood radius 0.11965
7: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  reciprocal condition number  3.9505e-16
8: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  There are other near singularities as well. 0.014315
9: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  pseudoinverse used at 0.043446
10: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  neighborhood radius 0.0065543
11: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  reciprocal condition number  2.2595e-16
12: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  ... :
  There are other near singularities as well. 4.2959e-05


there was no plot showed.  Maybe I used the wrong plot function or wrong polt parameters, I'm afraid.
How can I plot the GLM results? Please give me some instructions. 
Thank you! 



Goku Sun

unread,
Jun 12, 2020, 11:56:29 PM6/12/20
to brainGraph-help
Hi, Chris.

Some infomation you may need:

> X
      GroupA   GroupB   GroupC
 [1,]       1       0       0
 [2,]       1       0       0
 [3,]       1       0       0
...
[22,]       0       1       0
[23,]       0       1       0
[24,]       0       1       0
...
[42,]       0       0       1
[50,]       0       0       1
[51,]       0       0       1
[52,]       0       0       1

and covars_use only has two columns: Study.ID and Group, for simplify purpose.

Chris Watson

unread,
Jun 13, 2020, 1:06:49 AM6/13/20
to brainGr...@googlegroups.com
You may have to add "[[1]]" at the end of the call to the "plot" function.

plot(glm.res)[[1]]

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.
Message has been deleted

Goku Sun

unread,
Jun 13, 2020, 1:57:02 AM6/13/20
to brainGraph-help
Hi, Chris.

Sorry to bother you again... 
I did as you told me, then I got no plot but these messages from R console:

> plot(glm.res)[[1]]
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
`geom_smooth()` using formula 'y ~ x'
[[1]]
TableGrob (12 x 9) "layout": 18 grobs
    z         cells       name                                           grob
1   0 ( 1-12, 1- 9) background               rect[plot.background..rect.1312]
2   5 ( 6- 6, 4- 4)     spacer                                 zeroGrob[NULL]
3   7 ( 7- 7, 4- 4)     axis-l           absoluteGrob[GRID.absoluteGrob.1298]
4   3 ( 8- 8, 4- 4)     spacer                                 zeroGrob[NULL]
5   6 ( 6- 6, 5- 5)     axis-t                                 zeroGrob[NULL]
6   1 ( 7- 7, 5- 5)      panel                      gTree[panel-1.gTree.1290]
7   9 ( 8- 8, 5- 5)     axis-b           absoluteGrob[GRID.absoluteGrob.1294]
8   4 ( 6- 6, 6- 6)     spacer                                 zeroGrob[NULL]
9   8 ( 7- 7, 6- 6)     axis-r                                 zeroGrob[NULL]
10  2 ( 8- 8, 6- 6)     spacer                                 zeroGrob[NULL]
11 10 ( 5- 5, 5- 5)     xlab-t                                 zeroGrob[NULL]
12 11 ( 9- 9, 5- 5)     xlab-b titleGrob[axis.title.x.bottom..titleGrob.1301]
13 12 ( 7- 7, 3- 3)     ylab-l   titleGrob[axis.title.y.left..titleGrob.1304]
14 13 ( 7- 7, 7- 7)     ylab-r                                 zeroGrob[NULL]
15 14 ( 4- 4, 5- 5)   subtitle         zeroGrob[plot.subtitle..zeroGrob.1308]
16 15 ( 3- 3, 5- 5)      title          titleGrob[plot.title..titleGrob.1307]
17 16 (10-10, 5- 5)    caption          zeroGrob[plot.caption..zeroGrob.1310]
18 17 ( 2- 2, 2- 2)        tag              zeroGrob[plot.tag..zeroGrob.1309]

[[2]]
TableGrob (12 x 9) "layout": 18 grobs
    z         cells       name                                           grob
1   0 ( 1-12, 1- 9) background               rect[plot.background..rect.1354]
2   5 ( 6- 6, 4- 4)     spacer                                 zeroGrob[NULL]
3   7 ( 7- 7, 4- 4)     axis-l           absoluteGrob[GRID.absoluteGrob.1340]
4   3 ( 8- 8, 4- 4)     spacer                                 zeroGrob[NULL]
5   6 ( 6- 6, 5- 5)     axis-t                                 zeroGrob[NULL]
6   1 ( 7- 7, 5- 5)      panel                      gTree[panel-1.gTree.1332]
7   9 ( 8- 8, 5- 5)     axis-b           absoluteGrob[GRID.absoluteGrob.1336]
8   4 ( 6- 6, 6- 6)     spacer                                 zeroGrob[NULL]
9   8 ( 7- 7, 6- 6)     axis-r                                 zeroGrob[NULL]
10  2 ( 8- 8, 6- 6)     spacer                                 zeroGrob[NULL]
11 10 ( 5- 5, 5- 5)     xlab-t                                 zeroGrob[NULL]
12 11 ( 9- 9, 5- 5)     xlab-b titleGrob[axis.title.x.bottom..titleGrob.1343]
13 12 ( 7- 7, 3- 3)     ylab-l   titleGrob[axis.title.y.left..titleGrob.1346]
14 13 ( 7- 7, 7- 7)     ylab-r                                 zeroGrob[NULL]
15 14 ( 4- 4, 5- 5)   subtitle         zeroGrob[plot.subtitle..zeroGrob.1350]
16 15 ( 3- 3, 5- 5)      title          titleGrob[plot.title..titleGrob.1349]
17 16 (10-10, 5- 5)    caption          zeroGrob[plot.caption..zeroGrob.1352]
18 17 ( 2- 2, 2- 2)        tag              zeroGrob[plot.tag..zeroGrob.1351]

[[3]]
TableGrob (12 x 9) "layout": 18 grobs
    z         cells       name                                           grob
1   0 ( 1-12, 1- 9) background               rect[plot.background..rect.1398]
2   5 ( 6- 6, 4- 4)     spacer                                 zeroGrob[NULL]
3   7 ( 7- 7, 4- 4)     axis-l           absoluteGrob[GRID.absoluteGrob.1384]
4   3 ( 8- 8, 4- 4)     spacer                                 zeroGrob[NULL]
5   6 ( 6- 6, 5- 5)     axis-t                                 zeroGrob[NULL]
6   1 ( 7- 7, 5- 5)      panel                      gTree[panel-1.gTree.1376]
7   9 ( 8- 8, 5- 5)     axis-b           absoluteGrob[GRID.absoluteGrob.1380]
8   4 ( 6- 6, 6- 6)     spacer                                 zeroGrob[NULL]
9   8 ( 7- 7, 6- 6)     axis-r                                 zeroGrob[NULL]
10  2 ( 8- 8, 6- 6)     spacer                                 zeroGrob[NULL]
11 10 ( 5- 5, 5- 5)     xlab-t                                 zeroGrob[NULL]
12 11 ( 9- 9, 5- 5)     xlab-b titleGrob[axis.title.x.bottom..titleGrob.1387]
13 12 ( 7- 7, 3- 3)     ylab-l   titleGrob[axis.title.y.left..titleGrob.1390]
14 13 ( 7- 7, 7- 7)     ylab-r                                 zeroGrob[NULL]
15 14 ( 4- 4, 5- 5)   subtitle         zeroGrob[plot.subtitle..zeroGrob.1394]
16 15 ( 3- 3, 5- 5)      title          titleGrob[plot.title..titleGrob.1393]
17 16 (10-10, 5- 5)    caption          zeroGrob[plot.caption..zeroGrob.1396]
18 17 ( 2- 2, 2- 2)        tag              zeroGrob[plot.tag..zeroGrob.1395]

[[4]]
TableGrob (12 x 9) "layout": 18 grobs
    z         cells       name                                           grob
1   0 ( 1-12, 1- 9) background               rect[plot.background..rect.1444]
2   5 ( 6- 6, 4- 4)     spacer                                 zeroGrob[NULL]
3   7 ( 7- 7, 4- 4)     axis-l           absoluteGrob[GRID.absoluteGrob.1430]
4   3 ( 8- 8, 4- 4)     spacer                                 zeroGrob[NULL]
5   6 ( 6- 6, 5- 5)     axis-t                                 zeroGrob[NULL]
6   1 ( 7- 7, 5- 5)      panel                      gTree[panel-1.gTree.1422]
7   9 ( 8- 8, 5- 5)     axis-b           absoluteGrob[GRID.absoluteGrob.1426]
8   4 ( 6- 6, 6- 6)     spacer                                 zeroGrob[NULL]
9   8 ( 7- 7, 6- 6)     axis-r                                 zeroGrob[NULL]
10  2 ( 8- 8, 6- 6)     spacer                                 zeroGrob[NULL]
11 10 ( 5- 5, 5- 5)     xlab-t                                 zeroGrob[NULL]
12 11 ( 9- 9, 5- 5)     xlab-b titleGrob[axis.title.x.bottom..titleGrob.1433]
13 12 ( 7- 7, 3- 3)     ylab-l   titleGrob[axis.title.y.left..titleGrob.1436]
14 13 ( 7- 7, 7- 7)     ylab-r                                 zeroGrob[NULL]
15 14 ( 4- 4, 5- 5)   subtitle         zeroGrob[plot.subtitle..zeroGrob.1440]
16 15 ( 3- 3, 5- 5)      title          titleGrob[plot.title..titleGrob.1439]
17 16 (10-10, 5- 5)    caption          zeroGrob[plot.caption..zeroGrob.1442]
18 17 ( 2- 2, 2- 2)        tag              zeroGrob[plot.tag..zeroGrob.1441]

[[5]]
text[GRID.text.1445] 

[[6]]
text[GRID.text.1446] 

Chris Watson

unread,
Jun 13, 2020, 6:28:58 PM6/13/20
to brainGr...@googlegroups.com
Try:

arrangeGrob(plot(res.glm))
arrangeGrob(plot(res.glm)[[1]])
grid.arrange(grobs=plot(res.glm))
grid.arrange(grobs=plot(res.glm)[[1]])


--
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.

Goku Sun

unread,
Jun 14, 2020, 1:52:17 AM6/14/20
to brainGraph-help
Thank you, Chris!

I tried them, and the results are:
arrangeGrob(plot(res.glm))                     #  Console output some info like before, but less, and no plot.
arrangeGrob(plot(res.glm)[[1]])               #  Console output some info and 1 error, no plot
grid.arrange(grobs=plot(res.glm))           #  Console output some info and 1 error, no plot
grid.arrange(grobs=plot(res.glm)[[1]])     #  Some warnings and finally 1 page of 4 plots shows, yeah ~


You are very kind and patience, thank you!

Reply all
Reply to author
Forward
0 new messages