This function estimates the cross K-function between two sets, \(C\) and \(D\), of (homogenous or nonhomogeneous) point processes in time. It is evaluated in a grid of distances \(r\), and it can be optionally plotted. A test to assess the independence between the sets of processes, based on the cross K-function, is also implemented.
It calls the auxiliary functions NHKaux, NHKaux2, NHKaux3 and Kenv, not intended for users.
NHK(lambdaC, lambdaD, T=NULL, posC, typeC=1, posD, typeD=1, r=NULL, test=TRUE,
typeEst=2, nTrans=1000, conf=0.95, rTest=NULL, typePlot=" ",tit=NULL,
cores=1,fixed.seed=NULL,...)
A matrix of positive values. Each column is the intensity vector of one of the point processes in \(C\). If there is only one process in \(C\), it can be a vector or even a numeric value if the process is homogeneous.
A matrix of positive values. Each column is the intensity vector of one of the point process in \(D\). If there is only one process in \(D\), it can be a vector or even a numeric value if the process is homogeneous.
Numeric value. Length of the observed period. It only must be specified
if all the processes are homogeneous, that is if the number of rows in lambdaC
and lambdaD
is 1.
Numeric vector. Occurrence times of the points in all the point processes in \(C\).
Numeric vector with the same length as posC
. Code of the point process
in \(C\) where the points in posC
have occurred; see Details.
Numeric vector. Occurrence times of the points in all the point processes in \(D\).
Numeric vector with the same length as posD
. Code of the point process
in \(D\) where the points in posD
have occurred.
Optional. Numeric vector. Grid values where the K-function must be evaluated. If it is NULL, a default vector is used; see Details.
Optional. Logical flag. If it is TRUE, a test of independence and a 95% envelope for the K-function are calculated.
Optional. Two possible values: 1 or 2, which determines which one of the two available estimators of the function \(K_{ij}\) has to be used; see Details.
Optional. Numeric value. Only used if test=TRUE
. Number of translations to
be performed in the test and envelope calculation.
Optional. Numeric value in (0,1). Confidence level of the envelope for the K-function.
Optional. Numeric value. Maximum value of \(r\) used to calculate the test statistc, see Details.
Optional. Character string. If it is "Kfun" or "Kest" a plot of the values \(\hat K_{xy}(r)\) or \(\hat K_{xy}(r)/2r\) is shown. With any other value, no plot is carried out.
Optional. Title to be used in the plot of the K-function.
Optional. Number of cores of the computer to be used in the calculations.
An integer or NULL. If it is an integer, that is the value used to set the seed in random generation processes. It it is NULL, a random seed is used.
Further arguments to be passed to the function plot
.
A list with elements:
Vector of values \(r\) where the cross K-function is estimated.
Estimated values of \(K_{ij}(r)\).
Lower bounds of the envelope of\(K_{ij}(r)\).
Upper bounds of the envelope of \(K_{ij}(r)\).
Observed value of the test statistic.
Sample of the values of the test statistic obtained by random translations.
P-value of the test.
Length of the observed period of the processes.
The information about the processes is provided by arguments posC
, the vector of all the occurrence times
in the processes in \(C\), and typeC
, the vector of the code of the point process in set \(C\)
where each point in posC
has occurred; the second set \(D\) is characterized analogously by
typeD
and posD
.
This function estimates the cross K function between two sets, \(C\) and \(D\), of (homogenous or nonhomogeneous) point processes. Two different estimators are available, see Cebrian et al (2020) for details. The cross K-function measures the dependence between two point processes (or two sets of point processes) and counts the expected number of points in any of the processes in \(D\), within a given distance of a point in any of the processes in \(C\), adjusted for time varying intensity in the case of nonhomogenous processes. The cross K-function of independent Poisson processes is the length of the considered intervals, \(K_{CD}(r)=2r\). Then, values \(K_{CD}(r)/2r>1\) indicate attraction between the processes, while values lower than 1 indicate repulsion.
If argument r
is NULL, the following r-grid is used to evaluate the function
r1<-max(20, floor(T/20))
r<-seq(1,r1,by=2)
if (length(r)>200) r<-seq(1,r1,length.out=200)
Testing independence:
In order to test the independence hypothesis using this function, a test based on a Lotwick-Silverman approach, see Lotwick and Silverman (1982), is implemented. This test provides a nonparametric way to test independence given the marginal intensities of the processes. Using the Lotwick-Silverman approach, not only the p-value of the test but also an envelope for the \(K(r)\) values is calculated. The test statistic is based on the mean of values \(K(r)/(2r)\) evaluated in a given grid of r values.
In point processes, dependence often appears between close observations, and with high \(r\) values it is more difficult that the
K-function is able to discriminate between dependent and independent processes.
By this reason, the argument rTest
allows us to fix a maximum value of \(r\)
so that only K(r) estimations for \(r<rTest\) will be used to
calculate the test statistic. The value rTest
is drawn in the plot of the K-function
as a vertical grey line.
Cebrian, A.C., Abaurrea, J. and Asin, J. (2020). Testing independence between two point processes in time. Journal of Simulation and Computational Statistics.
Lotwick, H.W. and Silverman, B.W. (1982). Methods for analysing Spatial processes of several types of points. J.R. Statist. Soc. B, 44(3), pp. 406-13
# NOT RUN {
set.seed(122)
lambda1<-runif(100, 0.05, 0.1)
set.seed(121)
lambda2<-runif(100, 0.01, 0.2)
pos1<-simNHPc(lambda=lambda1, fixed.seed=123)$posNH
pos2<-simNHPc(lambda=lambda2, fixed.seed=123)$posNH
aux<-NHK(lambdaC=lambda1, lambdaD=lambda2, posC=pos1, posD=pos2, typePlot='Kest',
nTrans=200, cores=1, typeEst=2, fixed.seed=120)
aux$pv
#Sets with two processes
#pos3<-simNHPc(lambda=lambda1, fixed.seed=321)$posNH
#pos4<-simNHPc(lambda=lambda2, fixed.seed=321)$posNH
#aux<-NHK(lambdaC=cbind(lambda1,lambda2), lambdaD=cbind(lambda1,lambda2), posC=c(pos1,pos2),
# typeC=c(rep(1, length(pos1)), rep(2, length(pos2))), posD=c(pos3, pos4),
# typeD=c(rep(1, length(pos3)), rep(2, length(pos4))), typeplot='Kest', fixed.seed=120)
#aux$pv
# }
Run the code above in your browser using DataLab