[R-sig-Geo] No neighbours in sample using spatcounts package in R

Nick van Doormaal nick.vandoormaal at gmail.com
Wed Oct 19 15:01:03 CEST 2016


Dear list members,

I'm trying to do a bootstrap of a spatial count model using the
*spatcounts-package* in R. However, resampling with replacement may lead to
"islands", because sometimes no neighbors will be selected. I believe this
is causing the error message: Error: NA/NaN/Inf in foreign function call
(arg 1). Can somebody confirm this if this indeed the case? If so, is there
a way to get around it, so that I would still be able to carry out a
bootstrap?

Please find below the code to recreate the problem using the example
dataset of the spatcounts package.

Thank you for your time and I hope somebody can help me out a bit.

####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

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list