"Object NA" error when control for clustering

32 views
Skip to first unread message

Gershon Spitz

unread,
Sep 1, 2021, 5:41:05 AM9/1/21
to brainGr...@googlegroups.com
Dear Chris,

When generating random graphs controlling for clustering I have the following error:

Error in { : task 1 failed - "object 'NA' not found"

Code is:
kNumRandClust <- 1e2 # Create 100 graphs per group/density combination
bgl.rand <- g.rand <- small.clust.dt <- vector('list', length(g))
for (i in seq_along(g)) {
g.rand[[i]] <- vector('list', length=nobs(g[[i]]))
for (j in seq_len(nobs(g[[i]]))) {
g.rand[[i]][[j]] <- sim.rand.graph.par(g[[i]][j], level=g[[i]]$level,
kNumRandClust, clustering=T,
name=g[[i]][j]$name)
}
bgl.rand[[i]] <- as_brainGraphList(g.rand[[i]], type='random', level=g[[i]]$level)
small.clust.dt[[i]] <- small.world(g[[i]], bgl.rand[[i]])
}
small.clust.dt <- rbindlist(small.clust.dt)

My g object is attached. I am using a custom atlas (Schaefer).

Any help would be greatly appreciated.

Best wishes,
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

Chris Watson

unread,
Sep 1, 2021, 8:30:14 AM9/1/21
to brainGr...@googlegroups.com
That is related to the atlas. The fastest solution would be to add the following line (the first one) in the "sim.rand.graph.par" function:

tmp$atlas <- g$atlas
tmp <- make_brainGraph(tmp, type='random', level=level, set.attrs=TRUE, ...)

It is in the "isTRUE(clustering)" branch in that function.
You may have to also export the atlas itself when setting up the cluster by adding

.export='Schaefer2018_400Parcels_7Networks'

to the "foreach" function call. Unfortunately, I am still not sure this will work and do not know of the best workaround yet.

Just be aware that depending on your computer's capabilities, this will probably take a very long time.
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/CAAg2T0VpCvpS%2B4uYkk%3DqKTx8w-xCjZ8gu0o8phk59uaXJhrRGQ%40mail.gmail.com.

Gershon Spitz

unread,
Sep 1, 2021, 7:09:30 PM9/1/21
to brainGr...@googlegroups.com
Hi Chris,
Thank you for the reply.
I amended the function but still received the same error message.
I amended the function in the following way:

sim.rand.graph.par_v2 <- function (g, level = c("subject", "group"), N = 100L, clustering = FALSE,
  rewire.iters = max(10 * ecount(g), 10000L), cl = g$transitivity,
  max.iters = 100L, ...)
{
  stopifnot(is_igraph(g))
  level <- match.arg(level)
  if (!getDoParRegistered()) {
    clust <- makeCluster(getOption("bg.ncpus"))
    registerDoParallel(clust)
  }
  if (isTRUE(clustering)) {
    r <- foreach(i = seq_len(N), .packages = c("igraph",
      "brainGraph"), .export='Schaefer2018_400Parcels_7Networks') %dopar% {
      tmp <- sim.rand.graph.clust(g, rewire.iters, cl,
        max.iters)
      tmp$atlas <- g$atlas
      tmp <- make_brainGraph(tmp, type = "random", level = level,
        set.attrs = TRUE, ...)
      tmp
    }
  }
  else {
    if (is_connected(g)) {
      V(g)$degree <- degree(g)
      r <- foreach(i = seq_len(N)) %dopar% {
        tmp <- sample_degseq(V(g)$degree, method = "vl")
        tmp$Group <- g$Group
        tmp$name <- g$name
        tmp$threshold <- g$threshold
        tmp$density <- graph.density(tmp)
        tmp <- make_brainGraph(tmp, type = "random",
          level = level, set.attrs = TRUE, ...)
        tmp
      }
    }
    else {
      r <- foreach(i = seq_len(N)) %dopar% {
        tmp <- rewire(g, keeping_degseq(loops = FALSE,
          rewire.iters))
        tmp <- make_brainGraph(tmp, type = "random",
          level = level, set.attrs = TRUE, ...)
        tmp
      }
    }
  }
}

Reply all
Reply to author
Forward
0 new messages