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

조회 수: 4 (최근 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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by