R:x [[JJ]] [ISEQ]<- vjj : replacement has lenght zero (Library SpatialML::rgf)

问题描述 投票:0回答:1
'eRROR in x [[JJ]] [ISEQ]

这里是一个例子: <- vjj : replacement has length zero'# Install and load the required package install.packages("SpatialML") # Install if you haven't already library(SpatialML) # Define an example dataset set.seed(42) n <- 100 # Number of observations # Creating a dataframe with spatial coordinates Coord <- data.frame( x = runif(n, 0, 100), # X coordinate y = runif(n, 0, 100) # Y coordinate ) # Creating a dataframe with predictor variables and the categorical response variable df <- data.frame( category = sample(1:3, n, replace = TRUE), # Categorical numeric variable var1 = rnorm(n, mean = 50, sd = 10), # Predictor variable 1 (e.g., temperature) var2 = runif(n, 0, 1) # Predictor variable 2 (e.g., humidity) ) # Fit a Geographically Weighted Random Forest (GWRF) model for categorical data grf_model <- grf( formula = category ~ var1 + var2, # The response variable is categorical dframe = df, kernel = "adaptive", bw = 30, coords = Coord, # Spatial coordinates classification = TRUE # Specifying a categorical model )

如何解决此错误?可以运行GWRF进行分类,对吗?

有关该函数的详细信息是
Herey。
提前感谢您。

这个函数似乎是一个错误。在grf函数上运行

debug

,我们发现错误发生在以下行:

r geospatial random-forest weighted geographic-distance
1个回答
0
投票

通过拟合

LM_GofFit[m, 7] <- Lcl.Model$r.squared
模型来获得该对象。仔细阅读文档,我们发现该对象只有在运行回归时才包含
Lcl.Model
。因此,如果您正在运行 分类,就像这里的情况一样,对象不会具有
ranger::ranger()
值,并且运行

r.squared
将产生错误。
您应该向软件包创建者提交错误报告,但我可以提供临时修复程序。我们可以使用
r.squared

临时编辑功能。运行跟踪命令后,功能主体将打开一个新窗口。找到以下行:

Lcl.Model$r.squared
替换为:
trace(grf, edit = TRUE)
this将用Na替换
LM_GofFit[m, 7] <- Lcl.Model$r.squared
的零值。进行此更改后,该功能成功运行。

输出

LM_GofFit[m, 7] <- ifelse(is.null(Lcl.Model$r.squared), 
            NA, Lcl.Model$r.squared)

我将其保留给您以验证输出是否明智。
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.