You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to find parameters of binomial distribution?
3 views (last 30 days)
Show older comments
Dear all,
What code can I use in matlab to find the parameters of a binomial distribution? This question is very big. So I am restricting it to a specific situation.
X is binomiallly distributed with parameter n and fraction p. The parameter p is unknown.
What function in matlab can help me to find that parameter if for example it is known that X=randi(10,20,1); P(X<=4)=0.3?
Thank you in advance.
Accepted Answer
Star Strider
on 31 Jan 2019
If you have the Statsitics and Machine Learning Toolbox, see if the binofit (link) function will do what you want.
15 Comments
Clarisha Nijman
on 31 Jan 2019
Thank a lot Star,
I had also checked that option, but as I understand it just generally finds the cumulative distribution of that probablity distribution. That is not the function I am looking for. How to find the parameter if you know that the probability is for example P(X<=4)=0.3.
Star Strider
on 31 Jan 2019
My pleasure.
I am still not certain what result you want.
Y = 4/20;
N = 20;
P = 0.3;
X = binoinv(Y,N,P)
X =
4.0000
Clarisha Nijman
on 31 Jan 2019
Let me start with the way I understand the binoinv function works:
X is binomially distributed with N, P [N is number of trials, P is fraction of succeses]
F(k)=P(X<=k)=Y [F is cumlative distribution function, k is the actual number of sucesses, en Y is probability of the number of sucesses is less equal then k]
So binoinv computes the X, the limitting number of successes, such that F(k)=Y holds.
In my case every thing is known, except the P: The four other inputs are known: the N, the X, the k, and the Y are known. I cannot find a function in matlab to find the P
Star Strider
on 31 Jan 2019
I am not certain what you want to do or what function would be most appropriate, because I do not completely understand the problem you want to solve.
One option for ‘inverting’ a function would be to use it with an optimization function, and solve for the variable you want.
For example using fminsearch:
Y = 4/20;
N = 20;
X = 6;
Pr = fminsearch(@(P) norm(binoinv(Y,N,P) - X), 1)
produces:
Pr =
0.399999999999999
Experiment to get the result you want.
Clarisha Nijman
on 31 Jan 2019
The exact problem is:
I have a set of observations, X, and finding Q1, the first quartile (or 25th percentile) is not a problem.
Now I want to have the binomial distribution of the set of the observations less or equal then the first quartile (Q1). Given that the set of trials is known, I only need to find the the fraction (P)
Star Strider
on 1 Feb 2019
I still do not understand what you want. I have no idea what ‘P’ is and how it relates to your problem.
I will delete my Answer few hours.
Clarisha Nijman
on 1 Feb 2019
After reading and reading, it looks like the p is called the maximum likelihood. So the binofit mentioned by you seems to be the best solution. I am not really sure. I'll try to use that an see what it gives.
Star Strider
on 1 Feb 2019
Thjat is the only option I believe is appropriate.
Post back with your results.
Clarisha Nijman
on 1 Feb 2019
Thanks a lot Star,
Posting my results is not possible, it is a large data set of 360,000 observations! But I'll try to think of a small example that is can be verified easily.
Clarisha Nijman
on 1 Feb 2019
De results are not good!
Can you correct me? I will write what I understood:
binofit, finds ..... the maximum likelihood estimate OF the probability of success .......
and with mle function you find the maximum likelihood estimate FOR the probability of succes?
Star Strider
on 1 Feb 2019
It uses the mle (link) function to fit the distribution to your data. You can use it yourself to fit the binomial distributin to your data. Since mle, as is true of all nonlinear iterative parameter estimation methods, is sensitive to the initial parameter estimates, consider using mle with your data, and different initial parameter estimates to see if you can get a better fit.
I still do not understand what you are doing, or even if the binomial distribution would be appropriate for your data and experiment design. If it is not appropriate, that could be the reason you are having problems fitting it to your data.
Clarisha Nijman
on 1 Feb 2019
I just wanted to know how to find the fracion of a large data set that is said to be binomially distributed. suppose X are 20 realization and binomially distributed.
X=randi(10,20,1) and X~bin(20,p),, Find p by using a matlab code.
Star Strider
on 1 Feb 2019
For that problem, this appears to be the correct approach:
X=randi(10,20,1);
Px4 = nnz(X <= 4)/numel(X); % Single Probability
[P,Pci] = binofit(Px4, numel(X)) % Binomial Probability Of A ‘Px4’ Fraction Of ‘X’ Being <= 4, Those Being Defined As A ‘Success’
If you run this several times, you will get different results for each iteration, depending on the elements of ‘X’. and therefore the value of ‘Px4’.
Clarisha Nijman
on 2 Feb 2019
That is it!!!!!!
the problem was the interpretation of the first parameter of the binofit function.
But now I understand, x is not the number of the succeses, but the probability of success in a given binomial trial based on the ACTUAL number of successes,
Once more thanks a lot!!!!
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)