makeWeights.Rd
Given a distance matrix (symmetrical or not) and weighting function, calculate a spatial weights matrix with various ways of handling row-sums
makeWeights(
x,
bw,
mode = "adaptive",
weighting = "membership",
FUN = NULL,
offset = 0,
inf.val = NA,
minval = -Inf,
row.stand = FALSE,
clear.mem = FALSE
)
A matrix or distance object representing pairwise distances. The distances need not be symmetrical.
A number representing the bandwidth within neighbors are considered.
If mode = 'adaptive'
, bw
is the number of nearest neighbors. If mode = 'fixed'
,
bw
is the radius of the window in the map units.
One of 'adaptive'
, which considers a bw
number of nearest
neighbors; or 'fixed'
, which considers a fixed bandwidth window of radius bw
.
One of 'membership'
, which considers binary membership
such that neighbors are weighted 1 and non-neighbors 0; 'distance'
which
weighs neighbors according to FUN
with the raw distance matrix providing the
distance; or 'rank'
which uses the rank-distance (i.e. 1 for nearest neighbor,
2 for second nearest...) as the distance variable.
The distance function. Default is NULL
for 'membership'
, and
function(x) 1/(offset + x)
otherwise.
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 offset = 0
.
When singularities arise, (i.e. whenever the value is 1/0), by what value are
they replaced? Default is the FUN
of the lowest non-minval
value.
When distances are raw, what is the minimum allowable distance?
Default is -Inf
.
Logical or 'fuzzy'
. If TRUE
(the default), rows are standardized such
that they sum to one. If 'fuzzy'
, rows are standardized as a proportion of the
largest value.
Logical. Should gc
be run in the middle of the
calculation? Default is clear.mem
but set as TRUE
if memory limits are a concern.
A matrix of dimensions length(x) x length(x)
.
# 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')