Learn R Programming

GeoModels (version 2.2.2)

GeoNeighIndex: Spatial or spatiotemporal near neighbour indices.

Description

The function returns the indices associated with a given spatial (temporal) neighbour and/or distance. Optionally, a stochastic thinning mechanism can be applied to randomly retain only a fraction of the indices.

Usage

GeoNeighIndex(coordx, 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="iid")

Value

Returns a list containing the following components:

colidx

First vector of indices.

rowidx

Second vector of indices.

lags

Vector of spatial distances.

lagt

Vector of temporal distances.

Arguments

coordx

A numeric (\(d \times 2\))-matrix or (\(d \times 3\))-matrix. Coordinates on a sphere for a fixed radius radius are passed in lon/lat format expressed in decimal degrees.

coordy

A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is NULL.

coordz

A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is NULL.

coordt

A numeric vector assigning 1-dimension of temporal coordinates. Optional argument, default is NULL; if NULL then a spatial random field is expected.

coordx_dyn

A list of \(m\) numeric (\(d_t \times 2\))-matrices containing dynamical (in time) spatial coordinates. Optional argument, default is NULL.

distance

String; the name of the spatial distance. Default is "Eucl" (euclidean distance). See the Section Details of GeoFit.

neighb

Numeric; an optional (vector of) positive integer indicating the order of neighborhood. See the Section Details for more information.

maxdist

A numeric value denoting the maximum spatial distance; see Details.

maxtime

A numeric value denoting the maximum temporal distance; see Details.

radius

Numeric; a value indicating the radius of the sphere when using great-circle distances. Default value is 1.

bivariate

Logical; if FALSE (default) the data are interpreted as univariate spatial or spatio-temporal realisations. Otherwise, they are interpreted as a realization from a bivariate field.

p_neighb

Numeric; a value in \((0,1]\) specifying the expected fraction of nearest-neighbor pairs retained through stochastic thinning. If 1 (default), no thinning is applied and all nearest-neighbor pairs are used. If <1, pairs are randomly retained using independent Bernoulli sampling.

thin_method

String; thinning scheme used when p_neighb<1. Default is "iid"(independent Bernoulli thinning).

Details

The function returns spatial or spatio-temporal indices of the pairs that are neighbours of a given order and/or within a given distance threshold.

Examples

Run this code
require(GeoModels)
NN <- 400
coords <- cbind(runif(NN), runif(NN))

corrmodel <- "Matern"
scale <- 0.5/3
param <- list(mean=0, sill=1, nugget=0, scale=scale, smooth=0.5)

set.seed(951)
data <- GeoSim(coordx=coords, corrmodel=corrmodel,
              model="Gaussian", param=param)$data

sel <- GeoNeighIndex(coordx=coords, neighb=5)

data1 <- data[sel$colidx]
data2 <- data[sel$rowidx]

## plotting pairs that are neighbours of order 5
plot(data1, data2, xlab="", ylab="",
     main="h-scatterplot, neighb=5")

Run the code above in your browser using DataLab