The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Package {unisono}


Type: Package
Title: Uniformity-Based Isotropy Testing for Non-Scalar Objects
Version: 0.1.0
Depends: R (≥ 4.1.0)
Language: en-US
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.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: cli, CompQuadForm, dplyr, ggplot2, ggrepel, mvtnorm, purrr, Rcpp, rlang, tibble, tidyr
LinkingTo: Rcpp
Suggests: geoR, rmarkdown, sp, testthat (≥ 3.0.0), withr
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
URL: https://github.com/baumhakel/unisono
BugReports: https://github.com/baumhakel/unisono/issues
NeedsCompilation: yes
Packaged: 2026-11-11 15:16:31 UTC; baujuc12
Author: 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 <baumhakel@tugraz.at>
Repository: CRAN
Date/Publication: 2026-12-02 12:40:02 UTC

unisono: 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.

Author(s)

Maintainer: Julius Baumhakel baumhakel@tugraz.at (ORCID = 0009-0006-8999-7303) [copyright holder]

Authors:

Other contributors:

See Also

Useful links:


Compute Empirical Block Proportions for D-Dimensional Categorical Fields

Description

Calculates the normalized frequency of categorical states within a designated coordinate sub-window.

Usage

block_proportions(indexField, coords_list, nh, S)

Arguments

indexField

An array of spatial category indices with values in 1:nh[s]. Can be $D$-dimensional (N_1 x \dots x N_D) or $(D+1)$-dimensional (N_1 x \dots x N_D x S).

coords_list

A list of length $D$ containing integer coordinate vectors defining the spatial window indices along each spatial dimension.

nh

An integer vector of length $S$ (or scalar if $S = 1$) specifying the number of category bins for each stacked layer.

S

Integer scalar. The total number of stacked indicator layers.

Value

A numeric vector of length \sum_{s=1}^S n_{h, s} containing the concatenated empirical proportions across all $S$ layers.

Examples

## Not run: 
# Placeholder for examples if this function remains exported

## End(Not run)

Estimate Variance in Local (Block) Proportions Across Arbitrary-Dimensional Categorical Fields

Description

Computes empirical variance in block proportion vectors for categorical fields across $D$ spatial dimensions without explicitly materializing sparse one-hot indicator arrays in memory. Accepts either a single spatial field or an $S$-stacked multi-layer field (e.g., across distinct directions, variables, or time steps). Stacked encodings are concatenated along the categories axis, enabling joint cross-covariance estimation across all $S x n_h$ indicator components.

Usage

longrunvariance_from_indexfield(
  indexField,
  nh,
  window_dims,
  lims_mat,
  overlap_dims = rep(0L, length(window_dims))
)

Arguments

indexField

An array of category indices with values in 1:nh (where NA denotes unobserved boundary regions). Can be a $D$-dimensional array (N_1 x \dots x N_D) for a single field, or a $(D+1)$-dimensional array (N_1 x \dots x N_D x S) containing $S$ stacked fields sharing the same $n_h$ categorical scope.

nh

Integer scalar. The total number of categorical states (e.g., nrow(lags_list)).

window_dims

Integer vector defining the dimensions of the moving window.

lims_mat

A $D x 2$ matrix defining the spatial bounds for evaluation.

overlap_dims

Integer vector defining the step overlap along each spatial axis. Defaults to 0 across all dimensions.

Value

A list containing:

sig

The estimated long-run covariance matrix.

mu

The global spatial block proportions.

n_windows

The total number of subwindows evaluated.

Examples

## Not run: 
# Placeholder for examples if this function remains exported

## End(Not run)

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)
  }


Constructor for unifIsoResult objects

Description

Creates an object of class unifIsoResult, which stores the results of the uniformity-based isotropy test for spatial random fields.

Usage

new_unifIsoResult(
  statistic,
  stat_vec,
  p_value,
  moments,
  eigenvalues,
  n_obs,
  lags_list,
  window_dims,
  overlap_dims
)

Arguments

statistic

Numeric scalar. The overall test statistic.

stat_vec

Numeric vector. The test statistics for each individual lag set.

p_value

Numeric scalar. The computed p-value for the test.

moments

List. Contains the estimated long-run covariance matrix and proportions.

eigenvalues

Numeric vector. Eigenvalues of the estimated covariance matrix.

n_obs

Numeric vector. The number of observations used for each lag set.

lags_list

List of matrices. The lag vectors evaluated.

window_dims

Integer vector. Dimensions of the spatial moving window.

overlap_dims

Integer vector. Dimensions of overlap for the moving window.

Value

An object of class unifIsoResult.


Generate Lollipop Plot for Isotropy Results

Description

Constructs a standard Cartesian lollipop plot to visualize dependencies across lags when spatial dimensions exceed 2 or when angular rendering is disabled.

Usage

unifIsoResult_lollipop(
  uni.res,
  alpha,
  drawlabs = TRUE,
  cols = NULL,
  setnames = TRUE,
  width = 0.6
)

Arguments

uni.res

An object of class unifIsoResult.

alpha

Numeric. Significance level for confidence bounds.

drawlabs

Logical. If TRUE, adds text labels to the plot.

cols

Optional color palette.

setnames

Logical. If TRUE, prints facet labels.

width

Numeric. Width of the confidence bounds rectangles.

Value

A ggplot object.

Examples

## Not run: 
# Placeholder for lollipop plot usage

## End(Not run)

Generate Rose Plot for Isotropy Results

Description

Constructs a polar coordinate plot ("rose plot") to visualize directional dependencies in 2-dimensional spatial lags.

Usage

unifIsoResult_roseplot(
  uni.res,
  alpha,
  drawlabs = TRUE,
  cols = NULL,
  setnames = TRUE
)

Arguments

uni.res

An object of class unifIsoResult.

alpha

Numeric. Significance level for confidence bounds.

drawlabs

Logical. If TRUE, adds text labels to the plot.

cols

Optional color palette.

setnames

Logical. If TRUE, prints facet labels.

Value

A ggplot object.

Examples

## Not run: 
# Placeholder for rose plot usage

## End(Not run)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.