Dear List, I have got error message when I run the R-code. Can anyone has a suggestion? v.code <- df.bm7[,c(10:31)]; v.code[1:3,] names(v.code) CM = v.code # variable binomial code 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) dist60 <- dnearneigh(crd,0,60,longlat=F) dist60sw <- nb2listw(dist60, 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(dist60, style = "B") : Empty neighbour sets found And, here are my partial data and addition information just in case.> df2007.5k.s2[1:5,]Longitude Latitude Ring stage2 SBA corn sbn w.wit oats afl dbn vg.frt fidle grs.pstr wdlnd nlcd.ow nlcd.dec 821 419.9678 496.3359 5000 2 0.2041200 6.873500 6.515908 5.861865 5.139832 6.260552 5.087444 0.000000 4.818602 6.897949 4.927745 7.073408 7.348551 822 440.9583 533.2685 5000 2 1.1832698 6.829823 6.402711 4.098471 5.660730 6.394553 4.700505 0.000000 4.399483 6.885719 5.159137 5.779678 7.617312 823 434.2998 550.4301 5000 2 0.8419848 6.901722 6.377190 4.575569 5.571924 6.411776 4.450634 3.496515 4.537781 6.874229 5.001530 6.249959 7.497547 824 388.2020 550.3011 5000 2 0.5563025 7.116200 6.467652 3.973543 4.894322 6.279565 5.872954 5.460165 3.973543 6.985068 4.958779 6.431883 7.524418 825 365.8802 548.6984 5000 2 0.5314789 7.236186 6.739166 5.571924 5.729373 6.810875 6.049045 4.537781 3.973543 6.921747 5.335227 5.892576 7.425795 nlcd.shrb nlcd.grshrb forest o.legume devel wetland grains ra.SDI 821 5.504978 6.599838 6.661026 4.450634 6.974943 6.640015 4.838805 25.94976 822 5.758828 5.736926 5.027859 5.064582 6.652622 7.020253 3.973543 25.62106 823 5.840769 5.937286 5.399468 4.274550 6.959373 7.125071 4.496390 27.71064 824 5.571924 6.287365 6.217362 3.496515 6.860364 6.366780 4.098471 26.62635 825 5.593287 6.247655 5.642505 3.973543 6.816315 6.278132 5.014894 28.65973> v.code[1:5,]Latitude Longitude corn sbn afl grs.pstr nlcd.dec nlcd.grshrb devel wetland ra.SDI oats nlcd.shrb w.wit wdlnd nlcd.ow dbn vg.frt fidle forest 169 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 170 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 171 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 193 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 217 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 o.legume grains 169 0 1 170 0 1 171 1 1 193 0 0 217 0 0 Thank you in advance!! Steve Hong [[alternative HTML version deleted]]
Dear List, I have got error message when I run the R-code. I guess this happened when observation(s) has no neighborhood at specified distance. Is there any way/R-code to ignore one without neighborhood and proceed the simulation? v.code <- df.bm7[,c(10:31)]; v.code[1:3,] names(v.code) CM = v.code # variable binomial code 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) dist60 <- dnearneigh(crd,0,60,longlat=F) dist60sw <- nb2listw(dist60, 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(dist60, style = "B") : Empty neighbour sets found And, here are my partial data and addition information just in case.> df2007.5k.s2[1:5,]Longitude Latitude Ring stage2 SBA corn sbn w.wit oats afl dbn vg.frt fidle grs.pstr wdlnd nlcd.ow nlcd.dec 821 419.9678 496.3359 5000 2 0.2041200 6.873500 6.515908 5.861865 5.139832 6.260552 5.087444 0.000000 4.818602 6.897949 4.927745 7.073408 7.348551 822 440.9583 533.2685 5000 2 1.1832698 6.829823 6.402711 4.098471 5.660730 6.394553 4.700505 0.000000 4.399483 6.885719 5.159137 5.779678 7.617312 823 434.2998 550.4301 5000 2 0.8419848 6.901722 6.377190 4.575569 5.571924 6.411776 4.450634 3.496515 4.537781 6.874229 5.001530 6.249959 7.497547 824 388.2020 550.3011 5000 2 0.5563025 7.116200 6.467652 3.973543 4.894322 6.279565 5.872954 5.460165 3.973543 6.985068 4.958779 6.431883 7.524418 825 365.8802 548.6984 5000 2 0.5314789 7.236186 6.739166 5.571924 5.729373 6.810875 6.049045 4.537781 3.973543 6.921747 5.335227 5.892576 7.425795 nlcd.shrb nlcd.grshrb forest o.legume devel wetland grains ra.SDI 821 5.504978 6.599838 6.661026 4.450634 6.974943 6.640015 4.838805 25.94976 822 5.758828 5.736926 5.027859 5.064582 6.652622 7.020253 3.973543 25.62106 823 5.840769 5.937286 5.399468 4.274550 6.959373 7.125071 4.496390 27.71064 824 5.571924 6.287365 6.217362 3.496515 6.860364 6.366780 4.098471 26.62635 825 5.593287 6.247655 5.642505 3.973543 6.816315 6.278132 5.014894 28.65973> v.code[1:5,]Latitude Longitude corn sbn afl grs.pstr nlcd.dec nlcd.grshrb devel wetland ra.SDI oats nlcd.shrb w.wit wdlnd nlcd.ow dbn vg.frt fidle forest 169 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 170 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 171 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 193 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 217 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 o.legume grains 169 0 1 170 0 1 171 1 1 193 0 0 217 0 0 Thank you in advance!! Steve Hong [[alternative HTML version deleted]]