library(brainGraph)
library(data.table)
# Create example data
set.seed(123)
n <- 11 # Number of nodes
m <- 48 # Number of subjects
# Create 3D array A (n, n, m)
A <- array(rnorm(n * n * m), dim = c(n, n, m))
# Ensure A is symmetric
for (i in 1:m) {
A[, , i] <- (A[, , i] + t(A[, , i])) / 2
}
# Create covariate data frame
covars <- data.table(
Group1 = rep(1:2, each = m * 0.5),
Age = rnorm(m, 30, 5),
Sex = rep(0:1, times = m * 0.5),
Edu = sample(12:16, m, replace = TRUE),
SubjSleep = sample(0:1, m, replace = TRUE)
)
# Convert factor variables to numeric
covars$Group1 <- as.numeric(factor(covars$Group1))
covars$Sex <- as.numeric(factor(covars$Sex))
covars$Edu <- as.numeric(factor(covars$Edu))
covars$SubjSleep <- as.numeric(factor(covars$SubjSleep))
# Define contrast vector
contrasts <- c(0, 1, 0, 0, 0, 0)
# Check design matrix
design <- model.matrix(~ Group1 + Age + Sex + Edu + SubjSleep, data = covars)
print(design)
print(dim(design)) # Should be (48, 6)
# Check for NA values in A and covars
print(sum(
is.na(A))) # Should be 0
print(sum(
is.na(covars))) # Should be 0
# Run NBS
nbs.result <- NBS(A, covars, contrasts, con.type = "t", X = design, p.init = 0.001, N = 1000)
# View results
print(nbs.result)
Error Message:
Error in apply(x, 3L, qr.default, ...) : 'MARGIN' does not match dim(X)
This error only occurs when n (the number of nodes) is greater than 10. When n is 10 or less, the function works as expected.
Things I've tried:
Ensured that the dimensions of A are correct.
Confirmed that there are no NA values in A or covars.
Verified that the design matrix design is correctly specified.
Has anyone encountered a similar issue or have any suggestions on how to resolve this?
Thank you for your help!