creating standard error of mean for bar graphs in code, can you please correct/modify/help my code?

2 ビュー (過去 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);

採用された回答

Jeff Miller
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
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
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.
  1. The variable names in your code are inconsistent. You mentioned averageSize and avgSize. Make sure to use the same variable name throughout your code.
  2. 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);
  1 件のコメント
kevin
kevin 2023 年 4 月 29 日
how about this:
% Compute the SEM of the data for each bar in the avgSize plot
n = numel(avgSize);
SEM_avgSize = std(avgSize) / sqrt(n);
SEM_valuessize = 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_valuessize, '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);

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by