creating standard error of mean for bar graphs in code, can you please correct/modify/help my code?
5 次查看(过去 30 天)
显示 更早的评论
in my code i graphed my data and i simply want to show the standard error of mean for each bar in each bar plot. Heres what i have but I am not confident that it works can someone please confirm?
% Compute the SEM of the data for each bar in the Size plot
n = numel(averageSize);
SEM_avgSize = std(avgSize) / sqrt(n);
SEM_values = repmat(SEM_avgSize, n, 1);
% Plot the data with error bars
subplot(3, 4, 7);
bar(avgSize, 'LineWidth', 2);
hold on;
errorbar(1:n, avgSize, SEM_values, 'k.', 'LineWidth', 1.5);
hold off;
title('Average Size of Organelles', 'FontSize', fontSize);
xlabel('Zone', 'FontSize', fontSize);
ylabel('Size (\mum^2)', 'FontSize', fontSize);
set(gca, 'FontSize', fontSize);
0 个评论
采纳的回答
Jeff Miller
2023-4-28
Hard to say for sure without knowing what the original data were, but that doesn't look right to me. Can you explain how the values of avgSize were computed? Most likely, there should be a different value of SEM for each bar, computed using only the n and std of the scores that were averaged to get that bar's avgSize.
3 个评论
Jeff Miller
2023-4-29
Then after avgSize(k), I think it should be
SEM(k) = std(areas) * pixelSize^2 / sqrt(numel(areas));
更多回答(1 个)
LeoAiE
2023-4-28
Your code seems to be mostly correct, but there are a few things that need to be adjusted to compute and display the standard error of the mean (SEM) correctly for each bar in the bar plot.
- The variable names in your code are inconsistent. You mentioned averageSize and avgSize. Make sure to use the same variable name throughout your code.
- To calculate the SEM for each bar, you need to compute the standard deviation and SEM for each group (zone) separately.
Assuming averageSize is a matrix where each column represents a different zone, you can modify your code as follows:
% Compute the SEM of the data for each bar in the Size plot
n = size(averageSize, 1);
std_avgSize = std(averageSize, 0, 1); % Standard deviation for each zone
SEM_avgSize = std_avgSize / sqrt(n); % SEM for each zone
% Plot the data with error bars
avgSize_mean = mean(averageSize, 1); % Mean for each zone
num_zones = size(averageSize, 2);
subplot(3, 4, 7);
bar(avgSize_mean, 'LineWidth', 2);
hold on;
errorbar(1:num_zones, avgSize_mean, SEM_avgSize, 'k.', 'LineWidth', 1.5);
hold off;
title('Average Size of Organelles', 'FontSize', fontSize);
xlabel('Zone', 'FontSize', fontSize);
ylabel('Size (\mum^2)', 'FontSize', fontSize);
set(gca, 'FontSize', fontSize);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!