calculating the variability between three different mice and within one mouse code. pleas help to confirm works as intended
Ältere Kommentare anzeigen
Hi all, I have 6 mat files of data corresponding to 3 mice where 2 of the mat files correspond to 1 mouse yielding two mat files for each mouse.
I want to determine the variability within one mouse and then the variability between the mice, i have made a code to do this but as a novice matlab user i want to confirm and improve it. Can someone please help me to do this? Thanks!
% read in data from mat files
data = [];
for i = 1:3
mouse_data = [];
for j = 1:2
filename = sprintf('feature%d.mat', (i-1)*2+j);
temp = load(filename);
mouse_data = [mouse_data temp.(sprintf('feature%d', (i-1)*2+j))];
end
data = [data mouse_data];
end
% calculate the mean and variance for each mouse
mouse_mean = mean(data, 2);
mouse_var = var(data, 0, 2);
% calculate the mean and variance for all mice together
group_mean = mean(data(:));
group_var = var(data(:));
% plot the variance within and between the mice
figure;
bar([1 2 3], mouse_var);
xlabel('Mouse');
ylabel('Variance');
title('Variance within each mouse');
ylim([0 0.3]);
figure;
bar([1 2], [group_var, mean(mouse_var)]);
xlabel('Group');
ylabel('Variance');
title('Variance between mice and within-group variance');
ylim([0 0.3]);
xticklabels({'Between mice', 'Within-group'});
4 Kommentare
Star Strider
am 30 Apr. 2023
If you have the Statistics and Machine Learning Toolbox, explore the various analysis-of-variance functions. It would appear that at least anova1 could be appropriate.
Chanille
am 30 Apr. 2023
Like what is a an example to run these features through the anova1 test?
Chanille
am 30 Apr. 2023
@star strider
Star Strider
am 1 Mai 2023
See the documentation I linked to, first to be certain that it does what you want (since I’m not certain that I sufficiently understand the problem to be solved), and second to understand how to use the function and interpret its results.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu ANOVA finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!