-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.Network_analyses.R
65 lines (52 loc) · 2.1 KB
/
5.Network_analyses.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Network analyses
# setwd('E:/Shangri-La_2024/network')
# 加载包
library(readxl)
library(bipartite)
library(maxnodf)
library(tidyverse)
library(vegan)
library(ggplot2)
rm(list=ls())
set.seed(123)
network_data <- read_excel("data/network_matrix.xlsx", sheet="Sheet1")
# network_data <- subset(network_data,Plant_Species!="Euphorbia_jolkinii")
head(network_data)
network_data$lower <- network_data$AMFungi_OTUID
network_data$higher <- network_data$Plant_Species
network_data$webID <- paste0(network_data$Site,network_data$Plot)
network_data$freq <- network_data$Frequency
network_matrix <- network_data[,c("lower", "higher", "webID", "freq")]
network_matrix <- as.data.frame(network_matrix)
typeof(network_matrix)
network <- frame2webs(network_matrix,varnames=c("lower","higher","webID","freq"),type.out="list")
names(network)
########
# "weighted connectance", "weighted NODF"
network_index <- sapply(network, networklevel, index=c("weighted connectance", "weighted NODF"))
network_index
# "interaction evenness"
evenness_prod <- sapply(network, networklevel, index="interaction evenness", intereven="prod")
evenness_prod
#################################################################################
# weighted modularity; 定量模块观察值,每个网络重复三十次,取最大值
set.seed(123)
repeatmodule <- function(network,n){
likeliresult <- list()
m <- length(network)
for (i in 1:n) {
likeliresult[[i]] <- sapply(network,function(x)computeModules(x, method="Beckett")@likelihood)
}
result <- t(matrix(unlist(likeliresult),m,n))
rownames(result) <- 1:n
colnames(result) <- names(network)
result
}
module_rep <- repeatmodule(network,30)
module_index <- apply(module_rep,2,max)
module_index
save.image("network_analyses.RData")
# save.image("network_analyses_Eup.jo_excluded.RData")
#################################################################################
#################################################################################
#################################################################################