Learn R Programming

spNetwork (version 0.1.1)

kfunctions: Network k and g functions (experimental)

Description

Calculate the k and g functions for a set of points on a network (experimental).

Usage

kfunctions(
  lines,
  points,
  start,
  end,
  step,
  width,
  nsim,
  conf_int = 0.05,
  digits = 2,
  tol = 0.1,
  resolution = NULL,
  agg = NULL,
  verbose = TRUE
)

Arguments

lines

A SpatialLinesDataFrame with the sampling points. The geometries must be a SpatialLinesDataFrame (may crash if some geometries are invalid)

points

A SpatialPointsDataFrame representing the points on the network. These points will be snapped on the network.

start

A double, the start value for evaluating the k and g functions

end

A double, the last value for evaluating the k and g functions

step

A double, the jump between two evaluations of the k and g function

width

The width of each donut for the g-function

nsim

An integer indicating the number of Monte Carlo simulations required

conf_int

A double indicating the width confidence interval (default = 0.05)

digits

An integer indicating the number of digits to retain for the spatial coordinates

tol

When adding the points to the network, specify the minimum distance between these points and the lines' extremities. When points are closer, they are added at the extremity of the lines.

resolution

When simulating random points on the network, selecting a resolution will reduce greatly the calculation time. When resolution is null the random points can occur everywhere on the graph. If a value is specified, the edges are split according to this value and the random points are selected vertices on the new network.

agg

A double indicating if the events must be aggregated within a distance. If NULL, the events are aggregated by rounding the coordinates.

verbose

A Boolean indicating if progress messages should be displayed.

Value

A list with the following values :

  • plotkA ggplot2 object representing the values of the k-function

  • plotgA ggplot2 object representing the values of the g-function

  • valuesA DataFrame with the values used to build the plots

Details

The k-function is a method to characterize the dispersion of a set of points. For each point, the numbers of other points in subsequent radii are calculated. This empirical k-function can be more or less clustered than a k-function obtained if the points were randomly located in space. In a network, the network distance is used instead of the Euclidean distance. This function uses Monte Carlo simulations to assess if the points are clustered or dispersed, and gives the results as a line plot. If the line of the observed k-function is higher than the shaded area representing the values of the simulations, then the points are more clustered than what we can expect from randomness and vice-versa. The function also calculates the g-function, a modified version of the k-function using rings instead of disks. The width of the ring must be chosen. The main interest is to avoid the cumulative effect of the classical k-function.

Examples

Run this code
# NOT RUN {
networkgpkg <- system.file("extdata", "networks.gpkg", package = "spNetwork", mustWork = TRUE)
eventsgpkg <- system.file("extdata", "events.gpkg", package = "spNetwork", mustWork = TRUE)
main_network_mtl <- rgdal::readOGR(networkgpkg,layer="main_network_mtl", verbose=FALSE)
mtl_libraries <- rgdal::readOGR(eventsgpkg,layer="mtl_libraries", verbose=FALSE)
result <- kfunctions(main_network_mtl, mtl_libraries,
     start = 0, end = 2500, step = 10,
     width = 200, nsim = 50,
     conf_int = 0.05, tol = 0.1, agg = NULL,
     verbose = FALSE)
# }

Run the code above in your browser using DataLab