Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/makeneighborsw.R

The function `makeneighborsw()`

create a spatial weight matrix based on a given number of nearest
neighbors (option "neighbor" by default), based on a threshold distance (option method="distance")
or both these 2 methods.

1 | ```
makeneighborsw(coords,method="neighbor",m=1,d,cum=TRUE)
``` |

`coords` |
a matrix of spatial coordinates |

`method` |
"neighbor" by default, "distance" or "both" |

`m` |
number of nearest neighbors |

`d` |
threshold point |

`cum` |
if cum=TRUE, W is the sum of spatial weight matrix based on k nearest neighbours (for |

In the case of method="neighbor", for each site, we order the other sites by their distance from this
site. If cum=TRUE, for i, if j is among the *m^th*
nearest sites, then :

*W_ij=1*

else

*W_ij=0*

If cum=FALSE, for

*s_i*

, if

*s_j*

is the *m^th*
nearest site, then :

*W_ij=1*

else

*W_ij=0*

In case of ties, the nearest neighbour is randomly chosen.

In the case of method="distance", if site i is seperated from j by a distance lower
or equal to a given threshold :

*W_ij=1*

else

*W_ij=0*

In the case of method="both" W must verify the two first conditions.

A spatial weight matrix of size *n x n*

This function is not optimised for large dataset. User could find similar functions in
the package `spdep`

(`dnearneigh`

and `knearneigh`

). However, these functions
don't offer the possibility to use the two criteria in the same time. Moreover, an
inconvenient of `makeneighborsw`

is that the result is included in a matrix object
whereas most of functions of GeoXp use the `nb`

structure for spatial weight matrix.
An issue is to use the `mat2listw`

function and then selecting the `nb`

part, like the
in the examples.

Aragon Y., Thomas-Agnan C., Ruiz-Gazen A., Laurent T., Robidou L.

Thibault Laurent, Anne Ruiz-Gazen, Christine Thomas-Agnan (2012), GeoXp: An R Package for Exploratory Spatial Data Analysis. *Journal of Statistical Software*, 47(2), 1-23.

Roger S.Bivand, Edzer J.Pebesma, Virgilio Gomez-Rubio (2009), *Applied Spatial Data Analysis with R*, Springer.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ```
##
# data auckland
data(auckland)
coords <- cbind(auckland$Easting[1:10],auckland$Northing[1:10])
# matrix based on 5 nearest neighbors
W<-makeneighborsw(coords,method="neighbor",m=3)
# matrix based on a threshold distance
W1<-makeneighborsw(coords,method="distance",d=20)
# matrix based on the two methods
W2<-makeneighborsw(coords,method="both",m=3,d=20)
# representation of the 3 spatial weight matrices
op<-par(mfrow=c(2,2))
plot(mat2listw(W),coords,col="lightblue1",main="neighbor")
plot(mat2listw(W1),coords,col="lightblue2",main="distance")
plot(mat2listw(W2),coords,col="lightblue3",main="both")
par(op)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.