is this the correct way to determine variance? calculating the Fstats, p-value and variance.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
% load the feature matrices
feature1 = load('feature1.mat');
feature2 = load('feature2.mat');
feature3 = load('feature3.mat');
feature4 = load('feature4.mat');
feature5 = load('feature5.mat');
feature6 = load('feature6.mat');
% Combine the first two structs into a single struct
mouse1 = [feature1.features, feature2.features];
% Combine the next two structs into a single struct
mouse2 = [feature3.features, feature4.features];
% Combine the last two structs into a single struct
mouse3 = [feature5.features, feature6.features];
%extract fields
%mouse1 profilecounts
profileCounts1 = [mouse1(1).profileCounts; mouse1(2).profileCounts; mouse1(3).profileCounts; mouse1(4).profileCounts; mouse1(5).profileCounts; mouse1(6).profileCounts];
%mouse2 profilecounts
profileCounts2 = [mouse2(1).profileCounts; mouse2(2).profileCounts; mouse2(3).profileCounts; mouse2(4).profileCounts; mouse2(5).profileCounts; mouse2(6).profileCounts];
%%mouse3 profilecounts
profileCounts3 = [mouse3(1).profileCounts; mouse3(2).profileCounts; mouse3(3).profileCounts; mouse3(4).profileCounts; mouse3(5).profileCounts; mouse3(6).profileCounts];
% Concatenate profileCounts for each group
% Calculate the variance between the groups
var_between_groups = var([profileCounts1; profileCounts2; profileCounts3]);
% Calculate the degrees of freedom for the F-test
df_between_groups = 2; % the number of groups minus 1
df_within_groups = length(profileCounts1) + length(profileCounts2) + length(profileCounts3) - 3; % the total number of observations minus the number of groups
% Calculate the variance within each group
var_within_groups = (var(profileCounts1)*(length(profileCounts1)-1) + var(profileCounts2)*(length(profileCounts2)-1) + var(profileCounts3)*(length(profileCounts3)-1))/(length(profileCounts1) + length(profileCounts2) + length(profileCounts3) - 3);
% Calculate the variance between the groups
var_between_groups = var([profileCounts1; profileCounts2; profileCounts3]);
% Calculate the F-statistic
F_statistic = var_between_groups/var_within_groups;
% Calculate the degrees of freedom
df_between_groups = 2 - 1;
df_within_groups = length(profileCounts1) + length(profileCounts2) + length(profileCounts3) - 3;
% Calculate the p-value
p_value = 1 - fcdf(F_statistic, df_between_groups, df_within_groups);
% Determine if the variance between the groups is significant
if p_value < 0.05
disp('The variance between the groups is significant');
else
disp('The variance between the groups is not significant');
end
5 Kommentare
Cris LaPierre
am 5 Mai 2023
Bearbeitet: Cris LaPierre
am 5 Mai 2023
You didn't share your mat files, so the intent was to give others a way to find them. You now provide the link in your comment, so I've removed the flag.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Analysis of Variance and Covariance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!