Learn R Programming

spatstat.explore (version 3.3-1)

compileK: Generic Calculation of K Function and Pair Correlation Function

Description

Low-level functions which calculate the estimated \(K\) function and estimated pair correlation function (or any similar functions) from a matrix of pairwise distances and optional weights.

Usage

compileK(D, r, weights = NULL, denom = 1,
         check = TRUE, ratio = FALSE, fname = "K",
         samplesize=denom)

compilepcf(D, r, weights = NULL, denom = 1, check = TRUE, endcorrect = TRUE, ratio=FALSE, ..., fname = "g", samplesize=denom)

Value

An object of class "fv" representing the estimated function.

Arguments

D

A square matrix giving the distances between all pairs of points.

r

An equally spaced, finely spaced sequence of distance values.

weights

Optional numerical weights for the pairwise distances. A numeric matrix with the same dimensions as D. If absent, the weights are taken to equal 1.

denom

Denominator for the estimator. A single number, or a numeric vector with the same length as r. See Details.

check

Logical value specifying whether to check that D is a valid matrix of pairwise distances.

ratio

Logical value indicating whether to store ratio information. See Details.

...

Optional arguments passed to density.default controlling the kernel smoothing.

endcorrect

Logical value indicating whether to apply End Correction of the pair correlation estimate at r=0.

fname

Character string giving the name of the function being estimated.

samplesize

The sample size that should be used as the denominator when ratio=TRUE.

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au

Details

These low-level functions construct estimates of the \(K\) function or pair correlation function, or any similar functions, given only the matrix of pairwise distances and optional weights associated with these distances.

These functions are useful for code development and for teaching, because they perform a common task, and do the housekeeping required to make an object of class "fv" that represents the estimated function. However, they are not very efficient.

compileK calculates the weighted estimate of the \(K\) function, $$ \hat K(r) = (1/v(r)) \sum_i \sum_j 1\{ d_{ij} \le r\} w_{ij} $$ and compilepcf calculates the weighted estimate of the pair correlation function, $$ \hat g(r) = (1/v(r)) \sum_i \sum_j \kappa( d_{ij} - r ) w_{ij} $$ where \(d_{ij}\) is the distance between spatial points \(i\) and \(j\), with corresponding weight \(w_{ij}\), and \(v(r)\) is a specified denominator. Here \(\kappa\) is a fixed-bandwidth smoothing kernel.

For a point pattern in two dimensions, the usual denominator \(v(r)\) is constant for the \(K\) function, and proportional to \(r\) for the pair correlation function. See the Examples.

The result is an object of class "fv" representing the estimated function. This object has only one column of function values. Additional columns (such as a column giving the theoretical value) must be added by the user, with the aid of bind.fv.

If ratio=TRUE, the result also belongs to class "rat" and has attributes containing the numerator and denominator of the function estimate. (If samplesize is given, the numerator and denominator are rescaled by a common factor so that the denominator is equal to samplesize.) This allows function estimates from several datasets to be pooled using pool.

See Also

Kest, pcf for definitions of the \(K\) function and pair correlation function.

bind.fv to add more columns.

compileCDF for the corresponding low-level utility for estimating a cumulative distribution function.

Examples

Run this code
  ## Equivalent to Kest(japanesepines) and pcf(japanesepines)
  X <- japanesepines
  D <- pairdist(X)
  Wt <- edge.Ripley(X, D)
  lambda <- intensity(X)
  a <- (npoints(X)-1) * lambda
  r <- seq(0, 0.25, by=0.01)
  K <- compileK(D=D, r=r, weights=Wt, denom=a)
  g <- compilepcf(D=D, r=r, weights=Wt, denom= a * 2 * pi * r)

Run the code above in your browser using DataLab