Performs a test of Complete Spatial Randomness for a given point pattern, based on quadrat counts. Alternatively performs a goodness-of-fit test of a fitted inhomogeneous Poisson model. By default performs chi-squared tests; can also perform Monte Carlo based tests.
quadrat.test(X, ...)# S3 method for ppp
quadrat.test(X, nx=5, ny=nx,
alternative=c("two.sided", "regular", "clustered"),
method=c("Chisq", "MonteCarlo"),
conditional=TRUE, CR=1,
lambda=NULL, df.est=NULL,
...,
xbreaks=NULL, ybreaks=NULL, tess=NULL,
nsim=1999)
# S3 method for ppm
quadrat.test(X, nx=5, ny=nx,
alternative=c("two.sided", "regular", "clustered"),
method=c("Chisq", "MonteCarlo"),
conditional=TRUE, CR=1, df.est=NULL,
...,
xbreaks=NULL, ybreaks=NULL, tess=NULL,
nsim=1999)
# S3 method for quadratcount
quadrat.test(X,
alternative=c("two.sided", "regular", "clustered"),
method=c("Chisq", "MonteCarlo"),
conditional=TRUE, CR=1,
lambda=NULL, df.est=NULL,
...,
nsim=1999)
A point pattern (object of class "ppp"
)
to be subjected to the goodness-of-fit test.
Alternatively a fitted point process model (object of class
"ppm"
) to be tested.
Alternatively X
can be the result of applying
quadratcount
to a point pattern.
Numbers of quadrats in the xbreaks
and ybreaks
.
Character string (partially matched) specifying the alternative hypothesis.
Character string (partially matched) specifying the test to use:
either method="Chisq"
for the chi-squared test (the default),
or method="MonteCarlo"
for a Monte Carlo test.
Logical. Should the Monte Carlo test be conducted
conditionally upon the observed number of points of the pattern?
Ignored if method="Chisq"
.
Optional. Numerical value. The exponent for the Cressie-Read test statistic. See Details.
Optional. Pixel image (object of class "im"
)
or function (class "funxy"
) giving the predicted
intensity of the point process.
Optional. Advanced use only. The number of fitted parameters, or the number of degrees of freedom lost by estimation of parameters.
Ignored.
Optional. Numeric vector giving the nx
.
Optional. Numeric vector giving the ny
.
Tessellation (object of class "tess"
or something acceptable
to as.tess
) determining the
quadrats. Incompatible with nx, ny, xbreaks, ybreaks
.
The number of simulated samples to generate when
method="MonteCarlo"
.
An object of class "htest"
. See chisq.test
for explanation.
The return value is also an object of the special class
"quadrattest"
, and there is a plot method for this class.
See the examples.
These functions perform
The function quadrat.test
is generic, with methods for
point patterns (class "ppp"
), split point patterns
(class "splitppp"
), point process models
(class "ppm"
) and quadrat count tables (class "quadratcount"
).
if X
is a point pattern, we test the null hypothesis
that the data pattern is a realisation of Complete Spatial
Randomness (the uniform Poisson point process). Marks in the point
pattern are ignored. (If lambda
is given then the null
hypothesis is the Poisson process with intensity lambda
.)
if X
is a split point pattern, then for each of the
component point patterns (taken separately) we test
the null hypotheses of Complete Spatial Randomness.
See quadrat.test.splitppp
for documentation.
If X
is a fitted point process model, then it should be
a Poisson point process model. The
data to which this model was fitted are extracted from the model
object, and are treated as the data point pattern for the test.
We test the null hypothesis
that the data pattern is a realisation of the (inhomogeneous) Poisson point
process specified by X
.
In all cases, the window of observation is divided
into tiles, and the number of data points in each tile is
counted, as described in quadratcount
.
The quadrats are rectangular by default, or may be regions of arbitrary shape
specified by the argument tess
.
The expected number of points in each quadrat is also calculated,
as determined by CSR (in the first case) or by the fitted model
(in the second case).
Then the Pearson
If method="Chisq"
then a m
is the number of
quadrats and quadrat.test.ppp
). The default is to
compute the two-sided alternative
. An important requirement of the
If method="MonteCarlo"
then a Monte Carlo test is performed,
obviating the need for all expected counts to be at least 5. In the
Monte Carlo test, nsim
random point patterns are generated
from the null hypothesis (either CSR or the fitted point process
model). The Pearson
If conditional
is TRUE
then the simulated samples are
generated from the multinomial distribution with the number of “trials”
equal to the number of observed points and the vector of probabilities
equal to the expected counts divided by the sum of the expected counts.
Otherwise the simulated samples are independent Poisson counts, with
means equal to the expected counts.
If the argument CR
is given, then instead of the
Pearson CR=1
gives the Pearson CR=0
gives the likelihood ratio test statistic CR=-1/2
gives the Freeman-Tukey statistic CR=-1
gives the modified likelihood ratio test statistic CR=-2
gives Neyman's modified statistic
The return value is an object of class "htest"
.
Printing the object gives comprehensible output
about the outcome of the test.
The return value also belongs to
the special class "quadrat.test"
. Plotting the object
will display the quadrats, annotated by their observed and expected
counts and the Pearson residuals. See the examples.
Cressie, N. and Read, T.R.C. (1984) Multinomial goodness-of-fit tests. Journal of the Royal Statistical Society, Series B 46, 440--464.
quadrat.test.splitppp
,
quadratcount
,
quadrats
,
quadratresample
,
chisq.test
,
cdf.test
.
To test a Poisson point process model against a specific alternative,
use anova.ppm
.
# NOT RUN {
quadrat.test(simdat)
quadrat.test(simdat, 4, 3)
quadrat.test(simdat, alternative="regular")
quadrat.test(simdat, alternative="clustered")
## Likelihood ratio test
quadrat.test(simdat, CR=0)
## Power divergence tests
quadrat.test(simdat, CR=-1)$p.value
quadrat.test(simdat, CR=-2)$p.value
# Using Monte Carlo p-values
quadrat.test(swedishpines) # Get warning, small expected values.
# quadrat.test(swedishpines, method="M", nsim=4999)
# quadrat.test(swedishpines, method="M", nsim=4999, conditional=FALSE)
# }
# NOT RUN {
# quadrat counts
qS <- quadratcount(simdat, 4, 3)
quadrat.test(qS)
# fitted model: inhomogeneous Poisson
fitx <- ppm(simdat ~ x)
quadrat.test(fitx)
# an equivalent test (results differ due to discretisation effects):
quadrat.test(simdat, lambda=predict(fitx), df.est=length(coef(fitx)))
te <- quadrat.test(simdat, 4)
residuals(te) # Pearson residuals
plot(te)
plot(simdat, pch="+", cols="green", lwd=2)
plot(te, add=TRUE, col="red", cex=1.4, lty=2, lwd=3)
sublab <- eval(substitute(expression(p[chi^2]==z),
list(z=signif(te$p.value,3))))
title(sub=sublab, cex.sub=3)
# quadrats of irregular shape
B <- dirichlet(runifpoint(6, Window(simdat)))
qB <- quadrat.test(simdat, tess=B)
plot(simdat, main="quadrat.test(simdat, tess=B)", pch="+")
plot(qB, add=TRUE, col="red", lwd=2, cex=1.2)
# }
Run the code above in your browser using DataLab