Package 'unisono'

Title: Uniformity-Based Isotropy Testing for Non-Scalar Objects
Description: Hypothesis test for isotropy in random fields observed on regular grids, as proposed by Baumhakel, Hörmann and Neumann (2026) <doi:10.48550/arXiv.2611.14011>. Supports multivariate and abstract (e.g. scalar-, but also function- or object-valued) data. Directional dependencies in localized structures are evaluated via an argmax transformation based on a standard or user-defined objective function, with efficient 'C++' implementations. Includes diagnostic visualizations.
Authors: Julius Baumhakel [aut, cre, cph] (ORCID = 0009-0006-8999-7303), Siegfried Hörmann [ctb] (ORCID = 0000-0001-5878-2840), Matthias Neumann [ctb] (ORCID = 0000-0002-5782-6773)
Maintainer: Julius Baumhakel <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-12-02 21:10:50 UTC
Source: https://github.com/cran/unisono

Help Index


Plot method for unifIsoResult objects

Description

Generates diagnostic plots for spatial isotropy tests. Automatically selects between a rose plot (for 2D spatial lags) and a lollipop plot.

Usage

## S3 method for class 'unifIsoResult'
plot(
  x,
  alpha = 0.05,
  force_lollipop = FALSE,
  drawlabs = TRUE,
  cols = NULL,
  setnames = TRUE,
  ...
)

Arguments

x

An object of class unifIsoResult.

alpha

Numeric scalar. Significance level for plotted intervals. Default is 0.05.

force_lollipop

Logical. If TRUE, forces rendering of a lollipop plot even for 2D fields. Default is FALSE.

drawlabs

Logical. If TRUE, draws axis/plot labels. Default is TRUE.

cols

Optional vector of colors for the plot.

setnames

Logical. If TRUE, uses set names in the legend/labels. Default is TRUE.

...

Additional arguments passed to the underlying plotting functions.

Value

A plot object (depends on underlying functions, typically ggplot).

Examples

## Not run: 
# TODO: Add plotting example here

## End(Not run)

Print method for summary.unifIsoResult objects

Description

Print method for summary.unifIsoResult objects

Usage

## S3 method for class 'summary.unifIsoResult'
print(x, digits = max(3, getOption("digits") - 3), ...)

Arguments

x

An object of class summary.unifIsoResult.

digits

Integer. Number of significant digits to print.

...

Additional arguments passed to print.

Value

Invisibly returns the original object x.

Examples

## Not run: 
# TODO: Add basic print.summary example here

## End(Not run)

Print method for unifIsoResult objects

Description

Print method for unifIsoResult objects

Usage

## S3 method for class 'unifIsoResult'
print(x, digits = max(3, getOption("digits") - 3), ...)

Arguments

x

An object of class unifIsoResult.

digits

Integer. Number of significant digits to print.

...

Additional arguments passed to print.

Value

Invisibly returns the original object x.

Examples

## Not run: 
# TODO: Add basic printing example here

## End(Not run)

Print method for unifIsoResultLagTable objects

Description

Custom print method that formats and outputs the lag table families, applying ANSI color codes to highlight out-of-bounds empirical proportions.

Usage

## S3 method for class 'unifIsoResultLagTable'
print(x, ...)

Arguments

x

An object of class unifIsoResultLagTable.

...

Additional arguments passed to print.

Value

The function is called for its side effects (printing).

Examples

## Not run: 
# Placeholder for print.unifIsoResultLagTable example

## End(Not run)

Summary method for unifIsoResult objects

Description

Summary method for unifIsoResult objects

Usage

## S3 method for class 'unifIsoResult'
summary(object, alpha = 0.05, ...)

Arguments

object

An object of class unifIsoResult.

alpha

Numeric scalar. The significance level for confidence intervals. Default is 0.05.

...

Additional arguments passed to summary.

Value

An object of class summary.unifIsoResult.

Examples

## Not run: 
# TODO: Add basic summary example here

## End(Not run)

Isotropy test for random fields on a d-dimensional grid

Description

Performs a uniformity-based test of isotropy for spatial data observed on a regular grid, as proposed by Baumhakel et al. (2026). Accepted inputs are matrices, multidimensional arrays, 'SpatialGridDataFrame' and 'geodata' objects. At every location in the field, the objective function is evaluated over the specified spatial lags to find the maximizing direction. The empirical proportions of maximizers across directions are then compared with the uniform distribution; significant deviations indicate directional dependence (anisotropy).

Usage

uni_iso_grid(
  spdata,
  objfunc = "normdiff",
  minimize = FALSE,
  lags_list = NULL,
  window_dims = NULL,
  overlap_dims = NULL
)

## S3 method for class 'matrix'
uni_iso_grid(
  spdata,
  objfunc = "normdiff",
  minimize = FALSE,
  lags_list = NULL,
  window_dims = NULL,
  overlap_dims = NULL
)

## S3 method for class 'array'
uni_iso_grid(
  spdata,
  objfunc = "normdiff",
  minimize = FALSE,
  lags_list = NULL,
  window_dims = NULL,
  overlap_dims = NULL
)

## S3 method for class 'geodata'
uni_iso_grid(
  spdata,
  objfunc = "normdiff",
  minimize = FALSE,
  lags_list = NULL,
  window_dims = NULL,
  overlap_dims = NULL
)

## S3 method for class 'SpatialGridDataFrame'
uni_iso_grid(
  spdata,
  objfunc = "normdiff",
  minimize = FALSE,
  lags_list = NULL,
  window_dims = NULL,
  overlap_dims = NULL
)

## Default S3 method:
uni_iso_grid(
  spdata,
  objfunc = "normdiff",
  minimize = FALSE,
  lags_list = NULL,
  window_dims = NULL,
  overlap_dims = NULL
)

Arguments

spdata

A spatial data object containing the random field observed on a rectangular d-dimensional grid. Can be a 'matrix', 'array', a 'SpatialGridDataFrame', or a 'geodata' object. In the case of a matrix or array with scalar entries, where the last dimension represents the coordinate index of a multivariate field. The array may also contain general objects (lists).

objfunc

Character string or function. The objective function to be evaluated over directions to obtain the argmax. Must be vectorized. Default is '"normdiff"', which computes the squared Euclidean norm of the difference and is implemented in C++ for efficiency. This works only for scalar or multivariate numeric data.

minimize

Logical. Should the objective function be minimized instead of maximized? Default is 'FALSE' (maximize).

lags_list

A list of matrices, where each matrix represents a set of lag vectors (each row is a lag vector in the scale of the grid step size). If not specified, defaults to a single lag set of unit vectors in each spatial dimension and their negatives. Lag vectors in the same matrix need to be of the same norm and fulfill the condition outlined in Baumhakel et al. (2026).

window_dims

Integer vector. Dimensions of the moving window used to estimate the asymptotic long-run covariance matrix. If not specified, defaults to a vector of 2's.

overlap_dims

Integer vector. Dimensions of overlap for the moving window. If not specified, defaults to a vector of zeros.

Value

An object of class 'unifIsoResult' containing:

statistic

The overall test statistic value.

stat_vec

Vector of test statistics for each lag vector.

p_value

The p-value of the test.

moments

List containing the estimated proportions of maximizers and long-run covariance matrix ('sig').

eigenvalues

Eigenvalues of the estimated covariance matrix.

n_obs

Vector of the number of observations used for each lag set (edge of the domain cannot be used).

lags_list

The used list of lags.

window_dims

The used window dimensions.

overlap_dims

The used overlap dimensions.

References

Baumhakel, J., Hörmann, S., and Neumann, M. (2026). Testing isotropy of random fields with values in abstract spaces. arXiv preprint arXiv:2611.14011. doi:10.48550/arXiv.2611.14011

Examples

# geoR is required to run
if (requireNamespace("geoR", quietly = TRUE)) {

  set.seed(1)

  # simple example ----------------------------------------------------------
  # 2D domain, univariate, anisotropic
  sim1 <- geoR::grf(
    grid = expand.grid(1:15, 1:15),
    cov.pars = c(1, 1),
    aniso.pars = c(0, 2)
  )
  res1 <- uni_iso_grid(sim1, window_dims = c(5, 5))
  # all proportions lie outside joint confidence intervals
  print(summary(res1))
  plot(res1)
}


  if (requireNamespace("geoR", quietly = TRUE)) {
    # custom lag set, multivariate --------------------------------------------
    sim2 <- geoR::grf(
      grid = expand.grid(1:15, 1:15),
      nsim = 2,
      cov.pars = c(1, 2),
      aniso.pars = c(0, 2)
    )

    # test 2 sets of lags simultaneously
    lags_list <- list(
      rbind(diag(2, 2), diag(-2, 2)),
      matrix(c(1, 1, -1, -1, 1, -1, 1, -1), nrow = 4, ncol = 2)
    )

    res2 <- uni_iso_grid(sim2, lags_list = lags_list, window_dims = c(5, 5))
    # anisotropy is not detected in all directions
    print(summary(res2))
    plot(res2)

    # + custom objective function (sum of absolute differences, vectorized)
    f2 <- function(z0, zlagged) {
      diffs <- zlagged -
        matrix(rep(z0, nrow(zlagged)), nrow = nrow(zlagged), byrow = TRUE)
      return(rowSums(abs(diffs)))
    }
    res2a <- uni_iso_grid(
      sim2,
      objfunc = f2,
      lags_list = lags_list,
      window_dims = c(5, 5)
    )


    # 3D domain, list-valued --------------------------------------------------

    # generate exemplary list-valued field
    sim3 <- geoR::grf(
      grid = expand.grid(1:7, 1:7, 1:7),
      nsim = 2,
      cov.pars = c(1, 0.25)
    )
    dat3 <- sim3$dat
    dat3 <- ifelse(dat3 > 0, "+", "-")
    sim3.l <- lapply(1:nrow(dat3), function(i) dat3[i, ])
    dim(sim3.l) <- c(7, 7, 7)

    # custom objective function (x is single observation, y is list of observations)
    f3 <- function(x, yl) {
      return(sapply(yl, function(y) {
        sum(unlist(x) != unlist(y))
      }))
    }

    res3 <- uni_iso_grid(sim3.l, objfunc = f3)
    print(summary(res3))
    plot(res3)
  }