Categories &

Functions List

Class Definition: ExponentialDistribution

statistics: ExponentialDistribution

Exponential probability distribution object.

A ExponentialDistribution object consists of parameters, a model description, and sample data for a exponential probability distribution.

The exponential distribution is a continuous probability distribution with mean parameter mu that models the time between events in a Poisson process.

There are several ways to create a ExponentialDistribution object.

  • Fit a distribution to data using the fitdist function.
  • Create a distribution with fixed parameter values using the makedist function.
  • Use the constructor ExponentialDistribution (mu) to create a exponential distribution with fixed parameter value mu.
  • Use the static method ExponentialDistribution.fit (x, alpha, censor, freq, options) to fit a distribution to the data in x using the same input arguments as the expfit function.

It is highly recommended to use fitdist and makedist functions to create probability distribution objects, instead of the class constructor or the aforementioned static method.

Further information about the exponential distribution can be found at https://en.wikipedia.org/wiki/Exponential_distribution

See also: fitdist, makedist, expcdf, expinv, exppdf, exprnd, expfit, explike, expstat

Source Code: ExponentialDistribution

Properties

A positive scalar value characterizing the mean of the exponential distribution. You can access the mu property using dot name assignment.

Example: 1

 

 ## Create an Exponential distribution with default parameter
 pd = makedist ("Exponential")

 ## Query parameter 'mu' (mean parameter)
 pd.mu

 ## Set parameter 'mu'
 pd.mu = 2

 ## Use this to initialize or modify the mean parameter of an Exponential
 ## distribution. The mean parameter must be a positive real scalar.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 1

ans = 1
pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

                    

Example: 2

 

 ## Create an Exponential distribution object by calling its constructor
 pd = ExponentialDistribution (1.5)

 ## Query parameter 'mu'
 pd.mu

 ## This demonstrates direct construction with a specific mean parameter,
 ## useful for modeling waiting times with a known average.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 1.5

ans = 1.5000
                    

A character vector specifying the name of the probability distribution object. This property is read-only.

A scalar integer value specifying the number of parameters characterizing the probability distribution. This property is read-only.

A 1×1 cell array of character vectors with each element containing the name of a distribution parameter. This property is read-only.

A 1×1 cell array of character vectors with each element containing a short description of a distribution parameter. This property is read-only.

A 1×1 numeric vector containing the value of the distribution parameter. This property is read-only. You can change the distribution parameter by assigning a new value to the mu property.

A scalar numeric value containing the variance-covariance of the parameter estimate. The covariance matrix is only meaningful when the distribution was fitted to data. If the distribution object was created with fixed parameters, or a parameter of a fitted distribution is modified, then the variance-covariance is zero. This property is read-only.

A 1×1 logical vector specifying whether the parameter is fixed or estimated. true value corresponds to fixed parameter, false value corresponds to parameter estimate. This property is read-only.

A 1×2 numeric vector specifying the truncation interval for the probability distribution. First element contains the lower boundary, second element contains the upper boundary. This property is read-only. You can only truncate a probability distribution with the truncate method.

A logical scalar value specifying whether a probability distribution is truncated or not. This property is read-only.

A scalar structure containing the following fields:

  • data: a numeric vector containing the data used for distribution fitting.
  • cens: a numeric vector of logical values indicating censoring information corresponding to the elements of the data used for distribution fitting. If no censoring vector was used for distribution fitting, then this field defaults to an empty array.
  • freq: a numeric vector of non-negative integer values containing the frequency information corresponding to the elements of the data used for distribution fitting. If no frequency vector was used for distribution fitting, then this field defaults to an empty array.

Methods

ExponentialDistribution: p = cdf (pd, x)
ExponentialDistribution: p = cdf (pd, x, "upper")

p = cdf (pd, x) computes the CDF of the probability distribution object, pd, evaluated at the values in x.

p = cdf (…, "upper") returns the complement of the CDF of the probability distribution object, pd, evaluated at the values in x.

Example: 1

 

 ## Plot various CDFs from the Exponential distribution
 x = 0:0.01:10;
 pd1 = makedist ("Exponential", "mu", 1);
 pd2 = makedist ("Exponential", "mu", 2);
 pd3 = makedist ("Exponential", "mu", 3);
 p1 = cdf (pd1, x);
 p2 = cdf (pd2, x);
 p3 = cdf (pd3, x);
 plot (x, p1, "-b", x, p2, "-g", x, p3, "-r")
 grid on
 legend ({"mu = 1", "mu = 2", "mu = 3"}, "location", "southeast")
 title ("Exponential CDF")
 xlabel ("values in x")
 ylabel ("Cumulative probability")

 ## Use this to compute and visualize the cumulative distribution function
 ## for different Exponential distributions, showing how probability
 ## accumulates over values.

                    
plotted figure

ExponentialDistribution: x = icdf (pd, p)

x = icdf (pd, p) computes the quantile (the inverse of the CDF) of the probability distribution object, pd, evaluated at the values in p.

Example: 1

 

 ## Plot various iCDFs from the Exponential distribution
 p = 0.001:0.001:0.999;
 pd1 = makedist ("Exponential", "mu", 1);
 pd2 = makedist ("Exponential", "mu", 2);
 pd3 = makedist ("Exponential", "mu", 3);
 x1 = icdf (pd1, p);
 x2 = icdf (pd2, p);
 x3 = icdf (pd3, p);
 plot (p, x1, "-b", p, x2, "-g", p, x3, "-r")
 grid on
 legend ({"mu = 1", "mu = 2", "mu = 3"}, "location", "northwest")
 title ("Exponential iCDF")
 xlabel ("Probability")
 ylabel ("values in x")

 ## This demonstrates the inverse CDF (quantiles) for Exponential
 ## distributions, useful for finding values corresponding to
 ## given probabilities.

                    
plotted figure

ExponentialDistribution: r = iqr (pd)

r = iqr (pd) computes the interquartile range of the probability distribution object, pd.

Example: 1

 

 ## Compute the interquartile range for an Exponential distribution
 pd = makedist ("Exponential", "mu", 2)
 iqr_value = iqr (pd)

 ## Use this to calculate the interquartile range, which measures the spread
 ## of the middle 50% of the distribution, useful for understanding variability
 ## in waiting times.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

iqr_value = 2.1972
                    
ExponentialDistribution: m = mean (pd)

m = mean (pd) computes the mean of the probability distribution object, pd.

Example: 1

 

 ## Compute the mean for different Exponential distributions
 pd1 = makedist ("Exponential", "mu", 1);
 pd2 = makedist ("Exponential", "mu", 2);
 mean1 = mean (pd1)
 mean2 = mean (pd2)

 ## This shows how to compute the expected value for Exponential
 ## distributions with different mean parameters.

mean1 = 1
mean2 = 2
                    
ExponentialDistribution: m = median (pd)

m = median (pd) computes the median of the probability distribution object, pd.

Example: 1

 

 ## Compute the median for different Exponential distributions
 pd1 = makedist ("Exponential", "mu", 1);
 pd2 = makedist ("Exponential", "mu", 2);
 median1 = median (pd1)
 median2 = median (pd2)

 ## Use this to find the median value, which splits the distribution
 ## into two equal probability halves.

median1 = 0.6931
median2 = 1.3863
                    
ExponentialDistribution: nlogL = negloglik (pd)

nlogL = negloglik (pd) computes the negative loglikelihood of the probability distribution object, pd.

Example: 1

 

 ## Compute the negative loglikelihood for a fitted Exponential distribution
 pd = makedist ("Exponential", "mu", 2)
 rand ("seed", 5);
 data = random (pd, 100, 1);
 pd_fitted = fitdist (data, "Exponential")
 nlogL = negloglik (pd_fitted)

 ## This is useful for assessing the fit of an Exponential distribution to
 ## data, lower values indicate a better fit.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

pd_fitted =
  ExponentialDistribution

  exponential distribution
       mu = 2.22357   [1.84484, 2.73286]

nlogL = -179.91
                    
ExponentialDistribution: ci = paramci (pd)
ExponentialDistribution: ci = paramci (pd, Name, Value)

ci = paramci (pd) computes the lower and upper boundaries of the 95% confidence interval for each parameter of the probability distribution object, pd.

ci = paramci (pd, Name, Value) computes the confidence intervals with additional options specified by Name-Value pair arguments listed below.

NameValue
"Alpha"A scalar value in the range (0,1) specifying the significance level for the confidence interval. The default value 0.05 corresponds to a 95% confidence interval.
"Parameter"A character vector or a cell array of character vectors specifying the parameter names for which to compute confidence intervals. By default, paramci computes confidence intervals for all distribution parameters.

paramci is meaningful only when pd is fitted to data, otherwise an empty array, [], is returned.

Example: 1

 

 ## Compute confidence intervals for parameters of a fitted Exponential
 ## distribution
 pd = makedist ("Exponential", "mu", 2)
 rand ("seed", 5);
 data = random (pd, 1000, 1);
 pd_fitted = fitdist (data, "Exponential")
 ci = paramci (pd_fitted, "Alpha", 0.05)

 ## Use this to obtain confidence intervals for the estimated parameter (mu),
 ## providing a range of plausible values given the data.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

pd_fitted =
  ExponentialDistribution

  exponential distribution
       mu = 1.96471   [1.8484, 2.0924]

ci =

   1.8484
   2.0924

                    
ExponentialDistribution: y = pdf (pd, x)

y = pdf (pd, x) computes the PDF of the probability distribution object, pd, evaluated at the values in x.

Example: 1

 

 ## Plot various PDFs from the Exponential distribution
 x = 0:0.01:10;
 pd1 = makedist ("Exponential", "mu", 1);
 pd2 = makedist ("Exponential", "mu", 2);
 pd3 = makedist ("Exponential", "mu", 3);
 y1 = pdf (pd1, x);
 y2 = pdf (pd2, x);
 y3 = pdf (pd3, x);
 plot (x, y1, "-b", x, y2, "-g", x, y3, "-r")
 grid on
 legend ({"mu = 1", "mu = 2", "mu = 3"}, "location", "northeast")
 title ("Exponential PDF")
 xlabel ("values in x")
 ylabel ("Probability density")

 ## This visualizes the probability density function for Exponential
 ## distributions, showing the likelihood of different values.

                    
plotted figure

ExponentialDistribution: plot (pd)
ExponentialDistribution: plot (pd, Name, Value)
ExponentialDistribution: h = plot (…)

plot (pd) plots a probability density function (PDF) of the probability distribution object pd. If pd contains data, which have been fitted by fitdist, the PDF is superimposed over a histogram of the data.

plot (pd, Name, Value) specifies additional options with the Name-Value pair arguments listed below.

NameValue
"PlotType"A character vector specifying the plot type. "pdf" plots the probability density function (PDF). When pd is fit to data, the PDF is superimposed on a histogram of the data. "cdf" plots the cumulative density function (CDF). When pd is fit to data, the CDF is superimposed over an empirical CDF. "probability" plots a probability plot using a CDF of the data and a CDF of the fitted probability distribution. This option is available only when pd is fitted to data.
"Discrete"A logical scalar to specify whether to plot the PDF or CDF of a discrete distribution object as a line plot or a stem plot, by specifying false or true, respectively. By default, it is true for discrete distributions and false for continuous distributions. When pd is a continuous distribution object, option is ignored.
"Parent"An axes graphics object for plot. If not specified, the plot function plots into the current axes or creates a new axes object if one does not exist.

h = plot (…) returns a graphics handle to the plotted objects.

Example: 1

 

 ## Create an Exponential distribution with fixed parameter mu = 2 and plot its PDF.

 pd = makedist ("Exponential", "mu", 2)
 plot (pd)
 title ("Fixed Exponential distribution with mu = 2")

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

                    
plotted figure

Example: 2

 

 ## Generate a data set of 100 random samples from an Exponential
 ## distribution with parameter mu = 2. Fit an Exponential
 ## distribution to this data and plot its CDF superimposed over an empirical
 ## CDF.

 pd_fixed = makedist ("Exponential", "mu", 2)
 rand ("seed", 5);
 data = random (pd_fixed, 100, 1);
 pd_fitted = fitdist (data, "Exponential")
 plot (pd_fitted, "PlotType", "cdf")
 txt = "Fitted Exponential distribution with mu = %0.2f";
 title (sprintf (txt, pd_fitted.mu))
 legend ({"empirical CDF", "fitted CDF"}, "location", "southeast")

 ## Use this to visualize the fitted CDF compared to the empirical CDF of the
 ## data, useful for assessing model fit.

pd_fixed =
  ExponentialDistribution

  exponential distribution
       mu = 2

pd_fitted =
  ExponentialDistribution

  exponential distribution
       mu = 2.19518   [1.82129, 2.69797]

                    
plotted figure

Example: 3

 

 ## Generate a data set of 200 random samples from an Exponential
 ## distribution with parameter mu = 2. Display a probability
 ## plot for the Exponential distribution fit to the data.

 pd_fixed = makedist ("Exponential", "mu", 2)
 rand ("seed", 5);
 data = random (pd_fixed, 200, 1);
 pd_fitted = fitdist (data, "Exponential")
 plot (pd_fitted, "PlotType", "probability")
 txt = strcat ("Probability plot of fitted Exponential", ...
               " distribution with mu = %0.2f");
 title (sprintf (txt, pd_fitted.mu))
 legend ({"empirical CDF", "fitted CDF"}, "location", "southeast")

 ## This creates a probability plot to compare the fitted distribution to the
 ## data, useful for checking if the Exponential model is appropriate.

pd_fixed =
  ExponentialDistribution

  exponential distribution
       mu = 2

pd_fitted =
  ExponentialDistribution

  exponential distribution
       mu = 1.92184   [1.68101, 2.21869]

                    
plotted figure

ExponentialDistribution: [nlogL, param] = proflik (pd, pnum)
ExponentialDistribution: [nlogL, param] = proflik (pd, pnum, "Display", display)
ExponentialDistribution: [nlogL, param] = proflik (pd, pnum, setparam)
ExponentialDistribution: [nlogL, param] = proflik (pd, pnum, setparam, "Display", display)

[nlogL, param] = proflik (pd, pnum) returns a vector nlogL of negative loglikelihood values and a vector param of corresponding parameter values for the parameter in the position indicated by pnum. By default, proflik uses the lower and upper bounds of the 95% confidence interval and computes 100 equispaced values for the selected parameter. pd must be fitted to data.

[nlogL, param] = proflik (pd, pnum, "Display", "on") also plots the profile likelihood against the default range of the selected parameter.

[nlogL, param] = proflik (pd, pnum, setparam) defines a user-defined range of the selected parameter.

[nlogL, param] = proflik (pd, pnum, setparam, "Display", "on") also plots the profile likelihood against the user-defined range of the selected parameter.

For the exponential distribution, pnum = 1 selects the parameter mu.

When opted to display the profile likelihood plot, proflik also plots the baseline loglikelihood computed at the lower bound of the 95% confidence interval and estimated maximum likelihood. The latter might not be observable if it is outside of the used-defined range of parameter values.

Example: 1

 

 ## Compute and plot the profile likelihood for the mean parameter of a fitted
 ## Exponential distribution
 pd = makedist ("Exponential", "mu", 2)
 rand ("seed", 5);
 data = random (pd, 1000, 1);
 pd_fitted = fitdist (data, "Exponential")
 [nlogL, param] = proflik (pd_fitted, 1, "Display", "on");

 ## Use this to analyze the profile likelihood of the mean parameter (mu),
 ## helping to understand the uncertainty in parameter estimates given the data.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

pd_fitted =
  ExponentialDistribution

  exponential distribution
       mu = 1.97974   [1.86255, 2.10841]

                    
plotted figure

ExponentialDistribution: r = random (pd)
ExponentialDistribution: r = random (pd, rows)
ExponentialDistribution: r = random (pd, rows, cols, …)
ExponentialDistribution: r = random (pd, [sz])

r = random (pd) returns a random number from the distribution object pd.

When called with a single size argument, betarnd returns a square matrix with the dimension specified. When called with more than one scalar argument, the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a row vector of dimensions, sz.

Example: 1

 

 ## Generate random samples from an Exponential distribution
 pd = makedist ("Exponential", "mu", 2)
 rand ("seed", 5);
 samples = random (pd, 500, 1);
 hist (samples, 50)
 title ("Histogram of 500 random samples from Exponential(mu=2)")
 xlabel ("values in x")
 ylabel ("Frequency")

 ## This generates random samples from an Exponential distribution, useful
 ## for simulating waiting times or inter-arrival times.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

                    
plotted figure

ExponentialDistribution: s = std (pd)

s = std (pd) computes the standard deviation of the probability distribution object, pd.

Example: 1

 

 ## Compute the standard deviation for an Exponential distribution
 pd = makedist ("Exponential", "mu", 2)
 std_value = std (pd)

 ## Use this to calculate the standard deviation, which measures the variability
 ## in the distribution.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

std_value = 2
                    
ExponentialDistribution: t = truncate (pd, lower, upper)

t = truncate (pd, lower, upper) returns a probability distribution t, which is the probability distribution pd truncated to the specified interval with lower limit, lower, and upper limit, upper. If pd is fitted to data with fitdist, the returned probability distribution t is not fitted, does not contain any data or estimated values, and it is as it has been created with the makedist function, but it includes the truncation interval.

Example: 1

 

 ## Plot the PDF of an Exponential distribution, with parameter mu = 2,
 ## truncated at [1, 5] intervals. Generate 10000 random
 ## samples from this truncated distribution and superimpose a histogram scaled
 ## accordingly

 pd = makedist ("Exponential", "mu", 2)
 t = truncate (pd, 1, 3)
 rand ("seed", 5);
 data = random (t, 10000, 1);

 ## Plot histogram and fitted PDF
 plot (t)
 hold on
 hist (data, 100, 50)
 hold off
 title ("Exponential distribution (mu = 2) truncated at [1, 5]")
 legend ("Truncated PDF", "Histogram")

 ## This demonstrates truncating an Exponential distribution to a specific
 ## range and visualizing the resulting distribution with random samples.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

t =
  ExponentialDistribution

  exponential distribution
       mu = 2
  Truncated to the interval [1, 3]

                    
plotted figure

ExponentialDistribution: v = var (pd)

v = var (pd) computes the variance of the probability distribution object, pd.

Example: 1

 

 ## Compute the variance for an Exponential distribution
 pd = makedist ("Exponential", "mu", 2)
 var_value = var (pd)

 ## Use this to calculate the variance, which quantifies the spread of the
 ## distribution.

pd =
  ExponentialDistribution

  exponential distribution
       mu = 2

var_value = 4