cgstat
Mean centre and dispersion of points
cgstat(x, y = NULL, w = NULL, k = 1, lonlat = FALSE)The (weighted) mean centre of a point pattern, the standard deviations of
the two coordinates, the standard distance deviation (the root mean
squared distance from the mean centre), and the geometric and harmonic
means of the coordinates (Bachi 1957; Neft 1962). The mean centre is the
point that minimises the sum of squared distances to the points. The
dispersions divide by the total weight less k: k = 1 makes the
squared values unbiased for the variances; k = 2 is the convention of
some crime-mapping texts; k = 0 divides by the total weight.
That the mean centre minimises the weighted sum of squared distances is
proved in Lean: see proof("cgstat").
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.wNULLfor equal weights, or one non-negative weight per point (counts at a location, say), with a positive sum.kThe divisor offset: 0, 1 or 2; the total weight must exceed it.
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 named numeric vector: w (the total weight), mx, my (the
mean centre, in degrees when lonlat = TRUE), sx, sy (standard
deviations of the coordinates), sdd (the standard distance
deviation), gx, gy (geometric means) and hx, hy (harmonic
means). The last four are NaN for a coordinate with a non-positive
value under positive weight, and for lonlat = TRUE (they depend on the
origin of the coordinates). Lengths are in the unit of the coordinates,
or metres.
References
Section titled “References”Bachi, R. (1957). Statistical analysis of geographical series. Bulletin de l’Institut International de Statistique, 36(2), 229-240.
Neft, D. S. (1966). Statistical Analysis for Areal Distributions. Regional Science Research Institute, Philadelphia.
Examples
Section titled “Examples”set.seed(1)p <- cbind(x = rnorm(50, 100, 10), y = rnorm(50, 200, 5))cgstat(p)cgstat(p[, 1], p[, 2], w = rep(1:2, 25))cgstat(p, k = 0) # dispersions over n, not n - 1Generated from the R help page: cgstat in the R reference.