0

我使用以下代码生成了一个网络,我用它来计算网络指标,例如度数和图形强度。

dat <- node_dat %>% 
  filter(code == "25537") %>% 
  filter(monthyear =="2015/03")

#create network data
  
  AID = dat$code
  LOC = dat$station
  ping = dat$datetime # look for detection name may vary
  
  dat$diff_ID <- c(0, diff(AID))
  dat$diff_loc <- c(0, diff(as.factor(LOC))) #need to make LOC a factor as well!
  # could make T and time diff here but done it already
  
  # subset network for dat
  
  #find column numbers
  which(colnames(dat)=="diff_ID") #31
  which(colnames(dat)=="diff_loc") #32
  
  # make From and To columns when animal detection changes form one receiver to another
  
  move <- (dat[,31]==0 & dat[,32]!=0) #diff_id and diff_loc
  b <- rep(NA, length(move)) #creates an empty logit of the same proportions [1:N] 
  a <- rep(NA, length(move))
  c <- rep(NA, length(move))
  d <- rep(NA, length(move))
  e <- rep(NA, length(move))
  
  which(colnames(dat)=="station") #5
  b[move] <- dat[move, 5] #if b[TRUE] paste dat from column 5
  a[move] <- dat[(which(move)-1), 5] #which(converts T/F back into original characters)
  c[move] <- c(1:length(which(move)))
  d[move] <- dat[move, 1]
  e[move] <- dat[(which(move)-1), 1]
  
  dat$From <- a
  dat$To <- b
  dat$Movement <- c
  
  ######### Creating non-proportional, simple edge count matrices ########
  
  which(colnames(dat)=="From") #33
  which(colnames(dat)=="To") #34
  el_dat <- dat[,c(33,34)] #creates an edge list using the 'from' and 'to' columns (you may need to change the column numbers_ALL here from '13,14')
  el_dat <- na.omit(el_dat)# removes nas
  
  which(colnames(dat)=="time_diff") #28
  
  el_time_dat <- dat[,c(33,34,28)] #check these columns should be to and from and time difference, in that order
  el_time_dat <- na.omit(el_time_dat)
  
  #create non-directed network
  #and turn into adj matrix
  
  G <- graph.data.frame(el_dat,directed=FALSE) # creates a non-directed dat frame
  netG <- as_adjacency_matrix(G) # and turns it into a adj matrix
  netG <- as.matrix(netG, header=TRUE, row.names=1)
  
  dat_NET <- graph.adjacency(netG, mode = "undirected", diag = FALSE, weighted = TRUE)

我想针对空网络测试从该网络获得的指标。我尝试rg_reshuffling_w在 tnet 中使用该函数,但出现错误。

dat_NET_null <- rg_reshuffling_w(dat_NET, option="weights", directed=FALSE)
Error in if (NC == 2) net <- data.frame(tmp[, 1], tmp[, 2]) : 
  argument is of length zero

有没有人有一种随机化现有网络以创建空网络的好方法?我的数据集的链接在这里

4

0 回答 0