【问题标题】:RDA analysis in R gives error "attempt to set an attribute on NULL"R 中的 RDA 分析给出错误“尝试将属性设置为 NULL”
【发布时间】:2016-01-07 20:29:00
【问题描述】:

我正在使用 Vegan 包在 R 中运行分析。我只希望摘要提取一些值的方式非常简单。但它一直告诉我一条错误消息。为什么?

我有这个数据集

feed.raw1 =structure(c(0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
            5L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 7L, 11L, 3L, 1L, 
            0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 
            0L, 0L, 0L, 0L, 3L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
            0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 8L, 7L, 5L, 1L, 
            0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 10L, 5L, 0L, 0L, 1L, 0L, 0L, 
            0L, 0L, 0L, 0L, 0L, 1L, 5L, 0L, 0L, 8L, 9L, 0L, 0L, 5L, 0L, 0L, 
            0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 15L, 0L, 
            51L, 10L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 
            0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 3L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 
            0L, 0L, 0L, 45L, 203L, 17L, 54L, 4L, 1L, 0L, 0L, 0L, 0L, 10L, 
            9L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 12L, 0L, 
            0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 22L, 206L, 9L, 16L, 1L, 
            1L, 6L, 6L, 0L, 0L, 4L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
            0L, 7L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
            2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 12L, 3L, 1L, 0L, 
            0L, 0L, 0L, 0L, 0L, 0L, 23L, 4L, 1L, 2L, 0L, 2L, 0L, 0L, 0L, 
            0L, 0L, 0L, 0L, 0L, 76L, 0L, 96L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 
            11L, 0L, 3L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 270L, 
            144L, 7L, 8L, 15L, 6L, 6L, 2L, 6L, 1L, 25L, 5L, 0L, 1L, 1L, 0L, 
            0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 14L, 2L, 1L, 0L, 0L, 0L, 0L, 
            0L, 3L, 0L, 0L, 0L, 3L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
            0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 0L, 
            0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 7L, 0L, 0L, 0L, 0L, 0L, 
            0L, 14L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 
            0L, 0L), .Dim = c(12L, 32L), .Dimnames = list(c("a", "b", "c", 
                                                            "d", "e", "f", "g", "h", "i", "j", "k", "l"), c("a", "b", "c", 
                                                                                                            "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", 
                                                                                                            "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a1", "b1", 
                                                                                                            "c1", "d1", "e1", "f1")))

我正在运行这个分析:

library(vegan)
feed_raw.hel = decostand(feed.raw1, method = "pa")

pca.feed=vegan::rda(feed_raw.hel, scale=FALSE) 
head(summary(pca.feed))

它给了我这个错误:

Canonical correspondence analysis

Class: rda cca
Call: rda(X = feed_raw.hel, scale = FALSE)

Total inertia: 0

Eigenvalues:
Error in names(vec) <- paste("Ax", 1:length(vec), sep = "") : 
  attempt to set an attribute on NULL

【问题讨论】:

  • 您使用的是哪个版本的素食主义者?使用 vegan 2.3-2,我没有收到任何错误。
  • 我重新启动了 R 并且它工作了......真的不明白出了什么问题。
  • 太棒了!您能否将其标记为已回答。我在下面发布了输出。

标签: r pca vegan


【解决方案1】:

未发现错误(参见 OP 中的 cmets):

> library(vegan)
> feed_raw.hel = decostand(feed.raw1, method = "pa")
>
> pca.feed=vegan::rda(feed_raw.hel, scale=FALSE)
> head(summary(pca.feed))

Call:
rda(X = feed_raw.hel, scale = FALSE)

Partitioning of variance:
              Inertia Proportion
Total           5.394          1
Unconstrained   5.394          1

Eigenvalues, and their contribution to the variance

Importance of components:
                         PC1    PC2    PC3    PC4     PC5     PC6     PC7
Eigenvalue            2.0696 0.7676 0.6639 0.5502 0.41578 0.31941 0.22209
Proportion Explained  0.3837 0.1423 0.1231 0.1020 0.07708 0.05922 0.04117
Cumulative Proportion 0.3837 0.5260 0.6491 0.7511 0.82817 0.88739 0.92856
                          PC8     PC9    PC10    PC11
Eigenvalue            0.15383 0.11310 0.07857 0.03984
Proportion Explained  0.02852 0.02097 0.01457 0.00739
Cumulative Proportion 0.95708 0.97805 0.99261 1.00000

Scaling 2 for species and site scores
* Species are scaled proportional to eigenvalues
* Sites are unscaled: weighted dispersion equal on all dimensions
* General scaling constant of scores:  2.775394


Species scores

          PC1      PC2      PC3      PC4        PC5      PC6
a    -0.03289 -0.13245  0.18066  0.12616 -0.2028751  0.07257
b    -0.19170 -0.26686 -0.20142 -0.16621  0.0739356 -0.16726
c    -0.43542 -0.24013 -0.02194  0.16668 -0.0037653  0.18018
d    -0.43702  0.08614 -0.05548 -0.06814 -0.0009418 -0.03947
e    -0.24815 -0.06070  0.29795  0.18439 -0.0879021 -0.02246
f     0.08852  0.11597 -0.07947  0.02250 -0.0926734 -0.13060
....                                                    


Site scores (weighted sums of species scores)

          PC1      PC2      PC3     PC4     PC5     PC6
a    -1.65813  0.55267  0.90341  0.4485  0.8856 -0.7321
b    -1.70818  0.11084 -1.33080 -0.9734 -0.8929  0.4280
c    -0.25333 -1.02024  1.39160  0.9718 -1.5627  0.5590
d    -0.09478 -1.47685 -1.03494  1.1078  1.2228 -0.2536
e     0.26417  0.60502  0.71856 -0.6194  1.1614  1.2200
f     0.36048 -0.01608 -0.09826 -0.2709  0.3182  1.3866
....

【讨论】:

    【解决方案2】:

    我也遇到了这个问题,最后发现,至少在我的情况下,另一个包 (ade4) 也有一个 cca 函数,它掩盖了素食主义者中的 cca 函数。这在帮助文件中有些含糊地提到。我通过重新启动我的 R 会话(在 RStudio 中)并按以下顺序调用库来解决我的代码上的这个问题:

    library(ade4)
    library(vegan)
    

    然后 vegan::cca 函数接管 ade4::cca 函数。

    【讨论】:

    • vegan::cca()的显式调用应该做同样的事情。
    猜你喜欢
    • 2014-12-29
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 2015-02-03
    • 2021-08-10
    相关资源
    最近更新 更多