File size: 1,981 Bytes
d7989aa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
function [Corrected_P] = Run_Thresh_2D(TEMP1,TEMP2,ttesttype)
SHUFFLES=1000;
for shuffi=1:SHUFFLES
tempAB=cat(1,TEMP1,TEMP2);
idx=shuffle([ones(1,25),zeros(1,25)]);
A=tempAB(idx==1,:,:);
B=tempAB(idx==0,:,:);
if strmatch(ttesttype,'between')
[H,P,CI,STATS]=ttest2(A,B);
elseif strmatch(ttesttype,'within')
[H,P,CI,STATS]=ttest(A,B);
end
P(P<=.05)=NaN; P(P>.05)=0; P(isnan(P))=1;
P=squeeze(P); STATS.tstat=squeeze(STATS.tstat);
l=bwlabel(P);
dims=size(P);
lmax=max(reshape(l,1,dims(1)*dims(2)));
if lmax>0
for ei=1:lmax
[row,col] = find(l == ei);
for clusti=1:size(row,1);
temp(clusti) = abs(STATS.tstat(row(clusti),col(clusti)));
end
tempthresh(ei) = sum(temp); clear temp;
end
THRESH(shuffi) = max(tempthresh);
clear row col tempthresh ;
else
THRESH(shuffi) = 0;
end
clear H CI P STATS temp* A B idx l dims lmax;
end
THRESH=sort(THRESH);
ThisThreshold=THRESH(end-SHUFFLES*.05);
% NOW Run 1D size of effects
if strmatch(ttesttype,'between')
[H,P,CI,STATS]=ttest2(TEMP1,TEMP2);
elseif strmatch(ttesttype,'within')
[H,P,CI,STATS]=ttest(TEMP1,TEMP2);
end
P(P<=.05)=NaN; P(P>.05)=0; P(isnan(P))=1;
Corrected_P=zeros(50,751);
P=squeeze(P); STATS.tstat=squeeze(STATS.tstat);
l=bwlabel(P);
dims=size(P);
lmax=max(reshape(l,1,dims(1)*dims(2)));
if lmax>0
for ei=1:lmax
[row,col] = find(l == ei);
for clusti=1:size(row,1);
temp(clusti) = abs(STATS.tstat(row(clusti),col(clusti)));
end
if sum(temp) > ThisThreshold;
for clusti=1:size(row,1);
Corrected_P(row(clusti),col(clusti))=1;
end
end
clear temp row col;
end
end
clear H CI P STATS temp* A B idx l dims lmax;
clear THRESH ThisThreshold
|