Home

dnearneigh

dnearneigh is a function in the R package spdep used to construct a neighbourhood (neighbor) structure based on pairwise distances among a set of points. It returns a neighbour list object that identifies, for each observation, which other observations lie within a specified distance band. This type of structure is commonly used to build spatial weights for analyses such as Moran’s I, spatial regression, and other methods in spatial econometrics and geography.

How it works

The function takes coordinates or a spatial object and two distance thresholds, d1 and d2. For each

Output and usage

The result is an object of class nb, a list where each element contains the indices of

Example (conceptual)

coords <- cbind(x coordinates, y coordinates)

nb <- dnearneigh(coords, 0, 1000) # neighbors within 0 to 1000 units

observation
i,
all
other
observations
j
are
considered
neighbors
of
i
if
the
distance
between
i
and
j
satisfies
d1
<=
distance(i,
j)
<=
d2.
Distances
can
be
computed
as
Euclidean
distances
by
default,
or
as
great-circle
distances
if
longlat
=
TRUE
and
the
coordinates
are
geographic
(longitude
and
latitude).
The
diag
option
controls
whether
an
observation
is
allowed
to
be
its
own
neighbor;
typically
this
is
FALSE
unless
d1
<=
0
<=
d2.
The
row.names
argument
can
supply
names
for
the
observations.
neighboring
observations
for
the
corresponding
location.
This
nb
object
can
be
converted
to
a
weights
object
(for
example,
via
nb2listw)
and
used
in
spatial
statistical
routines.
dnearneigh
is
commonly
contrasted
with
other
neighbor-building
functions
like
knearneigh
(fixed
k
neighbors)
or
tri2nb
(triangulation-based
neighbors).