How can I draw 95% CI plot in my data?

59 ビュー (過去 30 日間)
Bluemin
Bluemin 2021 年 3 月 26 日
コメント済み: Muhammad Sajjad 2022 年 10 月 4 日
I have 1 data(100x1 matrix).
In Matlab, I want to draw 95% ci plot in my data
so, I found good code
like this
x = 1:100; % Create Independent Variable
y = randn(50,100); % Create Dependent Variable ‘Experiments’ Data
N = size(y,1); % Number of ‘Experiments’ In Data Set
yMean = mean(y); % Mean Of All Experiments At Each Value Of ‘x’
ySEM = std(y)/sqrt(N); % Compute ‘Standard Error Of The Mean’ Of All Experiments At Each Value Of ‘x’
CI95 = tinv([0.025 0.975], N-1); % Calculate 95% Probability Intervals Of t-Distribution
yCI95 = bsxfun(@times, ySEM, CI95(:)); % Calculate 95% Confidence Intervals Of All Experiments At Each Value Of ‘x’
figure
plot(x, yMean,'p') % Plot Mean Of All Experiments
hold on
plot(x, yCI95+yMean,'-r') % Plot 95% Confidence Intervals Of All Experiments
hold off
grid
but this graph is not what I wanted
How can i draw graph? like this..
  1 件のコメント
Muhammad Sajjad
Muhammad Sajjad 2022 年 10 月 4 日
how to plot median confidence interval

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

採用された回答

Star Strider
Star Strider 2021 年 3 月 26 日
Replace the second plot call with:
patch([x, fliplr(x)], [yCI95(1,:) fliplr(yCI95(2,:))], 'b', 'EdgeColor','none', 'FaceAlpha',0.25)
so the full code is now:
x = 1:100; % Create Independent Variable
y = randn(50,100); % Create Dependent Variable ‘Experiments’ Data
N = size(y,1); % Number of ‘Experiments’ In Data Set
yMean = mean(y); % Mean Of All Experiments At Each Value Of ‘x’
ySEM = std(y)/sqrt(N); % Compute ‘Standard Error Of The Mean’ Of All Experiments At Each Value Of ‘x’
CI95 = tinv([0.025 0.975], N-1); % Calculate 95% Probability Intervals Of t-Distribution
yCI95 = bsxfun(@times, ySEM, CI95(:)); % Calculate 95% Confidence Intervals Of All Experiments At Each Value Of ‘x’
figure
plot(x, yMean,'p') % Plot Mean Of All Experiments
hold on
% plot(x, yCI95+yMean,'-r') % Plot 95% Confidence Intervals Of All Experiments
patch([x, fliplr(x)], [yCI95(1,:) fliplr(yCI95(2,:))], 'b', 'EdgeColor','none', 'FaceAlpha',0.25)
hold off
grid
That should do what you want. (I appreciate your quoting my code!)
  1 件のコメント
Ashish Jadhav
Ashish Jadhav 2022 年 4 月 10 日
The 'y' here is array of 'experiments'. What does this mean? How do we define 'y' in our real single vector data set?

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by