Statistics: expfit

### Function Reference: `expfit`

statistics: muhat = expfit (x)
statistics: [muhat, muci] = expfit (x)
statistics: [muhat, muci] = expfit (x, alpha)
statistics: […] = expfit (x, alpha, censor)
statistics: […] = expfit (x, alpha, censor, freq)

Estimate mean and confidence intervals for the exponential distribution.

`muhat = expfit (x)` returns the maximum likelihood estimate of the mean parameter, muhat, of the exponential distribution given the data in x. x is expected to be a non-negative vector. If x is an array, the mean will be computed for each column of x. If any elements of x are NaN, that vector’s mean will be returned as NaN.

`[muhat, muci] = expfit (x)` returns the 95% confidence intervals for the parameter estimate. If x is a vector, muci is a two element column vector. If x is an array, each column of data will have a confidence interval returned as a two-row array.

`[…] = evfit (x, alpha)` also returns the `100 * (1 - alpha)` percent confidence intervals for the parameter estimates. By default, the optional argument alpha is 0.05 corresponding to 95% confidence intervals. Pass in `[]` for alpha to use the default values. Any invalid values for alpha will return NaN for both CI bounds.

`[…] = expfit (x, alpha, censor)` accepts a logical or numeric array, censor, of the same size as x with `1`s for observations that are right-censored and `0`s for observations that are observed exactly. Any non-zero elements are regarded as `1`s. By default, or if left empty, `censor = zeros (size (x))`.

`[…] = expfit (x, alpha, censor, freq)` accepts a frequency array, freq, of the same size as x. freq typically contains integer frequencies for the corresponding elements in x, but it can contain any non-integer non-negative values. By default, or if left empty, `freq = ones (size (x))`.

Matlab incompatibility: Matlab’s `expfit` produces unpredictable results for some cases with higher dimensions (specifically 1 x m x n x ... arrays). Octave’s implementation allows for n×D arrays, consistently performing calculations on individual column vectors. Additionally, censor and freq can be used with arrays of any size, whereas Matlab only allows their use when x is a vector.

A common alternative parameterization of the exponential distribution is to use the parameter λ defined as the mean number of events in an interval as opposed to the parameter μ, which is the mean wait time for an event to occur. λ and μ are reciprocals, i.e. μ = 1 / λ.

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

See also: expcdf, expinv, explpdf, exprnd, explike, expstat

Source Code: expfit

### Example: 1

     ## Sample 3 populations from 3 different exponential distibutions
     rande ("seed", 1);   # for reproducibility
     r1 = exprnd (2, 4000, 1);
     rande ("seed", 2);   # for reproducibility
     r2 = exprnd (5, 4000, 1);
     rande ("seed", 3);   # for reproducibility
     r3 = exprnd (12, 4000, 1);
     r = [r1, r2, r3];

     ## Plot them normalized and fix their colors
     hist (r, 48, 0.52);
     h = findobj (gca, "Type", "patch");
     set (h(1), "facecolor", "c");
     set (h(2), "facecolor", "g");
     set (h(3), "facecolor", "r");
     hold on

     ## Estimate their mu parameter
     muhat = expfit (r);

     ## Plot their estimated PDFs
     x = [0:max(r(:))];
     y = exppdf (x, muhat(1));
     plot (x, y, "-pr");
     y = exppdf (x, muhat(2));
     plot (x, y, "-sg");
     y = exppdf (x, muhat(3));
     plot (x, y, "-^c");
     ylim ([0, 0.6])
     xlim ([0, 40])
     legend ({"Normalized HIST of sample 1 with μ=2", ...
              "Normalized HIST of sample 2 with μ=5", ...
              "Normalized HIST of sample 3 with μ=12", ...
              sprintf("PDF for sample 1 with estimated μ=%0.2f", muhat(1)), ...
              sprintf("PDF for sample 2 with estimated μ=%0.2f", muhat(2)), ...
              sprintf("PDF for sample 3 with estimated μ=%0.2f", muhat(3))})
     title ("Three population samples from different exponential distibutions")
     hold off