makeWeights | R Documentation |
Given a a description of relationships, calculate a spatial weights matrix with various ways of handling row-sums
makeWeights(
x,
ID = NULL,
bw = NULL,
mode = "adaptive",
weighting = "membership",
FUN = NULL,
offset = 0,
inf.val = NA,
minval = 0,
def.neigh = 0,
row.stand = FALSE,
clear.mem = FALSE
)
x |
A vector representing group membership, or a matrix/distance object representing pairwise distances. The distances need not be symmetrical. |
ID |
A vector given the unique observation ID names. Default is
|
bw |
A number representing the bandwidth within neighbors are considered.
If |
mode |
One of |
weighting |
One of |
FUN |
The distance function. Default is |
offset |
What value is added to the denominator to prevent singularities from arising
(e.g. whenever the value is 1/0)? Larger values imply smaller distance-decay.
Default is |
inf.val |
When singularities arise, (i.e. whenever the value is 1/0), by what value are
they replaced? Default is the |
minval |
When distances are raw, what is the minimum allowable distance?
Default is |
def.neigh |
Numeric. At what distance (in the map units) are observations definitely neighbors?
All distances are subtracted by this value, and all resulting distances less than zero are reassigned
to |
row.stand |
Logical or |
clear.mem |
Logical. Should |
The description of relationships can either be a vector describing to which group an observation belongs, or a distance matrix and associated decay function.
A matrix of dimensions length(x) x length(x)
.
# Example 1: Calculate group-based weights
# Generate dummy group names
groups <- 1:4
# Create 10 dummy values assigned to those groups
x <- sample(groups, 10, replace = TRUE)
# Create group membership weights matrix
weights <- makeWeights(x)
# Example 2: Calculate distance-based weights
# Generate dummy observations
x <- runif(10, 0, 100)
# Get distance matrix
dists <- dist(x)
# Get fuzzy weights considering 5 nearest neighbors based on
# inverse square distance
weights <- makeWeights(dists, bw = 5,
mode = 'adaptive', weighting = 'distance',
FUN = function(x) 1/x^2, minval = 0.1,
row.stand = 'fuzzy')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.