我正在尝试使用 R 中的spatcounts-package进行空间计数模型的引导。但是,使用替换重新采样可能会导致“孤岛”,因为有时不会选择任何邻居。我相信这会导致错误消息:Error: NA/NaN/Inf in foreign function call (arg 1)
. 如果确实如此,有人可以证实这一点吗?如果是这样,有没有办法绕过它,这样我仍然可以执行引导程序?
请在代码下方找到使用 spatcounts 包的示例数据集重新创建问题的代码。
谢谢你的时间,我希望有人可以帮助我一点。
####START CODE#####
set.seed(987654321)
library(spatcounts)
AllData <- cbind(sim.Yin, sim.region, sim.fm.X)
colnames(AllData)[1:2] <- c("Yin", "Region")
idx <- sample(1:nrow(AllData), 100, replace=TRUE)
newdata.df <- AllData[idx,]
newdata.df <- newdata.df[order(newdata.df$Region),]
X <- as.data.frame(newdata.df[,3:4])
region <- as.data.frame(newdata.df$Region)
colnames(region) <- "V1"
Yin <- as.data.frame(newdata.df$Yin)
temp.idx <- sort(unique(newdata.df$Region))
g.temp <- sim.gmat[temp.idx,temp.idx]
TotalN <- rowSums(g.temp) ##CHECK IF THERE ARE ZEROS PRESENT IN THIS VECTOR.
##OTHERWISE RUN AGAIN UNTIL AT LEAST ONE ZERO
n.temp <- sim.nmat[temp.idx,]
n.temp$V2 <- temp.idx[match(n.temp$V2, temp.idx)]
n.temp$V3 <- temp.idx[match(n.temp$V3, temp.idx)]
n.temp$V4 <- temp.idx[match(n.temp$V4, temp.idx)]
n.temp$V5 <- temp.idx[match(n.temp$V5, temp.idx)]
n.temp$V6 <- TotalN
n.temp[is.na(n.temp)] <- 0
Yin.NB <- est.sc(Yin, ~ X[,1] + X[,2] -1,
region, model="NB", g.temp, n.temp, totalit=10) ##ERROR