Binomial parameter estimates with method of moments
parmhat = distfun_binofitmm( data )
a matrix of doubles, the data, in the set {0,1,2,3,...}.
a 1-by-2 matrix of doubles, the parameters of the Binomial distribution. parmhat(1) is N, parmhat(2) is pr.
Estimates the parameters of the Binomial distribution with method of moments. In other words, finds the parameters so that the mean and variance of the distribution are equal to the empirical mean and empirical variance of the data.
The implementation uses direct inversion. The exact solution may generate a non integer N : the estimated N is the integer nearest to the exact solution. Moreover, this may be lower than 1 : in this case, the estimate is set to 1.
// Samples from Binomial distribution with // N=12 and pr=0.42 data = [7 3 7 7 3 8 7 4 6 4] parmhat = distfun_binofitmm(data) N=parmhat(1); pr=parmhat(2); // Compare the (mean,variance) of the // distribution against the data : // must be close, but cannot be equal // because N must be integer. [M,V]=distfun_binostat(N,pr) M_data=mean(data) V_data=variance(data) // Error : We must have more than one data. // parmhat = distfun_binofitmm(0) // Error : The mean must be nonzero. // parmhat = distfun_binofitmm([0 0]) // Error : The estimated pr is lower or equal than zero // parmhat = distfun_binofitmm(1:7) // parmhat = distfun_binofitmm(1:8) | ![]() | ![]() |