From 14f16572be0f9f4b8c5e44644f861010f91da287 Mon Sep 17 00:00:00 2001 From: Wirkungstreffer Date: Wed, 20 Mar 2024 15:39:30 +0100 Subject: [PATCH] modified multiple files to cancel the statistical hypothesis test over normalized data, and adjusted the absolute mean value sequence of PAC. --- test_pipes/test_pac.m | 2 +- utils/calc_pac.m | 12 ++++++------ utils/shuffle_BS.m | 34 +++++++++++++++++----------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/test_pipes/test_pac.m b/test_pipes/test_pac.m index fcf7207..994ff94 100644 --- a/test_pipes/test_pac.m +++ b/test_pipes/test_pac.m @@ -34,7 +34,7 @@ EEG1 = pop_roi_connect(EEG, 'methods', {'PAC', 'MIM', 'COH'}, 'fcomb', fcomb); % test all 3 connectivity functions (data2spwctrgc, data2strgcmim, roi_pac) tic -EEG2 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'bs_outopts', 1, 'conn_stats', 'on', 'nshuf', 3, 'poolsize', 12); % compute only b_anti, b_anti_norm +EEG2 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'conn_stats', 'on', 'nshuf', 3, 'poolsize', 12); % compute only b_anti, b_anti_norm toc EEG3 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'bs_outopts', 1); % compute only b_anti, b_anti_norm diff --git a/utils/calc_pac.m b/utils/calc_pac.m index 493414b..eda0442 100644 --- a/utils/calc_pac.m +++ b/utils/calc_pac.m @@ -19,14 +19,14 @@ function [biv_orig, biv_anti, biv_orig_norm, biv_anti_norm] = calc_pac(BS, RTP) % Calculate absolute values of the cross-bispectrum - biv_orig = squeeze(([abs(mean(BS(1, 2, 2, :), 4)) abs(mean(BS(2, 1, 1, :), 4))])); % [Bkmm, Bmkk], average over frequency bands (4th dimension) - xx = BS - permute(BS, [2 1 3 4 5]); - biv_anti = squeeze(([abs(mean(xx(1, 2, 2, :), 4)) abs(mean(xx(2, 1, 1, :), 4))])); + biv_orig = squeeze(([mean(abs(BS(1, 2, 2, :)), 4) mean(abs(BS(2, 1, 1, :)), 4)])); % [Bkmm, Bmkk], average over frequency bands (4th dimension) + xx = BS - permute(BS, [2 1 3 4]); + biv_anti = squeeze(([mean(abs(xx(1, 2, 2, :)), 4) mean(abs(xx(2, 1, 1, :)), 4)])); % Calculate absolute values of the cross-bicoherence bicoh = BS ./ RTP; - biv_orig_norm = squeeze(([abs(mean(bicoh(1, 2, 2, :), 4)) abs(mean(bicoh(2, 1, 1, :), 4))])); % [Bkmm, Bmkk], average over frequency bands - xx = bicoh - permute(bicoh, [2 1 3 4 5]); - biv_anti_norm = squeeze(([abs(mean(xx(1, 2, 2, :), 4)) abs(mean(xx(2, 1, 1,:), 4))])); + biv_orig_norm = squeeze(([mean(abs(bicoh(1, 2, 2, :)), 4) mean(abs(bicoh(2, 1, 1, :)), 4)])); % [Bkmm, Bmkk], average over frequency bands + xx = bicoh - permute(bicoh, [2 1 3 4]); + biv_anti_norm = squeeze(([mean(abs(xx(1, 2, 2, :)), 4) mean(abs(xx(2, 1, 1,:)), 4)])); end \ No newline at end of file diff --git a/utils/shuffle_BS.m b/utils/shuffle_BS.m index 0d1196a..3c80775 100644 --- a/utils/shuffle_BS.m +++ b/utils/shuffle_BS.m @@ -49,7 +49,7 @@ error('fcomb.high must be smaller than fcomb.low - check the documentation for the "fcomb" input parameter in "shuffle_BS".') end - [nchan, ndat, nepo] = size(data); + [nchan, ndat, ~] = size(data); % [inds, PCA_inds] = fp_npcs2inds(npcs); if isempty(g.roi_selection) @@ -133,14 +133,14 @@ % Pre-allocate variables outside the parfor loop b_orig = zeros(nROI, nROI, nshuf); b_anti = zeros(nROI, nROI, nshuf); - b_orig_norm = zeros(nROI, nROI, nshuf); - b_anti_norm = zeros(nROI, nROI, nshuf); + % b_orig_norm = zeros(nROI, nROI, nshuf); + % b_anti_norm = zeros(nROI, nROI, nshuf); - for ishuf = 1:nshuf + parfor ishuf = 1:nshuf b_orig_ishuf = zeros(nROI, nROI); b_anti_ishuf = zeros(nROI, nROI); - b_orig_norm_ishuf = zeros(nROI, nROI); - b_anti_norm_ishuf = zeros(nROI, nROI); + % b_orig_norm_ishuf = zeros(nROI, nROI); + % b_anti_norm_ishuf = zeros(nROI, nROI); % Iterate over ROI pairs for proi = 1:nROI @@ -154,8 +154,8 @@ [RTP_low,~] = data2bs_threenorm(X(:, :)', ndat, floor(ndat/2), ndat, freqinds_low); [RTP_up,~] = data2bs_threenorm(X(:, :)', ndat, floor(ndat/2), ndat, freqinds_up); - [biv_orig_low, biv_anti_low, biv_orig_low_norm, biv_anti_low_norm] = calc_pac(BS_low, RTP_low); - [biv_orig_up, biv_anti_up, biv_orig_up_norm, biv_anti_up_norm] = calc_pac(BS_up, RTP_up); + [biv_orig_low, biv_anti_low] = calc_pac(BS_low, RTP_low); + [biv_orig_up, biv_anti_up] = calc_pac(BS_up, RTP_up); % PAC_km(f1, f2) = 0.5 * |Bkmm(f1, f2-f1)| + 0.5 * |Bkmm(f1, f2)| b_orig_ishuf(aroi,proi) = mean([biv_orig_up(1) biv_orig_low(1)]); @@ -163,11 +163,11 @@ b_anti_ishuf(aroi,proi) = mean([biv_anti_up(1) biv_anti_low(1)]); b_anti_ishuf(proi,aroi) = mean([biv_anti_up(2) biv_anti_low(2)]); - % normalized versions (for bicoherence) - b_orig_norm(aroi,proi) = mean([biv_orig_up_norm(1) biv_orig_low_norm(1)]); - b_orig_norm(proi,aroi) = mean([biv_orig_up_norm(2) biv_orig_low_norm(2)]); - b_anti_norm(aroi,proi) = mean([biv_anti_up_norm(1) biv_anti_low_norm(1)]); - b_anti_norm(proi,aroi) = mean([biv_anti_up_norm(2) biv_anti_low_norm(2)]); + % % normalized versions (for bicoherence) + % b_orig_norm(aroi,proi) = mean([biv_orig_up_norm(1) biv_orig_low_norm(1)]); + % b_orig_norm(proi,aroi) = mean([biv_orig_up_norm(2) biv_orig_low_norm(2)]); + % b_anti_norm(aroi,proi) = mean([biv_anti_up_norm(1) biv_anti_low_norm(1)]); + % b_anti_norm(proi,aroi) = mean([biv_anti_up_norm(2) biv_anti_low_norm(2)]); end end @@ -175,8 +175,8 @@ % Store the shuffle information b_orig(:,:, ishuf) = b_orig_ishuf; b_anti(:,:, ishuf) = b_anti_ishuf; - b_orig_norm(:,:, ishuf) = b_orig_norm_ishuf; - b_anti_norm(:,:, ishuf) = b_anti_norm_ishuf; + % b_orig_norm(:,:, ishuf) = b_orig_norm_ishuf; + % b_anti_norm(:,:, ishuf) = b_anti_norm_ishuf; end @@ -186,8 +186,8 @@ % Save PAC results in the output structure conn.PAC.b_orig = b_orig; conn.PAC.b_anti = b_anti; - conn.PAC.b_orig_norm = b_orig_norm; - conn.PAC.b_anti_norm = b_anti_norm; + % conn.PAC.b_orig_norm = b_orig_norm; + % conn.PAC.b_anti_norm = b_anti_norm; % shut down current parallel pool only if the toolbox is available if license('test', 'Distrib_Computing_Toolbox') && ~isempty(ver('parallel'))