Generate a spatial weight matrix of given size and number of nearest neighbors from randomly-located observations on the unit square.
generate_W(n, nneigh, seed=123)
the size of the matrix.
the number of nearest neighbors.
an integer to set the seed for the random generated locations.
The output matrix has zero diagonal and it is row-standardised.
n observations are allocated randomly in the unit square.
For each observation, the
nneigh closests observations w.r.t. the
Euclidean distance are assigned with a weight equal to 1/
a matrix of class
dgCMatrix (sparse matrix).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.