bivariate.density(data, ID = NULL, pilotH, globalH = pilotH,
adaptive = TRUE, edgeCorrect = TRUE, res = 50, WIN = NULL,
counts = NULL, intensity = FALSE, xrange = NULL,
yrange = NULL, trim = 5, gamma = NULL, atExtraCoords = NULL,
use.ppp.methods = TRUE, comment = TRUE)data.frame, list, matrix, or ppp givindata is a data structure with a third component/column indicating case (1) or control (0) status, ID must specify which of these groups we wish to estimate a density for. If ID is NULL (default), a deadaptive is TRUE (default), this value is taken to be the pilot bandwidth, used to construct the bivariate pilot density required for adaptive smoothing (see `adaptive is TRUE, this defaults to be the same as the pilot bandwidth. Ignored fTRUE.res. Currently, only res*res grids are supported. Defaultdata, if data contains unique observations. If NULL (default), the function assumeWIN = NULL) and data is not an object of class ppp, and ignored otherwise. A vector of length 2 giving the upper and lower limit5) that prevents excessively large bandwidths in adaptive smoothing by trimming the originally computed bandwidths h by trim times median(h). A value of gamma for adaptive bandwidth calculation (see `Details'). For adaptive relative risk estimation, this value can sensibly be chosen as common for both case and control densities (such as thatExtraCoords allows the user to speppp.object from the package spatstat to estimate the densTRUE."bivden". This is effectively a list with the following components:WIN are set to NAresres"gaus"data. For a fixed bandwidth estimate, this will simply be the identical value passed to and returned as pilotHglobalH if adaptive smoothing is employed, NA for fixed smoothingZm) for each coordinate of the evaluation grid. That is, these values are the bandwidths at that grid coordinate if, hypothetically, there was an observation there (along with the original data). These are used for edge-correction in adaptive densities (Marshall and Hazelton, 2010). Will be NA for fixed bandwidth estimatesdatazSpec for the observations in atExtraCoords, NA if atExtraCoords is not suppliedowin used as the study regionZm. If edgeCorrect = FALSE, all edge correction factors are set to and returned as 1dataqhzSpec for the observations in atExtraCoords; NA if atExtraCoords is not supplieddata. NULL when adaptive = FALSEgamma that was passed to the function, or the geometric mean term of the reciprocal of the square root of the pilot density values used to scale the adaptive bandwidths if gamma is not supplied. NULL when adaptive = FALSEdata were unique and counts = NULL, the returned counts will be a vector of ones equal to the number of coordinates in datadata that were used for the density estimation. If data originally contained duplicated coordinates, the returned data will contain only the unique coordinates, and should be viewed with respect to the returned value of countsres, the complexity of the study region and electing to edge-correct all have a direct impact upon the time it will take to estimate the density. Keeping use.ppp.methods = TRUE can drastically reduce this computational cost at the expense a degree of accuracy that is generally considered negligible for most practical purposes.data argumnent is a data.frame or matrix. Then for each observation data[i,1:2] (i = 1, 2, ... n), the bandwidth h[i] is given by
h[i]=globalH / ( w(data[i,1:2]; pilotH)^(1/2)*gamma )
where w is the fixed bandwidth pilot density constructed with bandwidth pilotH and the scaling parameter gamma is the geometric mean of the w^(-1/2) values. A detailed discussion on this construction is given in Silverman (1986).
If the data argument is a data.frame or a matrix, this must have exactly two columns containing the x ([,1]) and y ([,2]) data values, or exactly three columns with the third (rightmost) column giving ID information by way of a numeric, dichotomous indicator. Should data be a list, this must have two vector components of equal length named x and y. The user may specify a third component with the name ID giving the vector of corresponding ID information (must be of equal length to x and y). Alternatively, data may be an object of class ppp (see ppp.object). ID information can be stored in such an object through the argument marks. If data is a ppp object, the value of window of this object overrides the value of the argument WIN above.##Chorley-Ribble laryngeal cancer data ('spatstat' library)
data(chorley)
ch.lar.density <- bivariate.density(data = chorley, ID = "larynx",
pilotH = 1.5, adaptive = FALSE)
plot(ch.lar.density, col = "lightblue", phi = 30, theta = -30,
ticktype = "detailed", main = "chorley.larynx", display = "persp")
##PBC liver disease data
data(PBC)
pbc.adaptive.density <- bivariate.density(data = PBC$data, ID = 1,
pilotH = 350, WIN = PBC$owin)
#3D plot - may need to adjust size of RGL device. Hold left click
# to pan, hold right to zoom.
plot(pbc.adaptive.density, display = "3d", col = heat.colors(20),
main = "Density of PBC in north-east England", aspect = 1:2)Run the code above in your browser using DataLab