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!