How to find parameters of binomial distribution?
2 次查看(过去 30 天)
显示 更早的评论
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.
采纳的回答
Star Strider
2019-1-31
If you have the Statsitics and Machine Learning Toolbox, see if the binofit (link) function will do what you want.
15 个评论
Clarisha Nijman
2019-1-31
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
2019-1-31
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
2019-1-31
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
2019-1-31
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
2019-1-31
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
2019-2-1
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
2019-2-1
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
2019-2-1
Thjat is the only option I believe is appropriate.
Post back with your results.
Clarisha Nijman
2019-2-1
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
2019-2-1
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
2019-2-1
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
2019-2-1
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
2019-2-1
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
2019-2-2
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!!!!
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)