global_envelope_test_2d: 2D global envelope test

Description Usage Arguments Value References Examples

View source: R/envelopes2d.r

Description

Provides global envelope tests based on 2D functions

Usage

1
global_envelope_test_2d(obs, sim, rx, ry, ...)

Arguments

obs

A 2d matrix or 3d array containing the observed 2d functions.

sim

A 3d array containing the simulated 2d functions.

rx

Argument values for x-coordinate (first dimension of 2d functions).

ry

Argument values for y-coordinate (second dimension of 2d functions).

...

Additional parameters to be passed to global_envelope_test.

Value

An object of class "global_envelope_2d" (and "list"), which can be printed and plotted directly.

Essentially a data frame containing columns

Additionally, the return value has attributes method, type, alternative, k_alpha, alpha, k, p (and p_interval and ties if type is 'rank') and call, see more detailed description in global_envelope_test.

References

Mrkvička, T., Soubeyrand, S., Myllymäki, M., Grabarnik, P. and Hahn, U. (2016). Monte Carlo testing in spatial statistics, with applications to spatial residuals. Spatial Statistics 18, Part A: 40–53. doi: 10.1016/j.spasta.2016.04.005

Myllymäki, M., Mrkvička, T., Grabarnik, P., Seijo, H. and Hahn, U. (2017). Global envelope tests for spatial point patterns. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 79: 381–404. doi: 10.1111/rssb.12172

Mrkvička, T., Hahn, U. and Myllymäki, M. (2018). A one-way ANOVA test for functional data with graphical interpretation. arXiv:1612.03608 [stat.ME]

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Example of spatial point pattern residuals
#-------------------------------------------
if(require(spatstat, quietly=TRUE)) {
  data(cells)
  X <- cells
  # Fit the hard-core process
  model <- ppm(X, interaction=Hardcore())
  summary(model)
  HD <- 0.08168525 # Hard-core process
  # Choose a bandwitdh by Scott's rule of thumb
  ds <- bw.scott(X); ds
  # Calculate raw residuals of the fitted model
  u <- diagnose.ppm(model, type="raw", rbord = HD, which ="smooth",
                    sigma=ds, plot.it=FALSE)
  obs <- u$smooth$Z$v
  # Generate simulations from the hard-core null model
  nsim <- 1999
  simulations <- NULL
  ext.factor <- max(X$window$xrange[2]-X$window$xrange[1],
                    X$window$yrange[2]-X$window$yrange[1]) / 10
  win.extend <- owin(c(X$window$xrange[1]-ext.factor, X$window$xrange[2]+ext.factor),
                     c(X$window$yrange[1]-ext.factor, X$window$yrange[2]+ext.factor))
  mod02 <- list(cif="hardcore", par=list(beta=exp(model$fitin$coefs[1]),hc=HD), w=win.extend)
  # starting point pattern in an extended window
  x.start <- runifpoint(X$n, win=win.extend)
  # simulations
  for(sss in 1:nsim){
    uppp <- rmh(model=mod02, start=list(x.start=x.start), control=list(p=1,nrep=1e5,nverb=5000))
    f <- uppp$x > X$window$xrange[1] & uppp$x < X$window$xrange[2] &
         uppp$y > X$window$yrange[1] & uppp$y < X$window$yrange[2]
    simulations[[sss]] <- ppp(uppp$x[f], uppp$y[f], window=X$window)
  }
  # Calculate the raw residuals for simulations
  sim <- array(0, c(nsim, u$smooth$Z$dim))
  for(i in 1:length(simulations)) {
    model=ppm(simulations[[i]],interaction=Hardcore(HD));
    u_sim <- diagnose.ppm(model, type="raw", rbord = HD, which ="smooth", sigma=ds, plot.it=FALSE)
    sim[i,,] <- u_sim$smooth$Z$v
    if((i %% 100)==0) cat(i, ' ')
  }
  # Constract the global envelope test for the (2D) raw residuals
  res <- global_envelope_test_2d(obs, sim)
  par(mfrow=c(2,3))
  plot(res)
}

myllym/GET documentation built on Sept. 30, 2018, 5:49 a.m.