dnearneigh               package:spdep               R Documentation

_N_e_i_g_h_b_o_u_r_h_o_o_d _c_o_n_t_i_g_u_i_t_y _b_y _d_i_s_t_a_n_c_e

_D_e_s_c_r_i_p_t_i_o_n:

     The function identifies neighbours of region points by Euclidean
     distance between lower (greater than) and upper (less than or
     equal to) bounds, or with lonlat = TRUE, by Great Circle distance
     in kilometers.

_U_s_a_g_e:

     dnearneigh(x, d1, d2, row.names = NULL, lonlat = FALSE)

_A_r_g_u_m_e_n_t_s:

       x: matrix of point coordinates

      d1: lower distance bound

      d2: upper distance bound

row.names: character vector of region ids to be added to the neighbours
          list as attribute 'region.id', default 'seq(1, nrow(x))'

  lonlat: TRUE if point coordinates are longitude-latitude decimal
          degrees, in which case distances are measured in kilometers

_V_a_l_u_e:

     The function returns a list of integer vectors giving the region
     id numbers for neighbours satisfying the distance criteria.

_A_u_t_h_o_r(_s):

     Roger Bivand Roger.Bivand@nhh.no

_S_e_e _A_l_s_o:

     'knearneigh'

_E_x_a_m_p_l_e_s:

     data(columbus)
     k1 <- knn2nb(knearneigh(coords))
     all.linked <- max(unlist(nbdists(k1, coords)))
     col.nb.0.all <- dnearneigh(coords, 0, all.linked, row.names=rownames(columbus))
     summary(col.nb.0.all, coords)
     library(maptools)
     plot(polys, border="grey", forcefill=FALSE)
     plot(col.nb.0.all, coords, add=TRUE)
     title(main=paste("Distance based neighbours 0-",  format(all.linked),
      " distance units", sep=""))
     data(state)
     us48.fipsno <- read.geoda(system.file("etc/weights/us48.txt",
      package="spdep")[1])
     if (as.numeric(paste(version$major, version$minor, sep="")) < 19) {
      m50.48 <- match(us48.fipsno$"State.name", state.name)
     } else {
      m50.48 <- match(us48.fipsno$"State_name", state.name)
     }
     xy <- as.matrix(as.data.frame(state.center))[m50.48,]
     llk1 <- knn2nb(knearneigh(xy, k=1, lonlat=FALSE))
     all.linked <- max(unlist(nbdists(llk1, xy, lonlat=FALSE)))
     ll.nb <- dnearneigh(xy, 0, all.linked, lonlat=FALSE)
     summary(ll.nb, xy, lonlat=TRUE, scale=0.5)
     gck1 <- knn2nb(knearneigh(xy, k=1, lonlat=TRUE))
     all.linked <- max(unlist(nbdists(gck1, xy, lonlat=TRUE)))
     gc.nb <- dnearneigh(xy, 0, all.linked, lonlat=TRUE)
     summary(gc.nb, xy, lonlat=TRUE, scale=0.5)
     plot(ll.nb, xy)
     plot(diffnb(ll.nb, gc.nb), xy, add=TRUE, col="red", lty=2)
     title(main="Differences between Euclidean and Great Circle neighbours")

