Learn R Programming

McSpatial (version 2.0)

geodensity: Kernel density functions for geo-coded data

Description

Calculates kernel density functions for geo-coded data based on straight-line distances between observations

Usage

geodensity(longvar,latvar,window=.25,kern="tcub",alldata=FALSE)

Arguments

longvar
Longitude variable, in degrees.
latvar
Latitude variable, in degrees.
window
Window size. Default: 0.25.
kern
Kernel weighting functions. Default is the tri-cube. Options include "rect", "tria", "epan", "bisq", "tcub", and "trwt".
alldata
If alldata=T, each observation is used as a target value for x. When alldata=F, the function is estimated at a set of points chosen by the locfit program using an adaptive decision tree approach, and the smooth12 command is used to interpolate to the full set of observations. Specifying alldata=T can lead to long estimation times.

Value

target
The matrix of target values. Dimensions = ntx2, where nt is the number of target points. First column = longitude, second column = latitude.
dens.target
The estimated densities at the target coordinates.
denshat
The estimated densities at the original data points.

Details

The geodistance function is used to calculate straight-line distances between all observations and each target point. The vector of distances for a given target value is d. The window is determined by finding $dmax = quantile(d, window)$. The estimated density at the target point is simply:

$$f = \frac{1}{dmax*n} \sum_i K ( \frac{d_i}{dmax} ) $$

Available kernel weighting functions include the following:

Kernel Call abbreviation
Kernel function K(z) Rectangular
``rect'' $1/2 * I(|z|<1)$ <="" td="">
Triangular ``tria''
$(1-|z|) * I(|z|<1)$< td=""> Epanechnikov
``epan'' $3/4 * (1-z^2)*I(|z| < 1)$
Bi-Square ``bisq''
$15/16 * (1-z^2)^2 * I(|z| < 1)$ Tri-Cube
``tcub'' $70/81 * (1-|z|^3)^3 * I(|z| < 1)$
Tri-Weight ``trwt''
$35/32 * (1-z^2)^3 * I(|z| < 1)$ Kernel

The gaussian kernel is not available.

If alldata=T, each data point in turn is used as a target point. If alldata=F, locfit is used to find a set of target points, and the smooth12 command is used to interpolate to the full set of observations. The matrix of target coordinates is stored in target, and the estimated densities at the target points are stored in dens.target. If alldata=T, target contains the full set of values for longitude and latitude, and dens.target = denshat.

See Also

geodistance

geogravity

Examples

Run this code
## Not run: 
# library(spdep)
# library(RColorBrewer)
# cook <- readShapePoly(system.file("maps/CookCensusTracts.shp",package="McSpatial"))
# # measure distance to Chicago city center
# lmat <- coordinates(cook)
# cook$longitude <- lmat[,1]
# cook$latitude  <- lmat[,2]
# fit <- geodensity(cook$longitude, cook$latitude)
# cook$denshat <- fit$denshat
# brks <- seq(min(cook$denshat,na.rm=TRUE),max(cook$denshat,na.rm=TRUE),length=9)
# spplot(cook,"denshat",at=brks,col.regions=rev(brewer.pal(9,"RdBu")),
#   main="Census Tract Densities")
# ## End(Not run)

Run the code above in your browser using DataLab