【问题标题】:Incorrect Dimensions error with the function MRM, in the package ecodist包 ecodist 中的功能 MRM 的尺寸不正确错误
【发布时间】:2021-09-19 10:22:28
【问题描述】:

使用 Ecodist 包中的 MRM 功能时,出现以下错误:

Error in xj[i, , drop = FALSE] : incorrect number of dimensions

无论我做什么我都会得到这个错误,我什至在文档中的示例代码中得到它:

data(graze)

  # Abundance of this grass is related to forest cover but not location
  MRM(dist(LOAR10) ~ dist(sitelocation) + dist(forestpct), data=graze, nperm=10)

我不知道发生了什么。我试过其他电脑也遇到同样的错误,所以它甚至不限于我的机器(windows 10,完全更新)。

最好的,

【问题讨论】:

  • 这段代码对我来说很好,我没有收到任何错误。
  • 是的,我让我的朋友在他的机器上运行它,它也对他有用,所以这是我的问题......最糟糕的问题。我已将其范围缩小到与 spdep 包有关的内容,因为它在我不加载它的情况下工作。

标签: r dimensions


【解决方案1】:

感谢 Torsten Biemann 向我指出这一点。我不定期检查 stackoverflow,但随时欢迎您通过 ecodist 维护者地址给我发送电子邮件或在 https://github.com/phiala/ecodist 提出问题。

如上所述,该示例在干净的 R 会话中可以正常工作,但如果加载了 spdep,则会失败。我还没有弄清楚冲突,但问题在于在使用公式的机制中距离对象到矢量的隐含强制。如果您明确地这样做,该命令将正常工作。我会做一个补丁,首先在上面的github上,测试后发给CRAN。

# R --vanilla --no-save

library(ecodist)
data(graze)

# Works
set.seed(1234)
MRM(dist(LOAR10) ~ dist(sitelocation) + dist(forestpct), data=graze, nperm=10)


$coef
                   dist(LOAR10) pval
Int                   6.9372046  1.0
dist(sitelocation)   -0.4840631  0.6
dist(forestpct)       0.1456083  0.1

$r.squared
        R2       pval
0.04927212 0.10000000

$F.test
       F   F.pval
31.66549  0.10000


library(spdep)

# Fails
MRM(dist(LOAR10) ~ dist(sitelocation) + dist(forestpct), data=graze, nperm=10)


Error in xj[i, , drop = FALSE] : incorrect number of dimensions


# Explicit conversion to vector

graze.d <- with(graze, data.frame(LOAR10 = as.vector(dist(LOAR10)), sitelocation = as.vector(dist(sitelocation)), forestpct = as.vector(dist(forestpct))))

# Works
set.seed(1234)
MRM(LOAR10 ~ sitelocation + forestpct, data=graze.d, nperm=10)


$coef
                 LOAR10 pval
Int           6.9372046  1.0
sitelocation -0.4840631  0.6
forestpct     0.1456083  0.1

$r.squared
        R2       pval
0.04927212 0.10000000

$F.test
       F   F.pval
31.66549  0.10000

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 2023-03-19
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多