필터 지우기
필터 지우기

How to do lognormal fit

조회 수: 16 (최근 30일)
amrutha Priya
amrutha Priya 2013년 3월 5일
댓글: Fernanda Suarez Jaimes 2020년 3월 12일
I got the following plot after the simulation. Now, I want to fit it into log normal curve. Please, can you tell me the code to do that. http://i.imgur.com/VT70iYb.jpg
  댓글 수: 2
Image Analyst
Image Analyst 2013년 3월 5일
You could get a more accurate fit by using more bins in your histogram. The first few bins of a log normal are lower than the peak but you don't have enough bins to resolve that. Increase the number of bins and you'll probably see that.
the cyclist
the cyclist 2013년 3월 5일
What Image Analyst says is true, but if you have the underlying data, you should fit the data directly, not the bin counts of the data.

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

답변 (1개)

the cyclist
the cyclist 2013년 3월 5일
편집: the cyclist 2013년 3월 5일
If you have the Statistics Toolbox, you can use the lognfit() function.
Here is an example of using the function:
% Make up some data. (You should use your real data in place of x.)
x = lognrnd(1,0.3,10000,1);
% Fit the data
parmhat = lognfit(x);
% Plot comparison of the histogram of the data, and the fit
figure
hold on
% Empirical distribution
hist(x,0.1:0.1:10);
% Fitted distribution
xt = 0.1:0.1:10;
plot(xt,1000*lognpdf(xt,parmhat(1),parmhat(2)),'r')
  댓글 수: 6
the cyclist
the cyclist 2016년 1월 9일
I can see why that would be confusing. Sorry. Here is a better version of the code, where I have specified parameter names, instead of hard-coded numbers:
% Number of data points
N = 10000;
% Specify bin locations for histogram and fit
BIN_WIDTH = 0.1;
BIN_MAX = 10;
BIN_RANGE = BIN_WIDTH:BIN_WIDTH:BIN_MAX;
% Make up some data. (You should use your real data in place of x.)
x = lognrnd(1,0.3,N,1);
% Fit the data
parmhat = lognfit(x);
% Plot comparison of the histogram of the data, and the fit
figure
hold on
% Empirical distribution
hist(x,BIN_RANGE);
% Fitted distribution
xt = BIN_RANGE;
y_probability = BIN_WIDTH*lognpdf(xt,parmhat(1),parmhat(2));
y_count = N * y_probability;
h = plot(xt,y_count,'r');
set(h,'LineWidth',2)
The probability of landing in a particular bin is the pdf times the bin width. The count in a particular bin is that probability times the number in the sample. That is where the scaling factor came from. It was the bin width (0.1) times the number in the sample (10000).
I hope that is clearer now.
Fernanda Suarez Jaimes
Fernanda Suarez Jaimes 2020년 3월 12일
Do you know how can I regress a lognrnd time series?

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

Community Treasure Hunt

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

Start Hunting!

Translated by