[R] Simulation code error

Roger Bivand Roger.Bivand at nhh.no
Wed Jul 15 23:50:39 CEST 2009


This message is one of a number of identical copies, also cross-posted to
R-sig-geo, and in fact with an obvious solution that the author gives at the
end. The thread will be continued on R-sig-geo.

Cross posting is advised against expressly in e.g.
http://en.wikipedia.org/wiki/Crossposting, and leads to threads being left
dangling if solutions do not propagate to all lists where threads were
initiated.

Roger Bivand



Steve Hong wrote:
> 
> Dear List,
> 
> I have some problem with my simulation code. Here is output from R:
>> sim.sp <- function(data,CM,n,N)
> + {
> +   C <- matrix(rep(NA,N),ncol=1)
> + for(i in 1:N)
> + {
> + j <- n
> + xx <- which(colSums(CM[j,])==1)
> + V <- names(xx)
> + V <- paste(V, collapse="+")
> + V <- paste("SBA~", V)
> + rd <- round(nrow(data)*(2/3))
> + d <- sample(seq(1:nrow(data)),rd)
> + dat1 <- data[d,]
> + dat2 <- data[-d,]
> + crd <- cbind(dat1$Longitude,dat1$Latitude)
> + dist80 <- dnearneigh(crd,0,100,longlat=F)
> + dist80sw <- nb2listw(dist80, style="B")
> + fm <- errorsarlm(as.formula(V), data=dat1, listw=dist60sw)
> + pred <- predict(fm,dat2)
> + C[i,1] <- cor(dat2$SBA,pred)
> + out <- cbind(C)
> + }
> + colMeans(out)
> + }
>>
>> sim.sp(df2007.5k.s2,CM,1,1000)
> Error in nb2listw(dist80, style = "B") : Empty neighbour sets found
> 
> I guess I got error message since there are some observations without
> neighborhoods in the process of determining neighborhood structure
> randomly.
> Is there any way to ignore neighborhood structures with observations
> without
> neighborhoods and proceed the code?
> 
> Thank you in advance!!
> 
> Steve Hong
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/Simulation-code-error-tp24506052p24506545.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list