14.10 Weights Specification

Once neighbour objects are available, further choices need to be made in specifying the weights objects.

  • The nb2listw function is used to create a listw weights object with an nb object, a matching list of weights vectors, and a style specification
  • Because handling no-neighbour observations now begins to matter, the zero.policy= argument is introduced (default: FALSE)
  • n: number of observations
  • \(S_{0}\): sum of weights

The “B” binary style gives a weight of unity to each neighbour relationship, and typically up-weights units with no boundaries on the edge of the study area, having a higher count of neighbours.

nb_q |> nb2listw(style = "B") -> lw_q_B

lw_q_B |> 
    spweights.constants() |> 
    data.frame() |> 
    subset(select = c(n, S0))
##      n    S0
## 1 2495 14242

The “W” row-standardised style up-weights units around the edge of the study area that necessarily have fewer neighbours. This style first gives a weight of unity to each neighbour relationship, then it divides these weights by the per unit sums of weights (caution: avoid no-neighbors)

nb_q |> nb2listw(style = "W") -> lw_q_W

lw_q_W |> 
    spweights.constants() |> 
    data.frame() |> 
    subset(select = c(n, S0))
##      n   S0
## 1 2495 2495

14.10.1 Inverse Distance Weights

nb_d183 |> 
    nbdists(coords) |> 
    lapply(function(x) 1/(x/1000)) -> gwts

No-neighbour handling is by default to prevent the construction of a weights object, making the analyst take a position on how to proceed.

(nb_d183 |> nb2listw(glist=gwts, style="B") -> lw_d183_idw_B) |> 
    spweights.constants() |> 
    data.frame() |> 
    subset(select=c(n, S0))
##      n       S0
## 1 2495 1841.345

Use can be made of the zero.policy= argument to many functions used with nb and listw objects.

(nb_d16 |> 
    nb2listw(style="B", zero.policy=TRUE) |> 
    spweights.constants(zero.policy=TRUE) |> 
    data.frame() |> 
    subset(select=c(n, S0)))
##      n    S0
## 1 2488 15850