Categories &

Functions List

Function Reference: betafit

statistics: paramhat = betafit (x)
statistics: [paramhat, paramci] = betafit (x)
statistics: [paramhat, paramci] = betafit (x, alpha)
statistics: [paramhat, paramci] = betafit (x, alpha, freq)
statistics: [paramhat, paramci] = betafit (x, alpha, options)
statistics: [paramhat, paramci] = betafit (x, alpha, freq, options)

Estimate parameters and confidence intervals for the Beta distribution.

paramhat = betafit (x) returns the maximum likelihood estimates of the parameters of the Beta distribution given the data in vector x. paramhat([1, 2]) corresponds to the α and β shape parameters, respectively. Missing values, NaNs, are ignored.

[paramhat, paramci] = betafit (x) returns the 95% confidence intervals for the parameter estimates.

[…] = betafit (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.

[…] = betafit (params, x, freq) accepts a frequency vector, freq, of the same size as x. freq must contain non-negative integer frequencies for the corresponding elements in x. By default, or if left empty, freq = ones (size (x)).

[paramhat, paramci] = nbinfit (x, alpha, options) specifies control parameters for the iterative algorithm used to compute ML estimates with the fminsearch function. options is a structure with the following fields and their default values:

  • options.Display = "off"
  • options.MaxFunEvals = 400
  • options.MaxIter = 200
  • options.TolX = 1e-6

The Beta distribution is defined on the open interval (0,1). However, betafit can also compute the unbounded beta likelihood function for data that include exact zeros or ones. In such cases, zeros and ones are treated as if they were values that have been left-censored at sqrt (realmin) or right-censored at 1 - eps/2, respectively.

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

See also: betacdf, betainv, betapdf, betarnd, betalike, betastat

Source Code: betafit

Example: 1

 

 ## Sample 2 populations from different Beta distibutions
 randg ("seed", 1);   # for reproducibility
 r1 = betarnd (2, 5, 500, 1);
 randg ("seed", 2);   # for reproducibility
 r2 = betarnd (2, 2, 500, 1);
 r = [r1, r2];

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

 ## Estimate their shape parameters
 a_b_A = betafit (r(:,1));
 a_b_B = betafit (r(:,2));

 ## Plot their estimated PDFs
 x = [min(r(:)):0.01:max(r(:))];
 y = betapdf (x, a_b_A(1), a_b_A(2));
 plot (x, y, "-pr");
 y = betapdf (x, a_b_B(1), a_b_B(2));
 plot (x, y, "-sg");
 ylim ([0, 4])
 legend ({"Normalized HIST of sample 1 with α=2 and β=5", ...
          "Normalized HIST of sample 2 with α=2 and β=2", ...
          sprintf("PDF for sample 1 with estimated α=%0.2f and β=%0.2f", ...
                  a_b_A(1), a_b_A(2)), ...
          sprintf("PDF for sample 2 with estimated α=%0.2f and β=%0.2f", ...
                  a_b_B(1), a_b_B(2))})
 title ("Two population samples from different Beta distibutions")
 hold off

                    
plotted figure