Error in vapply

199 views
Skip to first unread message

Alice Ballerini

unread,
Oct 11, 2021, 7:09:56 AM10/11/21
to brainGraph-help
Hi Chris,
I'm using brainGraph 3.0.0, and R 4.1.1.
I've some problems with the random graphs creation.
I performed the graph creation (chapter 6) successfully, and obtained "g", a large list object. After that, I wanted to perform a small-world analysis, so, first, I run "analysis_random_graph" to generate random graphs.

Here the script:

> kNumRand <- 1e2
> clustering <- F
> outdir <- file.path(getwd(), ' ')
> rand_vars <- analysis_random_graphs(g, N=kNumRand, savedir=outdir, clustering=clustering)

It worked until the end

[1] "Random graphs for threshold #1; 13:33:12"

|========================================================================================================| 100%

[1] "Random graphs for threshold #2; 13:33:19"  |========================================================================================================| 100%

Etc etc (…)

[1] "Random graphs for threshold #46; 13:42:17"

|========================================================================================================| 100%

Error in vapply(rand, function(x) graph_attr(x[[1L]], "density"), numeric(1L)) : values must be length 1, but the result FUN(X[[2]]) is length 0

It seems that the problem is about "density". How can I solve this error?


Thank you in advance,

Alice

Chris Watson

unread,
Oct 11, 2021, 9:40:03 AM10/11/21
to brainGr...@googlegroups.com
Can you run "traceback()" to figure out where the error is occurring?

--
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/3f94205e-444f-4e0a-a721-99e32d3e4873n%40googlegroups.com.

Alice Ballerini

unread,
Oct 11, 2021, 10:08:08 AM10/11/21
to brainGraph-help
Sure, here's the output:

> traceback()
3: vapply(rand, function(x) graph_attr(x[[1L]], "density"), numeric(1L))
2: get_rand_attrs(rand.all, level)
1: analysis_random_graphs(g, N = kNumRand, savedir = outdir, clustering = clustering)

Chris Watson

unread,
Oct 13, 2021, 8:05:05 AM10/13/21
to brainGr...@googlegroups.com
The easiest way to fix this would be to update to the latest version on GitHub, as I fixed that bug in v3.0.1

Chris

Alice Ballerini

unread,
Oct 15, 2021, 4:09:42 AM10/15/21
to brainGraph-help
Ok Chris, I've update brainGraph from GitHub to the 3.0.2 version, but now I run in another different issue.

g <- lapply(seq_along(densities), function(x) make_brainGraphList(corrs[x], atlas='dk.scgm', modality= 'thickness', .progress=F, set.attrs = TRUE))

Error in { : task 1 failed - "'x' must be an array of at least two dimensions"

Called from: e$fun(obj, substitute(ex), parent.frame(), e$data)

Browse[1]> 


Traceback:

9. stop(simpleError(msg, call = expr))

8. e$fun(obj, substitute(ex), parent.frame(), e$data)

7. foreach(i = seq_len(kNumGraphs)) %dopar% { res <- loopfun(x[, , i], atlas, type, level, set.attrs, modality, weighting, threshold[i], name = gnames[i], Group = grpNames[i], subnet = subnet, mode = mode, diag = diag, weighted = weighted, ...

6. make_brainGraphList.array(A, atlas = atlas, type = type, level = level, set.attrs = set.attrs, modality = modality, weighting = weighting, threshold = threshold, mode = mode, weighted = weighted, diag = diag, gnames = gnames, grpNames = grpNames, .progress = .progress, ...

5. make_brainGraphList(A, atlas = atlas, type = type, level = level, set.attrs = set.attrs, modality = modality, weighting = weighting, threshold = threshold, mode = mode, weighted = weighted, diag = diag, gnames = gnames, grpNames = grpNames, .progress = .progress, ...

4. make_brainGraphList.corr_mats(corrs[x], atlas = "dk.scgm", modality = "thickness", .progress = F, set.attrs = TRUE)

3. make_brainGraphList(corrs[x], atlas = "dk.scgm", modality = "thickness", .progress = F, set.attrs = TRUE)

2. FUN(X[[i]], ...)

1. lapply(seq_along(densities), function(x) make_brainGraphList(corrs[x], atlas = "dk.scgm", modality = "thickness", .progress = F, set.attrs = TRUE))

Chris Watson

unread,
Oct 15, 2021, 6:38:27 AM10/15/21
to brainGr...@googlegroups.com
If you send me the data and the code you ran, I can take a look.
Chris

Alice Ballerini

unread,
Nov 25, 2021, 8:56:05 AM11/25/21
to brainGraph-help
Hi Chris,
sorry for the delay of answer.

The only way I found out to solve the problem is working with version 3.0.0 for the graph creation part (chapter 6), and then switch to version 3.0.2 for random graphs creations, bootstrapping and permutation testing (chapters 12 and 13).

I've only one question about permutation testing, when I look at vertex results with summary() I'm not able to explore all significative p-value. 
Here the output:

> summary(perms.btwn)

==========================================================================
Permutation analysis
==========================================================================
# of permutations: 1,000 
Level:  vertex 
Graph metric:  Betweenness centrality 
Alternative hypothesis:  Controlli - Pazienti != 0 
Alpha:  0.05 

     densities region btwn.cent.Controlli btwn.cent.Pazienti   obs.diff  perm.diff 95% CI low 95% CI high           p     p.fdr
  1:      0.05   lMOF            0.000000           42.00000 -125.00000  3.9944505  -51.19995   102.65894 0.024975025 0.6826507
  2:      0.05  lPCUN           97.584916           27.71731 -417.32297 19.3651220 -221.62027   320.19360 0.010989011 0.4505495
  3:      0.05  rpTRI          102.177072            0.00000 -387.42051  2.5697281 -168.77940   199.44740 0.001998002 0.1638362
  4:      0.06  lBSTS            0.000000            0.00000   45.00000  2.1036754    0.00000    17.66483 0.017982018 1.0000000
  5:      0.07   rINS            0.000000            0.00000  104.35030  8.0765130  -34.36589    94.67907 0.021978022 1.0000000
 ---                                                                                                                           
149:      0.48  rBSTS            5.642285           32.74255   40.94962  3.4487936  -31.53810    46.14055 0.039960040 0.7679820
150:      0.48  rLING           12.815940           56.79488   49.74544  0.9968945  -45.09371    50.26364 0.043956044 0.7679820
151:      0.48  rrMFG           26.132135           19.92565  -67.48543 -1.6899225  -58.76190    50.53594 0.026973027 0.7679820
152:      0.49   lMTG           40.342031           57.75034  -64.03756 -5.3436262  -51.43717    43.32533 0.010989011 0.8582781
153:      0.50  rcMFG           14.928471           70.30489  -55.37642  2.2801693  -34.33808    44.13289 0.009990010 0.8191808


How can I explore regions from 6 to 148?
Alternative, how can I filter for density?

Chris Watson

unread,
Nov 25, 2021, 9:42:53 AM11/25/21
to brainGr...@googlegroups.com
I believe the function (invisibly) outputs a list object with a data.table. So you should be able to do something like this:

summary(perms.btwn)$DT[p < 0.05]
summary(perms.btwn)$DT[density == 0.45]

Or whichever P-values and densities you're interested in.

Chris

Reply all
Reply to author
Forward
0 new messages