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

59 visualizaciones (últimos 30 días)
Bluemin
Bluemin el 26 de Mzo. de 2021
Comentada: Muhammad Sajjad el 4 de Oct. de 2022
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..

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Time Series en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by