nb2listw                package:spdep                R Documentation

_S_p_a_t_i_a_l _w_e_i_g_h_t_s _f_o_r _n_e_i_g_h_b_o_u_r_s _l_i_s_t_s

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

     The function supplements a neighbours list with spatial weights
     for the chosen coding scheme.

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

     nb2listw(neighbours, glist=NULL, style="W", zero.policy=FALSE)

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

neighbours: an object of class 'nb'

   glist: list of general weights corresponding to neighbours

   style: 'style' can take values W, B, C, U, and S

zero.policy: If FALSE stop with error for any empty neighbour sets, if
          TRUE permit the weights list to be formed with zero-length
          weights vectors

_D_e_t_a_i_l_s:

     Starting from a binary neighbours list, in which regions are
     either listed as neighbours or are absent (thus not in the set of
     neighbours for some definition), the function adds a weights list
     with values given by the coding scheme style chosen. B is the
     basic binary coding, W is row standardised (sums over all links to
     n), C is globally standardised (sums over all links to n), U is
     equal to C divided by the number of neighbours (sums over all
     links to unity), while S is the variance-stabilizing coding scheme
     proposed by Tiefelsdorf et al. 1999, p. 167-168 (sums over all
     links to n).

     If zero policy is set to TRUE, weights vectors of zero length are
     inserted for regions without neighbour in the neighbours list.
     These will in turn generate lag values of zero, equivalent to the
     sum of products of the zero row 't(rep(0,
     length=length(neighbours))) %*% x', for arbitraty numerical vector
     'x' of length 'length(neighbours)'. The spatially lagged value of
     x for the zero-neighbour region will then be zero, which may (or
     may not) be a sensible choice.

     If the sum of the glist vector for one or more observations is
     zero, a warning message is issued. The consequence for later
     operations will be the same as if no-neighbour observations were
     present and the zero.policy argument set to true.

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

     A 'listw' object with the following members: 

   style: one of W, B, C, U, S as above

neighbours: the input neighbours list

 weights: the weights for the neighbours and chosen style, with
          attributes set to report the type of relationships (binary or
          general, if general the form of the glist argument), and
          style as above

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

     Roger Bivand Roger.Bivand@nhh.no

_R_e_f_e_r_e_n_c_e_s:

     Tiefelsdorf, M., Griffith, D. A., Boots, B. 1999 A
     variance-stabilizing coding scheme for spatial link matrices,
     Environment and Planning A, 31, pp. 165-180.

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

     'summary.nb', 'read.gal'

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

     example(columbus)
     coords <- coordinates(columbus)
     cards <- card(col.gal.nb)
     col.w <- nb2listw(col.gal.nb)
     plot(cards, unlist(lapply(col.w$weights, sum)),xlim=c(0,10),
     ylim=c(0,10), xlab="number of links", ylab="row sums of weights")
     col.b <- nb2listw(col.gal.nb, style="B")
     points(cards, unlist(lapply(col.b$weights, sum)), col="red")
     col.c <- nb2listw(col.gal.nb, style="C")
     points(cards, unlist(lapply(col.c$weights, sum)), col="green")
     col.u <- nb2listw(col.gal.nb, style="U")
     points(cards, unlist(lapply(col.u$weights, sum)), col="orange")
     col.s <- nb2listw(col.gal.nb, style="S")
     points(cards, unlist(lapply(col.s$weights, sum)), col="blue")
     legend(x=c(0, 1), y=c(7, 9), legend=c("W", "B", "C", "U", "S"),
     col=c("black", "red", "green", "orange", "blue"), pch=rep(1,5))
     dlist <- nbdists(col.gal.nb, coords)
     dlist <- lapply(dlist, function(x) 1/x)
     col.w.d <- nb2listw(col.gal.nb, glist=dlist)
     summary(unlist(col.w$weights))
     summary(unlist(col.w.d$weights))
     # introducing other conditions into weights - only earlier sales count
     # see http://sal.uiuc.edu/pipermail/openspace/2005-October/000610.html
     data(baltimore)
     set.seed(211)
     dates <- sample(1:500, nrow(baltimore), replace=TRUE)
     nb_15nn <- knn2nb(knearneigh(cbind(baltimore$X, baltimore$Y), k=15))
     glist <- vector(mode="list", length=length(nb_15nn))
     for (i in seq(along=nb_15nn))
       glist[[i]] <- ifelse(dates[i] > dates[nb_15nn[[i]]], 1, 0)
     listw_15nn_dates <- nb2listw(nb_15nn, glist=glist, style="B")
     which(lag(listw_15nn_dates, baltimore$PRICE) == 0.0)
     which(sapply(glist, sum) == 0)
     ex <- which(sapply(glist, sum) == 0)[1]
     dates[ex]
     dates[nb_15nn[[ex]]]

