r-ecodist包中的功能MRM出现尺寸错误



当在包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,完全更新(。

最佳,

Joe

感谢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

最新更新