2

我正在使用 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)
4

1 回答 1

1

关键问题似乎是nset = 1:排列已生成并shuffleSet有效,但打印结果失败,因为一组被丢弃到向量并print需要一个矩阵。你可以得到排列,你可以使用排列,但你不能print

我们必须解决这个问题。

于 2016-06-30T05:01:27.453 回答