Adding variance as error bars on line plot
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Douglas Forsyth
le 29 Août 2018
Modifié(e) : Star Strider
le 29 Août 2018
I am plotting several datasets on a single figure where each point on the line is defined as the average of different runs of the same experiment.
It is simple enough to plot the lines of each datasets but is it also possible to include the variance either side of the average calculated at each data point on the lines?
Example: y1(1) = 1; y1(2) = 2; y1(3) = 3; %similar for y2 & y3 y = [mean(y1),mean(y2),mean(y3)]; x = [1,2,3]; plot(x,y); %How to add variance as shown as an error bar at y1, y2, y3....
0 commentaires
Réponse acceptée
Star Strider
le 29 Août 2018
Modifié(e) : Star Strider
le 29 Août 2018
There are probably several ways to do the plot, using the errorbar (link) function being the easiest.
See the links in those documentation pages for related functions.
EDIT —
A more useful metric than the variance is the standard error of the mean (SEM), calculated as the standard deviation divided by the square root of the number of observations. You can convert this to confidence intervals by multiplying it by the inverse value of the t-distribution with a given probability and degrees-of-freedon, given by the Statistics and Machine Learning Toolbox tinv (link) function.
Example —
x = 1:10; % Create Data
y1 = rand(1,10); % Create Data
y2 = rand(1,10); % Create Data
y3 = rand(1,10); % Create Data
ym = [y1; y2; y3];
N = size(ym,1);
y = mean(ym);
SEM = std(ym) / sqrt(N); % Standard Error Of The Mean
CI95 = SEM * tinv(0.975, N-1); % 95% Confidence Intervals
figure
errorbar(x, y, CI95)
grid
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Distribution Plots 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!