Main Content

binofit

Binomial parameter estimates

Description

pHat = binofit(r,n) returns the maximum likelihood estimates (MLEs) of the probability of success in a given binomial trial based on the number of successes r observed in n independent trials.

Note

When r is a vector, binofit, unlike most distribution fitting functions, treats r as a collection of measurements from separate samples. To treat r as a single sample and compute a single parameter estimate for it, use binofit(sum(r),sum(n)) when n is a vector, or binofit(sum(r),n*length(r)) when n is a scalar.

example

[pHat,pCI] = binofit(r,n) also returns the 95% confidence intervals for the parameter estimates.

[pHat,pCI] = binofit(r,n,alpha) specifies the confidence level for the confidence intervals to be 100(1 – alpha)%.

Examples

collapse all

Simulate the number of successes from an experiment with 100 trials, where the probability of success for each trial is 0.6.

rng(0,"twister") % For reproducibility
n = 100;
p = 0.6;
r = binornd(n,p);

Find the maximum likelihood estimate (MLE) and 99% confidence interval of the probability p.

[pHat,pCI] = binofit(r,n,0.01)
pHat = 
0.5500
pCI = 1×2

    0.4170    0.6781

The 99% confidence interval contains the MLE for p.

Input Arguments

collapse all

Number of successes, specified as a nonnegative scalar or an array of nonnegative scalars. The elements of r can be noninteger values. If both r and n are arrays, they must be the same size. If either r or n is a scalar, then binofit expands the scalar argument into a constant array of the same size as the other argument. If either r or n is an array, the ith element in pHat is the MLE estimate based on the number of successes r(i) in n(i) independent trials. The MLE estimate values in pHat are independent of each other.

Data Types: single | double

Number of trials, specified as a positive integer or an array of positive integers. If both r and n are arrays, they must be the same size. If either r or n is a scalar, then binofit expands the scalar argument into a constant array of the same size as the other argument. If either r or n is an array, the ith element in pHat is the MLE estimate based on the number of successes r(i) in n(i) independent trials. The MLE estimate values in pHat are independent of each other.

Data Types: single | double

Significance level for the confidence intervals, specified as a scalar in the range [0,1]. The confidence level is 100(1 – alpha)%, where alpha is the probability that the confidence intervals do not contain the true value.

Data Types: single | double

Output Arguments

collapse all

Binomial parameter estimates, returned as a numeric vector that has the same size as r and n. Each element in pHat is the MLE estimate of the binomial parameter computed using the corresponding elements in r and n.

Confidence intervals for the binomial parameter estimates, returned as a k-by-2 matrix of scalar values, where k is the number of elements in r and n. The first column of pCI contains the lower confidence bound for the binomial parameter, and the second column contains the upper confidence bound.

Note

binofit uses the Clopper–Pearson method to calculate confidence intervals. This method assumes that the values for the number of successes are integers. Therefore, the confidence intervals pCI might not be reliable when r contains noninteger values.

Alternative Functionality

binofit is a function specific to the binomial distribution. Statistics and Machine Learning Toolbox™ also offers the generic functions mle, fitdist, and paramci and the Distribution Fitter app, which support various probability distributions.

  • mle returns MLEs and the confidence intervals of MLEs for the parameters of various probability distributions. You can specify the probability distribution name or a custom probability density function.

  • Create a BinomialDistribution probability distribution object by fitting the distribution to data using the fitdist function or the Distribution Fitter app. The object property p stores the probability of success parameter estimate. To obtain the confidence interval for the parameter estimate, pass the object to paramci.

References

[1] Johnson, N. L., S. Kotz, and A. W. Kemp. Univariate Discrete Distributions. Hoboken, NJ: Wiley-Interscience, 1993.

Extended Capabilities

expand all

Version History

Introduced before R2006a