| Type: | Package |
| Title: | Level-Wise Statistics for Fuzzy Random Variables |
| Version: | 0.1.0 |
| Date: | 2026-10-06 |
| Description: | Level-wise statistical methods for fuzzy random variables, implementing the Puri-Ralescu framework. Provides level-wise empirical distribution functions, moments, covariance and correlation, a level-wise Kolmogorov-Smirnov goodness-of-fit test, an approximate fuzzy normal distribution with simulation, and level-wise central limit theorem and law of large numbers inference. The package only depends on base R. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| Imports: | stats, graphics, grDevices |
| Suggests: | testthat (≥ 3.0.0), knitr, rmarkdown |
| VignetteBuilder: | knitr |
| Config/testthat/version: | 3 |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-10-10 04:42:13 UTC; GUNJAN AGGRWAL |
| Author: | Gunjan Aggrwal |
| Maintainer: | Gunjan Aggrwal <gunjanuk1994@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-21 14:20:17 UTC |
Statistics of Fuzzy Random Variables: a Puri-Ralescu Framework
Description
FuzzyRandom is a computationally self-contained implementation of the
level-wise ("Puri-Ralescu") theory of statistics for fuzzy random
variables.
Details
Fuzzy numbers are represented through their alpha-level sets
[X^-(alpha), X^+(alpha)], and every statistical operator is defined
level-wise, so that the expectation, variance, covariance,
empirical distribution, law of large numbers and central limit
theorem are all handled in a single coherent framework.
The key design choices are:
A fuzzy number is a list of
alphalevels and the matching non-decreasinglower/ non-increasingupperenvelopes (classFuzzyNumber).A sample of fuzzy random variables is an
(n, m, 2)array of cuts (classFuzzySample),mbeing the number of levels.The covariance of two fuzzy random variables is returned as a level-wise
2 x 2matrix of covariances between the lower and upper endpoints (classFuzzyCovariance); scalar reductions are provided through the Feng-Hu-Shu integral and scalar product.The central limit theorem yields the fuzzy normal distribution (class
FuzzyNormal), whose level cuts are bivariate-normal intervals.
The package only depends on base R (stats, graphics).
References
Puri, M. L. and Ralescu, D. A. (1986). Fuzzy random variables. Journal of Mathematical Analysis and Applications, 114(2), 409-422.
Klement, E. P., Puri, M. L. and Ralescu, D. A. (1986). Limit theorems for fuzzy random variables. Proceedings of the Royal Society A, 407, 171-182.
Feng, Y., Hu, L. and Shu, H. (2002). The variance and covariance of fuzzy random variables and their applications. Fuzzy Sets and Systems, 128, 335-345.
A fuzzy number given by its alpha-level cuts
Description
Build a FuzzyNumber object from its
alpha-level envelopes. When alpha is not supplied it is taken as a
regularly spaced grid on [0, 1] with one node per supplied endpoint.
Usage
FuzzyNumber(alpha = NULL, lower, upper)
Arguments
alpha |
Numeric vector in |
lower |
Numeric; lower envelope, non-decreasing in |
upper |
Numeric; upper envelope, non-increasing in |
Value
An object of class "FuzzyNumber".
Examples
fn <- FuzzyNumber(alpha = c(0, 0.5, 1), lower = c(1, 2, 2), upper = c(4, 2, 2))
cuts(fn)
Build a sample of fuzzy random variables
Description
Build a sample of fuzzy random variables
Usage
FuzzySample(x, alpha = NULL)
Arguments
x |
Either a list of |
alpha |
Alpha grid shared by all observations. Required when |
Value
An object of class "FuzzySample".
Examples
set.seed(1)
s <- FuzzySample(list(
triangular_fuzzy(0, 1, 2),
triangular_fuzzy(1, 2, 3),
trapezoidal_fuzzy(0.5, 1, 3, 4)))
n_obs(s)
Alpha grid of a fuzzy object
Description
Alpha grid of a fuzzy object
Usage
alpha_levels(x)
Arguments
x |
A |
Value
Numeric vector of alpha levels.
Examples
alpha_levels(triangular_fuzzy(1, 2, 4))[1:3]
Coerce to a FuzzySample
Description
Coerces from a list of FuzzyNumber, an array, a data frame (with
columns id, alpha, lower, upper) or a single FuzzyNumber
(giving a sample of size 1).
Usage
as_fuzzy_sample(x, alpha = NULL, ...)
## Default S3 method:
as_fuzzy_sample(x, alpha = NULL, ...)
## S3 method for class 'FuzzyNumber'
as_fuzzy_sample(x, alpha = NULL, ...)
## S3 method for class 'data.frame'
as_fuzzy_sample(x, alpha = NULL, ...)
Arguments
x |
Object to coerce. |
alpha |
Alpha grid (for array/data-frame input). |
... |
Unused. |
Value
A FuzzySample.
Examples
fs <- as_fuzzy_sample(triangular_fuzzy(0, 1, 2))
n_obs(fs)
Central limit theorem for a fuzzy random sample
Description
Uses the level-wise central limit theorem (Puri & Ralescu, 1986): at each
level alpha the sample-mean endpoints are approximately normal, so
the fuzzy sample mean Xbar is approximately a
fuzzy_normal with mean expectation(x) and level-
wise covariance variance(x) / n.
Usage
clt(x, alpha = NULL, ...)
Arguments
x |
A |
alpha |
Numeric levels (default: those of |
... |
Unused. |
Value
An object of class c("FuzzyCLT","FuzzyNormal"). Its
cov is the covariance of Xbar (i.e. Sigma / n);
sigma is the limiting covariance Sigma.
Examples
set.seed(7)
s <- rnorm_fuzzy(500, triangular_fuzzy(0, 1, 2), diag(2) * 0.25)
cl <- clt(s); summary(cl)
simulate(cl, nsim = 4)
Correlation of two fuzzy random variables (sample)
Description
Level-wise Pearson correlation between the lower endpoints
(cor(X^-(alpha), Y^-(alpha))) and between the upper endpoints
(cor(X^+(alpha), Y^+(alpha))), plus the scalar reduction
\rho_{FHS}(X,Y)=\tfrac12\int_0^1\bigl[r_{--}(a)+r_{++}(a)\bigr]\,da.
Usage
correlation(x, y = NULL, alpha = NULL, ...)
## S3 method for class 'FuzzySample'
correlation(x, y = NULL, alpha = NULL, ...)
Arguments
x, y |
Two |
alpha |
Optional alpha grid. |
... |
Unused. |
Value
An object of class "FuzzyCorrelation" (with a scalar slot).
Examples
set.seed(5)
x <- FuzzySample(replicate(50, triangular_fuzzy(0, 1, 2), simplify = FALSE))
y <- FuzzySample(replicate(50, triangular_fuzzy(0, 1, 2), simplify = FALSE))
correlation(x, y)
Covariance of two fuzzy random variables (sample)
Description
Level-wise covariance. At each level alpha the covariance of
X and Y is the 2 x 2 matrix
Cov(X^-, Y^-) | Cov(X^-, Y^+) |
Cov(X^+, Y^-) | Cov(X^+, Y^+).
|
When y is omitted, x is paired with itself and the result is
the variance. A scalar reduction through the Feng–Hu–Shu integral
\mathrm{Cov}_{FHS}(X,Y)=\tfrac12\int_0^1\bigl[\mathrm{Cov}(X^-(a),Y^-(a))+
\mathrm{Cov}(X^+(a),Y^+(a))\bigr]\,da
is also returned.
Usage
covariance(x, y = NULL, alpha = NULL, ...)
## S3 method for class 'FuzzySample'
covariance(x, y = NULL, alpha = NULL, ...)
## S3 method for class 'FuzzySample'
cov(x, y = NULL, ...)
Arguments
x, y |
Two |
alpha |
Optional alpha grid. |
... |
Unused. |
Value
A FuzzyCovariance object.
Examples
set.seed(3)
x <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE))
y <- FuzzySample(replicate(30, triangular_fuzzy(1, 2, 3), simplify = FALSE))
covariance(x, y)
Cut of a fuzzy number at a single level
Description
Cut of a fuzzy number at a single level
Usage
cut_at(x, alpha, ...)
## S3 method for class 'FuzzyNumber'
cut_at(x, alpha = 0.5, ...)
Arguments
x |
A |
alpha |
A single level in |
... |
Unused. |
Value
A named numeric vector c(lower = ..., upper = ...).
Examples
cut_at(triangular_fuzzy(1, 2, 4), 0.5)
Alpha-level cuts of a fuzzy number
Description
Alpha-level cuts of a fuzzy number
Usage
cuts(x, alpha = NULL, ...)
## S3 method for class 'FuzzyNumber'
cuts(x, alpha = NULL, ...)
Arguments
x |
A |
alpha |
Optional alpha grid at which to evaluate the cuts. |
... |
Unused. |
Value
A numeric matrix with columns lower and upper.
Examples
fn <- triangular_fuzzy(1, 2, 4)
cuts(fn, alpha = c(0, 0.5, 1))
Default alpha grid
Description
A fine, regularly spaced grid on the closed unit interval used whenever a level-wise grid is not supplied explicitly by the caller.
Usage
default_alpha()
Value
A numeric vector of length 51 on [0, 1], containing 0 and 1.
Internal 2D ellipse points
Description
Internal helper used by plot.FuzzyCovariance.
Usage
ellipse_points(Sigma, mu, level = 0.95)
Expectation of a fuzzy random variable (sample)
Description
Level-wise expectation. For a sample the estimator is the level-wise mean of the alpha-cuts:
[E[X]]_{\alpha} = \Bigl[\,\frac1n\sum_i X_i^{-}(\alpha),\;
\frac1n\sum_i X_i^{+}(\alpha)\Bigr].
Usage
expectation(x, alpha = NULL, ...)
## S3 method for class 'FuzzySample'
expectation(x, alpha = NULL, ...)
## S3 method for class 'FuzzySample'
mean(x, ...)
Arguments
x |
A |
alpha |
Optional alpha grid on which to evaluate. |
... |
Unused. |
Value
A FuzzyNumber, the sample expectation.
Examples
set.seed(2)
s <- FuzzySample(replicate(40, triangular_fuzzy(-1, 0, 1), simplify = FALSE))
ex <- expectation(s); plot(ex, main = "sample mean")
Empirical distribution function of a fuzzy random sample
Description
Level-wise empirical cumulative distribution functions of the alpha-cut endpoints.
Usage
fuzzy_ecdf(x, alpha = NULL, at = NULL, ...)
## S3 method for class 'FuzzySample'
fuzzy_ecdf(x, alpha = NULL, at = NULL, ...)
Arguments
x |
A |
alpha |
Numeric vector of levels (default: the levels stored in
|
at |
Numeric grid on which to evaluate the CDFs (default: 201 points over the data range). |
... |
Unused. |
Value
An object of class "FuzzyECDF".
Examples
set.seed(8)
s <- FuzzySample(replicate(40, triangular_fuzzy(0, 1, 2), simplify = FALSE))
fe <- fuzzy_ecdf(s, alpha = c(0, 0.25, 0.5, 0.75, 1))
plot(fe)
A fuzzy number from a membership function evaluated on a grid
Description
Reconstructs the alpha-cuts of a (normal, quasi-concave) fuzzy number from
a membership function evaluated on a grid. The level set
{x : mu(x) >= alpha} is assumed to be a single interval.
Usage
fuzzy_from_membership(x, mu, alpha = NULL)
Arguments
x |
Sorted numeric grid of the support (unsorted grids are sorted). |
mu |
Membership values in |
alpha |
Optional alpha grid. |
Value
An object of class "FuzzyNumber".
Examples
x <- seq(-3, 3, length.out = 201)
mu <- pmax(1 - abs(x), 0) # triangular membership
fn <- fuzzy_from_membership(x, mu)
plot(fn)
Construct a fuzzy normal distribution
Description
A fuzzy normal distribution is the family, over levels alpha, of
bivariate-normal laws on the alpha-cut endpoints with fuzzy mean mean
and level-wise covariance cov.
Usage
fuzzy_normal(mean, cov = NULL, n = NULL)
Arguments
mean |
A |
cov |
A |
n |
Optional sample size associated with the mean (used by
|
Value
An object of class "FuzzyNormal".
Examples
fn <- fuzzy_normal(triangular_fuzzy(0, 1, 2), diag(2))
simulate(fn, nsim = 5)
Linearly interpolate the alpha-cuts of a fuzzy number
Description
Returns the lower and upper envelopes evaluated on the grid at.
Usage
interpolate_cuts(alpha, lower, upper, at)
Arguments
alpha |
Original grid of the fuzzy number (sorted in |
lower |
Lower envelope on |
upper |
Upper envelope on |
at |
Grid on which to evaluate the cuts. |
Interpolate a sample onto a new alpha grid
Description
Interpolate a sample onto a new alpha grid
Usage
interpolate_sample(obj, alpha)
Arguments
obj |
A |
alpha |
Target alpha grid. |
Value
An (n, m, 2) array of cuts on alpha.
Whether an object is a (valid) fuzzy number
Description
Whether an object is a (valid) fuzzy number
Usage
is_fuzzy_number(x)
Arguments
x |
Any R object. |
Value
Logical; TRUE if x is a valid FuzzyNumber.
Examples
is_fuzzy_number(triangular_fuzzy(0, 1, 2))
is_fuzzy_number(1:3)
Whether an object is a FuzzySample
Description
Whether an object is a FuzzySample
Usage
is_fuzzy_sample(x)
Arguments
x |
Any R object. |
Value
Logical.
Examples
is_fuzzy_sample(FuzzySample(list(triangular_fuzzy(0, 1, 2))))
One- and two-sample fuzzy Kolmogorov-Smirnov tests
Description
Performs, at each level alpha, a Kolmogorov-Smirnov test on the
lower and upper endpoints of the alpha-cuts. With p0 a one-sample
test against the CDF p0 is run; otherwise a two-sample test against
the second sample y is run. The result is a family of level-wise
tests consistent with the Puri-Ralescu level-wise approach.
Usage
ks_test(x, ...)
## S3 method for class 'FuzzySample'
ks_test(x, y = NULL, p0 = NULL, alpha = NULL, ...)
Arguments
x |
A |
... |
Additional arguments passed on to |
y |
A second |
p0 |
Null CDF for the one-sample test: a character string naming a CDF
in |
alpha |
Numeric vector of levels (default: those of |
Value
An object of class "FuzzyKS".
Examples
set.seed(9)
s <- FuzzySample(replicate(50, triangular_fuzzy(-1, 0, 1), simplify = FALSE))
ks_test(s, p0 = "pnorm")
Level-wise sample-mean convergence (LLN)
Description
Following Puri & Ralescu (1986), statistics on fuzzy random variables are
evaluated level-wise on the alpha-cuts. This function computes the fuzzy
sample mean for an increasing sequence of sample sizes and measures, at a
fixed level, the sup-norm distance between the size-s mean and the
full-sample mean. By the level-wise (fuzzy) law of large numbers this
distance shrinks to zero with the sample size (at rate 1/sqrt(s)
under the level-wise CLT).
Usage
lln(x, sizes = NULL, alpha = NULL, levels = c(0.5, 1), ...)
Arguments
x |
A |
sizes |
Integer vector of sample sizes (default: a grid from 5 up to
|
alpha |
Optional alpha grid on which to evaluate the means. |
levels |
Numeric levels at which to measure convergence, used by the
|
... |
Unused. |
Value
An object of class "FuzzyLLN" with components sizes,
means, full and alpha.
Examples
set.seed(23)
s <- rnorm_fuzzy(400, triangular_fuzzy(0, 1, 2), diag(2) * 0.25)
w <- lln(s)
plot(w)
summary(w)
Sup-norm distance of each mean to the full mean, at the requested levels
Description
Sup-norm distance of each mean to the full mean, at the requested levels
Usage
lln_distances(means, full, alpha, levels)
Arguments
means |
List of |
full |
The full-sample |
alpha |
Alpha grid shared by |
levels |
Levels at which the distance is measured. |
Value
A matrix with one column per level.
Sample from a bivariate normal distribution
Description
n independent draws from N_2(mu, Sigma) using the Cholesky
factorisation (after repair of Sigma).
Usage
mvrnorm_2d(n, mu, Sigma)
Arguments
n |
Number of draws. |
mu |
Length-2 numeric mean vector. |
Sigma |
2x2 covariance matrix. |
Value
An nx2 numeric matrix; column 1 is the lower endpoint,
column 2 the upper endpoint of a level cut.
Number of alpha levels of a fuzzy object
Description
Number of alpha levels of a fuzzy object
Usage
n_cuts(x)
Arguments
x |
A |
Value
Length-one integer.
Examples
n_cuts(triangular_fuzzy(1, 2, 4))
Number of observations in a sample
Description
Number of observations in a sample
Usage
n_obs(x)
Arguments
x |
A |
Value
Length-one integer.
Examples
s <- FuzzySample(list(triangular_fuzzy(0, 1, 2), triangular_fuzzy(1, 2, 3)))
n_obs(s)
Internal constructor for a FuzzyCovariance object
Description
Internal constructor for a FuzzyCovariance object
Usage
new_FuzzyCovariance(alpha, cov, scalar, type)
Arguments
alpha |
Alpha grid. |
cov |
Array of dim |
scalar |
Scalar reduction (Feng–Hu–Shu integral). |
type |
|
Internal constructor for a FuzzyNumber (no validation)
Description
Internal constructor for a FuzzyNumber (no validation)
Usage
new_FuzzyNumber(alpha, lower, upper)
Arguments
alpha |
Alpha grid. |
lower, upper |
Envelopes. |
Internal constructor (no validation) for FuzzySample objects
Description
Internal constructor (no validation) for FuzzySample objects
Usage
new_FuzzySample(arr, alpha)
Arguments
arr |
An |
alpha |
The shared alpha grid. |
Value
A FuzzySample object.
Project per-level endpoints onto the cone of valid nested cuts
Description
Enforces lower <= upper and monotonicity (lower non-decreasing,
upper non-increasing in alpha).
Usage
project_to_valid_cuts(lower, upper, alpha)
Arguments
lower, upper |
Numeric vectors, one entry per level. |
alpha |
Sorted grid in |
Value
A length-2 list with components lower and upper.
Repair a 2x2 covariance matrix for positive (semi)definiteness
Description
Symmetrizes Sigma and, if it is not positive (semi)definite, adds a
small diagonal ridge so that a Cholesky factor exists.
Usage
repair_cov_2x2(Sigma, eps = 1e-09)
Arguments
Sigma |
A 2x2 numeric matrix. |
eps |
Smallest eigenvalue threshold. |
Value
A symmetric, positive-definite 2x2 numeric matrix.
Sample fuzzy random variables from a fuzzy normal distribution
Description
Draws n fuzzy numbers whose alpha-cut endpoints have the
bivariate-normal level-wise distribution N_2(mu_alpha, Sigma_alpha).
Usage
rnorm_fuzzy(n, mean, cov = NULL, valid = TRUE, seed = NULL)
## S3 method for class 'FuzzyNormal'
simulate(object, nsim = 1, ...)
## S3 method for class 'FuzzyCLT'
simulate(object, nsim = 1, ...)
Arguments
n |
Sample size. |
mean |
A |
cov |
A |
valid |
Logical; whether to project draws to valid fuzzy numbers. |
seed |
Optional integer seed ( |
object |
A |
nsim |
Number of simulations. |
... |
Unused. |
Details
When valid = TRUE (the default) every draw is projected onto the
cone of valid, nested alpha-cuts (lower <= upper; lower non-decreasing and
upper non-increasing in alpha) so that it is a proper fuzzy number.
When valid = FALSE the raw, unprojected level-wise bivariate-normal
cuts are returned – useful for checking the level-wise central limit
theorem, where projection would bias the marginals.
Value
A FuzzySample of n fuzzy random variables.
Examples
set.seed(123)
s <- rnorm_fuzzy(80, triangular_fuzzy(0, 1, 2), diag(2) * 0.25)
plot(s, main = "fuzzy normal sample")
Scalar covariance (Feng–Hu–Shu integral)
Description
spectral_covariance returns the scalar covariance
\mathrm{Cov}_{FHS}(X,Y)=\tfrac12\int_0^1\bigl[\mathrm{Cov}(X^-(a),Y^-(a))+
\mathrm{Cov}(X^+(a),Y^+(a))\bigr]\,da.
Usage
spectral_covariance(x, y = NULL, alpha = NULL, ...)
## S3 method for class 'FuzzySample'
spectral_covariance(x, y = NULL, alpha = NULL, ...)
Arguments
x, y |
Two |
alpha |
Optional alpha grid. |
... |
Unused. |
Value
A length-one numeric.
Examples
set.seed(6)
x <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE))
spectral_covariance(x)
Scalar variance (Feng–Hu–Shu integral)
Description
spectral_variance returns spectral_covariance(x, x).
Usage
spectral_variance(x, alpha = NULL, ...)
Arguments
x |
A |
alpha |
Optional alpha grid. |
... |
Unused. |
Value
A length-one numeric.
Examples
set.seed(7)
x <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE))
spectral_variance(x)
Standardise an alpha grid
Description
Ensures a strictly increasing grid on [0, 1] containing 0 and 1.
Usage
standardise_alpha(alpha = NULL)
Arguments
alpha |
User-supplied alpha grid (may be |
Trapezoidal fuzzy number
Description
The trapezoidal fuzzy number with support [a, d] and core
[b, c] (a <= b <= c <= d).
Usage
trapezoidal_fuzzy(a, b, c, d, alpha = NULL)
Arguments
a, b, c, d |
Scalars with |
alpha |
Optional alpha grid. |
Value
An object of class "FuzzyNumber".
Examples
plot(trapezoidal_fuzzy(1, 2, 3, 5))
Trapezoidal quadrature over an alpha grid
Description
Approximates \int_0^1 f(\alpha)\,d\alpha by the composite trapezoidal
rule applied to the values of f on the grid alpha.
Usage
trapz_alpha(f, alpha = default_alpha())
Arguments
f |
Numeric vector of function values aligned with |
alpha |
Numeric vector of grid points, sorted in |
Value
A length-one numeric, the approximated integral.
Triangular fuzzy number
Description
The triangular fuzzy number with support [a, c] and core b
(a <= b <= c). Its alpha-cuts are
[a + (b-a)*alpha, c - (c-b)*alpha].
Usage
triangular_fuzzy(a, b, c, alpha = NULL)
Arguments
a, b, c |
Scalars with |
alpha |
Optional alpha grid (see |
Value
An object of class "FuzzyNumber".
Examples
plot(triangular_fuzzy(1, 2, 4))
Validate the structure of fuzzy-number cuts
Description
Validate the structure of fuzzy-number cuts
Usage
validate_cuts(alpha, lower, upper)
Arguments
alpha |
Sorted grid in |
lower |
Non-decreasing lower envelope. |
upper |
Non-increasing upper envelope, with |
Variance of a fuzzy random variable (sample)
Description
Level-wise variance, i.e. covariance of a sample with itself.
Returns the level-wise 2 x 2 matrix
[[Var(X^-), Cov(X^-,X^+)], [Cov(X^+,X^-), Var(X^+)] at each level,
together with the scalar Feng–Hu–Shu variance
\mathrm{Var}_{FHS}(X)=\tfrac12\int_0^1\bigl[\mathrm{Var}(X^-(a))+
\mathrm{Var}(X^+(a))\bigr]\,da.
Usage
variance(x, alpha = NULL, ...)
## S3 method for class 'FuzzySample'
variance(x, alpha = NULL, ...)
## S3 method for class 'FuzzySample'
var(x, ...)
Arguments
x |
A |
alpha |
Optional alpha grid. |
... |
Unused. |
Value
A FuzzyCovariance object (with type = "variance").
Examples
set.seed(4)
s <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE))
variance(s)