Skip to content

Commit

Permalink
Merge pull request #64 from TomMaullin/TFCEBugFix
Browse files Browse the repository at this point in the history
TFCE bug fix
  • Loading branch information
TomMaullin authored Oct 18, 2018
2 parents 9e5ae81 + 2f2d95e commit d20d734
Showing 1 changed file with 42 additions and 22 deletions.
64 changes: 42 additions & 22 deletions swe_cp_WB.m
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,14 @@ function swe_cp_WB(SwE)
end
end
if ~isMat

if TFCE

% Instantiate volume for TFCE conversion.
scorevol = zeros(DIM(1), DIM(2), DIM(3));

end

for bch = 1:nbch %-loop over blocks
blksz = ceil(mmv); %-block size
if bch ~= nbch
Expand Down Expand Up @@ -1626,50 +1634,62 @@ function swe_cp_WB(SwE)
minScore(b+1) = min(score);
end

% Calculate TFCE uncorrected p image.
if TFCE

% Obtain P values.
pvol=swe_hyptest(SwE, score, blksz, cCovBc, Cov_vis, dofMat);

% Current XYZ indices
currXYZ = XYZ(1:3, index);

if SwE.WB.stat == 'T'

% T stat from this bootstrap
scorevol(sub2ind(DIM,currXYZ(1,:),currXYZ(2,:),currXYZ(3,:))) = swe_invNcdf(pvol);

else

% F stat from this bootstrap (converted to Z).
scorevol(sub2ind(DIM,currXYZ(1,:),currXYZ(2,:),currXYZ(3,:))) = -swe_invNcdf(pvol);

end

end

end % (bch)

% Calculate TFCE uncorrected p image.
if TFCE

% Instantiate volume for TFCE conversion.
scorevol = zeros(DIM(1), DIM(2), DIM(3));

% Obtain P values.
pvol=swe_hyptest(SwE, score, blksz, cCovBc, Cov_vis, dofMat);

if SwE.WB.stat == 'T'

% T stat from this boostrap
scorevol(sub2ind(DIM,XYZ(1,:),XYZ(2,:),XYZ(3,:))) = swe_invNcdf(pvol);

if TFCE

if SwE.WB.stat == 'T'

% Bootstrapped tfce vol.
tfce = swe_tfce_transform(scorevol,H,E,C,dh);
tfce_neg = swe_tfce_transform(-scorevol,H,E,C,dh);
tfce_neg = swe_tfce_transform(-scorevol,H,E,C,dh);

else

% F stat from this boostrap (converted to Z).
scorevol(sub2ind(DIM,XYZ(1,:),XYZ(2,:),XYZ(3,:))) = -swe_invNcdf(pvol);


% Bootstrapped tfce vol.
tfce = swe_tfce_transform(scorevol,H,E,C,dh);

end

% Sum how many voxels are lower than the original parametric tfce.
tfce_uncP = tfce_uncP + (par_tfce<=tfce);
if SwE.WB.stat == 'T'
tfce_uncP_neg = tfce_uncP_neg + (par_tfce_neg<=tfce_neg);
end

% Record maxima for TFCE FWE p values.
maxTFCEScore(b+1) = max(tfce(:));
if SwE.WB.stat == 'T'
maxTFCEScore_neg(b+1) = max(tfce_neg(:));
end

clear tfce tfce_neg

end

else

%-Print progress information in command window
Expand Down

0 comments on commit d20d734

Please sign in to comment.