| Title: | Level-Wise Statistics for Fuzzy Random Variables |
|---|---|
| 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. |
| Authors: | Gunjan Aggrwal [aut, cre] (ORCID: <https://orcid.org/0009-0004-3213-4086>), Mukul Bijalwan [aut] (ORCID: <https://orcid.org/0009-0001-3040-6912>), Mukul Jain [aut] |
| Maintainer: | Gunjan Aggrwal <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-10-22 10:10:48 UTC |
| Source: | https://github.com/cran/FuzzyRandom |
Alpha grid of a fuzzy object
alpha_levels(x)alpha_levels(x)
x |
A |
Numeric vector of alpha levels.
alpha_levels(triangular_fuzzy(1, 2, 4))[1:3]alpha_levels(triangular_fuzzy(1, 2, 4))[1:3]
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).
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, ...)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, ...)
x |
Object to coerce. |
alpha |
Alpha grid (for array/data-frame input). |
... |
Unused. |
A FuzzySample.
fs <- as_fuzzy_sample(triangular_fuzzy(0, 1, 2)) n_obs(fs)fs <- as_fuzzy_sample(triangular_fuzzy(0, 1, 2)) n_obs(fs)
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.
clt(x, alpha = NULL, ...)clt(x, alpha = NULL, ...)
x |
A |
alpha |
Numeric levels (default: those of |
... |
Unused. |
An object of class c("FuzzyCLT","FuzzyNormal"). Its
cov is the covariance of Xbar (i.e. Sigma / n);
sigma is the limiting covariance Sigma.
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)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)
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
correlation(x, y = NULL, alpha = NULL, ...) ## S3 method for class 'FuzzySample' correlation(x, y = NULL, alpha = NULL, ...)correlation(x, y = NULL, alpha = NULL, ...) ## S3 method for class 'FuzzySample' correlation(x, y = NULL, alpha = NULL, ...)
x, y
|
Two |
alpha |
Optional alpha grid. |
... |
Unused. |
An object of class "FuzzyCorrelation" (with a scalar slot).
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)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)
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
is also returned.
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, ...)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, ...)
x, y
|
Two |
alpha |
Optional alpha grid. |
... |
Unused. |
A FuzzyCovariance object.
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)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
cut_at(x, alpha, ...) ## S3 method for class 'FuzzyNumber' cut_at(x, alpha = 0.5, ...)cut_at(x, alpha, ...) ## S3 method for class 'FuzzyNumber' cut_at(x, alpha = 0.5, ...)
x |
A |
alpha |
A single level in |
... |
Unused. |
A named numeric vector c(lower = ..., upper = ...).
cut_at(triangular_fuzzy(1, 2, 4), 0.5)cut_at(triangular_fuzzy(1, 2, 4), 0.5)
Alpha-level cuts of a fuzzy number
cuts(x, alpha = NULL, ...) ## S3 method for class 'FuzzyNumber' cuts(x, alpha = NULL, ...)cuts(x, alpha = NULL, ...) ## S3 method for class 'FuzzyNumber' cuts(x, alpha = NULL, ...)
x |
A |
alpha |
Optional alpha grid at which to evaluate the cuts. |
... |
Unused. |
A numeric matrix with columns lower and upper.
fn <- triangular_fuzzy(1, 2, 4) cuts(fn, alpha = c(0, 0.5, 1))fn <- triangular_fuzzy(1, 2, 4) cuts(fn, alpha = c(0, 0.5, 1))
Level-wise expectation. For a sample the estimator is the level-wise mean of the alpha-cuts:
expectation(x, alpha = NULL, ...) ## S3 method for class 'FuzzySample' expectation(x, alpha = NULL, ...) ## S3 method for class 'FuzzySample' mean(x, ...)expectation(x, alpha = NULL, ...) ## S3 method for class 'FuzzySample' expectation(x, alpha = NULL, ...) ## S3 method for class 'FuzzySample' mean(x, ...)
x |
A |
alpha |
Optional alpha grid on which to evaluate. |
... |
Unused. |
A FuzzyNumber, the sample expectation.
set.seed(2) s <- FuzzySample(replicate(40, triangular_fuzzy(-1, 0, 1), simplify = FALSE)) ex <- expectation(s); plot(ex, main = "sample mean")set.seed(2) s <- FuzzySample(replicate(40, triangular_fuzzy(-1, 0, 1), simplify = FALSE)) ex <- expectation(s); plot(ex, main = "sample mean")
Level-wise empirical cumulative distribution functions of the alpha-cut endpoints.
fuzzy_ecdf(x, alpha = NULL, at = NULL, ...) ## S3 method for class 'FuzzySample' fuzzy_ecdf(x, alpha = NULL, at = NULL, ...)fuzzy_ecdf(x, alpha = NULL, at = NULL, ...) ## S3 method for class 'FuzzySample' fuzzy_ecdf(x, alpha = NULL, at = NULL, ...)
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. |
An object of class "FuzzyECDF".
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)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)
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.
fuzzy_from_membership(x, mu, alpha = NULL)fuzzy_from_membership(x, mu, alpha = NULL)
x |
Sorted numeric grid of the support (unsorted grids are sorted). |
mu |
Membership values in |
alpha |
Optional alpha grid. |
An object of class "FuzzyNumber".
x <- seq(-3, 3, length.out = 201) mu <- pmax(1 - abs(x), 0) # triangular membership fn <- fuzzy_from_membership(x, mu) plot(fn)x <- seq(-3, 3, length.out = 201) mu <- pmax(1 - abs(x), 0) # triangular membership fn <- fuzzy_from_membership(x, mu) plot(fn)
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.
fuzzy_normal(mean, cov = NULL, n = NULL)fuzzy_normal(mean, cov = NULL, n = NULL)
mean |
A |
cov |
A |
n |
Optional sample size associated with the mean (used by
|
An object of class "FuzzyNormal".
fn <- fuzzy_normal(triangular_fuzzy(0, 1, 2), diag(2)) simulate(fn, nsim = 5)fn <- fuzzy_normal(triangular_fuzzy(0, 1, 2), diag(2)) simulate(fn, nsim = 5)
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.
FuzzyNumber(alpha = NULL, lower, upper)FuzzyNumber(alpha = NULL, lower, upper)
alpha |
Numeric vector in |
lower |
Numeric; lower envelope, non-decreasing in |
upper |
Numeric; upper envelope, non-increasing in |
An object of class "FuzzyNumber".
fn <- FuzzyNumber(alpha = c(0, 0.5, 1), lower = c(1, 2, 2), upper = c(4, 2, 2)) cuts(fn)fn <- FuzzyNumber(alpha = c(0, 0.5, 1), lower = c(1, 2, 2), upper = c(4, 2, 2)) cuts(fn)
FuzzyRandom is a computationally self-contained implementation of the
level-wise ("Puri-Ralescu") theory of statistics for fuzzy random
variables.
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 alpha levels and the matching
non-decreasing lower / non-increasing upper envelopes
(class FuzzyNumber).
A sample of fuzzy random variables is an (n, m, 2) array of cuts
(class FuzzySample), m being the number of levels.
The covariance of two fuzzy random variables is returned as a
level-wise 2 x 2 matrix of covariances between the lower and upper
endpoints (class FuzzyCovariance); 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).
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.
Build a sample of fuzzy random variables
FuzzySample(x, alpha = NULL)FuzzySample(x, alpha = NULL)
x |
Either a list of |
alpha |
Alpha grid shared by all observations. Required when |
An object of class "FuzzySample".
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)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)
Whether an object is a (valid) fuzzy number
is_fuzzy_number(x)is_fuzzy_number(x)
x |
Any R object. |
Logical; TRUE if x is a valid FuzzyNumber.
is_fuzzy_number(triangular_fuzzy(0, 1, 2)) is_fuzzy_number(1:3)is_fuzzy_number(triangular_fuzzy(0, 1, 2)) is_fuzzy_number(1:3)
Whether an object is a FuzzySample
is_fuzzy_sample(x)is_fuzzy_sample(x)
x |
Any R object. |
Logical.
is_fuzzy_sample(FuzzySample(list(triangular_fuzzy(0, 1, 2))))is_fuzzy_sample(FuzzySample(list(triangular_fuzzy(0, 1, 2))))
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.
ks_test(x, ...) ## S3 method for class 'FuzzySample' ks_test(x, y = NULL, p0 = NULL, alpha = NULL, ...)ks_test(x, ...) ## S3 method for class 'FuzzySample' ks_test(x, y = NULL, p0 = NULL, alpha = NULL, ...)
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 |
An object of class "FuzzyKS".
set.seed(9) s <- FuzzySample(replicate(50, triangular_fuzzy(-1, 0, 1), simplify = FALSE)) ks_test(s, p0 = "pnorm")set.seed(9) s <- FuzzySample(replicate(50, triangular_fuzzy(-1, 0, 1), simplify = FALSE)) ks_test(s, p0 = "pnorm")
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).
lln(x, sizes = NULL, alpha = NULL, levels = c(0.5, 1), ...)lln(x, sizes = NULL, alpha = NULL, levels = c(0.5, 1), ...)
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. |
An object of class "FuzzyLLN" with components sizes,
means, full and alpha.
set.seed(23) s <- rnorm_fuzzy(400, triangular_fuzzy(0, 1, 2), diag(2) * 0.25) w <- lln(s) plot(w) summary(w)set.seed(23) s <- rnorm_fuzzy(400, triangular_fuzzy(0, 1, 2), diag(2) * 0.25) w <- lln(s) plot(w) summary(w)
Number of alpha levels of a fuzzy object
n_cuts(x)n_cuts(x)
x |
A |
Length-one integer.
n_cuts(triangular_fuzzy(1, 2, 4))n_cuts(triangular_fuzzy(1, 2, 4))
Number of observations in a sample
n_obs(x)n_obs(x)
x |
A |
Length-one integer.
s <- FuzzySample(list(triangular_fuzzy(0, 1, 2), triangular_fuzzy(1, 2, 3))) n_obs(s)s <- FuzzySample(list(triangular_fuzzy(0, 1, 2), triangular_fuzzy(1, 2, 3))) n_obs(s)
Draws n fuzzy numbers whose alpha-cut endpoints have the
bivariate-normal level-wise distribution N_2(mu_alpha, Sigma_alpha).
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, ...)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, ...)
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. |
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.
A FuzzySample of n fuzzy random variables.
set.seed(123) s <- rnorm_fuzzy(80, triangular_fuzzy(0, 1, 2), diag(2) * 0.25) plot(s, main = "fuzzy normal sample")set.seed(123) s <- rnorm_fuzzy(80, triangular_fuzzy(0, 1, 2), diag(2) * 0.25) plot(s, main = "fuzzy normal sample")
spectral_covariance returns the scalar covariance
spectral_covariance(x, y = NULL, alpha = NULL, ...) ## S3 method for class 'FuzzySample' spectral_covariance(x, y = NULL, alpha = NULL, ...)spectral_covariance(x, y = NULL, alpha = NULL, ...) ## S3 method for class 'FuzzySample' spectral_covariance(x, y = NULL, alpha = NULL, ...)
x, y
|
Two |
alpha |
Optional alpha grid. |
... |
Unused. |
A length-one numeric.
set.seed(6) x <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE)) spectral_covariance(x)set.seed(6) x <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE)) spectral_covariance(x)
spectral_variance returns spectral_covariance(x, x).
spectral_variance(x, alpha = NULL, ...)spectral_variance(x, alpha = NULL, ...)
x |
A |
alpha |
Optional alpha grid. |
... |
Unused. |
A length-one numeric.
set.seed(7) x <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE)) spectral_variance(x)set.seed(7) x <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE)) spectral_variance(x)
The trapezoidal fuzzy number with support [a, d] and core
[b, c] (a <= b <= c <= d).
trapezoidal_fuzzy(a, b, c, d, alpha = NULL)trapezoidal_fuzzy(a, b, c, d, alpha = NULL)
a, b, c, d
|
Scalars with |
alpha |
Optional alpha grid. |
An object of class "FuzzyNumber".
plot(trapezoidal_fuzzy(1, 2, 3, 5))plot(trapezoidal_fuzzy(1, 2, 3, 5))
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].
triangular_fuzzy(a, b, c, alpha = NULL)triangular_fuzzy(a, b, c, alpha = NULL)
a, b, c
|
Scalars with |
alpha |
Optional alpha grid (see |
An object of class "FuzzyNumber".
plot(triangular_fuzzy(1, 2, 4))plot(triangular_fuzzy(1, 2, 4))
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
variance(x, alpha = NULL, ...) ## S3 method for class 'FuzzySample' variance(x, alpha = NULL, ...) ## S3 method for class 'FuzzySample' var(x, ...)variance(x, alpha = NULL, ...) ## S3 method for class 'FuzzySample' variance(x, alpha = NULL, ...) ## S3 method for class 'FuzzySample' var(x, ...)
x |
A |
alpha |
Optional alpha grid. |
... |
Unused. |
A FuzzyCovariance object (with type = "variance").
set.seed(4) s <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE)) variance(s)set.seed(4) s <- FuzzySample(replicate(30, triangular_fuzzy(0, 1, 2), simplify = FALSE)) variance(s)