フィルターのクリア

How to do lognormal fit

16 ビュー (過去 30 日間)
amrutha Priya
amrutha Priya 2013 年 3 月 5 日
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