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,完全更新)。
最好的,
乔
解决方案
感谢 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
推荐阅读
- javascript - 反应获取请求返回一个空数组
- c# - EF Core 从未包含的实体列表中填充“NotMapped 属性”
- arrays - 具有不同元素的多维数组;VBA excel
- logistic-regression - SPSS在逻辑回归的“步骤2”中遗漏了一个虚拟变量
- java - 在 Android 8+ 上录制电话
- python - 读取 xml 文件并使用特定字段输出到 csv
- python - 在 matplotlib 中垂直对齐共享相同 x 轴的时间序列(绘图和条形图)
- acumatica - 为什么在 PUT 上调用 Expand 和 Select 会导致返回 LESS 信息 - Acumatica REST API
- c - C 中结构的浅拷贝
- sqlite - 如何修复 SQLite 中错误的日期格式