Introduction to denstest

library(denstest)

Introduction

The denstest package provides tools for testing equality between groups of estimated density functions. It implements FDET (Fourier-based Density Equality Testing), a new method proposed by the author for comparing groups of density functions based on their global shape using Fourier transforms. FDET extends the idea of an earlier method by Delicado, which compares densities directly but does not rely on spectral representations. For clarity and reference, this earlier approach is referred to as DET (Density Equality Testing) within the author’s submitted paper.

In addition to FDET and DET, the package also includes MDET (Moment-based Density Equality Testing), another new method introduced by the author for detecting group differences in specific distributional features: expectation, variance, skewness, and kurtosis, as well as in arbitrary combinations of these four moments.

FDET and MDET are described in detail in the submitted paper, including their mathematical foundations, derivation, and use cases. DET is also presented in the same paper to contextualize the methodological development. For full theoretical background and illustrative examples, we recommend referring to the paper.

Overview of Functions

The main functions included in the denstest package are:

Below, we provide a brief example of how to use the denscomp() function.

set.seed(123)

n1 <- 5
n2 <- 5
n3 <- 5
group_sizes = c(n1, n2, n3)
sample_size <- 500

densities_group1 <- lapply(1:n1, function(i) {
  data <- rnorm(sample_size, 0, 0.3)
  d <- density(data)
  list(x = d$x, y = d$y)
})

densities_group2 <- lapply(1:n2, function(i) {
  data <- rnorm(sample_size, 0, 0.32)
  d <- density(data)
  list(x = d$x, y = d$y)
})

densities_group3 <- lapply(1:n3, function(i) {
  data <- rnorm(sample_size, 0.02, 0.28)
  d <- density(data)
  list(x = d$x, y = d$y)
})
      
L <- c(densities_group1, densities_group2, densities_group3)
      
cat("p-value:", denscomp(L, group_sizes, ft.lp.weight = "AbsRoot", seed = 1234, plot = TRUE))

#> p-value: 1e-04

References

For more detailed information on the methods used in this package, please refer to the following publications:

Anarat A., Krutmann, J., and Schwender, H. (2025). Testing for Differences in Extrinsic Skin Aging Based on Density Functions. Submitted.

Delicado, P. (2007). Functional k-sample problem when data are density functions. Computational Statistics, 22, 391–410. https://doi.org/10.1007/s00180-007-0047-y