SCN Individual contributions

38 views
Skip to first unread message

Gershon Spitz

unread,
Jul 26, 2020, 1:58:09 AM7/26/20
to brainGr...@googlegroups.com
Dear Chris,

Thank you for the speedy responses thus far with brainGraph.

I have been attempting to extract individuals contributions for SCN. The SCN analysis comprises two groups. I have used the Scheffer atlas and Freesurfer thickness modality. I am using brainGraph 2.7.3

I have two queries:

1) I have encountered an error when I run the aop and loo functions:

Error in { : task 1 failed - "must have >4 observations”

Running “as.numeric(myResids$resids.all$Group)” returns a numeric vector, without any NA or NULL values.

Any ideas what could be causing this error?


2) I would like to calculate individual contributions of certain network properties. I saw there was a previous thread on this. If, for example, I wanted to extract individual contribution to global efficiency or nodal efficiency would the edited function look like the following:

function (resids, corr.mat, level = c("global", "regional"), 
    control.value = 1) 
{
    Group <- Study.ID <- i <- NULL
    stopifnot(inherits(resids, "brainGraph_resids"))
    groups <- resids$groups
    kNumSubj <- resids$resids.all[, tabulate(Group)]
    if (is.numeric(control.value)) {
        control.int <- control.value
        control.str <- groups[control.int]
    }
    else {
        control.int <- which(groups %in% control.value)
        control.str <- control.value
    }
    patient.str <- groups[-control.int]
    patient.int <- seq_along(groups)[-control.int]
    control.inds <- resids$resids.all[, which(Group == control.str)]
    level <- match.arg(level)
    if (level == "global") {
        IC <- sapply(groups[-control.int], function(x) NULL)
        for (j in patient.int) {
            pat.inds <- resids$resids.all[, which(Group == patient.str)]
            IC[[groups[j]]] <- foreach(i = seq_len(kNumSubj[j]), 
                .combine = "c") %dopar% {
                resids.aop <- resids[c(control.inds, pat.inds[i])]
                resids.aop$resids.all[, `:=`(Group, control.str)]
                resids.aop$resids.all <- droplevels(resids.aop$resids.all)
                setkey(resids.aop$resids.all, Group)
                new.corr <- corr.matrix(resids.aop, densities = 0.1)[[1]]$R
             g <- graph_from_adjacency_matrix(corrs[[group.vec[i]]]$R, mode='undirected', diag=FALSE)
g.new <- graph_from_adjacency_matrix(new.corrs[[1]]$R, mode='undirected', diag=FALSE)
g.eff <- efficiency(g, 'global', use.parallel=FALSE)
g.eff.new <- efficiency(g.new, 'global', use.parallel=FALSE)
g.eff - g.eff.new
            }
            IC[[groups[j]]] <- cbind(resids$resids.all[groups[j], 
                c("Study.ID", "Group")], IC[[groups[j]]])
        }
        DT <- rbindlist(IC)
        setnames(DT, "V2", "IC")
    }
    else if (level == "regional") {
        RC <- sapply(groups[-control.int], function(x) NULL)
        for (j in patient.int) {
            pat.inds <- resids$resids.all[, which(Group == patient.str)]
            RC[[groups[j]]] <- foreach(i = seq_len(kNumSubj[j]), 
                .combine = "rbind") %dopar% {
                resids.aop <- resids[c(control.inds, pat.inds[i])]
                resids.aop$resids.all[, `:=`(Group, control.str)]
                resids.aop$resids.all <- droplevels(resids.aop$resids.all)
                setkey(resids.aop$resids.all, Group)
                new.corr <- corr.matrix(resids.aop, densities = 0.1)[[1]]$R
                g <- graph_from_adjacency_matrix(corrs[[group.vec[i]]]$R, mode='undirected', diag=FALSE)    # Add "weighted=TRUE" if you want a weighted metric
g.new <- graph_from_adjacency_matrix(new.corrs[[1]]$R, mode='undirected', diag=FALSE)
n.eff <- efficiency(g, 'nodal', use.parallel=FALSE)
n.eff.new <- efficiency(g.new, 'nodal', use.parallel=FALSE)
n.eff - n.eff.new
            }
            RC[[groups[j]]] <- cbind(resids$resids.all[groups[j], 
                c("Study.ID", "Group")], RC[[groups[j]]])
        }
        RC.dt <- rbindlist(RC)
        DT <- melt(RC.dt, id.vars = c("Study.ID", "Group"), variable.name = "region", 
            value.name = "RC")
    }
    out <- list(method = "Add one patient", level = level, DT = DT)
    class(out) <- c("IC", class(out))
    return(out)
}


Let me know if you need any more information and thanks for the continued support!

Gershon.

Chris Watson

unread,
Jul 26, 2020, 12:57:54 PM7/26/20
to brainGr...@googlegroups.com
1. That error comes from the "rcorr" function in "Hmisc", which is called in "corr.matrix". I am not sure what is causing the error without more information.
2. It looks correct at a glance but I am not 100% sure. Best thing would be to try it out and see what happens.

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/CA900870-F580-44C0-ABE1-AFA000FD7023%40monash.edu.

Gershon Spitz

unread,
Aug 26, 2020, 9:09:08 PM8/26/20
to brainGr...@googlegroups.com
Hi Chris,

After spending a long time trying to diagnose the problem with ‘app’ I think I have found the issue.

Indeed, it was in the correct.matrix function.

I found that replacing the line groups groups <- resids$groups with groups <- resids$groups[[1]] seemed to do the job.

So, it had to do with how groups were being assigned.


I thought this would also fix the ‘loo’ function, but this did not seem to do the trick. I wonder if there is any information I could supply to help diagnose the problem?

Best wishes,
Gershon.

Chris Watson

unread,
Aug 27, 2020, 12:18:06 PM8/27/20
to brainGr...@googlegroups.com
I am not sure what error you are seeing, or the exact code you are running, etc. I would need a lot more information to diagnose whatever issues you are experiencing but I am currently more focused on finishing up v3.0 which might take care of the issue itself.

Chris

Gershon Spitz

unread,
Aug 27, 2020, 6:42:23 PM8/27/20
to brainGr...@googlegroups.com
Thanks Chris, Ill look forward to v3. Hopefully this solves it.
Best

Reply all
Reply to author
Forward
0 new messages