Dear Chris,
I have been trying to perform "Multi-threshold permutation correction”. I have been following the example on page 74-75 of the user manual.
My installation set-up is: R 4.0.3; RStudio 1.3.1093; brainGraph 3.0.2; macOS Catalina 10.15.7
As I run my script:
mtpcVars <- data.table(level=rep(c('graph', 'vertex'), each=2), outcome=c('E.global.wt', 'Lp', 'strength', 'GC.wt'), alt='greater')
# Change H_A for 'Lp'
mtpcVars[outcome == 'Lp', alt := 'less']
setkey(mtpcVars, level, outcome)
# Different number of permutations based on the level
mtpcVars['graph', N := 1e4]
mtpcVars['vertex', N := 5e3]
# Generate permutation matrices using 'shuffleSet' from the 'permute' package
mtpcPerms <- list(vertex=shuffleSet(n=nrow(covars.dti[, 1:4]), nset=mtpcVars['vertex', unique(N)]), graph=shuffleSet(n=nrow(covars.dti[, 1:4]), nset=mtpcVars['graph', unique(N)]))
# Create the contrast matrix
mtpcContrast
mtpcVars
## level
## 1: graph
mtpcContrast <- matrix(c(0, 0, 0, 2,
0, 0, 0, -2),
nrow=2, byrow=TRUE,
dimnames=list(c('control > preems', 'preem > control')))
# Loop through the network metrics
# The 1st-level of the list is for each 'level' (i.e., 'graph' and 'vertex')
mtpc.diffs.list <- sapply(mtpcVars[, unique(level)], function(x) NULL)
for (x in names(mtpc.diffs.list)) { # Loop across 'level'
# The 2nd-level is for each network metric (for the given level 'x')
mtpc.diffs.list[[x]] <- sapply(mtpcVars[x, unique(outcome)], function(x) NULL)
for (y in mtpcVars[x, outcome]) {
mtpc.diffs.list[[x]][[y]] <-
mtpc(g, thresholds, covars=covars.dti[, 1:4], measure=y, contrasts=mtpcContrast,
con.type='t', level=x, N=mtpcVars[.(x, y), N], perms=mtpcPerms[[x]],
alt=mtpcVars[.(x, y), alt])
}
}
Error in apply(x, 3L, qr.default, ...) : 'MARGIN' does not match dim(X)
> traceback() gives:
12: stop("'MARGIN' does not match dim(X)")
11: apply(x, 3L, qr.default, ...)
10: qr.array(M)
9: qr(M)
8: MASS::Null(t(contrast))
7: partition(X, contrasts[[j]], part.method)
6: setup_randomise(perm.method, part.method, X, contrasts, ctype,
nC)
5: randomise(perm.method, part.method, N, perms, X, y, contrasts,
ctype, nC, n = n, p = p, ny = ny, dfR = dfR)
4: brainGraph_GLM(z, covars, measure, contrasts, con.type, outcome,
con.name = con.name, N = N, level = level, permute = TRUE,
perm.method = perm.method, part.method = part.method, perms = perms,
alpha = alpha, long = TRUE, ...)
3: FUN(X[[i]], ...)
2: lapply(g.list, function(z) brainGraph_GLM(z, covars, measure,
contrasts, con.type, outcome, con.name = con.name, N = N,
level = level, permute = TRUE, perm.method = perm.method,
part.method = part.method, perms = perms, alpha = alpha,
long = TRUE, ...))
1: mtpc(g, thresholds, covars = covars.dti[, 1:4], measure = y,
contrasts = mtpcContrast, con.type = "t", level = x, N = mtpcVars[.(x,
y), N], perms = mtpcPerms[[x]], alt = mtpcVars[.(x, y),
alt])
The "mtpcPerms" is a list of 2 elements
vertex [5000 x 67]
graph[5000 x 67]
67 is the number of my subjects.
SC of the mtpcContrast & mtpcVars also attached to this mail.
Do you have any idea, what is wrong with my set-up? I hope you can help me!
With best regards,
Virva
--
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/9a8839df-ae2e-4b8f-8162-e66156a61171n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/15da612e-4902-43a4-a3dc-ca721ba1206dn%40googlegroups.com.
I defined the function as you instructed and now the code seems to work. Thank you so much for your help!