1

我正在尝试使用以下代码运行 glm 分析:

ftP <- manyglm(AbundVec ~ as.matrix(traitVec)*trV, family = "poisson")

我目前收到以下错误消息:

[[<-.data.frame( , i, value = c( 54L *tmp*, 54L, 54L, 54L, 54L, : 替换有 60326 行,数据有 8618

作为第一步,我根据以下内容为丰度数据创建了一个物种 x 绘图矩阵:

AbundMat <- acast(Abund, plot~species, value.var="occurrence", fun.aggregate=length)

输出:class(AbundMat)=matrix, typeof(AbundMat)=integer, storage.mode(AbundMat)=integer, length(AbundMat)=8618, attributes(AbundMat)= 139(plots) 62(species)

然后我导入文件:

1)特征:具有62obs的data.frame。和 7 个变量(包括因子和数量);包括;typeof(Traits)=list 和 class(Traits)=df

2)处理:具有139obs的data.frame。和 2 个变量($plot 和 $site 作为因子);typeof(Treatment)=list and class(Treatment)=df

然后,我按照本文附录中描述的示例对丰度数据进行矢量化:CATS 回归 - 一种基于模型的方法来研究基于特征的社区组装 ( http://onlinelibrary.wiley.com/store/10.1111/2041-210X .12280/asset/supinfo/mee312280-sup-0003-AppendixS3.pdf?v=1&s=0037b03799e63903d896ba208fb2a6cc1b5605d0):

AbundVec <- as.vector(AbundMat)
    n.rows <- NROW(AbundMat)
    n.vars <- NCOL(AbundMat)
    sppVec <- rep(row.names(Traits), each=n.rows)
    traitVec <- Traits[rep(1:n.vars, each = n.rows),]
    siteVec <- rep(row.names(AbundMat), n.vars)
    Treatment <- as.factor(Treatment)
    levels(Treatment) <- c("A", "B", "C")
    trV <- rep(Treatment, n.vars)

最后,我执行一个 glm(需要包 mvabund):

ftP <- manyglm(AbundVec ~ as.matrix(traitVec)*trV, family = "poisson")

这个阶段我收到上面提到的错误信息: Error in [[<-.data.frame( *tmp*, i, value = c(54L, 54L, 54L, 54L, 54L, : replacement has 60326 rows, data has 8618

请注意 8618*7=60326 (我有 7 个特征变量)

当我将我的数据文件与 CATS 回归论文中描述的丰度示例数据文件进行比较时,我注意到示例数据文件具有以下 str() 输出:

str(GrazedPlants$abundMat) num [1:32, 1:68] 0 210 195 1 617 0 1 75 1 0 ... - attr( , "dimnames")=List of 2 ..$ : chr [1:32 [ _ 1:83] “ALYSALYS” “ANTHVULN” “APHYMONS” “ARENSERP” ...

→ typeof = 双,类 = 矩阵

当我对我的数据运行 str() 时,我得到:

str(AbundMat) int [1:139, 1:62] 0 0 0 0 0 0 0 0 0 1 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:139] “A01” “A02” “A03” “A04” ... ..$ : 字符 [1:62] “sp01” “sp02” “sp03” “sp04” ...

→ typeof = 整数,类 = 矩阵

我的处理和特征数据的格式似乎与示例数据集的格式相匹配,只是我的大多数特征都是因子(而在示例中它们都是数字的)。

所以,我想知道错误消息是否是由于 'AbundMat' 不是所需的 class=double 形式(而是整数)?

此外,根据 str() 输出,“AbundMat”中似乎缺少属性(级别)。

是否可以将矩阵生成为 double 类型(类似于示例数据矩阵)?

============ 附加说明:==========================

作为附加说明,此代码可用于强制数据与函数 manyglm() 一起使用。它仅使用一行数据(单个图)。我想知道如何为多个站点调整此代码,即我的数据集中的 139 个图?

y2 = c(t(grazedPlants$abundMat[1,])) # coercing the first row into a vector
y2
singleSite2 = data.frame(y2, grazedPlants$traits, check.names = F) # make a data frame from site abundances and traits
singleSite2
ft5 = manyglm(y2 ~ ., data = singleSite2, family = "negative.binomial")
ft5
summary(ft5, nBoot=1) # find which traits are important
plot(ft5)

==================================================== ==

非常感谢您的任何建议。

这些是我的数据集:

1)物种x地块丰度(计数)数据(文件名:Abund)

structure(list(plot = structure(c(47L, 47L, 48L, 51L, 53L, 54L), .Label = c("A01", "A02", "A03", "A04", "A05", "A06", "A07", "A08", "A09", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A20", "A21", "A22", "A23", "A24", "A25", "A26", "A27", "A28", "A29", "A30", "A31", "A32", "A33", "A34", "A35", "A36", "A37", "A38", "A39", "A40", "A41", "A42", "A43", "A44", "A45", "A46", "A47", "A48", "A49", "B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B09", "B10", "B11", "B12", "B13", "B14", "B15", "B16", "B17", "B18", "B19", "B20", "B21", "B22", "B23", "B24", "B25", "B26", "B27", "B28", "B29", "B30", "B31", "B32", "B33", "B34", "B35", "B36", "B37", "B38", "B39", "B40", "B41", "B42", "B43", "B44", "B45", "C01", "C02", "C03", "C04", "C05", "C06", "C07", "C08", "C09", "C10", "C11", "C12", "C13", "C14", "C15","C16", "C17", "C18", "C19", "C20", "C21", "C22", "C23", "C24", "C25", "C26", "C27", "C28", "C29", "C30", "C31", "C32", "C33", "C34", "C35", "C36", "C37", "C38", "C39", "C40", "C41", "C42", "C43", "C44", "C45"), class = "factor"), 
species = structure(c(46L, 47L, 47L, 47L, 47L, 47L), .Label = c("sp1", 
"sp10", "sp11", "sp12", "sp13", "sp14", "sp15", "sp16", "sp17", 
"sp18", "sp19", "sp2", "sp20", "sp21", "sp22", "sp23", "sp24", 
"sp25", "sp26", "sp27", "sp28", "sp29", "sp3", "sp30", "sp31", 
"sp32", "sp33", "sp34", "sp35", "sp36", "sp37", "sp38", "sp39", 
"sp4", "sp40", "sp41", "sp42", "sp43", "sp44", "sp45", "sp46", 
"sp47", "sp48", "sp49", "sp5", "sp50", "sp51", "sp52", "sp53", 
"sp54", "sp55", "sp56", "sp57", "sp58", "sp59", "sp6", "sp60", 
"sp61", "sp62", "sp7", "sp8", "sp9"), class = "factor"), 
occurrence = c(1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("plot", "species", "occurrence"), row.names = c(NA, 6L), class = "data.frame")

2)物种x性状数据(文件名:Traits)

structure(list(species = structure(c(1L, 12L, 23L, 34L, 45L, 56L, 60L, 61L, 62L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 57L, 58L, 59L), .Label = c("sp1", "sp10", "sp11", "sp12", "sp13", "sp14", "sp15", "sp16", "sp17", "sp18", "sp19", "sp2", "sp20", "sp21", "sp22", "sp23", "sp24", "sp25", "sp26", "sp27", "sp28", "sp29", "sp3", "sp30", "sp31", "sp32", "sp33", "sp34", "sp35", "sp36", "sp37", "sp38", "sp39", "sp4", "sp40", "sp41", "sp42", "sp43", "sp44", "sp45", "sp46", "sp47", "sp48", "sp49", "sp5", "sp50", "sp51", "sp52", "sp53", "sp54", "sp55", "sp56", "sp57", "sp58", "sp59", "sp6", "sp60", "sp61", "sp62", "sp7", "sp8", "sp9"), class = "factor"), trait1 = structure(c(3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 3L, 3L, 1L, 3L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 2L, 2L, 3L, 3L, 2L, 3L), .Label = c("<NA>", "a", "b"), class = "factor"), trait2 = structure(c(6L, 6L, 4L, 3L, 8L, 4L, 4L, 4L, 3L, 1L, 1L, 6L, 6L, 6L, 6L, 1L, 2L, 2L, 7L, 7L, 6L, 3L, 6L, 6L, 2L, 1L, 2L, 4L, 4L, 3L, 5L, 4L, 4L, 1L, 4L, 2L, 4L, 6L, 3L, 8L, 2L, 4L, 4L, 1L, 1L, 4L, 6L, 1L, 4L, 6L, 6L, 6L, 6L, 5L, 3L, 2L, 4L, 1L, 4L, 1L, 4L, 6L), .Label = c("<NA>", "c", "d", "e", "f", "g", "h", "i"), class = "factor"), trait3 = structure(c(4L, 4L, 4L, 6L, 4L, 1L, 6L, 2L, 2L, 2L, 2L, 1L, 6L, 4L, 4L, 6L, 3L, 6L, 3L, 3L, 6L, 2L, 2L, 2L, 6L, 2L, 6L, 4L, 4L, 4L, 6L, 2L, 6L, 2L, 6L, 2L, 2L, 2L, 6L, 6L, 6L, 2L, 6L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 6L, 4L, 5L, 4L, 4L, 2L, 2L, 2L, 6L, 2L, 6L, 6L), .Label = c("", "<NA>", "j", "k", "l", "m"), class = "factor"), trait4 = structure(c(4L, 4L, 2L, 2L, 5L, 3L, 2L, 3L, 1L, 5L, 1L, 3L, 3L, 3L, 3L, 5L, 1L, 4L, 2L, 2L, 1L, 5L, 1L, 3L, 3L, 1L, 5L, 3L, 1L, 5L, 5L, 2L, 2L, 1L, 1L, 3L, 1L, 3L, 5L, 2L, 4L, 3L, 1L, 1L, 1L, 4L, 3L, 5L, 3L, 2L, 2L, 2L, 3L, 5L, 5L, 4L, 3L, 1L, 2L, 1L, 2L, 4L), .Label = c("<NA>", "1", "2", "3", "4"), class = "factor"), trait5 = structure(c(12L, 14L, 9L, 2L, 21L, 9L, 1L, 14L, 9L, 22L, 2L, 12L, 12L, 4L, 12L, 14L, 6L, 14L, 12L, 11L, 12L, 3L, 1L, 1L, 3L, 1L, 2L, 12L, 5L, 12L, 2L, 17L, 2L, 1L, 16L, 19L, 15L, 19L, 12L, 10L, 3L, 12L, 18L, 12L, 19L, 8L, 12L, 20L, 16L, 12L, 7L, 12L, 13L, 9L, 11L, 5L, 2L, 1L, 14L, 11L, 12L, 16L), .Label = c("<NA>", "10", "12", "14", "15", "16", "17", "18", "20", "23", "25", "30", "32", "35", "4", "40", "50", "6", "7", "8", "9", "small"), class = "factor"), 
trait6 = structure(c(3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 
1L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 
3L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 1L, 3L, 3L, 
2L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L), .Label = c("<NA>", "p", 
"q"), class = "factor"), trait7 = c(0.61, 0.64, 0.61, 0.62, 
0.64, 0.61, 0.39, 0.13, 0.73, 0.75, 0.51, 0.77, 0.75, 0.6, 
0.88, 0.55, 0.61, 0.72, 0.64, 0.72, 0.65, 0.7, 0.85, 0.74, 
0.55, 0.76, 0.76, 0.43, 0.67, 0.48, 0.73, 0.88, 0.4, 0.46, 
0.48, 0.67, 0.67, 0.88, 0.53, 0.48, 0.93, 0.64, 0.62, 0.47, 
0.64, 0.64, 0.7, 0.64, 0.9, 0.85, 0.7, 0.86, 0.72, 0.43, 
0.33, 0.74, 0.52, 0.69, 0.75, 0.45, 0.88, 0.68)), .Names = c("species", "trait1", "trait2", "trait3", "trait4", "trait5", "trait6", "trait7"), class = "data.frame", row.names = c(NA, -62L))

3)治疗数据(文件名:Treatment)

    structure(list(plot = structure(1:139, .Label = c("A01", "A02", "A03", "A04", "A05", "A06", "A07", "A08", "A09", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A20", "A21", "A22", "A23", "A24", "A25", "A26", "A27", "A28", "A29", "A30", "A31", "A32", "A33", "A34", "A35", "A36", "A37", "A38", "A39", "A40", "A41", "A42", "A43", "A44", "A45", "A46", "A47", "A48", "A49", "B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B09", "B10", "B11", "B12", "B13", "B14", "B15", "B16", "B17", "B18", "B19", "B20", "B21", "B22", "B23", "B24", "B25", "B26", "B27", "B28", "B29", "B30", "B31", "B32", "B33", "B34", "B35", "B36", "B37", "B38", "B39", "B40", "B41", "B42", "B43", "B44", "B45", "C01", "C02", "C03", "C04", "C05", "C06", "C07", "C08", "C09", "C10", "C11", "C12", "C13", "C14", "C15", "C16", "C17", "C18", "C19", "C20", "C21", "C22", "C23", "C24", "C25", "C26", "C27", "C28", "C29", "C30", "C31", "C32", "C33", "C34", "C35", "C36", "C37", "C38", "C39", "C40", "C41", "C42", "C43", "C44", "C45"), class = "factor"), site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("A", "B", "C"), class = "factor")), .Names = c("plot", "site"), class = "data.frame", row.names = c(NA, -139L))

此外,这些是“grazedPlants.RData”文件的子集:

输入(头部(grazedPlants$aundMat))

    structure(list(X = structure(1:6, .Label = c("FC01", "FC02", 
    "FC03", "FC04", "FC05", "FC06", "FC07", "FC08", "NC01", "NC02", 
    "NC03", "NC04", "NC05", "NC06", "NC07", "NC08", "ND01", "ND02", 
    "ND03", "ND04", "ND05", "ND06", "ND07", "ND08", "TD01", "TD02", 
    "TD03", "TD04", "TD05", "TD06", "TD07", "TD08"), class = "factor"), 
        CAPSBURS = c(0L, 210L, 195L, 1L, 617L, 0L), CREPVESI.HAE = c(0L, 
        0L, 0L, 0L, 0L, 0L), GALICORR = c(0L, 0L, 0L, 0L, 0L, 0L), 
        MUSCNEGL = c(0L, 0L, 0L, 0L, 0L, 0L), BROMEREC = c(1L, 0L, 
        0L, 0L, 0L, 0L), ARENSERP = c(0L, 0L, 1L, 0L, 4L, 0L), VULPMYUR = c(0L, 
        28L, 3L, 0L, 0L, 8L), CERAPUMI = c(0L, 2L, 0L, 0L, 0L, 0L
        ), ORNICOLL = c(0L, 1L, 0L, 0L, 0L, 1L), VEROARVE = c(0L, 
        0L, 0L, 0L, 0L, 0L), GERAROTU = c(0L, 0L, 0L, 80L, 0L, 41L
        ), ERODCICU = c(0L, 0L, 0L, 1L, 0L, 3L), BROMHORD = c(0L, 
        735L, 0L, 72L, 0L, 4L), POABULB = c(0L, 209L, 110L, 2L, 0L, 
        0L), HORDMURI = c(5L, 11L, 0L, 0L, 0L, 0L), TARALAEV = c(0L, 
        0L, 0L, 0L, 0L, 0L), SANGMINO = c(0L, 0L, 0L, 0L, 1L, 0L), 
        TRIFSCAB = c(0L, 1L, 25L, 0L, 0L, 0L), CREPSANC.SAN = c(0L, 
        0L, 0L, 0L, 0L, 0L), ERYNCAMP = c(1L, 0L, 0L, 0L, 0L, 0L), 
        BROMDIAN = c(0L, 0L, 0L, 0L, 0L, 1L), STELMEDI = c(0L, 0L, 
        0L, 0L, 0L, 0L), ALYSALYS = c(0L, 0L, 0L, 0L, 0L, 0L), CERAGLOM = c(17L, 
        5L, 2L, 0L, 21L, 0L), EROPVERN = c(0L, 0L, 0L, 0L, 0L, 0L
        ), FESTRUBR = c(30L, 0L, 14L, 0L, 69L, 0L), FILAPYRA = c(0L, 
        0L, 9L, 0L, 0L, 0L), SCLEANNU = c(0L, 0L, 0L, 0L, 0L, 0L), 
        CAREHALL = c(80L, 21L, 0L, 2L, 0L, 368L), POTENEUM = c(2L, 
        1L, 0L, 0L, 0L, 0L), VICITETR.GRA = c(0L, 0L, 0L, 1L, 0L, 
        0L), SHERARVE = c(0L, 0L, 0L, 0L, 0L, 0L), POLYCALC = c(0L, 
        0L, 0L, 2L, 0L, 0L), VICISATI.SAT = c(0L, 0L, 0L, 0L, 0L, 
        0L), FILIVULG = c(0L, 0L, 0L, 126L, 16L, 0L), MYOSRAMO.RAM = c(0L, 
        56L, 0L, 0L, 0L, 27L), CAREHUMI = c(0L, 3L, 9L, 0L, 0L, 7L
        ), TARAOFFI = c(2L, 0L, 0L, 0L, 0L, 0L), HIPPCOMO = c(1L, 
        1L, 0L, 3L, 1L, 0L), FESTCHRI = c(0L, 0L, 0L, 0L, 13L, 0L
        ), KOELVALL = c(0L, 0L, 0L, 0L, 0L, 0L), ONONSTRI = c(0L, 
        0L, 0L, 0L, 0L, 0L), GENIHISP = c(0L, 0L, 0L, 0L, 0L, 0L), 
        CARTMITI = c(0L, 0L, 0L, 0L, 0L, 0L), ANTHVULN = c(0L, 0L, 
        0L, 0L, 0L, 0L), CENTPECT.SUP = c(0L, 0L, 0L, 0L, 0L, 0L), 
        LOTUCORN = c(0L, 0L, 0L, 0L, 0L, 1L), PLANLANC = c(0L, 0L, 
        0L, 1L, 0L, 0L), RANUBULB = c(0L, 0L, 0L, 0L, 15L, 0L), CHAMSAGI = c(0L, 
        0L, 0L, 0L, 0L, 0L), TEUCPOLI = c(0L, 0L, 0L, 0L, 0L, 0L), 
        THYMSERP = c(0L, 0L, 0L, 0L, 0L, 0L), COROMINI = c(0L, 0L, 
        0L, 0L, 0L, 0L), SALVPRAT = c(0L, 0L, 0L, 2L, 0L, 0L), ASTRMONS = c(0L, 
        0L, 0L, 0L, 0L, 0L), HIERPILO = c(1L, 0L, 0L, 0L, 0L, 0L), 
        LINUTENU.TEN = c(0L, 0L, 0L, 0L, 0L, 0L), APHYMONS = c(0L, 
        0L, 2L, 0L, 0L, 0L), TEUCCHAM = c(0L, 0L, 1L, 0L, 0L, 0L), 
        HELICANU = c(0L, 0L, 1L, 0L, 16L, 6L), HELINUMM = c(2L, 0L, 
        0L, 0L, 0L, 0L), CAREFLAC = c(18L, 0L, 0L, 57L, 0L, 8L), 
        STIPPENN = c(125L, 26L, 0L, 0L, 0L, 0L), INULMONT = c(0L, 
        0L, 1L, 0L, 0L, 0L), TEUCMONT = c(0L, 0L, 0L, 0L, 0L, 0L), 
        GLOBVULG = c(0L, 0L, 0L, 0L, 1L, 0L), HELIAPEN = c(0L, 1L, 
        0L, 0L, 0L, 0L), RANUGRAM = c(0L, 0L, 0L, 2L, 0L, 0L)), .Names = c("X", 
    "CAPSBURS", "CREPVESI.HAE", "GALICORR", "MUSCNEGL", "BROMEREC", 
    "ARENSERP", "VULPMYUR", "CERAPUMI", "ORNICOLL", "VEROARVE", "GERAROTU", 
    "ERODCICU", "BROMHORD", "POABULB", "HORDMURI", "TARALAEV", "SANGMINO", 
    "TRIFSCAB", "CREPSANC.SAN", "ERYNCAMP", "BROMDIAN", "STELMEDI", 
    "ALYSALYS", "CERAGLOM", "EROPVERN", "FESTRUBR", "FILAPYRA", "SCLEANNU", 
    "CAREHALL", "POTENEUM", "VICITETR.GRA", "SHERARVE", "POLYCALC", 
    "VICISATI.SAT", "FILIVULG", "MYOSRAMO.RAM", "CAREHUMI", "TARAOFFI", 
    "HIPPCOMO", "FESTCHRI", "KOELVALL", "ONONSTRI", "GENIHISP", "CARTMITI", 
    "ANTHVULN", "CENTPECT.SUP", "LOTUCORN", "PLANLANC", "RANUBULB", 
    "CHAMSAGI", "TEUCPOLI", "THYMSERP", "COROMINI", "SALVPRAT", "ASTRMONS", 
    "HIERPILO", "LINUTENU.TEN", "APHYMONS", "TEUCCHAM", "HELICANU", 
    "HELINUMM", "CAREFLAC", "STIPPENN", "INULMONT", "TEUCMONT", "GLOBVULG", 
    "HELIAPEN", "RANUGRAM"), row.names = c(NA, 6L), class = "data.frame")

输入(头部(grazedPlants$traits))

    structure(list(X = structure(c(9L, 20L, 28L, 42L, 7L, 4L), .Label = c("ALYSALYS", "ANTHVULN", "APHYMONS", "ARENSERP", "ASTRMONS", "BROMDIAN", "BROMEREC", "BROMHORD", "CAPSBURS", "CAREFLAC", "CAREHALL", "CAREHUMI", "CARTMITI", "CENTPECT.SUP", "CERAGLOM", "CERAPUMI", "CHAMSAGI", "COROMINI", "CREPSANC.SAN", "CREPVESI.HAE", "ERODCICU", "EROPVERN", "ERYNCAMP", "FESTCHRI", "FESTRUBR", "FILAPYRA", "FILIVULG", "GALICORR", "GENIHISP", "GERAROTU", "GLOBVULG", "HELIAPEN", "HELICANU", "HELINUMM", "HIERPILO", "HIPPCOMO", "HORDMURI", "INULMONT", "KOELVALL", "LINUTENU.TEN", "LOTUCORN", "MUSCNEGL", "MYOSRAMO.RAM", "ONONSTRI", "ORNICOLL", "PLANLANC", "POABULB", "POLYCALC", "POTENEUM", "RANUBULB", "RANUGRAM", "SALVPRAT", "SANGMINO", "SCLEANNU", "SHERARVE", "STELMEDI", "STIPPENN", "TARALAEV", "TARAOFFI", "TEUCCHAM", "TEUCMONT", "TEUCPOLI", "THYMSERP", "TRIFSCAB", "VEROARVE", "VICISATI.SAT", "VICITETR.GRA", "VULPMYUR"), class = "factor"), SM = c(0.587, -0.81, 0.446, 0.195, 0.357, -0.128), OFL = c(136.1359, 131.9466, 148.8626, 148.5717, 156.9126, 149.2011), RPH = c(1.4092797, 1.0612845, 0.729711, 0.7335391, 1.7941586, 1.4624131), VPH = c(1.12952674, 0.86161103, 0.54418607, 0.44006594, 1.49088504, 1.01091915), SLA = c(1.0997531, 1.0612576, 1.4866071, 1.0666007, 0.9769541, 1.1077584), LDMC = c(2.491384, 2.446196, 2.227827, 2.476604, 2.717145, 2.347065), LA = c(0.58658981, 0.29217792, 0.53604022, 0.07529993, 0.28781845, 0.68114674), 
    LNC = c(1.46497, 1.31874, 1.417831, 1.277482, 1.302021, 1.363778
    ), LCC = c(2.632749, 2.621413, 2.6114, 2.653969, 2.637665, 
    2.630081), LPC = c(0.40060595, 0.305709643, 0.543668171, 
    0.225178098, 0.135509475, 0.354213077)), .Names = c("X", "SM", "OFL", "RPH", "VPH", "SLA", "LDMC", "LA", "LNC", "LCC", "LPC"), row.names = c(NA, 6L), class = "data.frame"))

输入(头(放牧植物$治疗))

structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Names = c("FC01", "FC02", 
"FC03", "FC04", "FC05", "FC06"), .Label = c("Fertilised (Limestone)", 
"Pasture (Limestone)", "Pasture (Dolomite)", "Ungrazed (Dolomite)"
), class = "factor")
4

1 回答 1

0

使用您最近在此处发布的对象( AbundTraitsTreatment)并将它们与发布的链接对象(abundtraitstreatment)进行比较,您的基本问题是Traits不包含数字列。其他问题包括rownames()$分配。

作者的特征(数字列)

head(traits)
#                      SM      OFL       RPH       VPH       SLA     LDMC         LA      LNC      LCC       LPC
# CAPSBURS      0.5872967 136.1359 1.4092797 1.1295267 1.0997531 2.491384 0.58658981 1.464970 2.632749 0.4006060
# CREPVESI.HAE -0.8103945 131.9466 1.0612845 0.8616110 1.0612576 2.446196 0.29217792 1.318740 2.621413 0.3057096
# GALICORR      0.4463238 148.8626 0.7297110 0.5441861 1.4866071 2.227827 0.53604022 1.417831 2.611400 0.5436682
# MUSCNEGL      0.1951452 148.5717 0.7335391 0.4400659 1.0666007 2.476604 0.07529993 1.277482 2.653969 0.2251781
# BROMEREC      0.3571080 156.9126 1.7941586 1.4908850 0.9769541 2.717145 0.28781845 1.302021 2.637665 0.1355095
# ARENSERP     -0.1283229 149.2011 1.4624131 1.0109192 1.1077584 2.347065 0.68114674 1.363778 2.630081 0.3542131

你的特征(因子列+物种应该是rownames

head(Traits)
#   species trait1 trait2 trait3 trait4 trait5 trait6 trait7
# 1     sp1      b      g      k      3     30      q   0.61
# 2     sp2      b      g      k      3     35      q   0.64
# 3     sp3      a      e      k      1     20      q   0.61
# 4     sp4      a      d      m      1     10      p   0.62
# 5     sp5      a      i      k      4      9      q   0.64
# 6     sp6      a      e             2     20      q   0.61

调整因子类型rownames并将其转换为数字,然后您应该可以调用. 如果此处使用的这种转换没有意义,请务必调整Traits以反映数字数字。manyglm()

row.names(Traits) <- Traits$species          # ASSIGNING ROW NAMES TO SPECIES
Traits <- Traits[-1]                         # REMOVING FIRST COLUMN  
# CONVERT COLUMNS TO NUMERIC
Traits[, c(1:ncol(Traits))] <- sapply(Traits[, c(1:ncol(Traits))], as.numeric)

AbundVec <- as.vector(as.numeric(AbundMat))
N.rows <- NROW(AbundMat)
N.vars <- NCOL(AbundMat)
SppVec <- rep(row.names(Traits), each=N.rows)
TraitVec <- Traits[rep(1:N.vars, each=N.rows),]
SiteVec <- rep(row.names(AbundMat), N.vars)
Treatment = as.factor(Treatment$site)        # SELECT SPECIFIC COLUMN
levels(Treatment) <- c("A", "B", "C")       
TrV <- rep(Treatment, N.vars)

FtP <- manyglm(AbundVec ~ as.matrix(TraitVec)*TrV, family = "poisson")
于 2017-10-03T16:00:25.263 回答