Compare groups using TTEST2 and a FOR LOOP
6 views (last 30 days)
Show older comments
I have two separate files. One is 1000x50 and the other is 1000x30. The first table has 50 subjects (one column = one subject) and 1000 signals (rows = signals), whereas the second table has 30 subjects and 1000 signals. I want to perform a two sample ttest for each of the 1000 rows of data comparing the values between the 50 subject group (group1) and the 30 subject group (group2) and then find which of the 1000 rows have a p-value less than 0.05. I wanted to create a new variable that would find and contain all the p-values less than 0.05 but I'm having trouble doing so. I wrote some code below but not sure if I'm in the right direction. Any insights would be really appreciated!
for i=1:50
group1=data1(:,i)
for j=1:31
group2=data2(:,j)
[h(i,j),p(i,j)]=ttest2(group1,group2)
end
end
1 Comment
Dheeraj Singh
on 17 Dec 2019
Edited: Dheeraj Singh
on 17 Dec 2019
I think the above code should work fine. Just add a check for p-value and the second loop till 30.
for i=1:50
group1=data1(:,i)
for j=1:30
group2=data2(:,j)
[h(i,j),p]=ttest2(group1,group2)
if p<0.05
p_value(i,j)=p;
else
%set NaN or some other value
%p_value(i,j)=nan;
end
end
end
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!