How to find parameters of binomial distribution?

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.

 Risposta accettata

Star Strider
Star Strider il 31 Gen 2019
If you have the Statsitics and Machine Learning Toolbox, see if the binofit (link) function will do what you want.

15 Commenti

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.
My pleasure.
I am still not certain what result you want.
Using the binoinv (link) function, and the information from your original Question:
Y = 4/20;
N = 20;
P = 0.3;
X = binoinv(Y,N,P)
X =
4.0000
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
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.
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)
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.
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.
Thjat is the only option I believe is appropriate.
Post back with your results.
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.
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?
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.
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.
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’.
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!!!!
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by