Description Details Typical workflow Summary Further options and functions Author(s) References
The spptest library provides global envelope and deviation tests. Both type of tests are Monte Carlo tests, which demand simulations from the tested null model. Examples are mainly for spatial point processes, but the methods are applicable for any functional (or multivariate vector) data. (In the case of point processes, the functions are typically estimators of summary functions.) The main motivation for this package are the scalings for deviation tests and global envelope tests.
The package supports the use of the R library spatstat for generating simulations and calculating estimators of the chosen summary function, but alternatively these can be done by any other methods, thus allowing for any models/functions.
In the following, the use of the spptest library is demonstrated by its main function rank_envelope
,
but alternatively this step can be replaced by a call of another function for envelope or
deviation test (the main options are st_envelope
, qdir_envelope
,
deviation_test
).
1) The workflow utilizing spatstat:
E.g. Say we have a point pattern, for which we would like to test a hypothesis, as a ppp
object.
X <- spruces # an example pattern from spatstat
Test complete spatial randomness (CSR):
Use envelope
to create nsim simulations
under CSR and to calculate the functions you want.
Important: use the option 'savefuns=TRUE' and
specify the number of simulations nsim
.
See the help documentation in spatstat
for possible test functions (if fun
not given, Kest
is used,
i.e. an estimator of the K function).
Making 2499 simulations of CSR (note the number of points is not fixed here) and estimating K-function for each of them and data:
env <- envelope(X, nsim=2499, savefuns=TRUE)
Perform the test
res <- rank_envelope(env)
Plot the result
plot(res)
A goodness-of-fit of a parametric model (composite hypothesis case)
Fit the model to your data by means of the function
ppm
or kppm
.
See the help documentation for possible models.
Use dg.global_envelope
to create nsim simulations
from the fitted model, to calculate the functions you want,
and to make an adjusted global envelope test (either rank,
directional quantile or studentized global envelope test).
See the detailed example in saplings
.
Plot the result
plot(res)
2) The random labeling test with a mark-weighted K-function
Generate simulations (permuting marks) and estimate the chosen marked K_f-function for each pattern
using the function random_labelling
(requires R library marksummary
available from
https://github.com/myllym/
).
curve_set <- random_labelling(mpp, mtf_name = 'm', nsim=2499, r_min=1.5, r_max=9.5)
Then do the test and plot the result
res <- rank_envelope(curve_set); plot(res)
3) The workflow when using your own programs for simulations:
(Fit the model and) Create nsim simulations from the (fitted) null model.
Calculate the functions T_1(r), T_2(r), ..., T_nsim+1(r).
Use create_curve_set
to create a curve_set object
from the functions T_i(r), i=1,...,s+1.
Perform the test and plot the result
res <- rank_envelope(curve_set) # curve_set is the 'curve_set'-object you created
plot(res)
Note that for calculating an adjusted global envelope test for a composite hypothesis test,
you need to write some of your own code as the function dg.global_envelope
allows just models that can be simulated and fitted using spatstat.
Thus, to perform a test you always first need to obtain the test function T(r) for your data (T_1(r)) and for each simulation (T_2(r), ..., T_nsim+1(r)) in one way or another. Given the set of the functions T_i(r), i=1,...,nsim+1, you can perform a test by one of the following functions provided in this library:
Envelope tests:
rank_envelope
, the completely non-parametric rank envelope test
st_envelope
, the studentised envelope test, protected against unequal variance of T(r) for different distances r
qdir_envelope
, the directional quantile envelope test, protected against unequal variance and asymmetry of T(r) for different distances r
normal_envelope
, a parametric envelope test, which uses a normal approximation of T(r)
Deviation tests (no graphical interpretation):
deviation_test
Note that the recommended minimum number of simulations for the rank envelope test is nsim=2499, while, for the studentised and directional quantile envelope tests and deviation tests, it is nsim=99 (or 999). (For the normal test, see its documentation.)
See, in particular, rank_envelope
for further examples.
It is possible to modify the curve set T_1(r), T_2(r), ..., T_nsim+1(r) for the test.
(i) You can choose the interval of distances [r_min, r_max] by crop_curves
.
(ii) For better visualisation, you can take T(r)-T_0(r) by residual
.
Here T_0(r) is the expectation of T(r) under the null hypothesis.
The function envelope_to_curve_set
can be used to create a curve_set object
from the object returned by envelope
. An envelope
object can also
directly be given to the functions crop_curves
and residual
.
Further, as a further reminder, for composite hypotheses the library provides the function
dg.global_envelope
. See a detailed example in saplings
.
Mari Myllymäki (mari.j.myllymaki@gmail.com, mari.myllymaki@luke.fi), Henri Seijo (henri.seijo@aalto.fi, henri.seijo@iki.fi), Tomáš Mrkvička (mrkvicka.toma@gmail.com), Pavel Grabarnik (gpya@rambler.ru), Ute Hahn (ute@math.au.dk)
Myllymäki, M., Grabarnik, P., Seijo, H. and Stoyan. D. (2015). Deviation test construction and power comparison for marked spatial point patterns. Spatial Statistics 11, 19-34. doi: 10.1016/j.spasta.2014.11.004
Myllymäki, M., Mrkvička, T., Grabarnik, P., Seijo, H. and Hahn, U. (2016). Global envelope tests for spatial point patterns. Journal of the Royal Statistical Society: Series B (Statistical Methodology). doi: 10.1111/rssb.12172
Mrkvička, T., Myllymäki, M. and Hahn, U. (2016). Multiple Monte Carlo testing, with applications in spatial point processes. Statistics & Computing, accepted. (Preprint: arXiv:1506.01646 [stat.ME])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.