CDF values are on a scale of 0 to 1, how to scale?

7 ビュー (過去 30 日間)
Macy
Macy 2023 年 2 月 15 日
コメント済み: Vinayak Choyyan 2023 年 2 月 16 日
Hello,
I made a normal fit distribution for some data called "actual_values". The plot came out fine.
Now how do I display the values of the normal fit distribution? I want to display the 10 numbers predicted by the normal fit distribution. And these 10 values, as you can see from the plot, should be similar to the actual values. However when I output cdf(normalfit, actual_values), I get the values but they are on a scale of 0 to 1. How do I scale the cdf values? For example, the max value should be near 2310.
I think also I am thinking about this the wrong way, the "cdf(normalfit, actual_values)" looks like it is giving me values on the y-scale, and I need the corresponding x-values.
Table = readtable("practice3.xlsx");
actual_values = Table.values;
actual_values = sort(actual_values);
normalfit = fitdist(actual_values,'Normal'); % fit the normal distribution to the data
cdfplot(actual_values); % Plot the empirical CDF
x = 0:2310;
hold on
plot(x, cdf(normalfit, x), 'Color', 'r') % plot the normal distribution
hold off
grid on
cdf(normalfit, actual_values) %How do I scale the cdf values to the actual values? Or how can I extract them from the plot?
ans = 10×1
0.1530 0.1623 0.2616 0.2701 0.3051 0.4251 0.6078 0.6274 0.9307 0.9699
actual_values
actual_values = 10×1
50 80 350 370 450 700 1060 1100 2000 2310

回答 (1 件)

Vinayak Choyyan
Vinayak Choyyan 2023 年 2 月 15 日
Hello Macy,
As per my understanding, you are looking for the X axis values corresponding to Y axis values in ‘cdfplot’.
You can use
h = cdfplot(x)
which returns a handle of the empirical cdf plot line object. You can use ‘h’ to query or modify properties of the object after you create it. You can query it by using
h.XData
to get the X axis values. Here is and example code for the same.
Table = readtable("practice3.xlsx");
actual_values = Table.values;
actual_values = sort(actual_values);
normalfit = fitdist(actual_values,'Normal'); % fit the normal distribution to the data
[h,stats] =cdfplot(actual_values); % Plot the empirical CDF
x = 0:2310;
hold on
plot(x, cdf(normalfit, x), 'Color', 'r') % plot the normal distribution
hold off
grid on
h.XData
ans = 1×22
-Inf 50 50 80 80 350 350 370 370 450 450 700 700 1060 1060 1100 1100 2000 2000 2310 2310 Inf
h.YData
ans = 1×22
0 0 0.1000 0.1000 0.2000 0.2000 0.3000 0.3000 0.4000 0.4000 0.5000 0.5000 0.6000 0.6000 0.7000 0.7000 0.8000 0.8000 0.9000 0.9000 1.0000 1.0000
I hope this resolves the issue you are facing. If you would like to read more about ‘cdfplot’, please check out the following documentation Empirical cumulative distribution function (cdf) plot - MATLAB cdfplot - MathWorks India
  2 件のコメント
Macy
Macy 2023 年 2 月 15 日
This does not give the appropriate values in return. The cdf plot is the red line, I need those x-values for each point that corresponds to the empirical data (so I can calculate R^2).
Vinayak Choyyan
Vinayak Choyyan 2023 年 2 月 16 日
Hi Macy,
The red line is generated by this line in your code
plot(x, cdf(normalfit, x), 'Color', 'r')
You can verify this by commenting out the above line and seeing only the blue line.
The X axis values are in the variable ‘x’ which you created. Hence the ‘x’ values would be
x = 0:2310
And the corresponding Y axis values are given from
cdf(normalfit, x)
I hope this does resolve the issue you were facing.

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

カテゴリ

Help Center および File ExchangeExploration and Visualization についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by