MATLAB Answers

Binomial Distribution when mean and variance is given

조회 수: 7(최근 30일)
Soham Baste
Soham Baste 11 Apr 2021
댓글: dpb 11 Apr 2021
How do i plot a Binomial Distribution when i have been given its mean and variance for example like mean = 3, variance = 3 or 0.5,2.......these values dont satisfy the conditions for mean and variance which are mean should lie between 0 and 1 and variance should be less than mean(mean - 1)...But these are the values i have to find the binomial distribution for...this is code i have written....
mu = 3;
var = 3;
alpha = (((1-mu)/var)-1/mu).*mu^2;
beta = alpha((1/mu) - 1);
X = 0:0.01:1;
Y = betapdf(X,alpha,beta);
%plot(X,Y,'LineWidth',1);
xlabel('Thetha');
hold on
mu2 = 0.5;
var2 =2 ;
alpha2 = (((1-mu2)/var2)-1/mu2).*mu2^2;
beta2 = alpha2((1/mu2) - 1);
X2 = 0:0.01:1;
Y2 = betapdf(X2,alpha2,beta2);
plot(X2,Y2,'LineWidth',1);
hold off;

채택된 답변

dpb
dpb 11 Apr 2021
Well, sometimes one is given a nonsensical problem -- if so, then one has to inform the requestor of the fact and get a different problem formulation.
For a binomial you can write that
E(x)=np
V(x)=np(1-p) --> E(x)(1-p) or
V(x)/E(x)=(1-p) --> p=1-V(x)/E(x)
from which, if one is given values for both V and E, it's directly computable what pest must be. If it is outside [0,1], then the result is nonsensical and you have no choice but to return that result.
For the first case of V,E = 3, the answer is that p=0 and then the mean will be identical to 0 so that, too is nonsensical even though one can "solve" the two simultaneous equations algebraically to compute a value that satisfies the composite value of the quantitiy NP as a value, when substitute back to find
n=E/p --> inf
In short, the short answer is "You can't!" and shouldn't even try; simply check the bounds of the input and return error indication if the needed assumptions are not met.
That said, perhaps if we knew something of the problem space there might be some alternative interpretation to be made of the data and some other way to approach it rather than by the impossible.
  댓글 수: 3
dpb
dpb 11 Apr 2021
As written, that looks to me to be just a case of evaluating the given pdfs and then doing as you say, compute the given transformation with the two values for α and β. It would be an empirical pdf and cdf. MATLAB has functions for the latter if have Statistics TB and allowed to use it.
You could then fit the empirical to estimate coefficients of a beta distribution; there is, iirc, a specific function provided for it; nonlnear least-squares will do it otherwise.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by