How to compute the %age of data lies within the confidance interval?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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:
답변 (1개)
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), '%']);
disp(['Overall Percentage of Values within 95% Confidence Interval IP_OPT: ', num2str(overall_percentage_within_interval2), '%']);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!