unifit
statistics: ahat = unifit (x)
statistics: [ahat, bhat] = unifit (x)
statistics: [ahat, bhat, aci, bci] = unifit (x)
statistics: […] = unifit (x, alpha)
statistics: […] = unifit (x, alpha, freq)
Estimate parameters and confidence intervals for the continuous uniform distribution.
[ahat, bhat] = unifit (x) returns the maximum
likelihood estimates of the lower and upper endpoints, a and b,
of the continuous uniform distribution given the data in x. Each
estimate is returned as a separate output.
x may be a vector, which is fitted as a single sample, or a matrix, which is fitted column by column. For a matrix of columns ahat and bhat are -by- row vectors and aci and bci are -by-.
[ahat, bhat, aci, bci] = unifit (x) also
returns the 95% confidence intervals of the two estimates, one column per
column of x, with the lower bound in the first row and the upper bound
in the second. ahat is the upper bound of aci and bhat the
lower bound of bci, since no sample can fall outside the fitted range.
[…] = unifit (x, alpha) also returns the
100 * (1 - alpha) percent confidence intervals of the
estimated parameters. By default, the optional argument alpha is
0.05 corresponding to 95% confidence intervals. Pass in [] for
alpha to use the default values.
[…] = unifit (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)). This third
argument is an Octave extension; MATLAB’s unifit takes two inputs at
most, and freq is accepted for a vector x only.
Further information about the continuous uniform distribution can be found at https://en.wikipedia.org/wiki/Continuous_uniform_distribution
See also: unifcdf, unifinv, unifpdf, unifrnd, unifstat
Source Code: unifit
Sample 2 populations from different continuous uniform distributions
rand ('seed', 5); # for reproducibility
r1 = unifrnd (2, 5, 2000, 1);
rand ('seed', 6); # for reproducibility
r2 = unifrnd (3, 9, 2000, 1);
r = [r1, r2];
Plot them normalized and fix their colors
hist (r, 0:0.5:10, 2); h = findobj (gca, 'Type', 'patch'); set (h(1), 'facecolor', 'c'); set (h(2), 'facecolor', 'g'); hold on
Estimate their probability of success
a_bA = unifit (r(:,1)); a_bB = unifit (r(:,2));
Plot their estimated PDFs
x = [0:10];
y = unifpdf (x, a_bA(1), a_bA(2));
error: a_bA(2): out of bound 1 (dimensions are 1x1)
plot (x, y, '-pg');
y = unifpdf (x, a_bB(1), a_bB(2));
plot (x, y, '-sc');
xlim ([1, 10])
ylim ([0, 0.5])
legend ({'Normalized HIST of sample 1 with a=2 and b=5', ...
'Normalized HIST of sample 2 with a=3 and b=9', ...
sprintf("PDF for sample 1 with estimated a=%0.2f and b=%0.2f", ...
a_bA(1), a_bA(2)), ...
sprintf("PDF for sample 2 with estimated a=%0.2f and b=%0.2f", ...
a_bB(1), a_bB(2))})
title ('Two population samples from different continuous uniform distributions')
hold off