Title: | Statistical Methods for the Analysis of Case-Control Point Data |
---|---|
Description: | Statistical methods for analyzing case-control point data. Methods include the ratio of kernel densities, the difference in K Functions, the spatial scan statistic, and q nearest neighbors of cases. |
Authors: | Joshua French [aut, cre] |
Maintainer: | Joshua French <[email protected]> |
License: | GPL (>=2) |
Version: | 2.6.4 |
Built: | 2024-10-31 18:27:20 UTC |
Source: | https://github.com/jfrench/smacpod |
Argument check alternative
arg_check_alternative(alternative)
arg_check_alternative(alternative)
alternative |
One of "lower", "greater", "two.sided" |
circles.intersect
determines whether circles
intersect with each other.
circles.intersect(coords, r)
circles.intersect(coords, r)
coords |
A matrix of coordinates with the centroid of each circle. |
r |
A vector containing the radii of the circles.
The length of |
The algorithm is based on the premise that two circles intersect if, and only if, the distance between their centroids is between the sum and the difference of their radii. I have squared the respective parts of the inequality in the implemented algorithm.
Returns a matrix of logical values indicating whether the circles intersect.
Joshua French
# first two circles intersect each other, # the next two circles intersect each other # (but not the previous ones) # the last circles doesn't intersect any other circle co = cbind(c(1, 2, 5, 6, 9), c(1, 2, 5, 6, 9)) r = c(1.25, 1.25, 1.25, 1.25, 1.25) # draw circles circles.plot(co, r) # confirm intersections circles.intersect(co, r) # nested circles (don't intersect) co = matrix(rep(0, 4), nrow = 2) r = c(1, 1.5) circles.plot(co, r) circles.intersect(co, r)
# first two circles intersect each other, # the next two circles intersect each other # (but not the previous ones) # the last circles doesn't intersect any other circle co = cbind(c(1, 2, 5, 6, 9), c(1, 2, 5, 6, 9)) r = c(1.25, 1.25, 1.25, 1.25, 1.25) # draw circles circles.plot(co, r) # confirm intersections circles.intersect(co, r) # nested circles (don't intersect) co = matrix(rep(0, 4), nrow = 2) r = c(1, 1.5) circles.plot(co, r) circles.intersect(co, r)
plot.circles
creates a plot with one or more
circles (or adds them to an existing plot).
circles.plot( coords, r, add = FALSE, ..., nv = 100, border = NULL, ccol = NA, clty = 1, density = NULL, angle = 45, clwd = 1 )
circles.plot( coords, r, add = FALSE, ..., nv = 100, border = NULL, ccol = NA, clty = 1, density = NULL, angle = 45, clwd = 1 )
coords |
A matrix of coordinates with the centroid of each circle. |
r |
A vector containing the radii of the circles.
The length of |
add |
A logical value indicating whether the circles
should be added to an existing plot. Default is
|
... |
Additional arguments passed to the
|
nv |
Number of vertices to draw the circle. |
border |
A vector with the desired border of each
circle. The length should either be 1 (in which case
the border is repeated for all circles) or should match
the number of rows of |
ccol |
A vector with the desired color of each
circle. The length should either be 1 (in which case
the color is repeated for all circles) or should match
the number of rows of |
clty |
A vector with the desired line type of each
circle. The length should either be 1 (in which case
the line type is repeated for all circles) or should match
the number of rows of |
density |
A vector with the density for a patterned fill.
The length should either be 1 (in which case
the density is repeated for all circles) or should match
the number of rows of |
angle |
A vector with the angle of a patterned fill.
The length should either be 1 (in which case
the angle is repeated for all circles) or should match
the number of rows of |
clwd |
A vector with the desired line width of each
circle. The length should either be 1 (in which case
the line width is repeated for all circles) or should match
the number of rows of |
Joshua French
co = cbind(c(1, 2, 5, 6, 9), c(1, 2, 5, 6, 9)) r = c(1.25, 1.25, 1.25, 1.25, 1.25) # draw circles circles.plot(co, r) circles.plot(co, r, ccol = c("blue", "blue", "orange", "orange", "brown"), density = c(10, 20, 30, 40, 50), angle = c(45, 135, 45, 136, 90))
co = cbind(c(1, 2, 5, 6, 9), c(1, 2, 5, 6, 9)) r = c(1.25, 1.25, 1.25, 1.25, 1.25) # draw circles circles.plot(co, r) circles.plot(co, r, ccol = c("blue", "blue", "orange", "orange", "brown"), density = c(10, 20, 30, 40, 50), angle = c(45, 135, 45, 136, 90))
Extract clusters
## S3 method for class 'spscan' clusters(x, idx = seq_along(x$clusters), ...)
## S3 method for class 'spscan' clusters(x, idx = seq_along(x$clusters), ...)
x |
An object of class |
idx |
An index vector indicating the elements of
|
... |
Currently unimplemented |
A list. Each element of the list is a vector with the indices of event locations in the associated cluster.
data(grave) # apply scan method out = spscan.test(grave, nsim = 99) # print scan object clusters(out)
data(grave) # apply scan method out = spscan.test(grave, nsim = 99) # print scan object clusters(out)
Create gradient color scale with midpoint
gradient.color.scale( minval, maxval, n = 11, low = "blue", mid = "white", high = "red", midpoint = 0, ... )
gradient.color.scale( minval, maxval, n = 11, low = "blue", mid = "white", high = "red", midpoint = 0, ... )
minval |
The minimum value of the data to be colored |
maxval |
The maximum value of the data to be colored |
n |
The desired number of breaks (approximately) |
low |
The color for the low values |
mid |
The color used for the midpoint of the gradient |
high |
The color used for the high values |
midpoint |
The midpoint of the color scale |
... |
Arguments passed to |
A list with col
and breaks
components specifying the colors and breaks of the color scale.
Based on code from https://stackoverflow.com/a/10986203/5931362
data(grave) lr = logrr(grave) grad = gradient.color.scale(min(lr$v, na.rm = TRUE), max(lr$v, na.rm = TRUE)) plot(lr, col = grad$col, breaks = grad$breaks)
data(grave) lr = logrr(grave) grad = gradient.color.scale(min(lr$v, na.rm = TRUE), max(lr$v, na.rm = TRUE)) plot(lr, col = grad$col, breaks = grad$breaks)
This data set contains 143 observations of
medieval grave site data stored as a ppp
class
object from the spatstat.geom
package. The data are
marked as being "affected" by a tooth deformity or
"unaffected" by a tooth deformity.
data(grave)
data(grave)
ppp
(planar point process) class object
from the spatstat.geom
package.
Joshua French
Waller, L.A. and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
kd
determines the difference in estimated K
functions for a set of cases and controls.
kd( x, case = 2, r = NULL, rmax = NULL, breaks = NULL, correction = c("border", "isotropic", "Ripley", "translate"), nlarge = 3000, domain = NULL, var.approx = FALSE, ratio = FALSE )
kd( x, case = 2, r = NULL, rmax = NULL, breaks = NULL, correction = c("border", "isotropic", "Ripley", "translate"), nlarge = 3000, domain = NULL, var.approx = FALSE, ratio = FALSE )
x |
A |
case |
The name of the desired "case" group in
|
r |
Optional. Vector of values for the argument |
rmax |
Optional. Maximum desired value of the argument |
breaks |
This argument is for internal use only. |
correction |
Optional. A character vector containing any selection of the
options |
nlarge |
Optional. Efficiency threshold.
If the number of points exceeds |
domain |
Optional. Calculations will be restricted
to this subset of the window. See Details of
|
var.approx |
Logical. If |
ratio |
Logical.
If |
This function relies internally on the
Kest
and
eval.fv
. The arguments are essentially
the same as the Kest
function,
and the user is referred there for more details about
the various arguments.
Returns an fv
object. See documentation
for Kest
.
Joshua French
Waller, L.A. and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
data(grave) kd = kd(grave) plot(kd)
data(grave) kd = kd(grave) plot(kd)
kdest
computes the difference in estimated K functions for a set of
cases and controls, with KD(r) = K_case(r) - K_control(r)
denoting the
estimated difference at distance r
. If nsim > 0
, then pointwise
tolerance envelopes for KD(r)
are constructed under the random
labeling hypothesis for each distance r
. The summary
function
can be used to determine the distances for which KD(r)
is above or
below the tolerance envelopes. The plot
function will plot
KD(r)
versus r, along with the tolerance envelopes, the min/max
envelopes of KD(r)
simulated under the random labeling hypothesis, and
the average KD(r) under the random labeling hypothesis.
kdest( x, case = 2, nsim = 0, level = 0.95, r = NULL, rmax = NULL, breaks = NULL, correction = c("border", "isotropic", "Ripley", "translate"), nlarge = 3000, domain = NULL, var.approx = FALSE, ratio = FALSE )
kdest( x, case = 2, nsim = 0, level = 0.95, r = NULL, rmax = NULL, breaks = NULL, correction = c("border", "isotropic", "Ripley", "translate"), nlarge = 3000, domain = NULL, var.approx = FALSE, ratio = FALSE )
x |
A |
case |
The name of the desired "case" group in
|
nsim |
The number of simulated data sets from which to construct tolerance envelopes under the random labeling hypothesis. The default is 0 (i.e., no envelopes). |
level |
The level of the tolerance envelopes. |
r |
Optional. Vector of values for the argument |
rmax |
Optional. Maximum desired value of the argument |
breaks |
This argument is for internal use only. |
correction |
Optional. A character vector containing any selection of the
options |
nlarge |
Optional. Efficiency threshold.
If the number of points exceeds |
domain |
Optional. Calculations will be restricted to this subset of the window. See Details. |
var.approx |
Logical. If |
ratio |
Logical.
If |
This function relies internally on the Kest
and
eval.fv
functions. The arguments are essentially the same as the
Kest
function, and the user is referred there
for more details about the various arguments.
Returns a kdenv
object. See documentation
for Kest
.
Joshua French
Waller, L.A. and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
data(grave) # estimate and plot KD(r) kd1 = kdest(grave, case = "affected") plot(kd1, iso ~ r, ylab = "difference", legend = FALSE, main = "") kd2 = kdest(grave, case = 2, nsim = 9, level = 0.8) kd2 # print object summary(kd2) # summarize distances KD(r) outside envelopes plot(kd2) # manually add legend legend("bottomright", legend = c("obs", "avg", "max/min env", "95% env"), lty = c(1, 2, 1, 2), col = c("black", "red", "darkgrey", "lightgrey"), lwd = c(1, 1, 10, 10))
data(grave) # estimate and plot KD(r) kd1 = kdest(grave, case = "affected") plot(kd1, iso ~ r, ylab = "difference", legend = FALSE, main = "") kd2 = kdest(grave, case = 2, nsim = 9, level = 0.8) kd2 # print object summary(kd2) # summarize distances KD(r) outside envelopes plot(kd2) # manually add legend legend("bottomright", legend = c("obs", "avg", "max/min env", "95% env"), lty = c(1, 2, 1, 2), col = c("black", "red", "darkgrey", "lightgrey"), lwd = c(1, 1, 10, 10))
kdplus.test
performs a global test of clustering
for comparing cases and controls using the method of
Diggle and Chetwynd (1991). It relies on the difference
in estimated K functions.
kdplus.test(x)
kdplus.test(x)
x |
A |
A list providing the observed test statistic
(kdplus
) and the estimate p-value
pvalue
.
Joshua French
Waller, L.A. and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
Diggle, Peter J., and Amanda G. Chetwynd. "Second-order analysis of spatial clustering for inhomogeneous populations." Biometrics (1991): 1155-1163.
data(grave) # construct envelopes for differences in estimated K functions kdenv = kdest(grave, nsim = 9) kdplus.test(kdenv)
data(grave) # construct envelopes for differences in estimated K functions kdenv = kdest(grave, nsim = 9) kdplus.test(kdenv)
logrr
computes the estimated log relative risk of
cases relative to controls. The log relative risk at
location s is defined as r(s) = ln(f(s)/g(s))
. The
numerator, f(s)
, is the spatial density of the
case group. The denominator, g(s)
, is the spatial
density of the control group. If nsim > 0
, then
pointwise (at each pixel) tolerance envelopes are
estimated under the random labeling hypothesis. The
tolerance envelopes can be used to assess pixels where
the log relative risk differs significantly from zero.
See Details.
logrr( x, sigma = NULL, sigmacon = NULL, case = 2, nsim = 0, level = 0.9, alternative = "two.sided", envelope = "pixelwise", ..., bwargs = list(), weights = NULL, edge = TRUE, varcov = NULL, at = "pixels", leaveoneout = TRUE, adjust = 1, diggle = FALSE, kernel = "gaussian", scalekernel = is.character(kernel), positive = FALSE, verbose = TRUE, return_sims = FALSE )
logrr( x, sigma = NULL, sigmacon = NULL, case = 2, nsim = 0, level = 0.9, alternative = "two.sided", envelope = "pixelwise", ..., bwargs = list(), weights = NULL, edge = TRUE, varcov = NULL, at = "pixels", leaveoneout = TRUE, adjust = 1, diggle = FALSE, kernel = "gaussian", scalekernel = is.character(kernel), positive = FALSE, verbose = TRUE, return_sims = FALSE )
x |
A |
sigma |
Standard deviation of isotropic smoothing
kernel for cases. Either a numerical value, or a
function that computes an appropriate value of
|
sigmacon |
Standard deviation of isotropic smoothing
kernel for controls. Default is the same as
|
case |
The name of the desired "case" group in
|
nsim |
The number of simulated data sets from which to construct tolerance envelopes under the random labeling hypothesis. The default is 0 (i.e., no envelopes). |
level |
The level of the tolerance envelopes. |
alternative |
The type of envelopes to construct.
The default is |
envelope |
The type of envelope to construct. The
default is |
... |
Additional arguments passed to |
bwargs |
A list of arguments for the bandwidth
function supplied to |
weights |
Optional weights to be attached to the points.
A numeric vector, numeric matrix, an |
edge |
Logical value indicating whether to apply edge correction. |
varcov |
Variance-covariance matrix of anisotropic smoothing kernel.
Incompatible with |
at |
String specifying whether to compute the intensity values
at a grid of pixel locations ( |
leaveoneout |
Logical value indicating whether to compute a leave-one-out
estimator. Applicable only when |
adjust |
Optional. Adjustment factor for the smoothing parameter. |
diggle |
Logical. If |
kernel |
The smoothing kernel.
A character string specifying the smoothing kernel
(current options are |
scalekernel |
Logical value.
If |
positive |
Logical value indicating whether to force all density values to
be positive numbers. Default is |
verbose |
Logical value indicating whether to issue warnings about numerical problems and conditions. |
return_sims |
A logical value indicating whether
parts of the simulated data shoudl be returned. The
default is |
If nsim=0
, the plot
function creates a heat
map of the log relative risk. If nsim > 0
, the
plot
function colors the pixels where the
estimated log relative risk is outside the tolerance
envelopes created under the random labeling hypothesis
(i.e., pixels with potential clustering of cases or
controls). Colored regions with values above 0 indicate a
cluster of cases relative to controls (without
controlling for multiple comparisons), i.e., a region
where the the density of the cases is greater than the
the density of the controls. Colored regions with values
below 0 indicate a cluster of controls relative to cases
(without controlling for multiple comparisons), i.e., a
region where the density of the controls is greater than
the density of the cases.
The two.sided
alternative test constructs
two-sided tolerance envelopes to assess whether the
estimated r(s)
deviates more than what is expected
under the random labeling hypothesis. The greater
alternative constructs an upper tolerance envelope to
assess whether the estimated r(s)
is greater than
what is expected under the random labeling hypothesis,
i.e., where there is clustering of cases relative to
controls. The lower
alternative constructs a lower
tolerance envelope to assess whether the estimated
r(s)
is lower than what is expected under the
random labeling hypothesis, i.e., where there is
clustering of controls relative to cases.
If the estimated density of the case or control group
becomes too small, this function may produce warnings due
to numerical underflow. Increasing the bandwidth
(sigma
) may help.
The function produces an object of type
logrrenv
. Its components are similar to those
returned by the
density.ppp
, with the
intensity values replaced by the log ratio of spatial
densities of f and g. Includes an array simr
of
dimension c(nx, ny, nsim + 1), where nx and ny are the
number of x and y grid points used to estimate the
spatial density. simr[,,1]
is the log ratio of
spatial densities for the observed data, and the
remaining nsim
elements in the third dimension
of the array are the log ratios of spatial densities
from a new ppp simulated under the random labeling
hypothesis.
Joshua French (and a small chunk by the authors
of the density.ppp
)
function for consistency with the default behavior of
that function).
Waller, L.A. and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
Kelsall, Julia E., and Peter J. Diggle. "Kernel estimation of relative risk." Bernoulli (1995): 3-16.
Kelsall, Julia E., and Peter J. Diggle. "Non-parametric estimation of spatial variation in relative risk." Statistics in Medicine 14.21-22 (1995): 2335-2342.
Hegg, Alex and French, Joshua P. (2022) "Simultaneous tolerance bands of log relative risk for case-control point data. Technical report.
data(grave) # estimate and plot log relative risk r = logrr(grave, case = "affected") plot(r) # use scott's bandwidth r2 = logrr(grave, case = 2, sigma = spatstat.explore::bw.scott) plot(r2) # construct pointwise tolerance envelopes for log relative risk ## Not run: renv = logrr(grave, nsim = 9) print(renv) # print information about envelopes plot(renv) # plot results # plot using a better gradient grad = gradient.color.scale(min(renv$v, na.rm = TRUE), max(renv$v, na.rm = TRUE)) plot(renv, col = grad$col, breaks = grad$breaks, conlist = list(col = "lightgrey")) ## End(Not run)
data(grave) # estimate and plot log relative risk r = logrr(grave, case = "affected") plot(r) # use scott's bandwidth r2 = logrr(grave, case = 2, sigma = spatstat.explore::bw.scott) plot(r2) # construct pointwise tolerance envelopes for log relative risk ## Not run: renv = logrr(grave, nsim = 9) print(renv) # print information about envelopes plot(renv) # plot results # plot using a better gradient grad = gradient.color.scale(min(renv$v, na.rm = TRUE), max(renv$v, na.rm = TRUE)) plot(renv, col = grad$col, breaks = grad$breaks, conlist = list(col = "lightgrey")) ## End(Not run)
logrr.test
performs a global test of clustering
for comparing cases and controls using the log ratio of
spatial densities based on the method of Kelsall and
Diggle (1995).
logrr.test(x)
logrr.test(x)
x |
An |
A list providing the observed test statistic
(islogrr
) and the estimated p-value
(pvalue
).
Joshua French
Waller, L.A. and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
Kelsall, Julia E., and Peter J. Diggle. "Non-parametric estimation of spatial variation in relative risk." Statistics in Medicine 14.21-22 (1995): 2335-2342.
data(grave) ## Not run: logrrenv = logrr(grave, nsim = 9) logrr.test(logrrenv) ## End(Not run)
data(grave) ## Not run: logrrenv = logrr(grave, nsim = 9) logrr.test(logrrenv) ## End(Not run)
nn
determines the nearest neighbors for a set of
observations based on a distance matrix.
nn(d, k, method = "c", self = FALSE)
nn(d, k, method = "c", self = FALSE)
d |
A square distance matrix for the coordinates of interest. |
k |
The number of neighbors to return (if
|
method |
The method of determining the neighbors.
The default is |
self |
A logical indicating whether an observation
is a neighbor with itself. The default is
|
This function determine nearest neighbors in two ways: 1. number of neighbors or 2. distance.
If method = "c"
, then k
specifies the total
number of neighbors to return for each observation.
If method = "d"
, then k
specifies the maximum
distance for which an observation is considered a
neighbor.
The function returns the neighbors for each observation.
Returns a list with the nearest neighbors of each observation. For each element of the list, the indices order neighbors from nearest to farthest.
Joshua French
data(grave) # make distance matrix d = as.matrix(dist(cbind(grave$x, grave$y))) # 3 nearest neighbors nnc = nn(d, k = 3, method = "c") # nearest neighbors within k units of each observation nnd = nn(d, k = 200, method = "d")
data(grave) # make distance matrix d = as.matrix(dist(cbind(grave$x, grave$y))) # 3 nearest neighbors nnc = nn(d, k = 3, method = "c") # nearest neighbors within k units of each observation nnd = nn(d, k = 200, method = "d")
Determine non-overlapping clusters from a list of potential clusters.
noc(x)
noc(x)
x |
A list containing the potential clusters. |
The function takes a list of potential clusters. Each element of the list contains a potential cluster. The potential clusters are defined by the location indices of the regions comprising the clusters. Starting with the first potential cluster, the function excludes every potential cluster that intersects the first (any potential cluster that shares indices). Moving onto the next non-overlapping cluster, the process is repeated. The function returns the indices (in the list of clusters) of the clusters that do not overlap.
A vector with the list indices of the non-overlapping clusters.
Joshua French
x = list(1:2, 1:3, 4:5, 4:6, 7:8) noc(x)
x = list(1:2, 1:3, 4:5, 4:6, 7:8) noc(x)
kdenv
object.Plots an object from kdest
of
class kdenv
.
## S3 method for class 'kdenv' plot( x, ..., shadecol1 = "darkgrey", shadecol2 = "lightgrey", main = "", legend = FALSE )
## S3 method for class 'kdenv' plot( x, ..., shadecol1 = "darkgrey", shadecol2 = "lightgrey", main = "", legend = FALSE )
x |
An object of class |
... |
Additional graphical parameters passed to the
|
shadecol1 |
Color for min/max tolerance envelopes generated under the random labeling hypothesis. The default is a dark grey. |
shadecol2 |
Shade color for non-rejection envelopes.
The default is |
main |
A main title for the plot. The default is blank. |
legend |
Logical for whether a legend should
automatically be displayed. Default is |
The solid line indicates the observed difference in the K
functions for the cases and controls. The dashed line
indicates the average difference in the K functions
produced from the data sets simulated under the random
labeling hypothesis when executing the kdest
function. The shaded areas indicate the tolerance envelopes
constructed in x
for tolerance level level
and
the min/max envelopes constructed under the random labeling
hypothesis.
data(grave) kdenv = kdest(grave, nsim = 19, level = 0.9) plot(kdenv) plot(kdenv, legend = TRUE)
data(grave) kdenv = kdest(grave, nsim = 19, level = 0.9) plot(kdenv) plot(kdenv, legend = TRUE)
logrr
function.Plots objects of class logrrenv
produced by the
logrr
function.
## S3 method for class 'logrrenv' plot(x, ..., conlist = list(), main = "")
## S3 method for class 'logrrenv' plot(x, ..., conlist = list(), main = "")
x |
An object of class |
... |
Additional graphical parameters passed to the
|
conlist |
Additional argument passed to the
|
main |
A main title for the plot. Default is blank. |
An important aspect of this plot is the
color argument (col
) used for displaying
the regions outside the non-rejection envelopes. If NULL
(the implicit default), then the default color palette
used by image.im
will be used.
Simpler schemes, e.g., c("blue", "white", "orange") can
suffice. See the examples.
data(grave) ## Not run: logrrsim = logrr(grave, nsim = 9) plot(logrrsim) # no border or ribben (legend). Simple color scheme. plot(logrrsim, col = c("blue", "white", "orange"), ribbon = FALSE, box = FALSE) # alternate color scheme plot(logrrsim, col = topo.colors(12), conlist = list(col = "lightgrey")) ## End(Not run)
data(grave) ## Not run: logrrsim = logrr(grave, nsim = 9) plot(logrrsim) # no border or ribben (legend). Simple color scheme. plot(logrrsim, col = c("blue", "white", "orange"), ribbon = FALSE, box = FALSE) # alternate color scheme plot(logrrsim, col = topo.colors(12), conlist = list(col = "lightgrey")) ## End(Not run)
spscan.test
.Plots object of class scan
from
spscan.test
.
## S3 method for class 'spscan' plot(x, ..., nv = 100, border = NULL, ccol = NULL, clty = NULL, clwd = NULL)
## S3 method for class 'spscan' plot(x, ..., nv = 100, border = NULL, ccol = NULL, clty = NULL, clwd = NULL)
x |
An object of class |
... |
Additional graphical parameters passed to the
|
nv |
The number of vertices when drawing the cluster circles. Default is 100. |
border |
The border color of the circle. Default is NULL, meaning black. |
ccol |
Fill color of the circles. Default is NULL, indicating empty. |
clty |
Line type of circles. Default is NULL,
indicting |
clwd |
Line width of circles. Default is NULL,
indicating |
If border
, ccol
, clty
, or
clwd
are specified, then the length of these
vectors must match nrow(x$coords)
.
data(grave) out = spscan.test(grave, case = 2, alpha = 0.1, nsim = 49) plot(out, chars = c(1, 20), main = "most likely cluster", border = "orange", ccol = NA) # change color, lty, lwd of circles set.seed(2) out2 = spscan.test(grave, case = 2, alpha = 0.8, nsim = 49) plot(out2, chars = c(1, 20), border = "blue") plot(out2, chars = c(1, 20), border = c("blue", "orange"), clwd = c(3, 2), clty = c(2, 3))
data(grave) out = spscan.test(grave, case = 2, alpha = 0.1, nsim = 49) plot(out, chars = c(1, 20), main = "most likely cluster", border = "orange", ccol = NA) # change color, lty, lwd of circles set.seed(2) out2 = spscan.test(grave, case = 2, alpha = 0.8, nsim = 49) plot(out2, chars = c(1, 20), border = "blue") plot(out2, chars = c(1, 20), border = c("blue", "orange"), clwd = c(3, 2), clty = c(2, 3))
kdenv
objectPrint an kdenv
object produced by
kdest
.
## S3 method for class 'kdenv' print(x, ..., extra = FALSE)
## S3 method for class 'kdenv' print(x, ..., extra = FALSE)
x |
An object produced by the
|
... |
Not currently implemented. |
extra |
A logical value indicating whether extra
information related to the internal
|
Information about the kdest
Joshua French
kdenv_summary
objectPrint a kdenv_summary
object
## S3 method for class 'kdenv_summary' print(x, ...)
## S3 method for class 'kdenv_summary' print(x, ...)
x |
An object produced by |
... |
Not currently implemented. |
Print summary
Joshua French
kdplus_test
objectPrint a kdplus_test
object produced by
kdplus.test
.
## S3 method for class 'kdplus_test' print(x, ...)
## S3 method for class 'kdplus_test' print(x, ...)
x |
An object produced by the |
... |
Not currently implemented. |
Information about the test
Joshua French
logrr_test
objectPrint an logrr_test
object produced by
logrr.test
.
## S3 method for class 'logrr_test' print(x, ...)
## S3 method for class 'logrr_test' print(x, ...)
x |
An object produced by the |
... |
Not currently implemented. |
Information about the test
Joshua French
logrrenv
objectPrint a logrrenv
object produced by
logrr
.
## S3 method for class 'logrrenv' print(x, ...)
## S3 method for class 'logrrenv' print(x, ...)
x |
An object produced by the
|
... |
Not currently implemented. |
Information about the logrrenv
Joshua French
spscan.test
.Plots object of class spscan
from
spscan.test
.
## S3 method for class 'spscan' print(x, ..., extra = FALSE)
## S3 method for class 'spscan' print(x, ..., extra = FALSE)
x |
An object of class |
... |
Additional arguments affecting the summary produced. |
extra |
A logical value. Default is |
If border
, ccol
, clty
, or
clwd
are specified, then the length of these
vectors must match nrow(x$coords)
.
data(grave) out = spscan.test(grave, case = 2, alpha = 0.1) out
data(grave) out = spscan.test(grave, case = 2, alpha = 0.1) out
qnn.test
calculates statistics related to the q
nearest neighbors method of comparing case and control
point patterns under the random labeling hypothesis.
qnn.test(x, q = 5, case = 2, nsim = 499, longlat = FALSE)
qnn.test(x, q = 5, case = 2, nsim = 499, longlat = FALSE)
x |
A |
q |
A vector of positive integers indicating the
values of |
case |
The name of the desired "case" group in
|
nsim |
The number of simulations from which to compute p-value. |
longlat |
A logical value indicating whether
Euclidean distance ( |
Returns a list with the following components:
qsum |
A dataframe with the number of neighbors (q), test statistic (Tq), and p-value for each test. |
consum |
A dataframe with the contrasts (contrast), test statistic (Tcon), and p-value (pvalue) for the test of contrasts. |
Joshua French
Waller, L.A., and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
Cuzick, J., and Edwards, R. (1990). Spatial clustering for inhomogeneous populations. Journal of the Royal Statistical Society. Series B (Methodological), 73-104.
Alt, K.W., and Vach, W. (1991). The reconstruction of "genetic kinship" in prehistoric burial complexes-problems and statistics. Classification, Data Analysis, and Knowledge Organization, 299-310.
data(grave) qnn.test(grave, case = "affected", q = c(3, 5, 7, 9, 11, 13, 15))
data(grave) qnn.test(grave, case = "affected", q = c(3, 5, 7, 9, 11, 13, 15))
*S*tatistical *M*thods for the *A*nalysis of *C*ase-control *Po*int *D*ata
Statistical methods for analyzing case-control point data. Methods include the ratio of kernel densities, the difference in K Functions, the spatial scan statistic, and q nearest neighbors of cases.
Run
Maintainer: Joshua French [email protected] (ORCID)
spdensity
computes a kernel smoothed spatial
density function from a point pattern. This function is
basically a wrapper for density.ppp
.
The density.ppp
function computes
the spatial intensity of a point pattern; the spdensity
function scales the intensity to produce a true spatial density.
spdensity( x, sigma = NULL, ..., weights = NULL, edge = TRUE, varcov = NULL, at = "pixels", leaveoneout = TRUE, adjust = 1, diggle = FALSE, kernel = "gaussian", scalekernel = is.character(kernel), positive = FALSE, verbose = TRUE )
spdensity( x, sigma = NULL, ..., weights = NULL, edge = TRUE, varcov = NULL, at = "pixels", leaveoneout = TRUE, adjust = 1, diggle = FALSE, kernel = "gaussian", scalekernel = is.character(kernel), positive = FALSE, verbose = TRUE )
x |
Point pattern (object of class |
sigma |
The smoothing bandwidth (the amount of smoothing).
The standard deviation of the isotropic smoothing kernel.
Either a numerical value,
or a function that computes an appropriate value of |
... |
Additional arguments passed to |
weights |
Optional weights to be attached to the points.
A numeric vector, numeric matrix, an |
edge |
Logical value indicating whether to apply edge correction. |
varcov |
Variance-covariance matrix of anisotropic smoothing kernel.
Incompatible with |
at |
String specifying whether to compute the intensity values
at a grid of pixel locations ( |
leaveoneout |
Logical value indicating whether to compute a leave-one-out
estimator. Applicable only when |
adjust |
Optional. Adjustment factor for the smoothing parameter. |
diggle |
Logical. If |
kernel |
The smoothing kernel.
A character string specifying the smoothing kernel
(current options are |
scalekernel |
Logical value.
If |
positive |
Logical value indicating whether to force all density values to
be positive numbers. Default is |
verbose |
Logical value indicating whether to issue warnings about numerical problems and conditions. |
This function produces the spatial density of x
as an object of class im
.
Joshua French
Waller, L.A. and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
data(grave) contour(spdensity(grave))
data(grave) contour(spdensity(grave))
spscan.test
performs the spatial scan test of Kulldorf (1997) for
case/control point data.
spscan.test( x, case = 2, nsim = 499, alpha = 0.1, maxd = NULL, cl = NULL, longlat = FALSE )
spscan.test( x, case = 2, nsim = 499, alpha = 0.1, maxd = NULL, cl = NULL, longlat = FALSE )
x |
A |
case |
The name of the desired "case" group in
|
nsim |
The number of simulations from which to compute the p-value. A non-negative integer. Default is 499. |
alpha |
The significance level to determine whether a cluster is signficant. Default is 0.1. |
maxd |
The radius of the largest possible cluster to consider. Default
is |
cl |
A cluster object created by |
longlat |
A logical value indicating whether
Euclidean distance ( |
The test is performed using the random labeling hypothesis. The windows are circular and extend from the observed data locations. The clusters returned are non-overlapping, ordered from most significant to least significant. The first cluster is the most likely to be a cluster. If no significant clusters are found, then the most likely cluster is returned (along with a warning).
Setting cl
to a positive integer MAY speed up computations on
non-Windows computers. However, parallelization does have overhead cost, and
there are cases where parallelization results in slower computations.
Returns a list of length two of class
spscan
. The first element (clusters) is a list
containing the significant, non-overlapping clusters,
and has the the following components:
coords |
The centroid of the significant clusters. |
r |
The radius of the window of the clusters. |
pop |
The total population in the cluser window. |
cases |
The observed number of cases in the cluster window. |
expected |
The expected number of cases in the cluster window. |
smr |
Standarized mortaility ratio (observed/expected) in the cluster window. |
rr |
Relative risk in the cluster window. |
propcases |
Proportion of cases in the cluster window. |
loglikrat |
The loglikelihood ratio for the cluster window (i.e., the log of the test statistic). |
pvalue |
The pvalue of the test statistic associated with the cluster window. |
Various additional pieces of information are included for plotting, printing
Joshua French
Kulldorff M., Nagarwalla N. (1995) Spatial disease clusters: Detection and Inference. Statistics in Medicine 14, 799-810.
Kulldorff, M. (1997) A spatial scan statistic. Communications in Statistics – Theory and Methods 26, 1481-1496.
Waller, L.A. and Gotway, C.A. (2005). Applied Spatial Statistics for Public Health Data. Hoboken, NJ: Wiley.
data(grave) # apply scan method out = spscan.test(grave, case = "affected", nsim = 99) # print scan object out print(out, extra = TRUE) # summarize results summary(out) # plot results plot(out, chars = c(1, 20), main = "most likely cluster") # extract clusters from out # each element of the list gives the location index of the events in each cluster clusters(out) # get warning if no significant cluster out2 = spscan.test(grave, case = 2, alpha = 0.001, nsim = 0)
data(grave) # apply scan method out = spscan.test(grave, case = "affected", nsim = 99) # print scan object out print(out, extra = TRUE) # summarize results summary(out) # plot results plot(out, chars = c(1, 20), main = "most likely cluster") # extract clusters from out # each element of the list gives the location index of the events in each cluster clusters(out) # get warning if no significant cluster out2 = spscan.test(grave, case = 2, alpha = 0.001, nsim = 0)
kdenv
objectSummarize the sequences of distances for which the difference in estimated K
functions, KD(r) = K_case(r) - K_control(r)
, falls outside the
non-rejection envelopes.
## S3 method for class 'kdenv' summary(object, ...)
## S3 method for class 'kdenv' summary(object, ...)
object |
An object produced by the |
... |
Not currently implemented. |
A list that contains the sequences of indices for which the estimated difference in KD functions is above the envelopes, below the envelopes, and the vector of distances.
Joshua French
spscan.test
.Summarize object of class scan
from spscan.test
.
## S3 method for class 'spscan' summary(object, ..., idx = seq_along(object$clusters), digits = 1)
## S3 method for class 'spscan' summary(object, ..., idx = seq_along(object$clusters), digits = 1)
object |
An |
... |
Additional arguments affecting the summary produced. |
idx |
An index vector indicating the elements of |
digits |
Integer indicating the number of decimal places. |
Returns/prints a data frame. Each row of the data frame summarizes the centroid of each cluster, the cluster radius, the number of events in the cluster, the number of cases in the cluster, the expected number of cases in the cluster, the relative risk of the cluster (cases/events in cluster)(cases/events outside cluster), the natural logarithm of the test statistic, and the associated p-value.
data(grave) out = spscan.test(grave, nsim = 99, alpha = 0.8) summary(out)
data(grave) out = spscan.test(grave, nsim = 99, alpha = 0.8) summary(out)