View source: R/GeoNeighIndex.R
| GeoNeighIndex | R Documentation |
Builds directed nearest-neighbour candidate pairs for spatial, spatio-temporal, or bivariate data. Candidate pairs can optionally be thinned using independent Bernoulli sampling or an exact fixed-budget, stratum-wise design.
GeoNeighIndex(coordx=NULL, coordy=NULL, coordz=NULL, coordt=NULL,
coordx_dyn=NULL, distance="Eucl", neighb=4,
maxdist=NULL, maxtime=1, radius=1,
bivariate=FALSE, p_neighb=1,
thin_method="bernoulli", check.duplicates=FALSE)
coordx |
A numeric |
coordy |
Optional numeric vector giving a second spatial coordinate when coordinates are supplied separately. |
coordz |
Optional numeric vector giving a third spatial coordinate when coordinates are supplied separately. |
coordt |
A numeric vector giving the temporal coordinates. Optional
argument, default is |
coordx_dyn |
A list of numeric coordinate matrices. For spatio-temporal
data, the list must contain one coordinate matrix per element of |
distance |
Character string specifying the spatial distance. Default is
|
neighb |
A positive integer giving the nearest-neighbour candidate size. In the bivariate case, a length-three positive integer vector can be supplied for within-variable 1, cross-variable, and within-variable 2 pairs. |
maxdist |
Optional non-negative maximum spatial distance. In the bivariate case, a length-three vector can be supplied for the three pair types. |
maxtime |
A non-negative numeric value giving the maximum temporal
distance in the same units as |
radius |
Numeric radius used for spherical distances. Default is
|
bivariate |
Logical; if |
p_neighb |
Numeric scalar in |
thin_method |
Character string selecting the thinning design. Accepted
values are |
check.duplicates |
Logical. If |
The unthinned output is a directed candidate graph: rowidx identifies
candidate targets and colidx their neighbours. For a purely spatial
configuration with N locations and candidate size m, the regular
case contains approximately Nm directed candidate pairs.
For chordal and geodesic distances, nearest-neighbour ordering is built in
three-dimensional unit-sphere coordinates. Because chordal distance is monotone
in great-circle distance, this gives the correct global nearest-neighbour order,
including near the dateline and poles. Reported lags are then evaluated in the
requested spherical metric and scaled by radius.
For spatio-temporal data, temporal coordinates are treated as numeric coordinates, not as equally spaced indices. Candidate temporal separations are computed as
|t_i-t_j|,
and maxtime is interpreted as a temporal-distance threshold in the same
units as coordt. Thus irregularly spaced temporal coordinates are
supported directly.
With thin_method="bernoulli" and p_neighb < 1, candidate pairs
are retained independently. In the current constant-weight implementation the
inclusion probability is p_neighb, so the retained count is random with
expectation approximately p_{neighb}d.
With thin_method="FixedBudget" and p_neighb < 1, exactly
K=\mathrm{round}(p_{neighb}d) candidate pairs are retained, subject only
to truncation to the available candidate count. The budget is allocated across
natural candidate strata using proportional quotas with randomized residual
allocation, followed by sampling without replacement within each stratum. For
purely spatial data, strata are the target-specific nearest-neighbour lists.
For spatio-temporal data, target and temporal-lag descriptors define the
strata; for bivariate data, the variable-pair descriptors are also included.
The resulting global retained size is exact.
For thin_method="FixedBudget", the exact target is round(p d). Hence very small p_neighb values may legitimately return zero retained pairs. This is a valid graph-selection result; GeoFit rejects such a graph because a pairwise likelihood cannot be estimated without pair contributions. Exact duplicate observation locations are rejected before nearest-neighbor construction.
When p_neighb = 1, no thinning is applied, independently of
thin_method.
A list containing the pair indices and distances required by downstream GeoModels procedures. Depending on the setting, components include:
rowidx |
Directed target indices. |
colidx |
Directed neighbour indices. |
lags |
Spatial distances for the retained pairs. |
lagt |
Temporal distances for spatio-temporal pairs. |
first |
First variable indicator for bivariate pairs. |
second |
Second variable indicator for bivariate pairs. |
maxdist |
Spatial-distance threshold, when stored for the selected case. |
neighb |
Nearest-neighbour candidate size, when stored for the selected case. |
The function returns only the retained pair structure; it does not append summary fields such as candidate or retained counts. These can be obtained from the lengths of the returned index vectors.
Moreno Bevilacqua, moreno.bevilacqua89@gmail.com, https://sites.google.com/view/moreno-bevilacqua/home, Victor Morales Onate, victor.morales@uv.cl, https://sites.google.com/site/moralesonatevictor/, Christian Caamano-Carrillo, chcaaman@ubiobio.cl, https://www.researchgate.net/profile/Christian-Caamano
require(GeoModels)
NN <- 400
coords <- cbind(runif(NN), runif(NN))
## Full directed 5-NN candidate graph.
sel <- GeoNeighIndex(coordx=coords, neighb=5)
length(sel$rowidx)
## Bernoulli thinning: retained size is random with expectation 20 percent
## of the candidate graph.
set.seed(1)
sel_ber <- GeoNeighIndex(coordx=coords, neighb=5,
p_neighb=0.2, thin_method="bernoulli")
length(sel_ber$rowidx)
## Fixed-budget thinning: the global retained size is exact.
set.seed(1)
sel_fix <- GeoNeighIndex(coordx=coords, neighb=5,
p_neighb=0.2, thin_method="FixedBudget")
length(sel_fix$rowidx)
## Irregular temporal coordinates: maxtime is a distance threshold.
times <- c(0, 0.25, 1.1, 2.8)
sel_st <- GeoNeighIndex(coordx=coords[1:30, ], coordt=times,
neighb=3, maxtime=1)
head(sel_st$lagt)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.