Learn R Programming

latticeDensity (version 1.2.7)

crossvalDensity: UBC crossvalidation for the lattice-based density estimator.

Description

A function to perform crossvalidation to determine the smoothing parameter for the lattice-based density estimator. It minimizes the UCV criterion.

Usage

crossvalDensity(
  formLatticeOutput,
  PointPattern,
  M = 0.5,
  max_steps = 200,
  sparse = TRUE
)

Value

  • ucv The value of the goodness-of-fit statistic.

  • k The number of steps.

Arguments

formLatticeOutput

An object from formLattice or editLattice.

PointPattern

A matrix or data frame of locations.

M

The maximum probability that the random walk will move.

max_steps

The maximum number of steps attempted.

sparse

Whether spare matrix computations used.

Details

The function computes the k-step diffusion \(p_k = T^kp_0\), then computes the Unbiased CrossValidation (UCV) criterion of Sain, Baggerly and Scott (1994). This function can compute the UCV using either full matrix methods or sparse (default) matrix methods. The latter are almost always much faster, though it is possible that if the number of points in the point pattern is large compared to the number of nodes (an unlikely circumstance) that the full matrix method would be quicker. The sparse matrix approach typically uses less memory. The paper by Barry and McIntyre (2010) shows the approximation to the UCV used in this approach.

References

Crossvalidation of Multivariate Densities. Stephan R. Sain, Keith A. Baggerly, David W. Scott; Journal of the American Statistical Association, Vol. 89 (1994) 807-817

Julie McIntyre, Ronald P. Barry (2018) A Lattice-Based Smoother for Regions with Irregular Boundaries and Holes. Journal of Computational and Graphical Statistics. <doi:10.1080/10618600.2017.1375935>

Examples

Run this code
plot.new()
data(polygon1)
#
nodeFillingOutput <- nodeFilling(poly=polygon1, node_spacing=0.02)
plot(nodeFillingOutput)
formLatticeOutput <- formLattice(nodeFillingOutput)
plot(formLatticeOutput)
#
Pointdata <- splancs::csr(polygon1,75)
Pointdata <- Pointdata[Pointdata[,1]<0.5,]
plot(polygon1,type="n")
polygon(polygon1)
points(Pointdata,pch=19)
#
out <- crossvalDensity(formLatticeOutput,PointPattern=Pointdata, 
       M=0.5,max_steps = 70)
#
densityOut <- createDensity(formLatticeOutput,PointPattern=Pointdata, 
                          k=out$k,intensity=FALSE, sparse = TRUE)
plot(densityOut)
#
homerange(densityOut, percent = 0.95) 

Run the code above in your browser using DataLab