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
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 Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!