Main Content

EmpiricalDistribution

Empirical probability distribution object

Since R2025a

Description

An EmpiricalDistribution object consists of distribution name, object parameters, and input data for a nonparametric empirical distribution.

The empirical distribution is a nonparametric estimation of the cumulative distribution function (cdf) of a set of data.

Creation

Create an EmpiricalDistribution probability distribution object by fitting a distribution to data using fitdist.

Properties

expand all

Distribution Characteristics

This property is read-only.

Evaluation points, specified as a column vector, for fully observed, left-censored, right-censored, and double-censored data.

X contains values for uncensored observations from the input data. These observations are sorted and do not contain any duplicates.

X includes the minimum value of the input data as its first two values. These two values are useful for plotting X using the stairs function.

Data Types: single | double

This property is read-only.

Cumulative distribution function (cdf) values evaluated at the points in X, stored as a column vector. FX(i) contains the cdf value of X(i).

Data Types: single | double

This property is read-only.

Logical flag for truncated distribution, specified as a logical value. If IsTruncated equals 0, the distribution is not truncated. If IsTruncated equals 1, the distribution is truncated.

Data Types: logical

This property is read-only.

Truncation interval for the probability distribution, specified as a vector of scalar values containing the lower and upper truncation boundaries.

Data Types: single | double

Other Object Properties

This property is read-only.

Probability distribution name, specified as a character vector.

Data Types: char

This property is read-only.

Data used for distribution fitting, specified as a structure containing the following:

  • data: Data vector used for distribution fitting.

  • cens: Censoring vector, or empty if none.

  • freq: Frequency vector, or empty if none.

Data Types: struct

Object Functions

cdfCumulative distribution function
gatherGather properties of Statistics and Machine Learning Toolbox object from GPU
icdfInverse cumulative distribution function
iqrInterquartile range of probability distribution
meanMean of probability distribution
medianMedian of probability distribution
negloglikNegative loglikelihood of probability distribution
pdfProbability density function
plotPlot probability distribution object
randomRandom numbers
stdStandard deviation of probability distribution
truncateTruncate probability distribution object
varVariance of probability distribution

Examples

collapse all

Generate random data from a standard normal distribution. Visualize the data x using a histogram.

rng("twister") % For reproducibility
mu = 0;
sigma = 1;
normalpd = makedist("Normal");
x = random(normalpd, [100 1]);
histogram(x)

Figure contains an axes object. The axes object contains an object of type histogram.

The histogram has a typical bell-shape with a single mode.

Create a empirical distribution object by fitting a empirical distribution to the same data x using fitdist. It contains various distribution properties like evaluation points (X), cdf values (FX), and InputData.

empiricalpd =  fitdist(x,"Empirical");
properties(empiricalpd)
Properties for class prob.EmpiricalDistribution:

    DistributionName
    X
    FX
    Truncation
    IsTruncated
    InputData

Now, plot the evaluation points X and cdf values FX.

figure
plot(empiricalpd.X,empiricalpd.FX)
hold on

Superimpose the cdf returned from the ecdf function.

empiricalCdf = ecdf(empiricalpd.X);
plot(empiricalpd.X,empiricalCdf)
hold on

Superimpose the normal cdf.

normalCdf = cdf(normalpd,empiricalpd.X);
plot(empiricalpd.X,normalCdf)
legend("FX from empirical distribution object","Empirical cdf from ecdf","Known population (Normal) cdf", ...
    "Location","southeast")
hold off

Figure contains an axes object. The axes object contains 3 objects of type line. These objects represent FX from empirical distribution object, Empirical cdf from ecdf, Known population (Normal) cdf.

The plot shows that ecdf and FX contain identical values. The empirical cdf also closely follows the normal distribution cdf.

Version History

Introduced in R2025a