For a multitype point pattern, estimate the inhomogeneous version of the cross K function, which counts the expected number of points of type j within a given distance of a point of type i, adjusted for spatially varying intensity.
1 2 3 4 5 
X 
The observed point pattern, from which an estimate of the inhomogeneous cross type K function Kij(r) will be computed. It must be a multitype point pattern (a marked point pattern whose marks are a factor). See under Details. 
i 
The type (mark value)
of the points in 
j 
The type (mark value)
of the points in 
lambdaI 
Optional.
Values of the the estimated intensity of the subprocess of
points of type 
lambdaJ 
Optional.
Values of the the estimated intensity of the subprocess of
points of type 
r 
Optional. Numeric vector giving the values of the argument r at which the cross K function Kij(r) should be evaluated. There is a sensible default. Firsttime users are strongly advised not to specify this argument. See below for important conditions on r. 
breaks 
This argument is for advanced use only. 
correction 
A character vector containing any selection of the
options 
... 
Ignored. 
sigma 
Standard deviation of isotropic Gaussian smoothing kernel,
used in computing leaveoneout kernel estimates of

varcov 
Variancecovariance matrix of anisotropic Gaussian kernel,
used in computing leaveoneout kernel estimates of

lambdaIJ 
Optional. A matrix containing estimates of the
product of the intensities 
lambdaX 
Optional. Values of the intensity for all points of 
update 
Logical value indicating what to do when

leaveoneout 
Logical value (passed to 
This is a generalisation of the function Kcross
to include an adjustment for spatially inhomogeneous intensity,
in a manner similar to the function Kinhom
.
The inhomogeneous crosstype K function is described by Moller and Waagepetersen (2003, pages 4849 and 5153).
Briefly, given a multitype point process, suppose the subprocess of points of type j has intensity function lambda[j](u) at spatial locations u. Suppose we place a mass of 1/lambda[j](z) at each point z of type j. Then the expected total mass per unit area is 1. The inhomogeneous “crosstype” K function K[ij]inhom(r) equals the expected total mass within a radius r of a point of the process of type i.
If the process of type i points were independent of the process of type j points, then K[ij]inhom(r) would equal pi * r^2. Deviations between the empirical Kij curve and the theoretical curve pi * r^2 suggest dependence between the points of types i and j.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The arguments i
and j
will be interpreted as
levels of the factor X$marks
. (Warning: this means that
an integer value i=3
will be interpreted as the number 3,
not the 3rd smallest level).
If i
and j
are missing, they default to the first
and second level of the marks factor, respectively.
The argument lambdaI
supplies the values
of the intensity of the subprocess of points of type i
.
It may be either
(object of class "im"
) which
gives the values of the type i
intensity
at all locations in the window containing X
;
containing the values of the
type i
intensity evaluated only
at the data points of type i
. The length of this vector
must equal the number of type i
points in X
.
which can be evaluated to give values of the intensity at any locations.
(object of class "ppm"
, "kppm"
or "dppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
if lambdaI
is omitted then it will be estimated
using a leaveoneout kernel smoother.
If lambdaI
is omitted, then it will be estimated using
a ‘leaveoneout’ kernel smoother,
as described in Baddeley, \Moller
and Waagepetersen (2000). The estimate of lambdaI
for a given
point is computed by removing the point from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point in question. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
Similarly lambdaJ
should contain
estimated values of the intensity of the subprocess of points of
type j
. It may be either a pixel image, a function,
a numeric vector, or omitted.
Alternatively if the argument lambdaX
is given, then it specifies
the intensity values for all points of X
, and the
arguments lambdaI
, lambdaJ
will be ignored.
The optional argument lambdaIJ
is for advanced use only.
It is a matrix containing estimated
values of the products of these two intensities for each pair of
data points of types i
and j
respectively.
The argument r
is the vector of values for the
distance r at which Kij(r) should be evaluated.
The values of r must be increasing nonnegative numbers
and the maximum r value must exceed the radius of the
largest disc contained in the window.
The argument correction
chooses the edge correction
as explained e.g. in Kest
.
The pair correlation function can also be applied to the
result of Kcross.inhom
; see pcf
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r 
the values of the argument r at which the function Kij(r) has been estimated 
theo 
the theoretical value of Kij(r) for a marked Poisson process, namely pi * r^2 
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function Kij(r)
obtained by the edge corrections named.
The arguments i
and j
are always interpreted as
levels of the factor X$marks
. They are converted to character
strings if they are not already character strings.
The value i=1
does not
refer to the first level of the factor.
.
Baddeley, A., Moller, J. and Waagepetersen, R. (2000) Non and semiparametric estimation of interaction in inhomogeneous point patterns. Statistica Neerlandica 54, 329–350.
Moller, J. and Waagepetersen, R. Statistical Inference and Simulation for Spatial Point Processes Chapman and Hall/CRC Boca Raton, 2003.
Kcross
,
Kinhom
,
Kdot.inhom
,
Kmulti.inhom
,
pcf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35  # Lansing Woods data
woods < lansing
ma < split(woods)$maple
wh < split(woods)$whiteoak
# method (1): estimate intensities by nonparametric smoothing
lambdaM < density.ppp(ma, sigma=0.15, at="points")
lambdaW < density.ppp(wh, sigma=0.15, at="points")
K < Kcross.inhom(woods, "whiteoak", "maple", lambdaW, lambdaM)
# method (2): leaveoneout
K < Kcross.inhom(woods, "whiteoak", "maple", sigma=0.15)
# method (3): fit parametric intensity model
fit < ppm(woods ~marks * polynom(x,y,2))
# alternative (a): use fitted model as 'lambda' argument
K < Kcross.inhom(woods, "whiteoak", "maple",
lambdaI=fit, lambdaJ=fit, update=FALSE)
K < Kcross.inhom(woods, "whiteoak", "maple",
lambdaX=fit, update=FALSE)
# alternative (b): evaluate fitted intensities at data points
# (these are the intensities of the subprocesses of each type)
inten < fitted(fit, dataonly=TRUE)
# split according to types of points
lambda < split(inten, marks(woods))
K < Kcross.inhom(woods, "whiteoak", "maple",
lambda$whiteoak, lambda$maple)
# synthetic example: type A points have intensity 50,
# type B points have intensity 100 * x
lamB < as.im(function(x,y){50 + 100 * x}, owin())
X < superimpose(A=runifpoispp(50), B=rpoispp(lamB))
K < Kcross.inhom(X, "A", "B",
lambdaI=as.im(50, Window(X)), lambdaJ=lamB)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.