| Title: | Tests for First-Order Separability in Spatio-Temporal Point Processes |
|---|---|
| Description: | Provides statistical tools for testing first-order separability in spatio-temporal point processes, that is, whether the spatio-temporal intensity function can be expressed as a product of spatial and temporal components. The package implements several hypothesis tests, including exact and asymptotic methods for Poisson and non-Poisson processes. Methods include global envelope tests, chi-squared-type statistics, and a novel Hilbert-Schmidt independence criterion (HSIC) test with block or pure permutations. Simulation studies and real-world examples, including the 2001 UK foot-and-mouth disease outbreak data, illustrate its utility. The package encompasses all simulation studies and applications presented in Ghorbani et al. (2021, 2025). |
| Authors: | Mohammad Ghorbani [author, creator], Nafiseh Vafaei [author] |
| Maintainer: | Mohammad Ghorbani <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.1 |
| Built: | 2026-06-04 10:01:34 UTC |
| Source: | https://github.com/mghorbani01/septest |
Permutes the temporal component of a spatio-temporal dataset in a block-wise manner while keeping the spatial coordinates fixed. This is used to generate permuted replicates under the null model of first-order separability.
block.permut(nblocks, X, nperm = 1999)block.permut(nblocks, X, nperm = 1999)
nblocks |
Integer (>= 2). Number of consecutive temporal blocks after ordering events by time. |
X |
Numeric matrix or data frame with at least three columns |
nperm |
Integer (>= 1). Number of permuted datasets to generate. At most
|
The function first orders the events by time and partitions the ordered sequence into
nblocks consecutive blocks of equal size. The block labels are permuted (excluding the identity
permutation), and the time values are reassigned according to the permuted block order.
If nrow(X) is not divisible by nblocks, the last nrow(X) %% nblocks events are not
included in the block permutation and are appended unchanged to each permuted dataset.
For details of the block permutation procedure, see the Supplementary Materials in Ghorbani et al. (2025).
sim.procedures covers both pure and block permutation methods.
A list of length min(nperm, factorial(nblocks) - 1). Each element is a matrix with the same
number of columns as X; the third column contains the block-permuted time values.
Ghorbani, M., Vafaei, N. and Myllymäki, M. (2025). A kernel-based test for the first-order separability of spatio-temporal point processes, TEST.
set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) perms <- block.permut(nblocks = 5, X = X, nperm = 10) head(perms[[1]], 5)set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) perms <- block.permut(nblocks = 5, X = X, nperm = 10) head(perms[[1]], 5)
Computes spatial and temporal bandwidths for kernel-based estimation of the intensity of a
spatio-temporal point pattern. The spatial bandwidth is estimated from the spatial coordinates
using Diggle's (1985) mean-square error method via bw.diggle.
The temporal bandwidth is estimated from the time coordinates using the Sheather–Jones
direct plug-in method (bw = "SJ-dpi") as implemented in density.
calc.bandwidths.and.edgecorr( X, s.region, t.region, n.grid, epsilon = NULL, delta = NULL )calc.bandwidths.and.edgecorr( X, s.region, t.region, n.grid, epsilon = NULL, delta = NULL )
X |
A numeric matrix or data frame with at least three columns giving the |
s.region |
A numeric matrix with two columns giving the vertices of the polygonal spatial observation window in order (the first vertex need not be repeated at the end). |
t.region |
A numeric vector of length 2 giving the temporal observation window
|
n.grid |
An integer vector of length 3 giving the number of grid cells in the |
epsilon |
Optional positive numeric. Spatial bandwidth. If |
delta |
Optional positive numeric. Temporal bandwidth. If |
Edge-correction factors are computed for Gaussian kernels as the kernel mass inside the
observation window: . The temporal correction is computed
exactly on t.region. The spatial correction is computed using a bounding-box
approximation of the polygonal spatial window (i.e., W is replaced by its bounding
rectangle).
The spatial window is converted to an owin object, and the spatial
bandwidth is estimated using bw.diggle on the corresponding ppp
object. The temporal bandwidth is taken as the bandwidth selected by density with
bw = "SJ-dpi" over the interval t.region.
The returned edge-correction factors are kernel masses inside the window. If you use them for intensity estimation with edge correction, typical usage is to divide by these factors.
A list with components:
Numeric vector of length 3: c(epsilon, epsilon, delta).
Numeric vector of length nrow(X) giving temporal edge masses
.
Numeric vector of length nrow(X) giving spatial edge masses computed on the
bounding box of s.region.
Baddeley A, Rubak E, Turner R (2015). Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Diggle, P.J. (1985). A Kernel Method for Smoothing Point Process Data. Journal of the Royal Statistical Society, Series C, 34, 138–147.
set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol = 2, byrow = TRUE) t.region <- c(0, 10) n.grid <- c(25, 25, 20) res <- calc.bandwidths.and.edgecorr(X, s.region, t.region, n.grid) str(res)set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol = 2, byrow = TRUE) t.region <- c(0, 10) n.grid <- c(25, 25, 20) res <- calc.bandwidths.and.edgecorr(X, s.region, t.region, n.grid) str(res)
Checks the validity of common inputs used by spatio-temporal estimation and simulation
routines: event locations X, spatial window specification s.region, temporal window
t.region, and grid resolution n.grid.
check.args(X, s.region, t.region, n.grid = c(25L, 25L, 20L))check.args(X, s.region, t.region, n.grid = c(25L, 25L, 20L))
X |
A matrix or data frame with at least three columns giving event coordinates
|
s.region |
Spatial observation region specification. Either:
All values must be finite. |
t.region |
Numeric vector of length 2 giving |
n.grid |
Integer vector of length 3 giving the number of grid cells in the |
This function is intended as a lightweight argument checker used internally by multiple functions. It can also be called directly for debugging input issues.
Invisibly returns NULL. Called for its side effect of throwing an error if inputs are invalid.
X <- cbind(runif(100), runif(100), runif(100, 0, 10)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol = 2, byrow = TRUE) t.region <- c(0, 10) check.args(X, s.region, t.region, n.grid = c(25, 25, 20))X <- cbind(runif(100), runif(100), runif(100, 0, 10)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol = 2, byrow = TRUE) t.region <- c(0, 10) check.args(X, s.region, t.region, n.grid = c(25, 25, 20))
Performs a chi-squared test for testing first-order separability of a spatio-temporal point process. Two procedures are available:
"pure_per"Classical asymptotic chi-squared test of independence on a space–time count table.
"block_per"Monte Carlo permutation test based on block-wise permutations of the time component.
chi2.test( X, sim.procedure = c("pure_per", "block_per"), nblocks = 5L, nperm = 199L, n.time = 2L, n.space = 3L, t.region = c(0, 1), s.region = c(0, 1, 0, 1) )chi2.test( X, sim.procedure = c("pure_per", "block_per"), nblocks = 5L, nperm = 199L, n.time = 2L, n.space = 3L, t.region = c(0, 1), s.region = c(0, 1, 0, 1) )
X |
A numeric matrix or data frame with at least three columns giving event coordinates
|
sim.procedure |
Character string specifying the procedure: |
nblocks |
Integer (>= 2). Number of temporal blocks used for block permutation (only for |
nperm |
Integer (>= 1). Number of Monte Carlo permutations (only for |
n.time |
Integer (>= 2). Number of temporal intervals in the contingency table. |
n.space |
Integer (>= 2). The spatial domain is partitioned into |
t.region |
Numeric vector of length 2 giving the temporal window |
s.region |
Spatial window specification. By default, the bounding box |
The classical procedure ("pure_per") applies a chi-squared test of independence to the
n.space^2 by n.time contingency table of counts.
The permutation procedure ("block_per") generates nperm block-permuted datasets under the null
using sim.procedures with method = "block", recomputes the chi-squared statistic for each,
and returns a Monte Carlo p-value computed as .
Numeric scalar: the p-value of the test.
Mohammad Ghorbani [email protected]
Nafiseh Vafaei [email protected]
Ghorbani M., Vafaei N., Dvořák J., Myllymäki M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics and Data Analysis, 161, 107245.
Ghorbani, M., Vafaei, N. and Myllymäki, M. (2025). A kernel-based test for the first-order separability of spatio-temporal point processes, TEST.
chisq.test.stPP, sim.procedures, block.permut
set.seed(124) lambda <- get.lambda.function(N = 200, g = 50, model = 4) Lmax <- get.lambda.max(N = 200, g = 50, model = 4) X <- rstpoispp(lambda, Lmax) # Classical chi-squared test chi2.test(X, sim.procedure = "pure_per", n.time = 2, n.space = 3) # Monte Carlo permutation test with blocks chi2.test(X, sim.procedure = "block_per", nblocks = 5, nperm = 100)set.seed(124) lambda <- get.lambda.function(N = 200, g = 50, model = 4) Lmax <- get.lambda.max(N = 200, g = 50, model = 4) X <- rstpoispp(lambda, Lmax) # Classical chi-squared test chi2.test(X, sim.procedure = "pure_per", n.time = 2, n.space = 3) # Monte Carlo permutation test with blocks chi2.test(X, sim.procedure = "block_per", nblocks = 5, nperm = 100)
Performs the classical (asymptotic) chi-squared test of first-order separability by constructing a space–time contingency table of counts and applying a chi-squared test of independence.
chisq.test.stPP( X, n.space = 2L, n.time = 3L, s.region = c(0, 1, 0, 1), t.region = c(0, 1) )chisq.test.stPP( X, n.space = 2L, n.time = 3L, s.region = c(0, 1, 0, 1), t.region = c(0, 1) )
X |
A numeric matrix or data frame with at least three columns giving event coordinates
|
n.space |
Integer (>= 2). Number of bins per spatial axis. The contingency table has
|
n.time |
Integer (>= 2). Number of temporal bins (columns of the contingency table). |
s.region |
Numeric vector of length 4 giving the spatial bounding box
|
t.region |
Numeric vector of length 2 giving the temporal window |
The spatial domain is partitioned into n.space bins in each coordinate direction
(yielding n.space^2 spatial cells), and the temporal domain is partitioned into
n.time intervals. Bin boundaries are defined using empirical quantiles of the
observed coordinates, with the first/last boundaries fixed to the provided spatial and
temporal windows.
This implementation uses chisq.test on the contingency table of space–time counts.
If expected counts are very small, the chi-squared approximation may be poor; in that case consider
using a Monte Carlo approach (e.g., block permutation) as implemented in chi2.test.
A list with components:
Numeric scalar. The chi-squared test statistic.
Numeric scalar. The p-value of the chi-squared test.
Integer matrix of dimension n.space^2 by n.time containing the space–time counts.
Jiří Dvořák [email protected]
Ghorbani M., Vafaei N., Dvořák J., Myllymäki M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics and Data Analysis, 161, 107245.
lambda <- get.lambda.function(N = 200, g = 50, model = 4) Lmax <- get.lambda.max(N = 200, g = 50, model = 4) X <- rstpoispp(lambda, Lmax) result <- chisq.test.stPP(X, n.space = 2, n.time = 2) print(result)lambda <- get.lambda.function(N = 200, g = 50, model = 4) Lmax <- get.lambda.max(N = 200, g = 50, model = 4) X <- rstpoispp(lambda, Lmax) result <- chisq.test.stPP(X, n.space = 2, n.time = 2) print(result)
Performs a nonparametric test of first-order separability between space and time in a spatio-temporal point process using the distance-based Hilbert–Schmidt independence criterion (dHSIC). The test statistic evaluates whether the spatio-temporal intensity can be factorized as a function of spatial coordinate times as a function of temporal coordinate.
dHS.test( X, sim.procedure = c("pure_per", "block_per"), nblocks = 7L, nperm = 1999L, nsim = 199L, bandwidth = NULL )dHS.test( X, sim.procedure = c("pure_per", "block_per"), nblocks = 7L, nperm = 1999L, nsim = 199L, bandwidth = NULL )
X |
A numeric matrix or data frame with at least three columns giving event coordinates
|
sim.procedure |
Character string specifying the permutation strategy:
|
nblocks |
Integer (>= 2). Number of temporal blocks for block permutation (only for |
nperm |
Integer (>= 1). Number of block permutations (only for |
nsim |
Integer (>= 1). Number of pure permutations (only for |
bandwidth |
Optional numeric. Fixed bandwidth to use with |
Two permutation strategies are supported:
"pure_per"Randomly permutes the time component across events.
"block_per"Uses block-wise permutation of the time component via sim.procedures
with method = "block" to preserve short-range temporal dependence.
The Monte Carlo p-value is computed with the standard +1 correction:
, where is the number of permutations.
A list with components:
Monte Carlo p-value based on the adaptive-bandwidth Gaussian kernel.
Monte Carlo p-value based on the fixed-bandwidth Gaussian kernel, or NA if bandwidth = NULL.
Bandwidth selected by dHSIC::dhsic(..., kernel = "gaussian").
The dHSIC method is implemented via the dHSIC package. When sim.procedure = "pure_per",
dHS.test() internally calls global.envelope.test for computational efficiency.
Ghorbani, M., Vafaei, N. and Myllymäki, M. (2025). A kernel-based test for the first-order separability of spatio-temporal point processes, TEST.
sim.procedures, block.permut, chi2.test
if (requireNamespace("dHSIC", quietly = TRUE)) { set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) # Pure permutation test result <- dHS.test(sim.procedure = "pure_per", X = X, nsim = 199, bandwidth = 0.05) print(result$p.value) # Block permutation test result_block <- dHS.test(sim.procedure = "block_per", X = X, nblocks = 5, nperm = 100, bandwidth = 0.05) print(result_block$p.value.bw) }if (requireNamespace("dHSIC", quietly = TRUE)) { set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) # Pure permutation test result <- dHS.test(sim.procedure = "pure_per", X = X, nsim = 199, bandwidth = 0.05) print(result$p.value) # Block permutation test result_block <- dHS.test(sim.procedure = "block_per", X = X, nblocks = 5, nperm = 100, bandwidth = 0.05) print(result_block$p.value.bw) }
Computes kernel-smoothed estimates of spatial, temporal, separable, and non-separable spatio-temporal intensity functions on a regular space-time grid, together with separability diagnostics used in first-order separability analysis.
estimate.intensity.pixel(X, s.region, t.region, n.grid, edge, owin = NULL)estimate.intensity.pixel(X, s.region, t.region, n.grid, edge, owin = NULL)
X |
Numeric matrix/data.frame with three columns |
s.region |
Numeric matrix with two columns defining the spatial window (typically polygon vertices).
Grid limits are taken as |
t.region |
Numeric vector of length 2 giving the temporal window |
n.grid |
Integer vector of length 3 giving grid resolution in |
edge |
List with components |
owin |
Optional observation window of class |
The estimator uses product Gaussian kernels with supplied bandwidths and (Gaussian)
edge-correction factors, typically produced by calc.bandwidths.and.edgecorr.
A list with grid coordinates x,y,t, intensity estimates, the diagnostic S.fun,
its marginal summaries S.space and S.time, and deviation measures.
Ghorbani, M., Vafaei, N., Dvořák, J., and Myllymäki, M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
S.based.functions, calc.bandwidths.and.edgecorr
n <- 100 X <- cbind(x = stats::runif(n), y = stats::runif(n), t = stats::runif(n, 0, 10)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol=2, byrow=TRUE) t.region <- c(0, 10) n.grid <- c(10, 10, 5) edge <- list(bw = c(0.05, 0.05, 0.5), space = rep(1, n), time = rep(1, n)) res <- estimate.intensity.pixel(X, s.region, t.region, n.grid, edge) str(res)n <- 100 X <- cbind(x = stats::runif(n), y = stats::runif(n), t = stats::runif(n, 0, 10)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol=2, byrow=TRUE) t.region <- c(0, 10) n.grid <- c(10, 10, 5) edge <- list(bw = c(0.05, 0.05, 0.5), space = rep(1, n), time = rep(1, n)) res <- estimate.intensity.pixel(X, s.region, t.region, n.grid, edge) str(res)
Computes kernel-based spatial, temporal, separable, and non-separable intensity
estimates evaluated at the observed spatio-temporal event locations. The function
also returns the separability diagnostic and global deviation measures
quantifying departures from first-order separability.
estimate.intensity.point(X, n.grid, edge)estimate.intensity.point(X, n.grid, edge)
X |
Numeric matrix/data.frame with three columns |
n.grid |
Integer. Included for API compatibility with grid-based routines; not used. |
edge |
List with components |
Pairwise Gaussian kernel weights are computed in each dimension and diagonal entries are set to zero to remove self-contributions.
A list with components S.fun, deviation measures, and estimated
intensity components at the observed points.
X <- cbind(stats::runif(50), stats::runif(50), stats::runif(50)) edge <- list(bw = c(0.1, 0.1, 0.1), space = 1, time = 1) res <- estimate.intensity.point(X, n.grid = 50, edge = edge) str(res)X <- cbind(stats::runif(50), stats::runif(50), stats::runif(50)) edge <- list(bw = c(0.1, 0.1, 0.1), space = 1, time = 1) res <- estimate.intensity.point(X, n.grid = 50, edge = edge) str(res)
It returns estimates of the full spatio-temporal intensity together with its
spatial and temporal marginal components.
The output also includes the test statistic
and its spatial and temporal marginal profiles
and
(equations (11)–(13) in Ghorbani et al., 2021),
as well as several deviation tests (e.g., equation (15) in Ghorbani et al., 2021)
that quantify departures from first-order separability.
estimate.st.intensity( X, s.region, t.region, at = c("pixels", "points"), n.grid = c(25, 25, 20) )estimate.st.intensity( X, s.region, t.region, at = c("pixels", "points"), n.grid = c(25, 25, 20) )
X |
A numeric matrix with three columns giving the event coordinates
( |
s.region |
A numeric matrix with two columns defining the polygonal boundary of the spatial observation region. |
t.region |
A numeric vector of length 2 specifying the temporal observation window. |
at |
Character string; either |
n.grid |
A numeric vector of length 3 giving the number of grid cells in
the |
The estimation follows the kernel framework of
Ghorbani et al. (2021). A Gaussian kernel is applied in each
spatial and temporal dimension. Spatial bandwidths are estimated using
Diggle’s method, and the temporal bandwidth is obtained by the
Sheather–Jones direct plug-in (SJ-DPI) approach
(see calc.bandwidths.and.edgecorr for implementation details).
Edge corrections are computed analytically using Gaussian tail probabilities
(see calc.bandwidths.and.edgecorr for implementation details).
The non-separable intensity estimate is
where , and and are Gaussian kernels with spatial and temporal
bandwidths and . and are spatial and temporal edge corrections, respectively.
For estimate of the separable counterparts and more details see equations (3)-(5) in Ghorbani et al., 2021).
The separability test is:
where is the number of observed points.
Several deviation statistics are provided to quantify departures from separability
deviation.t1: Integral of absolute deviations .
deviation.t2: Integral of absolute deviation of inverse intensities .
deviation.t3: Sum of log-ratio deviations .
deviation.t4: Integral of the S-function.
When at = "points", intensities and diagnostics are evaluated at
the observed event locations.
A list containing:
Grid vectors for x, y, and t (returned only when at = "pixels").
Estimated spatial bandwidth used in Gaussian kernels.
Estimated temporal bandwidth.
Estimated spatial intensity surface (pixels only).
Estimated temporal intensity profile (pixels only).
Separable spatio-temporal intensity estimate.
Non-separable spatio-temporal intensity estimate.
Test function as the ratio of non-separable to separable intensity estimates.
Marginal sum of over time (space profile).
Marginal sum of over space (time profile).
Deviation statistic: Integral of absolute deviations.
Deviation statistic: absolute deviation of inverse intensities.
Deviation statistic: sum of log-ratio deviations.
Total integral of the S-function.
Mohammad Ghorbani [email protected]
Nafiseh Vafaei [email protected]
Ghorbani M., Vafaei N., Dvořák J., Myllymäki M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
calc.bandwidths.and.edgecorr,
global.envelope.test,
chi2.test,
dHS.test
set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) s.region <- matrix(c(0, 0, 1, 0, 1, 1, 0, 1), ncol = 2, byrow = TRUE) t.region <- c(0, 10) result <- estimate.st.intensity(X, s.region, t.region, at = "pixels", n.grid = c(64, 64, 32)) str(result$S.fun) image(result$S.fun[,,5], main = "S-function slice at t[5]", col = topo.colors(50)) contour(result$S.fun[,,5], add=TRUE) str(result[c("deviation.t1","deviation.t3","deviation.t4")])set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) s.region <- matrix(c(0, 0, 1, 0, 1, 1, 0, 1), ncol = 2, byrow = TRUE) t.region <- c(0, 10) result <- estimate.st.intensity(X, s.region, t.region, at = "pixels", n.grid = c(64, 64, 32)) str(result$S.fun) image(result$S.fun[,,5], main = "S-function slice at t[5]", col = topo.colors(50)) contour(result$S.fun[,,5], add=TRUE) str(result[c("deviation.t1","deviation.t3","deviation.t4")])
Simulates a space–time Gaussian random field on a regular grid.
The field is returned as a 3D array and can be used as a latent field for
log-Gaussian Cox process (LGCP) simulation.
Gauss.st.F( xlim = c(0, 1), ylim = c(0, 1), tlim = c(0, 1), par1 = c(1, 0.05), par2 = c(1, 0.06), sigmas = c(0.5, 0.5, 1), grid = c(15L, 15L, 10L) )Gauss.st.F( xlim = c(0, 1), ylim = c(0, 1), tlim = c(0, 1), par1 = c(1, 0.05), par2 = c(1, 0.06), sigmas = c(0.5, 0.5, 1), grid = c(15L, 15L, 10L) )
xlim, ylim, tlim
|
Numeric vectors of length 2 giving the ranges for the spatial and temporal
axes. Defaults are |
par1 |
Numeric vector of length 2 giving the temporal covariance parameters
|
par2 |
Numeric vector of length 2 giving the spatial covariance parameters
|
sigmas |
Numeric vector of length 3 specifying the weights
|
grid |
Integer vector of length 3 giving the number of grid points in the |
The simulated field is a weighted sum of three independent Gaussian components:
where is a purely spatial field, is a purely temporal field,
and is a spatio-temporal field with separable exponential covariance
in space and time.
The function uses mvrnorm for multivariate normal simulation
and rdist to compute pairwise distances for covariance
matrix construction.
Spatial and temporal covariances are exponential. The spatio-temporal component uses a separable
covariance . Simulation is performed via Cholesky
factors without constructing the full covariance matrix.
A list with components:
Numeric array of dimension c(nx, ny, nt) containing simulated field values.
Numeric vector of length nx with x-grid coordinates.
Numeric vector of length ny with y-grid coordinates.
Numeric vector of length nt with time-grid coordinates.
Mohammad Ghorbani [email protected]
Nafiseh Vafaei [email protected]
Ghorbani M., Vafaei N., Dvořák J., Myllymäki M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics and Data Analysis, 161, 107245.
if (requireNamespace("MASS", quietly = TRUE) && requireNamespace("fields", quietly = TRUE)) { set.seed(1) field <- Gauss.st.F( xlim = c(0, 1), ylim = c(0, 1), tlim = c(0, 1), par1 = c(1, 0.05), par2 = c(1, 0.06), sigmas = c(0.5, 0.5, 1), grid = c(15, 15, 10) ) # Inspect dimensions and visualize one time slice dim(field$Z) image(field$xcoord, field$ycoord, field$Z[, , 1], main = "Gaussian Random Field (t = 1)", col = RColorBrewer::brewer.pal(11, "Spectral")) }if (requireNamespace("MASS", quietly = TRUE) && requireNamespace("fields", quietly = TRUE)) { set.seed(1) field <- Gauss.st.F( xlim = c(0, 1), ylim = c(0, 1), tlim = c(0, 1), par1 = c(1, 0.05), par2 = c(1, 0.06), sigmas = c(0.5, 0.5, 1), grid = c(15, 15, 10) ) # Inspect dimensions and visualize one time slice dim(field$Z) image(field$xcoord, field$ycoord, field$Z[, , 1], main = "Gaussian Random Field (t = 1)", col = RColorBrewer::brewer.pal(11, "Spectral")) }
Returns an intensity function corresponding to one of four
models used for simulation experiments in Ghorbani et al. (2021). Each model is a
mixture of a separable "background" component and a structured (generally non-separable)
spatio-temporal Gaussian bump. The models provide different degrees of
space–time separability, allowing for controlled experiments on separability testing.
get.lambda.function( N, g, model = 1L, mu1 = 0.5, sd1 = 0.2, mu2 = c(0.5, 0.5), sd2 = c(0.2, 0.2), mu3 = c(0.3, 0.3, 0.2), sd3 = c(0.05, 0.05, 0.05) )get.lambda.function( N, g, model = 1L, mu1 = 0.5, sd1 = 0.2, mu2 = c(0.5, 0.5), sd2 = c(0.2, 0.2), mu3 = c(0.3, 0.3, 0.2), sd3 = c(0.05, 0.05, 0.05) )
N |
Numeric scalar (> 0). Baseline intensity level (interpreted as an expected total count after scaling in the calling simulator; see details below). |
g |
Numeric scalar (>= 0). Weight of the structured (non-separable) component. |
model |
Integer in |
mu1 |
Numeric scalar. Mean of the temporal Gaussian background term (models 2 and 4). |
sd1 |
Numeric scalar (> 0). Standard deviation of the temporal Gaussian background term (models 2 and 4). |
mu2 |
Numeric vector of length 2. Mean of the spatial 2D Gaussian background term (models 3 and 4). |
sd2 |
Numeric vector of length 2 with positive entries. Standard deviations of the spatial 2D Gaussian background term (models 3 and 4). |
mu3 |
Numeric vector of length 3. Mean of the structured (non-separable) 3D Gaussian component. |
sd3 |
Numeric vector of length 3 with positive entries. Standard deviations of the structured 3D Gaussian component. |
The returned function is intended for use in simulation (e.g., for generating spatio-temporal Poisson point patterns under varying degrees of separability).
The intensity is constructed as:
where is a nonnegative 3D Gaussian density (via norm3d) and the background term
depends on model:
Homogeneous background:
Temporal inhomogeneity only: , where
is a 1D Gaussian density (dnorm).
Spatial inhomogeneity only: , where
is a 2D Gaussian density (norm2d).
Separable spatial-temporal inhomogeneity:
.
Note: since Gaussian densities can exceed 1 for small standard deviations, N is best interpreted
as a scaling parameter used by the calling simulator. Ensure is nonnegative over the
intended domain.
See more details in Ghorbani et al. (2021), Section 6.1.
A function of the form function(x, y, t) representing the selected intensity surface.
This function is primarily intended for generating intensity functions used in
simulation studies. In particular, rstpoispp calls
get.lambda.function() internally to construct intensity models for
simulating spatio-temporal Poisson point processes with controlled separability.
Mohammad Ghorbani [email protected]
Nafiseh Vafaei [email protected]
Ghorbani, M., Vafaei, N., Dvořák, J., and Myllymäki, M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
rstpoispp,
norm3d,
norm2d,
chi2.test,
dHS.test
# Choose model 4: non-separable spatio-temporal intensity lambda <- get.lambda.function(N = 210, g = 50, model = 4) lambda(0.5, 0.5, 0.5) # Evaluate intensity at center of space-time domain # Visualize spatial intensity at fixed time for model 2 lambda2 <- get.lambda.function(N = 200, g = 50, model = 2) x <- y <- seq(0, 1, length.out = 100) z <- outer(x, y, function(x, y) lambda2(x, y, t = 0.5)) par(mar = c(5, 4, 4, 6)) fields::image.plot(x, y, z, main = "Intensity at t = 0.5 (Model 2)", col = topo.colors(50))# Choose model 4: non-separable spatio-temporal intensity lambda <- get.lambda.function(N = 210, g = 50, model = 4) lambda(0.5, 0.5, 0.5) # Evaluate intensity at center of space-time domain # Visualize spatial intensity at fixed time for model 2 lambda2 <- get.lambda.function(N = 200, g = 50, model = 2) x <- y <- seq(0, 1, length.out = 100) z <- outer(x, y, function(x, y) lambda2(x, y, t = 0.5)) par(mar = c(5, 4, 4, 6)) fields::image.plot(x, y, z, main = "Intensity at t = 0.5 (Model 2)", col = topo.colors(50))
Computes a practical upper bound for the spatio-temporal intensity models used in
get.lambda.function. The bound is intended for thinning/rejection sampling
in simulation routines such as rstpoispp.
get.lambda.max( N, g, model = 1L, mu1 = 0.5, sd1 = 0.2, mu2 = c(0.5, 0.5), sd2 = c(0.2, 0.2), mu3 = c(0.3, 0.3, 0.2), sd3 = c(0.05, 0.05, 0.05) )get.lambda.max( N, g, model = 1L, mu1 = 0.5, sd1 = 0.2, mu2 = c(0.5, 0.5), sd2 = c(0.2, 0.2), mu3 = c(0.3, 0.3, 0.2), sd3 = c(0.05, 0.05, 0.05) )
N |
Numeric scalar (> 0). Total expected number of events (baseline intensity level). |
g |
Numeric scalar (>= 0). Weight of the structured (non-separable) component. |
model |
Integer in |
mu1 |
Numeric scalar. Mean of the temporal Gaussian background term (models 2 and 4). |
sd1 |
Numeric scalar (> 0). Standard deviation of the temporal Gaussian background term. |
mu2 |
Numeric vector of length 2. Mean of the spatial Gaussian background term (models 3 and 4). |
sd2 |
Numeric vector of length 2 with positive entries. Standard deviations of the spatial background term. |
mu3 |
Numeric vector of length 3. Mean of the structured spatio-temporal Gaussian component. |
sd3 |
Numeric vector of length 3 with positive entries. Standard deviations of the structured component. |
The bound is computed using analytic maxima of Gaussian density components (at their modes), which yields a conservative and fast-to-evaluate upper bound when the component functions are Gaussian product densities.
The intensity models are mixtures of a background term and a structured spatio-temporal Gaussian bump. This function returns an upper bound obtained by evaluating each Gaussian density component at its mode. This upper bound is typically sufficient for rejection sampling when generating realizations of inhomogeneous Poisson or Cox point processes.
If norm2d and norm3d in this package are Gaussian product densities (independent components),
then the maxima are available in closed form:
If your norm2d/norm3d use a different parameterization, this bound should be updated accordingly.
Numeric scalar. A conservative upper bound for the selected intensity model.
Nafiseh Vafaei [email protected]
Mohammad Ghorbani [email protected]
Ghorbani, M., Vafaei, N., Dvořák, J., and Myllymäki, M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics and Data Analysis, 161, 107245.
get.lambda.function, rstpoispp
# Example 1: Homogeneous model (Model 1) get.lambda.max(N = 200, g = 50, model = 1) # Example 2: Non-separable spatio-temporal model (Model 4) get.lambda.max(N = 200, g = 50, model = 4)# Example 1: Homogeneous model (Model 1) get.lambda.max(N = 200, g = 50, model = 1) # Example 2: Non-separable spatio-temporal model (Model 4) get.lambda.max(N = 200, g = 50, model = 4)
Performs a global envelope test of the null hypothesis of first-order separability
for a spatio-temporal point process. The observed separability diagnostics
, and/or are compared
to a reference distribution obtained from permuted versions of the data.
global.envelope.test( X, sim.procedure = c("pure_per", "block_per"), nsim = 25L, nblocks = 5L, nperm = 199L, n.grid = c(20L, 20L, 10L), s.region = matrix(c(0, 0, 1, 0, 1, 1, 0, 1), ncol = 2, byrow = TRUE), t.region = c(0, 1), owin = NULL, eps = NULL, del = NULL, tests = c("S.test", "S.space.test", "S.time.test"), GET.args = NULL )global.envelope.test( X, sim.procedure = c("pure_per", "block_per"), nsim = 25L, nblocks = 5L, nperm = 199L, n.grid = c(20L, 20L, 10L), s.region = matrix(c(0, 0, 1, 0, 1, 1, 0, 1), ncol = 2, byrow = TRUE), t.region = c(0, 1), owin = NULL, eps = NULL, del = NULL, tests = c("S.test", "S.space.test", "S.time.test"), GET.args = NULL )
X |
A numeric matrix or data frame with at least three columns giving |
sim.procedure |
Character string specifying the permutation strategy:
|
nsim |
Integer. Number of permutations for |
nblocks |
Integer (>= 2). Number of temporal blocks for block permutation.
Used only for |
nperm |
Integer. Number of block permutations for |
n.grid |
Integer/numeric vector of length 3 specifying grid resolution in |
s.region |
Numeric matrix with two columns specifying polygon vertices of the spatial window. |
t.region |
Numeric vector of length 2 specifying temporal window |
owin |
Optional window of class |
eps |
Optional numeric scalar (>0). Spatial bandwidth. If |
del |
Optional numeric scalar (>0). Temporal bandwidth. If |
tests |
Character vector indicating which diagnostics to test. Any of
|
GET.args |
Optional named list of extra arguments passed to
|
Two permutation strategies are supported:
"pure_per"Pure permutation: randomly permutes the time coordinates.
"block_per"Block permutation: permutes time in blocks to preserve short-range temporal dependence.
The GET package is used to construct global envelopes and compute p-values.
The null hypothesis is
The function computes the chosen diagnostics using S.based.functions
on a pixel grid (at="pixels") and applies global_envelope_test.
To keep curve lengths identical (required by GET), any NA values induced by
an owin mask are removed using the same indices for the observed and all simulated curves.
A list with components:
Spatial bandwidth used.
Temporal bandwidth used.
For each requested test: p-values for ERL and AREA envelopes, plus optional plots if created.
Nafiseh Vafaei [email protected]
Mohammad Ghorbani [email protected]
Ghorbani, M., Vafaei, N., Dvořák, J., and Myllymäki, M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
S.based.functions,
sim.procedures,
block.permut,
global_envelope_test,
plot.global_envelope
if (requireNamespace("GET", quietly = TRUE)) { set.seed(123) X <- cbind(stats::runif(100), stats::runif(100), stats::runif(100, 0, 1)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol = 2, byrow = TRUE) t.region <- c(0, 1) res <- global.envelope.test( X = X, sim.procedure = "pure_per", nsim = 19, n.grid = c(10,10,10), s.region = s.region, t.region = t.region, tests = c("S.test","S.time.test") ) str(res) }if (requireNamespace("GET", quietly = TRUE)) { set.seed(123) X <- cbind(stats::runif(100), stats::runif(100), stats::runif(100, 0, 1)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol = 2, byrow = TRUE) t.region <- c(0, 1) res <- global.envelope.test( X = X, sim.procedure = "pure_per", nsim = 19, n.grid = c(10,10,10), s.region = s.region, t.region = t.region, tests = c("S.test","S.time.test") ) str(res) }
Evaluates the density of a bivariate normal distribution with mean vector
and diagonal covariance matrix (independent components).
The density is the product of the two univariate normal densities:
norm2d(x, y, mu = c(0, 0), sd = c(1, 1), log = FALSE)norm2d(x, y, mu = c(0, 0), sd = c(1, 1), log = FALSE)
x |
Numeric vector of x-coordinate(s). |
y |
Numeric vector of y-coordinate(s). |
mu |
Numeric vector of length 2 giving |
sd |
Numeric vector of length 2 giving positive standard deviations |
log |
Logical; if |
Numeric vector of densities (or log-densities) with length determined by standard
recycling rules for x and y.
Mohammad Ghorbani [email protected]
Nafiseh Vafaei [email protected]
# Evaluate the density at the peak norm2d(0.5, 0.5, mu = c(0.5, 0.5), sd = c(0.2, 0.2)) # Evaluate at multiple x values norm2d(c(0.3, 0.7), 0.5, mu = c(0.5, 0.5), sd = c(0.2, 0.2)) # Visualize on a grid x <- y <- seq(0, 1, length.out = 100) f <- Vectorize(function(x, y) norm2d(x, y, mu = c(0.5, 0.5), sd = c(0.2, 0.2))) z <- outer(x, y, f) image(x, y, z, col = terrain.colors(50), main = "Bivariate Normal Intensity") contour(x, y, z, add = TRUE)# Evaluate the density at the peak norm2d(0.5, 0.5, mu = c(0.5, 0.5), sd = c(0.2, 0.2)) # Evaluate at multiple x values norm2d(c(0.3, 0.7), 0.5, mu = c(0.5, 0.5), sd = c(0.2, 0.2)) # Visualize on a grid x <- y <- seq(0, 1, length.out = 100) f <- Vectorize(function(x, y) norm2d(x, y, mu = c(0.5, 0.5), sd = c(0.2, 0.2))) z <- outer(x, y, f) image(x, y, z, col = terrain.colors(50), main = "Bivariate Normal Intensity") contour(x, y, z, add = TRUE)
Evaluates a trivariate normal density on with independent components
(diagonal covariance). The density is the product of three univariate normal densities:
norm3d(x, y, t, mu = c(0.3, 0.3, 0.2), sd = c(0.05, 0.05, 0.05), log = FALSE)norm3d(x, y, t, mu = c(0.3, 0.3, 0.2), sd = c(0.05, 0.05, 0.05), log = FALSE)
x |
Numeric vector of x-coordinate(s). |
y |
Numeric vector of y-coordinate(s). |
t |
Numeric vector of time coordinate(s). |
mu |
Numeric vector of length 3 giving |
sd |
Numeric vector of length 3 giving positive standard deviations |
log |
Logical; if |
Numeric vector of densities (or log-densities) with length determined by standard
recycling rules for x, y, and t.
Mohammad Ghorbani [email protected]
Ghorbani, M., Vafaei, N., Dvořák, J., and Myllymäki, M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
norm2d, get.lambda.function, estimate.st.intensity
norm3d(0.3, 0.3, 0.2) # peak value at the mean (with default parameters) norm3d(c(0.2, 0.3), 0.3, 0.2) x <- y <- seq(0, 1, length.out = 100) z <- outer(x, y, function(x, y) norm3d(x, y, t = 0.2)) image(x, y, z, col = heat.colors(50), main = "Spatial slice of norm3d at t = 0.2")norm3d(0.3, 0.3, 0.2) # peak value at the mean (with default parameters) norm3d(c(0.2, 0.3), 0.3, 0.2) x <- y <- seq(0, 1, length.out = 100) z <- outer(x, y, function(x, y) norm3d(x, y, t = 0.2)) image(x, y, z, col = heat.colors(50), main = "Spatial slice of norm3d at t = 0.2")
Produces a side-by-side plot comparing the temporal component of an original spatio-temporal point pattern with that of a permuted (or block-permuted) version. This graphical diagnostic is intended to assess the effect of temporal reordering procedures used in separability tests.
plot_procedures( original, permuted, title = "Permutation", col = c("blue", "red"), pch = 1, ... )plot_procedures( original, permuted, title = "Permutation", col = c("blue", "red"), pch = 1, ... )
original |
A matrix or data frame with at least three columns |
permuted |
A matrix or data frame with the same structure as |
title |
Character string; title for the permuted panel. |
col |
Character vector of length 2 giving colors for the original and permuted panels. |
pch |
Plotting character passed to |
... |
Further graphical parameters passed to |
The function is commonly employed to visualize temporal permutations
generated by procedures such as sim.procedures or
block.permut, which underpin pure and block permutations-based
inference for first-order separability (see Ghorbani et al., 2021,
Section 3.2).
The function uses base R graphics to display two panels:
The temporal ordering of the original point pattern.
The temporal ordering after permutation or block permutation.
This diagnostic is particularly useful when validating permutation-based
inference procedures such as chi2.test,
dHS.test, and global.envelope.test.
The function is invoked for its side effect of producing a plot and returns no value.
Nafiseh Vafaei [email protected]
Ghorbani, M., Vafaei, N., Dvořák, J., & Myllymäki, M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
sim.procedures,
block.permut,
dHS.test,
chi2.test
set.seed(123) X <- cbind(x = runif(20), y = runif(20), time = seq(0, 1, length.out = 20)) # Example: visualize pure permutation sim_pure <- sim.procedures(X, nperm = 1, method = "pure")[[1]] plot_procedures(X, sim_pure, title = "Pure Permutation") # Example: visualize block permutation (requires Block_permutation) if (requireNamespace("combinat", quietly = TRUE)) { sim_block <- block.permut(nblocks = 4, X = X, nperm = 1)[[1]] plot_procedures(X, sim_block, title = "Block Permutation") }set.seed(123) X <- cbind(x = runif(20), y = runif(20), time = seq(0, 1, length.out = 20)) # Example: visualize pure permutation sim_pure <- sim.procedures(X, nperm = 1, method = "pure")[[1]] plot_procedures(X, sim_pure, title = "Pure Permutation") # Example: visualize block permutation (requires Block_permutation) if (requireNamespace("combinat", quietly = TRUE)) { sim_block <- block.permut(nblocks = 4, X = X, nperm = 1)[[1]] plot_procedures(X, sim_block, title = "Block Permutation") }
Produces diagnostic plots for spatio-temporal determinantal point process
(DPP) simulations or fitted models. The function formats the plot title
based on the spatial and temporal interaction parameters and
, automatically displaying either the parameters themselves or
their reciprocals when greater than 1.
plot_stDPP(data, type = c("3D", "space", "time"), alpha_s, alpha_t)plot_stDPP(data, type = c("3D", "space", "time"), alpha_s, alpha_t)
data |
A spatio-temporal point pattern object suitable for
|
type |
Character string specifying the type of plot to produce.
This is passed directly to |
alpha_s |
Numeric scalar (> 0). Spatial interaction parameter of the DPP model. |
alpha_t |
Numeric scalar (> 0). Temporal interaction parameter of the DPP model. |
If and , the title displays
and , which correspond to interaction
ranges. Otherwise, the parameters are shown directly.
The function then calls plot.ST.pp() to produce the actual plot.
No return value. The function is called for its side effect of producing a diagnostic plot.
# Simulate a stationary separable Matérn ST-DPP sim <- rstDPP( mode = "stationary", model = "S", spectral = "matern", alpha_s = 10, alpha_t = 4.7, nu = 2, eps = 1, lambda_max = 70, grid_size = 1.5 ) plot_stDPP(sim, type = "3D", alpha_s = 10, alpha_t = 4.7)# Simulate a stationary separable Matérn ST-DPP sim <- rstDPP( mode = "stationary", model = "S", spectral = "matern", alpha_s = 10, alpha_t = 4.7, nu = 2, eps = 1, lambda_max = 70, grid_size = 1.5 ) plot_stDPP(sim, type = "3D", alpha_s = 10, alpha_t = 4.7)
Produces a sequence of spatial raster maps displaying the evolution of a simulated or fitted spatio-temporal log-Gaussian Cox process (LGCP) over time. Each map shows the latent Gaussian random field (intensity surface) at a given time slice, with the corresponding observed point events overlaid. This visualization helps interpret temporal evolution and spatial clustering patterns in simulated or fitted LGCP models.
plot_stlgcp(data)plot_stlgcp(data)
data |
A list containing components from a spatio-temporal LGCP model or simulation output:
|
The function plots up to 10 evenly spaced time slices from the latent intensity field
and overlays the corresponding point events accumulated up to each time point.
Each panel represents a spatial realization at a fixed time , providing
a visual summary of the dynamic spatio-temporal structure of the LGCP.
This approach follows the visualization principles used in Ghorbani et al. (2021, 2025), where LGCPs are employed to assess the behavior of separability diagnostics and kernel-based tests in complex, non-separable point process settings. The raster intensity surfaces illustrate latent heterogeneity, while the overlaid points display observed event clustering relative to the underlying field.
Time slices are selected at evenly spaced quantiles of the temporal domain, and each plot includes:
A raster map of the latent intensity surface at time ;
White contour lines showing equal-intensity regions;
Overlaid black points representing events observed up to .
The resulting plots are arranged into a single grid layout using the patchwork package for ease of comparison.
A combined ggplot object displaying up to ten spatial raster maps arranged
in a grid layout (by default, two rows and up to five columns).
Each panel corresponds to one time slice. The function returns the combined plot object.
Nafiseh Vafaei [email protected]
Ghorbani M., Vafaei N., Dvořák J., Myllymäki M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
Gauss.st.F for simulating spatio-temporal Gaussian random fields;
get.lambda.function and rstpoispp
for generating intensity-based spatio-temporal point processes.
# Example: visualize a spatio-temporal LGCP simulation out <- rstLGCPP(xlim = c(0,1), ylim = c(0,1), tlim = c(0,1), grid = c(15,15,10)) plot_stlgcp(data = out)# Example: visualize a spatio-temporal LGCP simulation out <- rstLGCPP(xlim = c(0,1), ylim = c(0,1), tlim = c(0,1), grid = c(15,15,10)) plot_stlgcp(data = out)
Provides flexible visualization tools for spatio-temporal point patterns. Depending on the chosen display type, the function produces one of three plots:
A 3D scatterplot showing event locations in space–time ("3D");
A 2D spatial projection of points in the spatial plane ("space");
A temporal histogram with an overlaid kernel density curve ("time").
The input dataset must contain three columns corresponding to the spatial (x, y)
and temporal (t) coordinates of events.
plot_stpp(data, type = c("3D", "space", "time"), time_bins = 30, title = NULL)plot_stpp(data, type = c("3D", "space", "time"), time_bins = 30, title = NULL)
data |
A numeric matrix or data frame with at least three columns representing event coordinates.
If |
type |
Character string specifying the type of visualization to produce:
|
time_bins |
Integer specifying the number of bins in the histogram when |
title |
Optional character string giving a plot title. If |
The function serves as an exploratory tool for investigating the spatial, temporal, or joint space–time structure of point pattern data. Such visualization is often a first step before conducting statistical analyses of separability or intensity modeling (see Ghorbani et al., 2021).
Displays events in a 3D coordinate system using the scatterplot3d package, allowing a quick assessment of clustering and temporal trends in space–time.
Projects points onto the spatial plane (x–y),
showing spatial structure independent of time.
Displays the marginal temporal distribution of events as a histogram with a kernel density overlay, facilitating the visual detection of temporal nonstationarity.
Visualization is particularly useful for validating the realism of simulated
data (e.g. from rstpoispp or Gauss.st.F)
and for preliminary inspection prior to applying tests such as
chi2.test, global.envelope.test, or
dHS.test.
Produces a plot as a side effect. Nothing is returned.
The 3D visualization requires the scatterplot3d package.
Nafiseh Vafaei [email protected]
Ghorbani M., Vafaei N., Dvořák J., Myllymäki M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
rstpoispp,
estimate.st.intensity,
plot_stlgcp,
chi2.test,
dHS.test
set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) # Visualize point pattern in 3D space–time plot_stpp(X, type = "3D") # View spatial projection plot_stpp(X, type = "space") # Inspect temporal distribution plot_stpp(X, type = "time", time_bins = 20)set.seed(123) X <- cbind(runif(100), runif(100), runif(100, 0, 10)) # Visualize point pattern in 3D space–time plot_stpp(X, type = "3D") # View spatial projection plot_stpp(X, type = "space") # Inspect temporal distribution plot_stpp(X, type = "time", time_bins = 20)
Performs a circular random shift of the temporal coordinate in a spatio-temporal
point pattern. This operation preserves the spatial configuration while
randomizing the temporal component under the assumption of temporal stationarity.
The shift amount is drawn uniformly from and applied modulo 1, ensuring
that the time window is maintained. The resulting dataset can be used to construct
null models for hypothesis testing of first-order separability or temporal independence.
random.shift(X, shifted_col = 3)random.shift(X, shifted_col = 3)
X |
A numeric matrix or data frame containing the spatio-temporal point pattern. Must include at least one numeric column representing time. |
shifted_col |
Integer index specifying which column to shift (typically the
time coordinate). Default is |
The circular random shift is a common resampling procedure for generating null models of temporal randomness while preserving the overall temporal marginal distribution and spatial structure.
For each dataset, a single uniform random shift value
is drawn and added to the temporal
coordinate. The shifted times are then wrapped around the unit interval:
A matrix or data frame (matching the input type) with the time column shifted modulo 1.
Ghorbani, M., Vafaei, N., Dvořák, J., and Myllymäki, M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
set.seed(123) X <- cbind(runif(100), runif(100), runif(100)) # x, y, t X_shifted <- random.shift(X) # Compare original and shifted time values head(X[,3]) head(X_shifted[,3]) # Verify shift visually plot(X[, 3], type = "o", col = "blue", ylab = "Time", xlab = "Index", main = "Original vs Shifted Times") lines(X_shifted[, 3], type = "o", col = "red") legend("topright", legend = c("Original", "Shifted"), col = c("blue", "red"), lty = 1, pch = 1)set.seed(123) X <- cbind(runif(100), runif(100), runif(100)) # x, y, t X_shifted <- random.shift(X) # Compare original and shifted time values head(X[,3]) head(X_shifted[,3]) # Verify shift visually plot(X[, 3], type = "o", col = "blue", ylab = "Time", xlab = "Index", main = "Original vs Shifted Times") lines(X_shifted[, 3], type = "o", col = "red") legend("topright", legend = c("Original", "Shifted"), col = c("blue", "red"), lty = 1, pch = 1)
Generates a realization of a spatio-temporal determinantal point process (DPP)
using a user-defined spectral density model.
The function supports both separable (model = "S") and non-separable
(model = "NS") dependence structures and allows for either exponential
or Mat\'ern-type spectral densities.
The simulation is performed on a 3D spatio-temporal frequency grid and can
incorporate user-specified intensity functions for thinning.
rstDPP( mode = c("stationary", "inhom"), model = c("S", "NS"), spectral = c("exp", "matern"), alpha_s, alpha_t = NULL, lambda_max, nu = 2, eps = 1, lambda_s = NULL, lambda_non_s = NULL, grid_size = 4 )rstDPP( mode = c("stationary", "inhom"), model = c("S", "NS"), spectral = c("exp", "matern"), alpha_s, alpha_t = NULL, lambda_max, nu = 2, eps = 1, lambda_s = NULL, lambda_non_s = NULL, grid_size = 4 )
mode |
Character. Type of dependence model:
|
model |
Character. Type of dependence model:
|
spectral |
Character. Type of spectral density function to use:
|
alpha_s |
Numeric. Spatial decay or range parameter in the spectral density. |
alpha_t |
Numeric. Temporal decay or range parameter in the spectral density. |
lambda_max |
Numeric. The maximum intensity value used for thinning. Must be specified. |
nu |
Numeric. Smoothness parameter for the Mat\'ern-type spectral density
(only relevant if |
eps |
Numeric. Degree of separability for the Mat\'ern model:
|
lambda_s |
Optional. Intensity function |
lambda_non_s |
Optional. Intensity function |
grid_size |
Numeric. Half-width of the spatio-temporal frequency grid.
The total grid size is |
This function implements a spectral simulation method for spatio-temporal DPPs, following the theoretical framework introduced in Vafaei et al. (2023) and Ghorbani et al. (2025).
The algorithm proceeds as follows:
Construct a 3D grid of spatial and temporal frequency components
.
Evaluate the chosen spectral density across the grid.
Use the resulting spectral values as eigenvalues to simulate a realization
of a DPP via .
Optionally apply thinning using a user-defined intensity function
, scaled by lambda_max, to induce inhomogeneity.
Two spectral families are supported:
Exponential form:
Mat\'ern-type form:
where determines the degree of separability between
space and time.
This framework enables simulation of spatio-temporal point patterns that exhibit varying degrees of spatial–temporal dependence, providing a versatile tool for evaluating separability tests and modeling non-separable dynamics.
A numeric matrix with three columns (x, y, t) representing
the retained spatio-temporal events after thinning.
Vafaei, N., Ghorbani, M., Ganji, M., and Myllymäki, M. (2023). Spatio-temporal determinantal point processes. arXiv:2301.02353.
Ghorbani, M., Vafaei, N., and Myllymäki, M. (2025). A kernel-based test for the first-order separability of spatio-temporal point processes. TEST, 34, 580-611. https://doi.org/10.1007/s11749-025-00972-y
plot_stpp for visualizing spatio-temporal point patterns.
# Simulate a stationary separable Mat\'ern ST-DPP if (requireNamespace("spatstat", quietly = TRUE)) { sim <- rstDPP( mode = "stationary", model = "S", spectral = "matern", alpha_s = 10, alpha_t = 4.7, nu = 2, eps = 1, lambda_max = 70, grid_size = 2 ) plot_stDPP(sim, type = "3D", alpha_s = 10, alpha_t = 4.7) # example 2 # Generate realization sim <- rstDPP(mode = "stationary", model = "S", spectral = "matern", alpha_s = 10, alpha_t = 4.7, nu = 2, eps = 1, lambda_s = 70, lambda_non_s = NULL, grid_size = 2, lambda_max=70) head(sim) }# Simulate a stationary separable Mat\'ern ST-DPP if (requireNamespace("spatstat", quietly = TRUE)) { sim <- rstDPP( mode = "stationary", model = "S", spectral = "matern", alpha_s = 10, alpha_t = 4.7, nu = 2, eps = 1, lambda_max = 70, grid_size = 2 ) plot_stDPP(sim, type = "3D", alpha_s = 10, alpha_t = 4.7) # example 2 # Generate realization sim <- rstDPP(mode = "stationary", model = "S", spectral = "matern", alpha_s = 10, alpha_t = 4.7, nu = 2, eps = 1, lambda_s = 70, lambda_non_s = NULL, grid_size = 2, lambda_max=70) head(sim) }
Generates a realization of a spatio-temporal LGCP over a user-defined domain. The process is simulated using a log-Gaussian random field combined with a deterministic trend function, and points are generated by thinning a homogeneous Poisson process.
rstLGCPP( xlim = NULL, ylim = NULL, tlim = NULL, grid = c(15, 15, 10), mu = NULL, Lambda = NULL, Lmax = NULL, par1 = c(1, 0.05), par2 = c(1, 0.06), sigmas = c(0.5, 0.5, 1), mu_par = c(1.2, 0.25, 5) )rstLGCPP( xlim = NULL, ylim = NULL, tlim = NULL, grid = c(15, 15, 10), mu = NULL, Lambda = NULL, Lmax = NULL, par1 = c(1, 0.05), par2 = c(1, 0.06), sigmas = c(0.5, 0.5, 1), mu_par = c(1.2, 0.25, 5) )
xlim, ylim, tlim
|
Numeric vectors of length 2 specifying the spatial and temporal domains. |
grid |
Integer vector of length 3 specifying the number of grid cells in x, y, and t. |
mu |
Optional. A function of (x, y, t, par) defining a deterministic trend. Default is nonlinear. |
Lambda |
Optional. A user-supplied 3D intensity array or function. If |
Lmax |
Optional. Maximum intensity used for thinning. Can be numeric or a function. If |
par1, par2
|
Parameters for temporal and spatial exponential covariance models, respectively. |
sigmas |
Weights for combining spatial, temporal, and spatio-temporal components of the latent Gaussian field. |
mu_par |
Parameters passed to the default trend function |
A list with:
A data frame of simulated spatio-temporal points.
The latent Gaussian field output from Gauss.st.F.
out <- rstLGCPP(xlim = c(0,1), ylim = c(0,1), tlim = c(0,1), grid = c(15,15,10)) plot_stlgcp(data = out) plot_stpp(data = out$st.lgcp, type = "3D")out <- rstLGCPP(xlim = c(0,1), ylim = c(0,1), tlim = c(0,1), grid = c(15,15,10)) plot_stlgcp(data = out) plot_stpp(data = out$st.lgcp, type = "3D")
Generates a realization of an inhomogeneous Poisson point process (STPP)
in space and time using the standard thinning method.
The user provides an intensity function and an upper
bound on its value over the observation window.
The algorithm first samples candidate events uniformly over space and time
and then retains each candidate with probability proportional to its
normalized intensity .
rstpoispp( lambda, Lmax, s.region = splancs::as.points(c(0, 1, 1, 0), c(0, 0, 1, 1)), t.region = c(0, 1) )rstpoispp( lambda, Lmax, s.region = splancs::as.points(c(0, 1, 1, 0), c(0, 0, 1, 1)), t.region = c(0, 1) )
lambda |
A function of the form |
Lmax |
A numeric value giving the known or estimated maximum of the intensity function |
s.region |
A matrix with two columns giving the polygonal spatial window. Each row is a vertex of the polygon. Default is the unit square. |
t.region |
A numeric vector of length 2 giving the temporal observation window. Default is |
The method implements the classical thinning algorithm for simulating inhomogeneous Poisson processes:
Draw , where
and denote the spatial and temporal window measures.
Generate candidate points uniformly over
.
Retain each point independently with probability
.
The result is a realization of an inhomogeneous STPP with intensity function
.
This simulator underpins the spatio-temporal framework introduced in
Ghorbani et al. (2021, 2025) for studying first-order separability.
By selecting appropriate intensity functions (see get.lambda.function),
users can generate fully separable, partially separable, or non-separable
spatio-temporal patterns, enabling direct evaluation of separability tests such as
chi2.test, global.envelope.test, or
dHS.test.
A numeric matrix with three columns (x, y, t) representing the retained points from the inhomogeneous Poisson process.
The intensity function should return non-negative
numeric values and be bounded above by Lmax across the observation domain.
Mohammad Ghorbani [email protected]
Nafiseh Vafaei [email protected]
Ghorbani M., Vafaei N., Dvořák J., Myllymäki M. (2021). Testing the first-order separability hypothesis for spatio-temporal point patterns. Computational Statistics & Data Analysis, 161, 107245.
Ghorbani, M., Vafaei, N. and Myllymäki, M. (2025). A kernel-based test for the first-order separability of spatio-temporal point processes, TEST .
get.lambda.function to construct spatio-temporal intensity models;
get.lambda.max to compute intensity maxima;
estimate.st.intensity for intensity estimation;
plot_stpp for visualization.
# Example 1: Simulate a separable spatio-temporal Poisson process lambda <- get.lambda.function(N = 200, g = 50, model = 1) Lmax <- get.lambda.max(N = 200, g = 50, model = 1) X <- rstpoispp(lambda, Lmax) head(X) # Example 2: Non-separable model (Model 4) lambda <- get.lambda.function(N = 200, g = 50, model = 4) Lmax <- get.lambda.max(N = 200, g = 50, model = 4) sim_data <- rstpoispp(lambda, Lmax) # Spatial projection of simulated events plot(sim_data[, 1:2], asp = 1, main = "Spatial Projection of Simulated stPP") # Example 3: 3D visualization using plot_ST_pp() plot_stpp(X, type = "3D", title="Realisation of a stPP")# Example 1: Simulate a separable spatio-temporal Poisson process lambda <- get.lambda.function(N = 200, g = 50, model = 1) Lmax <- get.lambda.max(N = 200, g = 50, model = 1) X <- rstpoispp(lambda, Lmax) head(X) # Example 2: Non-separable model (Model 4) lambda <- get.lambda.function(N = 200, g = 50, model = 4) Lmax <- get.lambda.max(N = 200, g = 50, model = 4) sim_data <- rstpoispp(lambda, Lmax) # Spatial projection of simulated events plot(sim_data[, 1:2], asp = 1, main = "Spatial Projection of Simulated stPP") # Example 3: 3D visualization using plot_ST_pp() plot_stpp(X, type = "3D", title="Realisation of a stPP")
Computes kernel-based estimates of the spatio-temporal intensity and related
separability diagnostics, either on a regular spatio-temporal grid ("pixels")
or at the observed event locations ("points").
S.based.functions( X, s.region, t.region, owin = NULL, at = c("pixels", "points"), n.grid = c(25L, 25L, 20L), epsilon = NULL, delta = NULL, output = "all" )S.based.functions( X, s.region, t.region, owin = NULL, at = c("pixels", "points"), n.grid = c(25L, 25L, 20L), epsilon = NULL, delta = NULL, output = "all" )
X |
Numeric matrix/data.frame with three columns giving |
s.region |
Numeric matrix with two columns giving polygon vertices of the spatial window. |
t.region |
Numeric vector of length 2 giving the temporal window |
owin |
Optional spatial window of class |
at |
Character string: |
n.grid |
Integer vector of length 3 giving the grid resolution in |
epsilon |
Optional numeric scalar (>0). Spatial bandwidth. If |
delta |
Optional numeric scalar (>0). Temporal bandwidth. If |
output |
Character string selecting which component to return. Use |
The function is a wrapper that (i) validates inputs, (ii) computes bandwidths and
Gaussian edge-correction masses via calc.bandwidths.and.edgecorr, and
(iii) delegates the actual estimation to estimate.intensity.pixel or
estimate.intensity.point.
When at="points", spatial/temporal profiles such as S.space and S.time are typically
not defined and are returned as NULL by the pointwise routine.
If output="all", returns the full list produced by the chosen computation routine, augmented with
epsilon and delta.
If output is a single component name, returns a list with:
The requested component.
Spatial bandwidth used.
Temporal bandwidth used.
Coordinates returned by the underlying routine (may be NULL).
X <- cbind(stats::runif(50), stats::runif(50), stats::runif(50)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol = 2, byrow = TRUE) t.region <- c(0, 1) res_all <- S.based.functions(X, s.region, t.region, at = "points") res_Sfun <- S.based.functions(X, s.region, t.region, at = "points", output = "S.fun")X <- cbind(stats::runif(50), stats::runif(50), stats::runif(50)) s.region <- matrix(c(0,0, 1,0, 1,1, 0,1), ncol = 2, byrow = TRUE) t.region <- c(0, 1) res_all <- S.based.functions(X, s.region, t.region, at = "points") res_Sfun <- S.based.functions(X, s.region, t.region, at = "points", output = "S.fun")
Implements two types of permutation procedures for resampling the time component of spatio-temporal point process data:
"pure"Pure random permutation of the time coordinates.
"block"Block permutation where the time dimension is divided into consecutive blocks, and permutations are applied at the block level.
These procedures are used for generating surrogate datasets under the null hypothesis of first-order separability.
sim.procedures(X, nperm = 1999, nblocks = 4, method = c("block", "pure"))sim.procedures(X, nperm = 1999, nblocks = 4, method = c("block", "pure"))
X |
A numeric matrix or data frame with at least three columns, where the third column represents time. |
nperm |
Integer. The number of permuted datasets to generate. |
nblocks |
Integer. The number of temporal blocks to use for block permutation. Must be > 2. |
method |
Character. The permutation strategy to use. One of |
A list of nperm matrices. Each matrix is a permuted version of the original input X, where the third column (time) has been resampled based on the selected method.
set.seed(123) X <- cbind(runif(100), runif(100), sort(runif(100))) # Pure permutation sims_pure <- sim.procedures(X, nperm = 10, method = "pure") head(sims_pure[[1]]) # Block permutation sims_block <- sim.procedures(X, nperm = 10, nblocks = 5, method = "block") # Visualize the first result from block permutation plot_stpp(sims_block[[1]], type = "3D")set.seed(123) X <- cbind(runif(100), runif(100), sort(runif(100))) # Pure permutation sims_pure <- sim.procedures(X, nperm = 10, method = "pure") head(sims_pure[[1]]) # Block permutation sims_block <- sim.procedures(X, nperm = 10, nblocks = 5, method = "block") # Visualize the first result from block permutation plot_stpp(sims_block[[1]], type = "3D")