Compare groups using TTEST2 and a FOR LOOP

6 次查看(过去 30 天)
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 个评论
Dheeraj Singh
Dheeraj Singh 2019-12-17
编辑:Dheeraj Singh 2019-12-17
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

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by