メインコンテンツ

EmpiricalDistribution

Empirical probability distribution object

Since R2025a

Description

An EmpiricalDistribution probability distribution object contains the 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, represented as a numeric column vector of 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, represented as a numeric column vector. FX(i) contains the cdf value of X(i).

Data Types: single | double

This property is read-only.

Logical flag for a truncated distribution, represented as 0 or 1. If IsTruncated is 0, the distribution is not truncated. If IsTruncated is 1, the distribution is truncated.

Data Types: logical

This property is read-only.

Truncation interval for the probability distribution, represented as a vector of numeric scalars containing the lower and upper truncation boundaries.

Data Types: single | double

Other Object Properties

This property is read-only.

Probability distribution name, represented as a character vector.

Data Types: char

This property is read-only.

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

  • data – Data vector used for distribution fitting

  • cens – Censoring vector (empty if none)

  • freq – Frequency vector (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 an empirical probability distribution object by using fitdist to fit an empirical distribution to the same data x. The object contains various distribution properties, such as the 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

Plot the evaluation points X and the cdf values FX.

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

Superimpose the empirical cdf returned by 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 follow each other closely. The empirical cdf also closely follows the normal distribution cdf.

Alternative Functionality

You can use the distribution-specific function ecdf with a data sample to evaluate its empirical cdf at a vector of points or a matrix of intervals. Use the ecdfhist function to calculate heights and bin centers for an empirical cdf.

Version History

Introduced in R2025a