How can I combine probability distribution objects?

8 次查看(过去 30 天)
Are there operators probability distribution objects? For example,
>>load hospital
>>xA = hospital.Weight;
>>pdA = fitdist(xA,'Normal')
Suppose I have a similar second record
>>hospitalB
where there are k times as many patients. Then I could write
>>pdboth = fitdist([xA;xB],'Normal');
but if I've only got the pd and weighting - or want to do some other weighting - I'd like to do something like
>>pdboth = pdA + k*pdB;
Does this sort of operator exist, or do I need to convert to a pdf and then fit a new distribution?
  1 个评论
Tom Lane
Tom Lane 2015-12-13
What are you expecting from the addition? Are you looking for a mixture of Gaussians (perhaps a bimodal distribution with one peak from each distribution)?

请先登录,再进行评论。

回答(1 个)

Arnab Sen
Arnab Sen 2015-12-31
I understand that you would like to achieve pooled weighted distribution of two distributions. There is no in-built functions in MATLAB to achieve this goal. However, it is possible to calculate it manually.
Consider following MATLAB code snippet for illustration:
>>muA=pdA.mu;
>>sigA=pdA.sigma;
>>lA=length(xA);
>>muB=pdB.mu;
>>sigB=pdB.sigma;
>>lB=length(xB);
>>pdboth=fitdist([xA;xB],'Normal');
%Calculate mean and standard deviation programmatically
>>muC=(muA*lA+k*muB*lB)/(lA+k*lB);
>>varC=((lA-1)*sigA^2+k*(lB-1)*sigB^2)(lA+k*lB-(k+1));
>>sigC=sqrt(varC);
>>pdboth.mu=muC;
>>pdboth.sigma=sigC;
In simple words we are calculating 'pdboth' as the distribution of xC=[xA;xB;xB;...ktimes]. You can also simply create a vector 'xC' as above and compute 'pdboth'.
For more details of the calculation as shown in the code, refer to the following link:

Community Treasure Hunt

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

Start Hunting!

Translated by