How to compute the %age of data lies within the confidance interval?

1 回表示 (過去 30 日間)
Ahmed
Ahmed 2024 年 2 月 22 日
回答済み: Voss 2024 年 2 月 22 日
I have two datasets of size e.g., IP0 = 101 500 and IPOPT = 101 500 and the 90% confidance interval is plotted below in figure. The confidance interval of IP0 is wider (black-dashed lines) than IPOPT (red-dashed lines). I want to find the percentage of values of IP0 lies within the confidance of IP0 and then the percentage of values of IPOPT lies within the IP0 interval. Since IP0 is wider than the IPOPT therefore the percentage value of the IPOPT should be higher. I am using following code and getting same answer for both cases (90%). Does my code is correct?
% Compute the 90% confidence interval for each column
confidence_interval = prctile(ip0in, [5, 95], 2);
confidence_interval2 = prctile(IP_OPT, [5, 95], 2);
% Count the number of values within the confidence interval for each column
within_interval_count = sum(ip0in >= confidence_interval(:, 1) & ip0in <= confidence_interval(:, 2), 1);
within_interval_count2 = sum(IP_OPT >= confidence_interval(:, 1) & IP_OPT <= confidence_interval(:, 2), 1);
% Calculate the overall percentage of values within the confidence interval
overall_percentage_within_interval = sum(within_interval_count) / numel(ip0in) * 100;
overall_percentage_within_interval2 = sum(within_interval_count) / numel(IP_OPT) * 100;
disp(['Overall Percentage of Values within 95% Confidence Interval IP0IN: ', num2str(overall_percentage_within_interval), '%']);
disp(['Overall Percentage of Values within 95% Confidence Interval IP_OPT: ', num2str(overall_percentage_within_interval2), '%']);
  2 件のコメント
Image Analyst
Image Analyst 2024 年 2 月 22 日
I formatted your code for you but it still doesn't run. It would be easier for someone to answer you if you had attached the variables in a .mat file.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Ahmed
Ahmed 2024 年 2 月 22 日
@Image Analyst I have attached the data.

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

回答 (1 件)

Voss
Voss 2024 年 2 月 22 日
You have a missing "2" in the calculation of overall_percentage_within_interval2. You're using within_interval_count and you should be using within_interval_count2.
overall_percentage_within_interval = sum(within_interval_count) / numel(ip0in) * 100;
overall_percentage_within_interval2 = sum(within_interval_count) / numel(IP_OPT) * 100;
% ^^ missing "2"
S = load('data.mat');
ip0in = S.IP0;
IP_OPT = S.IPOPT;
% Compute the 90% confidence interval for each column
confidence_interval = prctile(ip0in, [5, 95], 2);
confidence_interval2 = prctile(IP_OPT, [5, 95], 2);
% Count the number of values within the confidence interval for each column
within_interval_count = sum(ip0in >= confidence_interval(:, 1) & ip0in <= confidence_interval(:, 2), 1);
within_interval_count2 = sum(IP_OPT >= confidence_interval(:, 1) & IP_OPT <= confidence_interval(:, 2), 1);
% Calculate the overall percentage of values within the confidence interval
overall_percentage_within_interval = sum(within_interval_count) / numel(ip0in) * 100;
overall_percentage_within_interval2 = sum(within_interval_count2) / numel(IP_OPT) * 100;
% ^ 2 was missing
Now the IPOPT is higher, as expected:
disp(['Overall Percentage of Values within 95% Confidence Interval IP0IN: ', num2str(overall_percentage_within_interval), '%']);
Overall Percentage of Values within 95% Confidence Interval IP0IN: 90%
disp(['Overall Percentage of Values within 95% Confidence Interval IP_OPT: ', num2str(overall_percentage_within_interval2), '%']);
Overall Percentage of Values within 95% Confidence Interval IP_OPT: 94.1307%

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by