我正在使用 vegan-package 进行 PRC,但是当我尝试对结果执行 Anova 时遇到了麻烦。我收到以下错误消息:
Error in doShuffleSet(spln[[i]], nset = nset, control) :
number of items to replace is not a multiple of replacement length
问题源于 permute-package 的 shuffleSet-function。我在下面创建了一个可重现的示例。奇怪的是 shuffle-function 不会造成麻烦,但 shuffleSet-function 会。
在我的实验中,对 4 只动物进行了 3 次治疗。动物以不同的顺序接受治疗。随着时间的推移,每天收集 5 个样本。
我想在动物内部而不是在它们之间改变我的观察。因此我使用 AnimalID 作为一个块。
我想置换天数(在我的实际实验中,动物多次接受相同的治疗),但在一天内保持测量值不变。因此,我选择自由排列 Days,并且在 Days 内没有排列。
require(permute)
TreatmentLevels=3
Animals=4
TimeSteps=5
AnimalID=rep(letters[1:Animals],each=TreatmentLevels*TimeSteps)
Time=rep(1:TimeSteps,Animals=TreatmentLevels)
#treatments were given in different order per animal.
Day=rep(c(1,2,3,2,3,1,3,2,1,2,3,1),each=TimeSteps)
Treatment=rep(rep(LETTERS[1:TreatmentLevels],each=TimeSteps),Animals)
dataset=as.data.frame(cbind(AnimalID,Treatment,Day,Time))
ctrl=how(blocks = dataset$AnimalID,plots = Plots(strata=dataset$Day,type = "free"),
within=Within(type="none"), nperm = 999)
#this works
shuffle(60,control=ctrl)
#this giveas an error
shuffleSet(60,nset=1,control=ctrl)
shuffleSet(60,nset=10,control=ctrl)
问题似乎出在块中。因为这行得通
dataset$AnimalDay=factor(paste0(dataset$AnimalID,dataset$Day))
ctrl=how(plots = Plots(strata=dataset$AnimalDay,type = "free"),
within=Within(type="none"), nperm = 999)
#this works
shuffle(60,control=ctrl)
shuffleSet(60,nset=1,control=ctrl)
shuffleSet(60,nset=10,control=ctrl)