geofit
Estimate parameter and confidence intervals for the geometric distribution.
pshat = geofit (x) returns the maximum likelihood estimate
(MLE) of the probability of success for the geometric distribution. x
must be a vector.
[pshat, psci] = geofit (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.
[…] = geofit (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)).
The geometric distribution models the number of failures (x) of a Bernoulli trial with probability ps before the first success.
Further information about the geometric distribution can be found at https://en.wikipedia.org/wiki/Geometric_distribution
See also: geocdf, geoinv, geopdf, geornd, geostat
Source Code: geofit
## Sample 2 populations from different geometric distibutions
rande ("seed", 1); # for reproducibility
r1 = geornd (0.15, 1000, 1);
rande ("seed", 2); # for reproducibility
r2 = geornd (0.5, 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
pshatA = geofit (r(:,1));
pshatB = geofit (r(:,2));
## Plot their estimated PDFs
x = [0:15];
y = geopdf (x, pshatA);
plot (x, y, "-pg");
y = geopdf (x, pshatB);
plot (x, y, "-sc");
xlim ([0, 15])
ylim ([0, 0.6])
legend ({"Normalized HIST of sample 1 with ps=0.15", ...
"Normalized HIST of sample 2 with ps=0.50", ...
sprintf("PDF for sample 1 with estimated ps=%0.2f", ...
mean (pshatA)), ...
sprintf("PDF for sample 2 with estimated ps=%0.2f", ...
mean (pshatB))})
title ("Two population samples from different geometric distibutions")
hold off
|