# NHD: Estimating the D-function In IndTestPP: Tests of Independence and Analysis of Dependence Between Point Processes in Time

## Description

This function estimates the cross nearest neighbour distance distribution function, D, between two sets, C and D, of (homogenous or nonhomogeneous) point processes. The D-function is evaluated in a grid of values r, and it can be optionally plotted.

It calls the auxiliary functions NHDaux and other functions, not intended for users.

## Usage

 ```1 2``` ```NHD(lambdaC, lambdaD, T=NULL,Ptype='inhom', posC, typeC=1, posD, typeD=1, r = NULL, dplot = TRUE, tit = "D(r)",...) ```

## Arguments

 `lambdaC` 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. `lambdaD` 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. `T` Numeric value. Length of the observed period. It only must be specified if the number of rows in `lambdaC` and `lambdaD` is 1. `Ptype` Optional. Label: "hom" or "inhom". The first one indicates that all the point processes in sets C and D are homogeneous. `posC` Numeric vector. Occurrence times of the points in all the point processes in C. `typeC` Numeric vector with the same length as `posC`. Code of the point process in C where points in `posC` have occurred. See Details. `posD` Numeric vector. Occurrence times of the points in all the point processes in D. `typeD` Numeric vector with the same length as `posD`. Code of the point process in D where points in `posD` have occurred. `r` Numeric vector. Values where the D-function must be evaluated. If it is NULL, a default vector is used, see Details. `dplot` Optional. A logical flag. If it is TRUE, the D-function is plotted. `tit` Optional. The title to be used in the plot of the D-function. `...` Further arguments to be passed to the function `plot`.

## Details

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 D-function between two sets, C and D, of (homogenous or nonhomogeneous) point processes, see Cebrian et al (2020) for details of the estimation. The D-function is the distribution function of the distances from a point in a process in C to the nearest point in a process D. In homogeneous proceesses, it estimates the probability that at least one point in a process in set D occurs at a distance lower than r of a given point in a process in set C. If the processes are nonhomogenous, the inhomogenous version of the function, adjusted for time varying intensities, is used. It is calculated using the Hanisch estimator, see Van Lieshout (2006) Small values of the D-function suggest few points in processes in D in the r-neighbourhood of points of processes in C. Large values indicate that points in processes in D are attracted by those of processes in C.

For inference about independence of the processes, K and J-functions should be used.

If argument `r` is NULL, the following 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)

## Value

A list with elements:

 `r` Vector of values r where the D-function is estimated. `NHDr` Estimated values of D_{CD}(r). `T` Length of the observed period.

## References

Cebrian, A.C., Abaurrea, J. and Asin, J. (2020). Testing independence between two point processes in time. Journal of Simulation and Computational Statistics.

Van Lieshout, M.N.M. (2006) A J-function for marked point patterns. AISM, 58, 235-259. DOI 10.1007/s10463-005-0015-7

`NHK`, `NHJ`, `NHF`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17``` ```#Sets C and D with independent NHPPs set.seed(123) lambda1<-runif(500, 0.05, 0.1) set.seed(124) lambda2<-runif(500, 0.01, 0.2) pos1<-simNHPc(lambda=lambda1, fixed.seed=123)\$posNH pos2<-simNHPc(lambda=lambda2, fixed.seed=123)\$posNH aux<-NHD(lambdaC=lambda1, lambdaD=lambda2, posC=pos1, typeC=1, posD=pos2, typeD=1) aux\$NHDr #Example with independent NHPPs #pos3<-simNHPc(lambda=lambda1, fixed.seed=321)\$posNH #pos4<-simNHPc(lambda=lambda2, fixed.seed=321)\$posNH #aux<-NHD(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)))) #aux\$NHDr ```