rnnhcl
Risk-adjusted nearest-neighbour hierarchical clustering
rnnhcl( x, y = NULL, base, bw = NULL, h, p = 0.5, minpts = 10, k = 1, c = 1, lonlat = FALSE)Nearest-neighbour clustering (as nnhclu(), first order) with the
threshold distance adjusted for a baseline population at risk, so that
incidents dense only because people are dense there are not called a
cluster. In nnhclu() the threshold is the mean nearest-neighbour
distance under complete spatial randomness plus z standard errors,
0.5 sqrt(A / n) + z sqrt((4 - pi) A / (4 pi)) / n, which is
f / sqrt(lambda) with lambda = n / A and
f = 0.5 + z sqrt((4 - pi) / (4 pi n)). Here the uniform intensity is
replaced by the intensity the n incidents would have if they followed
the baseline: lambda_i = n b(p_i) / B, where b is the normal-kernel
density (bandwidth h) of the baseline units with sizes bw and B is
their total, and two incidents i and j are linked when
|p_i - p_j| < f / sqrt((lambda_i + lambda_j) / 2). Taking the mean of
the two intensities is this function’s reading of “the threshold at the
pair’s baseline density” (the published description does not say how
the two ends combine); a uniform baseline gives back nnhclu()’s
threshold. Grouping is nnhclu()’s first order; higher orders are not
formed.
Parameters
Section titled “Parameters”x, yThe points:
xandynumeric vectors of equal length; orxa matrix or data frame with columns namedxandy(orXandY, assf::st_coordinates()names them, orlonandlatwithlonlat = TRUE) andyNULL; orxan sf or sfc object of POINT geometries, whose coordinate reference system must agree withlonlat. An unnamed two-column matrix is read asxtheny; other columns are never taken by position. Vectors given separately (x,y, andwortwhere a function takes them) are matched by name when every one is named and no name repeats, as elsewhere in the package; otherwise by position. No missing or infinite values.baseThe baseline units: coordinates as for
x(zone centroids, or points), in the same system asx(degrees whenlonlat = TRUE).bwNULLfor size 1 each, or the baseline sizes (populations), numbers from 0 with a positive sum.hThe bandwidth of the baseline’s normal kernel, positive, in the unit of the coordinates (metres when
lonlat = TRUE).pThe one-tailed probability that a pair is as close by chance: one number strictly between 0 and 1.
minptsThe fewest points a cluster keeps: a whole number from 2.
kThe divisor offset: 0, 1 or 2; the total weight must exceed it.
cThe multiplier of each cluster’s standard deviational ellipse (see
sdell()).lonlatFALSE(the default) whenxandyare planar coordinates in one length unit;TRUEwhen they are longitude and latitude in degrees, which are then projected to metres byeqproj()about their own centre, and centres are returned in degrees. It is never guessed.
Returns
Section titled “Returns”A list: cl, each point’s cluster (a row of clusters) or NA;
clusters, a data frame of points, mx, my, wx, wy, a, b
and angle as in nnhclu(); thr, each point’s own threshold
f / sqrt(lambda_i).
References
Section titled “References”Johnson, S. C. (1967). Hierarchical clustering schemes. Psychometrika, 32(3), 241-254. doi:10.1007/BF02289588
Clark, P. J. and Evans, F. C. (1954). Distance to nearest neighbor as a measure of spatial relationships in populations. Ecology, 35(4), 445-453. doi:10.2307/1931034
Examples
Section titled “Examples”set.seed(1)town <- cbind(x = rnorm(400, 0, 1), y = rnorm(400, 0, 1))inc <- rbind(town[1:60, ], cbind(x = rnorm(15, 3, 0.1), y = rnorm(15, 3, 0.1)))r <- rnnhcl(inc, base = town, h = 0.5, minpts = 5)r$clustersGenerated from the R help page: rnnhcl in the R reference.