How can I combine probability distribution objects?
Show older comments
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 Comment
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)?
Answers (1)
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 Exploration and Visualization 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!