is this the correct way to determine variance? calculating the Fstats, p-value and variance.

1 次查看(过去 30 天)
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 个评论
Cris LaPierre
Cris LaPierre 2023-5-5
编辑:Cris LaPierre 2023-5-5
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.
Laura
Laura 2023-5-7
@Cris LaPierre Oh I understand, thanks!! Since my intent is to compare each field variable (profileCounts, zoneArea et al.) in feature 1 and 2 (group1) to feature 3 and 4 (group2) then to feature 5 and 6 (group3) and I was having a hard time getting doing that with anova would this work where the comparisons were performed brute force? Is this method correct or is there another method? Would greatly appreciate your helpp!!! by the way i added the files for ease.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Analysis of Variance and Covariance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by