简体   繁体   English

如何解决错误因素在 R 中的错误级别

[英]How to solve error factor has bad level in R

I have some difficulties applying the inhomogeneous G-function to my point pattern in R .我在R非均匀 G 函数应用于我的点模式时遇到了一些困难。 In order to use GmultiInhom , I first tried to convert my point pattern bci.tree8pppa to a multitype pattern:为了使用GmultiInhom ,我首先尝试将我的点模式bci.tree8pppa转换为多类型模式:

bci.tree8multi = ppp(bci.tree8pppa$x, bci.tree8pppa$y, window=owin(c(0,1000), c(0,500)), marks = factor(bci.tree8pppa$marks[,3]))

Then applied the G-function as follows:然后应用G函数如下:

G = GmultiInhom(bci.tree8multi, marks(bci.tree8multi) == species1, marks(bci.tree8multi) == species2, lambdaI = lambda1points, lambdaJ = lambda2points, lambdamin = min(lambda2points), r = c(0,r1,r2,r3))

But this yields the error: "Error in split.default(X, group): factor has bad level"但这会产生错误: "Error in split.default(X, group): factor has bad level"

How can I solve this?我该如何解决这个问题? Thank you in advance!先感谢您!

For the benefit of any R programmers out there: I traced the error message "factor has bad level" to the C source code for .Internal(split.default(x,f)) in the base R system.为了任何R程序员的利益:我在基础R系统中的.Internal(split.default(x,f))的 C 源代码中追踪了错误消息"factor has bad level" This error message can occur only when f is a list rather than a factor .仅当flist而不是factor时,才会出现此错误消息。 The code converts f to a factor using the function interaction which performs character string manipulations.该代码使用执行字符串操作的 function interactionf转换为因子。 This conversion can go wrong, in the sense that the resulting factor has "bad levels": the integer representation of the factor includes values less than 1 or greater than the number of levels of the factor.这种转换可能 go 是错误的,因为结果因子具有“不良水平”:因子的 integer 表示包括小于 1 或大于因子水平数的值。 Then the error occurs.然后发生错误。

The original post has not provided a working example, so it's difficult to figure out exactly how the code in spatstat::GmultiInhom caused the wrong type of data to be fed to split.default .原始帖子没有提供一个工作示例,因此很难弄清楚spatstat::GmultiInhom中的代码是如何导致将错误类型的数据提供给split.default However, it must be related to the misuse of the argument r .但是,它必须与参数r的滥用有关。 The code in spatstat will be tightened to enforce stricter requirements on the format of r . spatstat中的代码将被收紧,以对r的格式执行更严格的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM