problem in plotting cdf for gamma distribution

2 ビュー (過去 30 日間)
aboltabol
aboltabol 2018 年 5 月 10 日
コメント済み: aboltabol 2018 年 5 月 11 日
Hello all I have a data series of size 16436x1. I have calculated the gamma CDF for the series using 'gamcdf' function. While plotting the result using plot('data','data_cdf) [data is the data series and data_cdf is the gamma CDF of the data], I am getting the plot (attached). I am confused as to why there are multiple lines in the graph? Please help I am attaching the files: data.mat, plot.pdf. data.mat contains two vectors: train(original data) and train_cdf(gamma CDF of the data)

採用された回答

John D'Errico
John D'Errico 2018 年 5 月 10 日
編集済み: John D'Errico 2018 年 5 月 10 日
Is your data sorted in increasing order? (No, it is not.)
Plot draws a line from one point to the next. But you r data is not in increasing order. So what do you get? Lines all over the place, back and forth.
Just sort your data first.
help sort
  1 件のコメント
aboltabol
aboltabol 2018 年 5 月 11 日
Thanks John. Sorting the data solves my problem

サインインしてコメントする。

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 5 月 10 日
編集済み: Ameer Hamza 2018 年 5 月 10 日
It appears that you evaluated the cdf functions for all the values in train. This is not necessary and also creating the problem in your case. Although you can use sort as suggested in @John's answer. But here is an alternate approach, which saves you from calculating and plotting a lot of points which are not even necessary. Although it seems that you estimated Gamma distribution parameters but for completeness here is the whole code,
param = gamfit(train);
param =
0.1306 8.2937 <-- These are estimated parameters of Gamma distribution
^ is k ^ is theta
x = 0:0.1:max(train); % you can plot to whtver value you want, i just used max(data)
cdf_values = gamcdf(x, param(1), param(2));
plot(x, cdf_values);
Also, in this case, you just need to calculate and plot few hundred points as compared 16436 points in your case, whereas the plot looks same.
  1 件のコメント
aboltabol
aboltabol 2018 年 5 月 11 日
Thanks Ameer. Actually, I am taking the gamma inverse in the next step to correct one series w.r.t to the gamma parameters of another, hence I have to take the whole series in the calculation. Thanks for your suggestion and help regarding the plotting issue.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by