我在R中编写以下函数,以计算网络中两组节点之间的连通性:
Cdiff <-function(data){
net <- EBICglasso(cor_auto(data), nrow(data))
a <- sum(abs(net[-c(15:20),-c(15:20)]))/2
b <-sum(abs(net[-c(1:14, 21:24),-c(1:14, 21:24)]))/2
c <-sum(abs(net))/2
d <- a+b
diff <- c-d
return(diff)}
然后,我编写以下代码进行排列测试,以计算来自两个网络的两个值之间的差异:
x1<-net1
x2<-net2
nobs1 <- nrow(x1)
nobs2 <- nrow(x2)
dataall <- rbind(x1, x2)
Nsim=1000
diFF = vector(length=Nsim)
for(i in 1:Nsim){
b <- 1:(nobs1 + nobs2)
s <- sample(1:(nobs1 + nobs2), nobs1, replace = FALSE)
x1perm <- dataall[s, ]
x2perm <- dataall[b[-s], ]
diFF[i] = Cdiff(x1perm) - Cdiff(x2perm)
}
在这里,我计算观察到的差异:
diff1 <- Cdiff(x1)
diff2 <- Cdiff(x2)
observed.statistic <- diff1 - diff2