From a pdf to a histogram.
28 views (last 30 days)
Show older comments
Hi. I have the two parameters of the lognormal so i can plot the pdf. If i want to convert the density into a histogram i should calculate the integral under the curve associated to bins of a certain width, right? I know mu and sigma of the pdf and nothing else. How can i extract values of the density associated to bins of width of 100? My x goes from 0 to 250000 approx. I cannot calculate manually 2500 integrals to build the histogram.
4 Comments
Pawel Tokarczuk
on 9 Aug 2017
"The sum of two pdf's is their convolution."
No; if 2 variables, x and y, have pdf's p(x) and q(y), then the convolution of p and q is the pdf of the sum (x + y). The (weighted and normalized) sum of 2 pdf's is a mixture.
José-Luis
on 9 Aug 2017
Edited: José-Luis
on 9 Aug 2017
"The sum of two pdf's is their convolution".
Erroneous comment was mine.
Pawel is right. I don't know how one goes about mixing two pdf's but there is some literature on it.
That reference is pretty old so there might be newer (hopefully better) methods. Some fitting is required.
Answers (3)
David Gonzalez
on 7 Aug 2017
Hi,
You can use the function lognrnd(mu,sigma) to sample the lognormal density without computing the integral. Then, you can use hist(x,nbins) to create the histogram. Here is an example:
hist(lognrnd(0,1,[3000,1]),100) % lognormal histogram with mu=0, sigma=1, 30000 samples and 100 bins
David
Torsten
on 9 Aug 2017
I don't understand the problem you have.
The probability P that a person in Europe has income x is
P(income=x)=sum_{i=1}^{N} P(income=x|person comes from country i)*P(person comes from country i)
where N is the number of countries you want to take into consideration.
Thus the aggregated probability density function is
d_aggregated(x)=sum_{i=1}^{N} w_i * d_i(x)
where w_i is the number of people in country i divided by the total number of people in the countries under consideraton and d_i(x) is the pdf for the incomes in country i.
Best wishes
Torsten.
2 Comments
Torsten
on 9 Aug 2017
m1 = ...;
m2 = ...;
s1 = ...;
s2 = ...;
x = 0:0.02:10;
y = 0.6*lognpdf(x,m1,s1)+0.4*lognpdf(x,m2,s2);
plot(x,y)
Best wishes
Torsten.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!