Categories &

Functions List

Function Reference: unidfit

statistics: Nhat = unidfit (x)
statistics: [Nhat, Nci] = unidfit (x)
statistics: [Nhat, Nci] = unidfit (x, alpha)
statistics: [Nhat, Nci] = unidfit (x, alpha, freq)

Estimate parameter and confidence intervals for the discrete uniform distribution.

Nhat = unidfit (x) returns the maximum likelihood estimate (MLE) of the maximum observable value for the discrete uniform distribution. x must be a vector.

[Nhat, Nci] = unidfit (x, alpha) also returns the 100 * (1 - alpha) percent confidence intervals of the estimated parameter. By default, the optional argument alpha is 0.05 corresponding to 95% confidence intervals. Pass in [] for alpha to use the default values.

[…] = unidfit (x, alpha, freq) accepts a frequency vector, 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)).

Further information about the discrete uniform distribution can be found at https://en.wikipedia.org/wiki/Discrete_uniform_distribution

See also: unidcdf, unidinv, unidpdf, unidrnd, unidstat

Source Code: unidfit

Example: 1

Sample 2 populations from different discrete uniform distributions

 rand ('seed', 1);    # for reproducibility
 r1 = unidrnd (5, 1000, 1);
 rand ('seed', 2);    # for reproducibility
 r2 = unidrnd (9, 1000, 1);
 r = [r1, r2];

Plot them normalized and fix their colors

 hist (r, 0:0.5:20.5, 1);
 h = findobj (gca, 'Type', 'patch');
 set (h(1), 'facecolor', 'c');
 set (h(2), 'facecolor', 'g');
 hold on

Estimate their probability of success

 NhatA = unidfit (r(:,1));
 NhatB = unidfit (r(:,2));

Plot their estimated PDFs

 x = [0:10];
 y = unidpdf (x, NhatA);
 plot (x, y, '-pg');
 y = unidpdf (x, NhatB);
 plot (x, y, '-sc');
 xlim ([0, 10])
 ylim ([0, 0.4])
 legend ({'Normalized HIST of sample 1 with N=5', ...
          'Normalized HIST of sample 2 with N=9', ...
          sprintf("PDF for sample 1 with estimated N=%0.2f", NhatA), ...
          sprintf("PDF for sample 2 with estimated N=%0.2f", NhatB)})
 title ('Two population samples from different discrete uniform distributions')
 hold off
plotted figure