Adonis2:通过“how()”进行重复测量时阻止错误

问题描述 投票:0回答:1

我有一个研究设计,其中我在五个区块(B1-B5)中种植了三种不同的植物(S1 - S3),并采用两种不同的处理(T1,T2)。我在两个时间点(Y1-Y2)对土壤微生物进行了采样。

我想找出植物处理年份对微生物群落组成的影响(所有三向和双向相互作用对我来说都很重要)。按照我的理解,我需要将块和图(重复测量的主题;块 x 植物 x 处理组合)作为随机效应(首先作为块,后者用于重复测量)。

经过大量调查,我发现了permute包和相关的在线问题,这几乎让我到达了我需要去的地方。我认为我构建的模型是正确的,但 Adonis2 不合作。这是我的代码:

library(vegan)
library(tidyr)
library(dplyr)
library(tibble) #i think these would do.. if not, I apologize!

meta.raw<- as.factor(c(1:60))

meta.raw %>%
  as.data.frame() %>%
  `colnames<-`("sample") %>%
  mutate(block = rep(paste0("B", sample(1:5)), 2, each = 6),
         crop = rep(c("S1","S2","S3"), 10, each = 2),
         trt = rep (c("T1", "T2"), 30),
         year = rep(c("Y1", "Y2"), 2, each = 15),
         plot = paste0(block,crop,trt)) -> meta
  
matrix(round(runif(n=6000, min=0, max=2000), 0), nrow=60) %>%
  as.data.frame() %>%
  mutate(sample = as.factor(c(1:60))) %>%
  column_to_rownames("sample")-> df

# how1: Syntax as it appears on "permute" vignette, (as far as I can tell)

h1 <- how(within = Within(type = "series"),
         plots = Plots(strata = meta$plot),
         blocks = Blocks(strata = meta$block),
         nperm = 499)

adonis2(df ~ crop*trt*year,
        data = meta,
        dist = "bray",
        perm = h1,
        by = "margin")
# this doesn't work:
# Error in check(sn, control = control, quietly = quietly) : 
#   Number of observations and length of Block 'strata' do not match.

# how 2: passing within and plots inside how() and passing blocking to strata = argument in adonis2()

h2 <- how(within = Within(type = "series"),
         plots = Plots(strata = meta$plot),
         nperm = 499) # no blocks here

adonis2(df ~ crop*trt*year,
        data = meta,
        dist = "bray",
        perm = h2,
        strata = meta$block, # block here instead
        by = "margin")
# this works... but is it "correct"?
# Permutation test for adonis under reduced model
# Marginal effects of terms
# Blocks:  strata 
# Plots: meta$plot, plot permutation: none
# Permutation: series
# Number of permutations: 499
# 
# adonis2(formula = df ~ crop * trt * year, data = meta, permutations = h2, by = "margin", strata = meta$block, dist = "bray")
#               Df SumOfSqs      R2      F Pr(>F)
# crop:trt:year  2   0.1027 0.03085 0.9117      1
# Residual      48   2.7043 0.81219              
# Total         59   3.3296 1.00000  

#how 3: passing blocking vairable within how() but not in the same syntax as it appears in the "permute" vingette

h3 <- how(within = Within(type = "series"),
         plots = Plots(strata = meta$plot),
         blocks = meta$block,
         nperm = 499)

adonis2(df ~ crop*trt*year,
        data = meta,
        dist = "bray",
        perm = h3,
        by = "margin")
# this also works???
# Permutation test for adonis under reduced model
# Marginal effects of terms
# Blocks:  meta$block 
# Plots: meta$plot, plot permutation: none
# Permutation: series
# Number of permutations: 499
# 
# adonis2(formula = df ~ crop * trt * year, data = meta, permutations = h3, by = "margin", dist = "bray")
#               Df SumOfSqs      R2      F Pr(>F)
# crop:trt:year  2   0.1007 0.02936 0.8709      1
# Residual      48   2.7760 0.80897              
# Total         59   3.4316 1.00000

我做错了什么(或做对了)?我觉得第一个选项应该是正确的,但它显然不起作用...人们也出现了相同的错误消息,但它似乎只是针对不平衡的数据(也许),而我的是(至少是补了一个)。

提前谢谢大家:)

r vegan permute
1个回答
0
投票

第一个选项使用

Blocks()
函数,是错误的。我知道permute中有
is
一个Blocks()函数,但它没有被使用,我现在不记得曾经使用过这个。也许我认为使用像设置绘图内和绘图级别限制这样的函数在设计中设置块可能会更整洁。但我还没有让这个功能起作用,我很可能会删除这个功能,或者让它按需要工作。

您采用了 2 个方法,因为

adonis2()
正在内部传递给
perm
的内容上设置块元素。它正在更新
how()
,但现在你有两个
how
,我认为这是不可取的。

方法三是执行此操作的首选方法。实际上,我个人更喜欢使用

with()
来完成,以避免重复使用
meta$
来引用列:

h3 <- with(
  how(within = Within(type = "series"),
      plots = Plots(strata = plot),
      blocks = block,
      nperm = 499)
  )

如果您看到我在文档等的任何地方使用

Blocks()
,请告诉我在哪里,以便我可以更正它。

© www.soinside.com 2019 - 2024. All rights reserved.