在R中使用spatcounts包的示例中没有邻居-错误:外部函数调用中的NA/NaN/Inf(arg 1)

在R中使用spatcounts包的示例中没有邻居-错误:外部函数调用中的NA/NaN/Inf(arg 1),r,poisson,statistics-bootstrap,neighbours,R,Poisson,Statistics Bootstrap,Neighbours,我正在尝试使用R中的spatcounts包对空间计数模型进行引导。但是,使用替换进行重新采样可能会导致“孤岛”,因为有时不会选择邻居。我认为这是导致错误消息的原因:error:NA/NaN/Inf in foreign function call(arg 1)。如果情况确实如此,有人能证实这一点吗? 如果是这样的话,有没有办法绕过它,这样我仍然可以进行引导 请在下面找到使用spatcounts包的示例数据集重新创建问题的代码 谢谢你抽出时间,我希望有人能帮我一点忙 ####START CODE#

我正在尝试使用R中的spatcounts包对空间计数模型进行引导。但是,使用替换进行重新采样可能会导致“孤岛”,因为有时不会选择邻居。我认为这是导致错误消息的原因:
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
#####开始代码#####
种子集(987654321)
图书馆(数目)
所有数据