Package 'FuzzyRandom'

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

Help Index


Alpha grid of a fuzzy object

Description

Alpha grid of a fuzzy object

Usage

alpha_levels(x)

Arguments

x

A FuzzyNumber or FuzzySample.

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 FuzzySample.

alpha

Numeric levels (default: those of x).

...

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

ρFHS(X,Y)=12∫01[r−−(a)+r++(a)] da.\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 FuzzySample objects.

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

CovFHS(X,Y)=12∫01[Cov(X−(a),Y−(a))+Cov(X+(a),Y+(a))] da\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 FuzzySample objects (or x alone for the variance).

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 FuzzyNumber.

alpha

A single level in ⁠[0, 1]⁠.

...

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 FuzzyNumber (or other compatible object).

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

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]]α=[ 1n∑iXi−(α),  1n∑iXi+(α)].[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 FuzzySample.

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 FuzzySample.

alpha

Numeric vector of levels (default: the levels stored in x).

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 [0, 1] evaluated at x.

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 FuzzyNumber (the fuzzy mean).

cov

A 2 x 2 covariance matrix, a length-4 vector, or a FuzzyCovariance whose levels match mean.

n

Optional sample size associated with the mean (used by clt).

Value

An object of class "FuzzyNormal".

Examples

fn <- fuzzy_normal(triangular_fuzzy(0, 1, 2), diag(2))
simulate(fn, nsim = 5)

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 [0, 1], strictly increasing.

lower

Numeric; lower envelope, non-decreasing in alpha.

upper

Numeric; upper envelope, non-increasing in alpha.

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)

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

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.


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 FuzzyNumber objects, an (n, m, 2) numeric array of cuts (dimension 3 = c("lower", "upper")), or an existing FuzzySample.

alpha

Alpha grid shared by all observations. Required when x is an array with an unlabelled third dimension; otherwise inferred.

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)

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 FuzzySample.

...

Additional arguments passed on to ks.test.

y

A second FuzzySample for a two-sample test (default NULL).

p0

Null CDF for the one-sample test: a character string naming a CDF in stats (e.g. "pnorm") or a function p0(q).

alpha

Numeric vector of levels (default: those of x).

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 FuzzySample.

sizes

Integer vector of sample sizes (default: a grid from 5 up to x$n).

alpha

Optional alpha grid on which to evaluate the means.

levels

Numeric levels at which to measure convergence, used by the summary, as.data.frame and plot methods (default c(0.5, 1)).

...

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)

Number of alpha levels of a fuzzy object

Description

Number of alpha levels of a fuzzy object

Usage

n_cuts(x)

Arguments

x

A FuzzyNumber or FuzzySample.

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 FuzzySample.

Value

Length-one integer.

Examples

s <- FuzzySample(list(triangular_fuzzy(0, 1, 2), triangular_fuzzy(1, 2, 3)))
n_obs(s)

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 FuzzyNumber (the fuzzy mean) or a FuzzyNormal.

cov

A 2 x 2 covariance matrix, a length-4 vector, or a FuzzyCovariance. Ignored if mean is a FuzzyNormal.

valid

Logical; whether to project draws to valid fuzzy numbers.

seed

Optional integer seed (NULL leaves the RNG alone).

object

A FuzzyNormal (or FuzzyCLT) object.

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

CovFHS(X,Y)=12∫01[Cov(X−(a),Y−(a))+Cov(X+(a),Y+(a))] da.\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 FuzzySample objects (or x alone).

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 FuzzySample.

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)

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 a <= b <= c <= d.

alpha

Optional alpha grid.

Value

An object of class "FuzzyNumber".

Examples

plot(trapezoidal_fuzzy(1, 2, 3, 5))

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 a <= b <= c.

alpha

Optional alpha grid (see FuzzyNumber).

Value

An object of class "FuzzyNumber".

Examples

plot(triangular_fuzzy(1, 2, 4))

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

VarFHS(X)=12∫01[Var(X−(a))+Var(X+(a))] da.\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 FuzzySample.

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)