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

60 vues (au cours des 30 derniers jours)
Bluemin
Bluemin le 26 Mar 2021
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 commentaire
Muhammad Sajjad
Muhammad Sajjad le 4 Oct 2022
how to plot median confidence interval

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 26 Mar 2021
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 commentaire
Ashish Jadhav
Ashish Jadhav le 10 Avr 2022
The 'y' here is array of 'experiments'. What does this mean? How do we define 'y' in our real single vector data set?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Time Series dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by