필터 지우기
필터 지우기

From a pdf to a histogram.

조회 수: 5 (최근 30일)
Alfonso Russo
Alfonso Russo 2017년 8월 7일
댓글: Torsten 2017년 8월 9일
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
Pawel Tokarczuk
Pawel Tokarczuk 2017년 8월 9일
"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
José-Luis 2017년 8월 9일
편집: José-Luis 2017년 8월 9일
"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.

댓글을 달려면 로그인하십시오.

답변 (3개)

David Gonzalez
David Gonzalez 2017년 8월 7일
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
  댓글 수: 2
Alfonso Russo
Alfonso Russo 2017년 8월 7일
it will only plot the histogram. i need the values associated to each bin since i have several distributions that i need to add together. Is there a way to extract the values associated to each bin in order to add up 0-100 bins coming from different lognormals?
Alfonso Russo
Alfonso Russo 2017년 8월 8일
Moreover, if my lognormal described a random variable X across say 322000000 observation and i wanted to specify only the bins' width and not the number of bins (so that MatLab can show how many bins are created) how should i modify the code?

댓글을 달려면 로그인하십시오.


Sean de Wolski
Sean de Wolski 2017년 8월 7일
Look at the 'Normalization' property of histcounts.
  댓글 수: 2
Alfonso Russo
Alfonso Russo 2017년 8월 8일
It does not work. I need exactly the densities associated to approx 2500 bins of width = 100.
Alfonso Russo
Alfonso Russo 2017년 8월 8일
편집: Alfonso Russo 2017년 8월 8일
There is something that might work since histcounts allows me to use 'Normalization' and 'Countdensity' as properties. How can i set my variable X as coming from a lognormal with defined mu and sigma and divide it into bins of width of 100 so that i can use histcounts(X, 'Normalization', 'countdesity') ?

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2017년 8월 9일
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
Alfonso Russo
Alfonso Russo 2017년 8월 9일
Imagine that i have two lognormals L1 and L2 with parameters (m1,s1) and (m2,s2) and weights w1=0.6 and w2=0.4. To obtain the aggregated PDF i should tipe on matlab:
d_aggregated(x)= 0.6 * 1/(s1*x*sqrt(2*pi))*exp(- ((log(x)- m1).^2))/(2*(s1.^2)) + 0.4 * 1/(s2*x*sqrt(2*pi))*exp( - ((log(x) - m2).^2))/(2*(s2.^2))
% obtaining the aggregated PDF.
Is it correct? Once calculated, is there a way of plot it? Like plot(d_aggregated(x))?
Torsten
Torsten 2017년 8월 9일
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by