我有 100 个矩阵,我需要对所有矩阵进行相同的分析。
###DADOSEXEMPLO##
vetor <- c(1, 5, 3, 8, 2, 9, 3, 2:15, 1, 5, 3, 6, 5, 9, 3 )
matrix(vetor, 7, 7)
matrix<-matrix(vetor, 7, 7)
matcor <- cor(matrix, method = "spearman")
matrixnetwork = graph.adjacency(matcor, mode="undirected", weighted = TRUE,
add.colnames=NULL, diag=FALSE)
plot(matrixnetwork)
matrix
###BOOT
N <- 7L
set.seed(2023)
R <- 100L
BIPERMUT<- vector("list", length = R)
for(i in seq.int(R)) {
indices <- sample(N, replace = TRUE)
BIPERMUT[[i]] <- permute(matrixnetwork, sample(vcount(matrixnetwork)))
##ANALYSE
degree(BIPERMUT[[1]], normalized = FALSE, loops = FALSE)
我尝试了,但这并没有运行分析 100 倍,而是运行 100 倍重新采样:
for(i in seq.int(R)) {
indices <- sample(N, replace = TRUE)
boot_degree= degree(g_boot_list[[i]], normalized = FALSE, loops = FALSE)
在
boot_degree
循环之前创建结果向量 for
。
boot_degree <- vector("list", R)
for(i in seq.int(R)) {
boot_degree[[i]] <- degree(g_boot_list[[i]], normalized = FALSE, loops = FALSE)
}
另一种方法是
lapply
为 degree
的每个成员发挥 g_boot_list
的作用。
boot_degree2 <- lapply(g_boot_list, degree, normalized = FALSE, loops = FALSE)
identical(boot_degree, boot_degree2) # TRUE