# How can I combine probability distribution objects?

20 views (last 30 days)
Jo Williams on 3 Dec 2015
Answered: Arnab Sen on 31 Dec 2015
Are there operators probability distribution objects? For example,
>>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?
Tom Lane on 13 Dec 2015
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)?

Arnab Sen on 31 Dec 2015
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:

### Categories

Find more on Birnbaum-Saunders Distribution in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!