我无法在 R 的“permute”包中准确定义我的排列设计/层次结构。
给定一组假设的地块,其中我记录了物种的出现,我想在地块内重新排列物种,同时保持每个地块中的物种数量,并保持整个物种库中单个物种的总体丰度。
最终,我试图建立一个在地块级别(每个地块有 n 个物种)以及整个物种库级别(每个物种的总观察值)受限的零分布。
# build dataset representing the presence/absence of 10 species (columns)
# in 100 plots (rows)
set.seed(123)
dat = matrix(
sample(c(0,1), size = 100*10, replace = T, prob = c(0.75, 0.25)),
nrow = 100,
ncol = 10) # let this matrix represent the observed data
rowSums(dat) # represents the number of species present in each plot
colSums(dat) # represents the overall number of observations of each species
relative_abund = colSums(dat) / sum(dat)
# proportion of occurrences of each species in the entire species pool
# use "permute" package to shuffle species in plots
# while maintaining the total number of species in each plot
# and the relative abundance of all species in the species pool
library(permute)
# single permutation of "plot # 1" maintaining number of species per plot
dat[1, shuffle(dat[1,])]
# single permutation maintaining total observations of "species # 1"
dat[shuffle(dat[,1]), 1 ]
# use permutation design/control to shuffle data, such that
rowSums(permuted_dat) == rowSums(dat)
colSums(permuted_dat) == colSums(dat) # at least approximately