Error during make_brainGraphList

214 views
Skip to first unread message

Gershon Spitz

unread,
Aug 3, 2021, 1:53:38 AM8/3/21
to brainGr...@googlegroups.com
Dear Chris,

I am receiving an error when running the make_brainGraphList for my set of matrices. I have looked at the other forum posts and don't believe others have encountered this issue.

I am replicating the pipeline outlined by Yun et al. (attached). Their pipeline should operate just like fmri. Ie., matrices of correlations/covariances.

I have followed your manual, but am receiving an error message when running make_brainGraphList. 

The error is: task 1 failed - "invalid 'length.out' value"

When I try to run make_brainGraphList for a single participant I receive the following error: Error in seq_len(x) : argument must be coercible to non-negative integer

I am using R version 4.0.3, brainGraph version 3.0.2.

I am using a custom atlas.

I have attached the participant mats object, a single participant text file as an example, and the custom atlas R object for reference.

My code is as follows:

grps <- c('Control', 'TBI')
# Get all relevant filenames
datadir <- 'data'
covars.all <- fread(file.path(datadir, 'covars_original_V4.csv'))
matfiles <- list(A=list.files(datadir, pattern='covar_network.csv', full.names=T))
inds <- lapply(grps, function(x) covars.all[Group == x, which=TRUE])
# Output directory to save the data
today <- format(Sys.Date(), '%Y-%m-%d')
savedir <- file.path('results', today)

modality <- 'fmri'
thresholds <- rev(seq(0.001, 0.01, 0.001))
my.mats <- create_mats(matfiles$A, modality=modality)
A.norm.sub <- my.mats$A.norm.sub
A.norm.mean <- my.mats$A.norm.mean

atlas <- 'Schaefer2018_400Parcels_7Networks'
g <- g.group <- vector('list', length(thresholds))
for (j in seq_along(thresholds)) {
g[[j]] <- make_brainGraphList(A.norm.sub[[j]], atlas, modality=modality,
weighting='sld', threshold=thresholds[j],
weighted=TRUE, gnames=covars.all$Study.ID,
groups=covars.all$Group)

g.group[[j]] <- make_brainGraphList(A.norm.mean[[j]], atlas, modality=modality,
weighting='sld', threshold=thresholds[j],
weighted=TRUE, gnames=grps)
}

Single participant:
g <- make_brainGraphList(A.norm.sub[[1]][,,1], atlas = 'Schaefer2018_400Parcels_7Networks', modality=modality,
threshold=thresholds[1],
name=covars.all$Study.ID[1],
Group=covars.all$Group[1])


Kind regards,
Gershon.

--

GERSHON SPITZ
PhD, BA
Research Fellow, National Health and Medical Research Council

Research Fellow, Monash-Epworth Rehabilitation Research Centre

Deputy Program Lead, Brain Injury and Rehabilitation

Monash University
Turner Institute for Brain and Mental Health

School of Psychological Sciences
18 Innovation Walk
Clayton, VIC 3800

OP-BRAI200001 684..700.pdf
Schaefer2018_400Parcels_7Networks.RData
covars_original_V4.csv
sub-003_covar_network.csv

Chris Watson

unread,
Aug 3, 2021, 8:33:32 AM8/3/21
to brainGr...@googlegroups.com
First, the argument for "make_brainGraphList" should be "grpNames", not "groups". (The User Guide is out of date here).

Second, the atlas's "name" column should be of type *character*, not *factor*.

I think if you change these, the code should run, but let me know.

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/CAAg2T0Xmv%3DSLpSN7y_usgKJRpt9-BJfbiP4dOSFA5vz20zGHmQ%40mail.gmail.com.

jonata...@gmail.com

unread,
Aug 3, 2021, 11:08:23 AM8/3/21
to brainGraph-help
Hi Gershon,

I had the same issue with this novel method. It might have something to do with the distribution of the scores in your matrix. The values derived from this approach, which are not truly correlations, mostly concentrates towards 0 or 1 (inverse U-shaped distribution).

In my case, I had to be extra careful with the cut-offs. It is possible that you don't have enough values corresponding to a density of 0.001 (which is very restrictive). 

You might want to try densities of 0.2 and above, although do not expect fully connected graphs or graph metrics to behave as 'expected'. I am also trying these new methods to derive individual-scores from SCN, but none seem to work well.

Best,
Jonatan

Gershon Spitz

unread,
Aug 3, 2021, 10:40:18 PM8/3/21
to brainGr...@googlegroups.com
Dear Chris, Jonatan,

Thank you for your replies. I have changed the code to 'grpNames' and converted the atlas name to 'character'. 

This seems to solve the initial error, but am now getting a new error upon completion of 'make_brainGraphList'.

The error is:
scheduled cores 1, 2, 3, 4, 5, 6, 7, 8 did not deliver results, all values of the jobs will be affected.

It seems to have resulted in no output in the 'g'. All subject graphs are empty.
However, g.group does have results.

Any ideas what may be causing this error at the subject level. Clearly, because I would like to compare subject graphs it's vital I have this information!

The code I am using is:
####CODE
thresholds <- 0.3
sub.thresh <- 0.5          
modality <-  'fmri'
thrs.by <- 'consensus'
my.mats <- create_mats(matfiles$A,                  
                       modality = modality,
                       threshold.by = thrs.by,        
                       mat.thresh = thresholds,
                       sub.thresh = sub.thresh,
                       inds = inds)

A.norm.sub <- my.mats$A.norm.sub
A.norm.mean <- my.mats$A.norm.mean

atlas <- 'Schaefer2018_400Parcels_7Networks'
g <- g.group <- vector('list', length(thresholds))

for (j in seq_along(thresholds)) {
  g[[j]] <- make_brainGraphList(my.mats$A.norm.sub[[j]], atlas, modality = modality,    
                                weighting = 'pearson', threshold = thresholds[j],
                                weighted = T, gnames = covars$Study.ID,  
                                grpNames = covars$Group)
 
  g.group[[j]] <- make_brainGraphList(my.mats$A.norm.mean[[j]], atlas, modality = modality,  
                                      weighting = 'pearson', threshold = thresholds[j],
                                      weighted = T, gnames = grps)      
}

In addition, I would like to test some things by running on a single participant using the following code:
g_singlesub <- make_brainGraphList(A.norm.sub[[1]][,,1], atlas, modality = modality,     # A.bin[[j]], or A.norm.sub[[j]] if weighted = T?
                                weighting = 'pearson', threshold = thresholds[1],
                                weighted = T, gnames = covars$Study.ID[1],     # weighted T or NULL
                                grpNames = covars$Group[1])

However, I am receiving the following error:
Error in make_brainGraphList.array(A.norm.sub[[1]][, , 1], atlas, modality = modality,  :
  length(gnames) == kNumGraphs is not TRUE

The length of A.norm.sub[[1]][, , 1] is 160000 and gnames is 1. How do I get around this?

Kind regards,
Gershon.

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

Jonatan Ottino

unread,
Aug 3, 2021, 10:47:03 PM8/3/21
to brainGr...@googlegroups.com
Gershon,

it might be the case that none of your subjects meet the criteria of having a “correlation” greater than 0.5 in 50% of the group. I got that error several times with the consensus threshold approach.

J.

On Aug 3, 2021, at 10:40 PM, 'Gershon Spitz' via brainGraph-help <brainGr...@googlegroups.com> wrote:



Gershon Spitz

unread,
Aug 3, 2021, 11:24:04 PM8/3/21
to brainGr...@googlegroups.com
Thank you for the quick reply Jonatan.
How did you solve this? Did you reduce the consensus threshold?
I am able to derive subject matrices;ie., in 'matfiles'. Does the thresholding take place during graph creation?

Best,
Gershon.

Chris Watson

unread,
Aug 4, 2021, 7:41:44 AM8/4/21
to brainGr...@googlegroups.com
To test on a single subject, you probably need the first argument to be "A.norm.sub[[i]][, , 1, drop=FALSE]" (as it expects a 3D array).

I was able to run it without error on your first subject. I did not try the others because all of the matrices in "A.norm.sub" are fully connected; it seems you did not threshold them in any way.
Thresholding takes place *before* graph creation. See e.g. Chapter 7 of the User Guide.

Chris

Gershon Spitz

unread,
Aug 5, 2021, 7:31:34 AM8/5/21
to brainGr...@googlegroups.com
Hi Chris,

Thank you for the consistently fast and helpful responses.

I think we are making progress. However, I am obtaining another error, which seems to be specific to only certain participants.

For example, when I run 'make_brainGraphList' for participant 1, I get the following error: "number of items to replace is not a multiple of replacement length"

I assume this is not a concern given the command finishes running and I can successfully extract the graph metrics.

However, for other participants, such as 2, and 5, I obtain the following error: "number of items to replace is not a multiple of replacement lengthError in { :
  task 1 failed - "'x' must be an array of at least two dimensions""

This does not output any results.

I have attached the matrices of select participants: 1,3,4 seem to output results, 2,5 have errors.

I hope to use the binary matrices for my analyses using the following code:

inds <- lapply(grps, function(x) covars[Group == x, which = T])
modality <- 'fmri'
thresholds <- 0.2
sub.thresh <- 0.5
my.mats <- create_mats(matfiles$A, modality=modality,
mat.thresh=thresholds, sub.thresh=sub.thresh, inds=inds)
A.norm.sub <- my.mats$A.norm.sub
A.bin <- my.mats$A.bin
A.norm.mean <- my.mats$A.norm.mean

atlas <- 'Schaefer2018_400Parcels_7Networks'
g <- g.group <- vector('list', length(thresholds))

g_singlesub1 <- make_brainGraphList(sub1mat, atlas, modality = modality,    
                                weighting=NULL, threshold = thresholds[1],
                                weighted = NULL, gnames = covars$Study.ID[1],    

                                grpNames = covars$Group[1])


Thank you,
Gershon.


sub5mat.rds
sub4mat.rds
sub2mat.rds
sub1mat.rds
sub3mat.rds

Chris Watson

unread,
Aug 5, 2021, 8:36:54 AM8/5/21
to brainGr...@googlegroups.com
For that error, please see a previous posting on this list about errors with "within_module_deg_z_score". Specifically, you can edit the function (before running your code); the line containing "rowSums" should look like this:

x <- rowSums(A[memb == S, memb == S, drop=FALSE])

Then it should run without error.
I will try to include this in a bugfix release but do not know when it will be released.
Chris

Gershon Spitz

unread,
Aug 5, 2021, 5:07:47 PM8/5/21
to brainGr...@googlegroups.com
Perfect!
Thanks Chris. Changing within_module_deg_z_score worked.

Best wishes,
Gershon.

Reply all
Reply to author
Forward
0 new messages