Binomial parameter estimates

`phat = binofit(x,n)`

[phat,pci] = binofit(x,n)

[phat,pci] = binofit(x,n,alpha)

`phat = binofit(x,n)`

returns
a maximum likelihood estimate of the probability of success in a given
binomial trial based on the number of successes, `x`

,
observed in `n`

independent trials. If ```
x
= (x(1), x(2), ... x(k))
```

is a vector, `binofit`

returns
a vector of the same size as `x`

whose ith entry
is the parameter estimate for `x(i)`

. All `k`

estimates
are independent of each other. If `n = (n(1), n(2), ..., n(k))`

is
a vector of the same size as `x`

, the binomial fit, `binofit`

,
returns a vector whose ith entry is the parameter estimate based on
the number of successes `x(i)`

in `n(i)`

independent
trials. A scalar value for `x`

or `n`

is
expanded to the same size as the other input.

`[phat,pci] = binofit(x,n)`

returns
the probability estimate, `phat`

, and the 95% confidence
intervals, `pci`

. `binofit`

uses
the Clopper-Pearson method to calculate confidence intervals.

`[phat,pci] = binofit(x,n,alpha) `

returns the `100(1 - alpha)`

% confidence intervals.
For example, `alpha`

`=`

`0.01`

yields
99% confidence intervals.

**Note**

`binofit`

behaves differently than other Statistics and Machine Learning Toolbox™ functions
that compute parameter estimates, in that it returns independent estimates
for each entry of `x`

. By comparison, `expfit`

returns
a single parameter estimate based on all the entries of `x`

.

Unlike most other distribution fitting functions, the `binofit`

function
treats its input `x`

vector as a collection of measurements
from separate samples. If you want to treat `x`

as
a single sample and compute a single parameter estimate for it, you
can use `binofit(sum(x),sum(n))`

when `n`

is
a vector, and `binofit(sum(X),N*length(X))`

when `n`

is
a scalar.

This example generates a binomial sample of 100 elements, where the probability of success in a given trial is 0.6, and then estimates this probability from the outcomes in the sample.

r = binornd(100,0.6); [phat,pci] = binofit(r,100) phat = 0.5800 pci = 0.4771 0.6780

The 95% confidence interval, `pci`

, contains
the true value, 0.6.

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