trying to do anova1 for multiple classes

2 Ansichten (letzte 30 Tage)
Abdullah Almohammadi
Abdullah Almohammadi am 6 Sep. 2022
Beantwortet: Shivansh am 29 Sep. 2023
i have 4 classes of size (72,22,22) and i want to do anova1 for each pair of the (22,22) in those classes .
for example; i wanna grab, let's say, pair (2,3) in each class and do the anova for each pair in the 4 arrays, so the output would be an array of (22,22)representing P-values of each pair across 4 classes. hopefullay my code explains what i am trying to say :)
i have tried this piece of code but im not sure cuz the results are kinda odd; i guess the issue is in 2 for loops. here is the code
>> x = load("plv_8_12.mat");
x = x.plv;
size(x)
ans =
2592 22 22
S1C1 =x(1:72,:,:);
S1C2 = x(649:720,:,:);
S1C3 = x(1297:1368,:,:);
S1C4 = x(1945:2016,:,:);
p_all = [];
for x =1:22
for y=1:22
tc1 = S1C1(:,x,y);
tc2 = S1C2(:,x,y);
tc3 = S1C3(:,x,y);
tc4 = S1C4(:,x,y);
temp = [tc1 tc2 tc3 tc4];
%p_all(x,y) = anova1(temp);
[p,tbl,stats]=anova1(temp);
close all
end
end

Antworten (1)

Shivansh
Shivansh am 29 Sep. 2023
Hi Abdullah,
I understand that you want to get results with anova1 function for each pair of the classes defined by you.
Your code looks fine, but there is a small issue with the way you are storing the p-values. I believe that the issue lies in storage of p-values for each pair of (x,y) in the loop. The 'p' variable is getting overwritten in each iteration of the loop instead of being stored. To store the p-values for each pair, you can modify your code as follows:
x = load("plv_8_12.mat");
x = x.plv;
size(x)
ans =
2592 22 22
S1C1 = x(1:72,:,:);
S1C2 = x(649:720,:,:);
S1C3 = x(1297:1368,:,:);
S1C4 = x(1945:2016,:,:);
p_all = zeros(22, 22); % Initialize p-values matrix
for x = 1:22
for y = 1:22
tc1 = S1C1(:,x,y);
tc2 = S1C2(:,x,y);
tc3 = S1C3(:,x,y);
tc4 = S1C4(:,x,y);
temp = [tc1 tc2 tc3 tc4];
[p, ~, ~] = anova1(temp);
p_all(x, y) = p; % Store p-value in the matrix
end
end
In this modified code, I added a `p_all` matrix to store the p-values for each pair of (x, y) in the loop. The `p_all` matrix is initialized with zeros, and in each iteration of the loop, the corresponding p-value is stored in the matrix using the indices (x, y). This way, you will have the p-values for each pair of (x, y) across the four classes in the `p_all` matrix.
I hope it resolves your issue!

Kategorien

Mehr zu Analysis of Variance and Covariance finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by