OSCR

Neural mechanisms of time-forward predictions for naturalistic auditory tone sequences.

Code ↔ Paper

26 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 26 matches · 2 of them tie a paragraph to a whole file, not to given lines: weak matches, whose lines are not tinted
  1. [1] § Methods › Directed connectivity analysis with Granger causality ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/NASTD_ECoG_Connectivity_Main_lk.m, lines 996–1094 · score 0.88 · IFC ventral, dlPFC, auditory hierarchy, auditory cortex, BA, Brodmann
  2. [2] § Results › Changes in directed connectivity during sequence processing and sensory prediction ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/NASTD_ECoG_Connectivity_Main_lk.m, lines 996–1094 · score 0.83 · dlPFC, Brodmann area, auditory hierarchy, auditory cortex, IPL, IFC
  3. [3] § Methods › iEEG data preprocessing ↔ AnalysisCode/Analysis_and_Plotting/Prediction/Helper Functions/NASTD_ECoG_Predict_CompPredp33_Subs_ManualArtifactCorrection.m, lines 43–149 · score 0.82 · Hilbert transform, amplitude envelop, baseline corrected, FieldTrip, smoothed, artifacts
  4. [4] § Methods › iEEG data preprocessing ↔ AnalysisCode/Preprocessing/IED_detector_rev3.7.2014/spike_detector_hilbert_v16_byISARG.m, lines 1–84 · score 0.79 · interictal epileptiform discharges, frequency bands, Hilbert, Butterworth, algorithm, IED
  5. [5] § Methods › Directed connectivity analysis with Granger causality ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/HelperFunctions/NASTD_ECoG_Connectivity_CalculateGC_oldoption.m, lines 394–533 · score 0.76 · median model, Granger Causality, full model, selected model, pairwise, electrode pair
  6. [6] § Methods › iEEG data preprocessing ↔ AnalysisCode/Preprocessing/IED_detector_rev3.7.2014/spike_detector_hilbert_v16_byISARG.m, lines 1–84 · score 0.72 · interictal epileptiform discharges, detection, segments, algorithm, events, IEDs
  7. [7] § Methods › iEEG data preprocessing ↔ AnalysisCode/Preprocessing/NASTD_ECoG_Preproc_Main.m, lines 254–317 · score 0.65 · Heartbeat related artifacts, algorithm, ECG, pulse, phase, thresholding
  8. [8] § Methods › Neural correlates of sensory history integration (SHI) ↔ AnalysisCode/Analysis_and_Plotting/HistoryTracking/HelperFunctions/NASTD_ECoG_HisTrack_CombineExpKvals.m, lines 118–169 · score 0.63 · cross validation, Model selection, fold, squared, regression, winning
  9. [9] § Methods › Neural correlates of sensory history integration (SHI) ↔ AnalysisCode/Analysis_and_Plotting/HistoryTracking/HelperFunctions/NASTD_ECoG_HisTrack_CompExpKvals.m, lines 525–591 · score 0.63 · cross validation, Model selection, fold, squared, regression, winning
  10. [10] § Results › Changes in directed connectivity during sequence processing and sensory prediction ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/HelperFunctions/NASTD_ECoG_Connectivity_CalculateGC_oldoption.m, lines 394–533 · score 0.61 · frequency domain GC, Granger causality, selected electrodes, pairwise, electrode pair, spectral
  11. [11] § Results › Paradigm and experimental design ↔ ParadigmCode/sfa_expt4_makeTrainingStim.m, lines 70–109 · score 0.61 · 220–880 Hz, penultimate tone, unique sequences, 220 Hz, semitones, tone pitch
  12. [12] § Results › Paradigm and experimental design ↔ ParadigmCode/sfa_expt4_makeStim.m, lines 11–115 · score 0.61 · 220–880 Hz, penultimate tone, unique sequences, 220 Hz, semitones, tone pitch
  13. [13] § Methods › Directed connectivity analysis with Granger causality ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/HelperFunctions/NASTD_ECoG_Connectivity_PlotSignElecCon_AllSubTDLobes.m, lines 1640–1726 · score 0.60 · frontal parietal, parietal temporal, frontal temporal, lobes, prediction error, electrode pairs
  14. [14] § Methods › iEEG data preprocessing ↔ AnalysisCode/Preprocessing/NASTD_ECoG_Preproc_Main.m, lines 254–317 · score 0.60 · phase shift, pass filter, Butterworth, zero, block, preprocessing
  15. [15] § Methods › iEEG data preprocessing ↔ AnalysisCode/Preprocessing/NASTD_ECoG_Preproc_SubPreprocSettings.m, lines 412–483 · score 0.60 · band stop, pass filter, lying, noise, block, preprocessing
  16. [16] § Results › Neural correlates of tone sequence tracking ↔ AnalysisCode/Analysis_and_Plotting/StimulusCorrelation/NASTD_ECoG_StimCorr_Main_lk.m, lines 100–164 · score 0.58 · amplitude envelopes, range activity, high gamma, field, ERF, MEG
  17. [17] § Results › Neural correlates of tone sequence tracking ↔ AnalysisCode/Analysis_and_Plotting/Prediction/NASTD_ECoG_Predict_Main_lk.m, lines 119–216 · score 0.58 · amplitude envelopes, range activity, high gamma, field, ERF, MEG
  18. [18] § Methods › Paradigm and experimental setup ↔ ParadigmCode/sfa_expt4_getParamsTraining.m, the whole file · a weak match · score 0.57 · fixation point, instructed, keyboard, laptop, training, window
  19. [19] § Methods › Neural correlates of tone sequence tracking ↔ AnalysisCode/Analysis_and_Plotting/Prediction/NASTD_ECoG_Predict_Main_lk.m, lines 119–216 · score 0.55 · amplitude envelops, frequency band, high gamma, tone sequence, beta, alpha
  20. [20] § Methods › Neural correlates of prediction and prediction error ↔ AnalysisCode/Analysis_and_Plotting/Prediction/Helper Functions/NASTD_ECoG_Predict_CompPred_Sample_Subs_FTPL.m, lines 133–189 · score 0.55 · Temporal clusters, linear regressions, prediction error, permutation, shuffling, tone duration
  21. [21] § Methods › Directed connectivity analysis with Granger causality ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/HelperFunctions/NASTD_ECoG_Connectivity_CalculateGC_pertone.m, lines 510–565 · score 0.53 · Granger Causality, full model, pairwise, connectivity, tone
  22. [22] § Methods › Paradigm and experimental setup ↔ ParadigmCode/sfa_expt4_getParams.m, the whole file · a weak match · score 0.52 · fixation point, keyboard, laptop, feedback, window, Paradigm
  23. [23] § Results › Changes in directed connectivity during sequence processing and sensory prediction ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/HelperFunctions/NASTD_ECoG_Connectivity_PlotGC_statp1top31_acrossTDs+seqs.m, lines 1–71 · score 0.52 · linear fit, PE Pred, slopes, electrode pairing, broadband, lobe
  24. [24] § Results › Changes in directed connectivity during sequence processing and sensory prediction ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/HelperFunctions/NASTD_ECoG_Connectivity_PlotGC_statp1top31_acrossTDs+seqs_alltones.m, lines 1–66 · score 0.52 · linear fit, PE Pred, slopes, electrode pairing, broadband, lobe
  25. [25] § Results › Changes in directed connectivity during sequence processing and sensory prediction ↔ AnalysisCode/Analysis_and_Plotting/Connectivity/NASTD_ECoG_Connectivity_Main_lk.m, lines 102–163 · score 0.52 · Granger causality, S2, ECoG, high gamma, lobe, parietal
  26. [26] § Methods › Experimental stimuli ↔ ParadigmCode/sfa_expt4_makeStim.m, lines 11–115 · score 0.51 · 220–880 Hz, 220 Hz, semitone, distance, log, pitches

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 1,208 lines · 52 KB · no license · 3 matches

  1. %% Project: NASTD_ECoG
  2. %Compute Granger Causality (GC) directed connectivity measures to
  3. %determine:
  4. %1) the interplay between frontal and temporal prediction effect electrodes (time-wise GC in the HP2-LP30Hz band)
  5. %2) the interplay between frontal and temporal complex prediciton error (PE) effect eletrodes (frequency-wise GC in the high gamma band)
  6. %3) the interplay between frontal prediction and temporal PE effect electrodes
  7. %4) the interplay between global SHI and prediciton effect electrodes
  8. %% 0.1) Specify vars, paths, and setup fieldtrip
  9. addpath('/isilon/LFMI/VMdrive/Thomas/NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/')
  10. %Add project base path
  11. NASTD_ECoG_setVars
  12. paths_NASTD_ECoG = NASTD_ECoG_paths;
  13. % addpath(genpath(paths_NASTD_ECoG.BaseDir));
  14. addpath(genpath(paths_NASTD_ECoG.ScriptsDir));
  15. %Add project base and script dir
  16. %Determine subjects
  17. sub_list = vars.sub_list;
  18. %Load in file with individual preproc infos
  19. subs_PreProcSettings = NASTD_ECoG_Preproc_SubPreprocSettings;
  20. ToneDur_text = {'0.2' '0.4'};
  21. plot_poststepFigs = 0;
  22. save_poststepFigs = 1;
  23. %% 1) Select and plot electrodes for which GC will be analyzed
  24. param.pval_plotting = 0.01; %Pval thresh for plotting
  25. param.pval_FDR = 0.05;
  26. param.FDRcorrect = 0;
  27. param.plot_SubplotperTW = 1; %Common plot across TW
  28. param.ElecSelect = 'All'; %StimCorr, All
  29. param.SamplesTW = 25; %25 = 50ms TW
  30. param.Label_TW = num2str(round(param.SamplesTW/512,2));
  31. param.ToneIndex = 33;
  32. InputDataType = {'HP05toLP30Hz'};
  33. InputEffectType = {'PredEffect', 'ComplexPredErrEffect'};
  34. ToneDur_text = {'0.2' '0.4'};
  35. subs = sub_list(vars.validSubjs);
  36. %1.1 Highlight same-subject electrodes with selected p-value for either prediciton OR complex prediction error effect
  37. % for i_effect = 1:length(InputEffectType)
  38. % for i_inputData = 1:length(InputDataType)
  39. % NASTD_ECoG_Connectivity_PlotSignElec_AllSubTD...
  40. % (subs, ...
  41. % InputEffectType{i_effect}, InputDataType{i_inputData}, ToneDur_text, ...
  42. % param,...
  43. % save_poststepFigs, paths_NASTD_ECoG)
  44. % end
  45. % end
  46. % %1.2 Highlight same-subject electrodes with selected p-value
  47. % %with prediciton (for HP2toLP30Hz) AND complex prediction error (for HighGamma_LogAmp) effect
  48. % NASTD_ECoG_Connectivity_PlotSignElecPred2PE_AllSubTD...
  49. % (subs, ...
  50. % ToneDur_text, ...
  51. % param,...
  52. % save_poststepFigs, paths_NASTD_ECoG)
  53. % %1.3 Create output file specifiying selected electrodes
  54. subs = sub_list(vars.validSubjs);
  55. plot_poststepFigs = 0;
  56. param.pval_plotting = 0.05; %Pval thresh
  57. param.FDRcorrect = 0;
  58. param.pval_FDR = 0.05;
  59. param.ElecSelect = 'All'; %StimCorr, All
  60. InputDataType = {'HP05toLP30Hz'};%, 'HighGamma_LogAmp'};
  61. %Effect-based p-val thresholded electrode selection
  62. % SelElecs = NASTD_ECoG_Connectivity_ReadOutGCElecs_AllSubTD...
  63. % (subs, ...
  64. % InputDataType, ToneDur_text, ...
  65. % param, plot_poststepFigs, ...
  66. % paths_NASTD_ECoG);
  67. % %%Select all existing electrodes (independent of effect or threshold)
  68. % SelElecs = NASTD_ECoG_Connectivity_ReadOutAllElecs_AllSubTD...
  69. % (subs, ...
  70. % plot_poststepFigs, ...
  71. % paths_NASTD_ECoG);
  72. %1.5 Create Plot showing electrode connections that are the basis for GC calculation
  73. %Across subjects and TD, color-coded for region, sign-coded for prediction-effect-type.
  74. %Plot separately for each electrode-selection based on different prediction-effect-types.
  75. % NASTD_ECoG_Connectivity_PlotSignElecConnectionsforGC_AllSubTD...
  76. % (subs, ...
  77. % InputDataType, ToneDur_text, ...
  78. % param, plot_poststepFigs, ...
  79. % paths_NASTD_ECoG);
  80. %
  81. % NASTD_ECoG_Connectivity_PlotSignElecCon_AllSubTDLobes... %For Pred-Pred & PE-PE, all lobes together with optional connection lines
  82. % (subs, ...
  83. % InputDataType, ToneDur_text, ...
  84. % param, plot_poststepFigs, ...
  85. % paths_NASTD_ECoG);
  86. %% 2) Compute Granger Causality (GC) for specific electrode combinations
  87. %Hypotheses:
  88. %Spatial:
  89. %Frontal P -> Temporal P > Chance
  90. %Temporal PE -> Frontal PE > Chance (CAVE: few frontal PE)
  91. %Frontal P -> Temporal PE > Frontal P <- Temporal PE
  92. %Temporal:
  93. %P -> PE electrodes stronger in earlier TW compared to late TW
  94. %P -> PE electrodes stronger in earlier TW compared to P <- PE electrodes
  95. %Spectral:
  96. %P -> PE: low frequencies (alpha/beta)
  97. %P <- PE: high gamma
  98. %P -> P: low frequencies (alpha/beta)
  99. %PE -> PE: high gamma
  100. addpath('/isilon/LFMI/VMdrive/Thomas/toolboxes/mvgc_v1.3/');
  101. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.01uncorr.mat') %p < 0.01 thresh,uncorr elec selection
  102. load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.05uncorr.mat') %p < 0.05 thresh,uncorr elec selection
  103. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.025FDRcorr.mat') %p < 0.025 thresh, FDRcorr elec selection
  104. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_AllElecs.mat') % no thresh, all elec selection
  105. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.05uncorr_HighGamma.mat') %p < 0.05 thresh,uncorr elec selection
  106. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.01uncorr_HighGamma.mat') %p < 0.05 thresh,uncorr elec selection
  107. % Computing how many significant electrodes per lobe (frontal, parietal, and temporal) and prediction vs. PE effect for Table S2
  108. % Define keywords for each lobe
  109. % frontalKeywords = ["AntPFC", "PrecentralG", "IFG"];
  110. % parietalKeywords = ["SupParLob", "PostcentralG", "SupramarginalG"];
  111. % temporalKeywords = ["VentralT", "STG", "MTG"];
  112. %
  113. % % Extract AnatCat Label column
  114. % predLabels = SelElecs.PredEffect.("AnatCat Label");
  115. % predLabelsStr = string(predLabels);
  116. % predLabelsStr(contains(predLabelsStr, "OccipitalL")) = []; % Remove entries containing "OccipitalL"
  117. % [uniqueLabels1, ~, idx1] = unique(predLabelsStr);
  118. % counts1 = accumarray(idx1, 1);
  119. % PredlabelCountsTable = table(uniqueLabels1, counts1, 'VariableNames', {'Label', 'Count'});
  120. %
  121. % peLabels = SelElecs.PEEffect.("AnatCat Label");
  122. % peLabelsStr = string(peLabels);
  123. % peLabelsStr(contains(peLabelsStr, "OccipitalL")) = []; % Remove entries containing "OccipitalL"
  124. % [uniqueLabels2, ~, idx2] = unique(peLabelsStr);
  125. % counts2 = accumarray(idx2, 1);
  126. % PElabelCountsTable = table(uniqueLabels2, counts2, 'VariableNames', {'Label', 'Count'});
  127. %
  128. % countLobes = @(data, keywords) sum(any(contains(data, keywords), 2));
  129. %
  130. % % Count electrodes per lobe for each effect using the strict word-boundary matching
  131. % frontalPredCount = countLobes(predLabelsStr, frontalKeywords);
  132. % parietalPredCount = countLobes(predLabelsStr, parietalKeywords);
  133. % temporalPredCount = countLobes(predLabelsStr, temporalKeywords);
  134. %
  135. % frontalPECount = countLobes(peLabelsStr, frontalKeywords);
  136. % parietalPECount = countLobes(peLabelsStr, parietalKeywords);
  137. % temporalPECount = countLobes(peLabelsStr, temporalKeywords);
  138. %
  139. % % Create the output table
  140. % LobeSummaryTable = table(["Frontal"; "Parietal"; "Temporal"], ...
  141. % [frontalPredCount; parietalPredCount; temporalPredCount], ...
  142. % [frontalPECount; parietalPECount; temporalPECount], ...
  143. % 'VariableNames', {'Lobe', 'PredCount', 'PECount'});
  144. % writetable(LobeSummaryTable, ['/isilon/LFMI/VMdrive/Lua/NASTD/Figures/ElectrodeCountsPerLobe.csv']);
  145. %% Compute GC
  146. param.GC = [];
  147. param.GC.fs = 512;
  148. param.GC.downsample = 0; %Cave: Downsampling lead to problems with tone sample selection
  149. if param.GC.downsample == 0
  150. param.GC.newfs = param.GC.fs;
  151. else
  152. param.GC.newfs = param.GC.fs/param.GC.downsample;
  153. end
  154. param.GC.nvars = 2;
  155. param.GC.regmode = 'OLS'; % VAR model estimation regression mode ('OLS', 'LWR' or empty for default
  156. param.GC.maxmorder = 50; % maximum model order for model order estimation, rule of thumb = number of samples per input data snippet, but not > 100
  157. % param.GC.morder = 'AIC'; % model order to use ('actual', 'AIC', 'BIC' or supplied numerical value)
  158. param.GC.tstat = 'F'; % statistical test for MVGC: 'F' for Granger's F-test (default) or 'chi2' for Geweke's chi2 test
  159. param.GC.alpha = 0.05; % significance level for significance test
  160. param.GC.mhtc = 'FDRD'; % multiple hypothesis test correction (see routine 'significance')
  161. param.GC.ElecPairEffect = {'Pred_Pred','PE_PE','Pred_PE','PE_Pred'};
  162. %param.GC.ElecPairEffect = {'Pred_Pred', 'PE_PE'};
  163. %param.GC.ElecPairEffect = {'Pred_PE', 'PE_Pred'};
  164. param.GC.ElecPairRegion = 'AllRegions';
  165. param.GC.InputDataType = {'Broadband'}; %{'Broadband', 'HP05toLP30Hz', 'HighGamma_LogAmp'};
  166. % param.GC.tone_aggregation = {32, 33, 34};
  167. % param.GC.tone_aggregation = {31, 33, 34};
  168. %param.GC.tone_aggregation = {1, 6, 11, 16, 21, 26, 31};
  169. %param.GC.tone_aggregation = {2, 7, 12, 17, 22, 27, 32};
  170. % param.GC.tone_aggregation = {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};
  171. % param.GC.tone_aggregation = {30, 31, 32};
  172. %param.GC.tone_aggregation = {30, 31, 32, 33, 34};
  173. param.GC.tone_aggregation = {34};
  174. param.GC.tone_aggregation_label = cellfun(@(c)[c],param.GC.tone_aggregation);
  175. param.GC.tone_aggregation_label = num2str((param.GC.tone_aggregation_label),'_%d');
  176. param.GC.tone_aggregation_label = erase(param.GC.tone_aggregation_label, ' ');
  177. param.GC.epochdur_ms = 'full'; %'full', 200, 100
  178. if strcmp(param.GC.epochdur_ms, 'full')
  179. param.GC.epochdur_ms_label = 'fullTW';
  180. else
  181. param.GC.epochdur_ms_label = [num2str(param.GC.epochdur_ms) 'msTW'];
  182. end
  183. % Across-trial GC estimates
  184. % parfor i_sub = vars.validSubjs
  185. %
  186. % tic
  187. % GCdata{i_sub} = ... %Compute GC for aggregated tones
  188. % NASTD_ECoG_Connectivity_CalculateGC_aggrtone ...
  189. % (sub_list, i_sub, ...
  190. % ToneDur_text, SelElecs, ...
  191. % param, paths_NASTD_ECoG);
  192. % GCdata{i_sub} = ... %Compute GC for each single tone
  193. % NASTD_ECoG_Connectivity_CalculateGC_pertone ...
  194. % (sub_list, i_sub, ...
  195. % ToneDur_text, SelElecs, ...
  196. % param, paths_NASTD_ECoG);
  197. % disp(['-- GC computation for sub: ' sub_list{i_sub} ' finished after ' num2str(round(toc/60),2) ' min --'])
  198. %
  199. % end
  200. %save output
  201. % path_outputdata = ([paths_NASTD_ECoG.ECoGdata_Connectivity 'GC/']);
  202. % if (~exist(path_outputdata, 'dir')); mkdir(path_outputdata); end
  203. % label_outputdata = ['GCdata_n' num2str(length(vars.validSubjs)) '_' ...
  204. % param.GC.ElecPairRegion '_' ...
  205. % param.GC.InputDataType{1} param.GC.tone_aggregation_label '_' ...
  206. % param.GC.epochdur_ms_label '_ensemnorm'];
  207. % %save([path_outputdata label_outputdata], 'GCdata','-v7.3')
  208. % load([path_outputdata label_outputdata], 'GCdata')
  209. % Across-trial GC estimates for selected trial IDs
  210. FTPL_ratings = load([paths_NASTD_ECoG.Analysis_Behavior 'FTPLratings/Allsub_n8/Data/', 'Trialwise_FTPL_allsubs.mat']);
  211. FTPL_ratings = FTPL_ratings.Trialwise_FTPL;
  212. rows_all = strcmp(FTPL_ratings.ToneDur, 'all'); %Take ratings across both TD conditions
  213. FTPL_all = FTPL_ratings(rows_all, :);
  214. sub_list_FTPL = sub_list(2:9);
  215. % Averaging over trialwise data for low-FTPL trials and for high-FTPL
  216. % trials
  217. low_FTPL_all = {};
  218. high_FTPL_all = {};
  219. for i_sub = 1:length(sub_list_FTPL)
  220. current_subID = sub_list_FTPL(i_sub);
  221. % Find all rows in FTPL_all for this subject
  222. subj_rows = strcmp(FTPL_all.SubID, current_subID);
  223. % Get the FTPL ratings for this subject
  224. ratings_subj = FTPL_all.FTPLrating(subj_rows);
  225. median_subj = median(ratings_subj, 'omitnan');
  226. % Create logical indices for low and high FTPL relative to
  227. % subject-specific median of ratings
  228. low_idx = ratings_subj < median_subj;
  229. low_idx = FTPL_all.TrialNum(low_idx); % TrialIDs for low FTPL
  230. low_FTPL_all{i_sub} = low_idx;
  231. high_idx = ratings_subj > median_subj;
  232. high_idx = FTPL_all.TrialNum(high_idx);
  233. high_FTPL_all{i_sub} = high_idx;
  234. end
  235. path_outputdata = ([paths_NASTD_ECoG.ECoGdata_Connectivity 'GC/']);
  236. % parfor i_sub = vars.validSubjs(2:9)
  237. % tic
  238. % GCdata_lowFTPL{i_sub} = ... %Compute GC for aggregated tones
  239. % NASTD_ECoG_Connectivity_CalculateGC_aggrtone_SelTrials ...
  240. % (sub_list, i_sub, ...
  241. % ToneDur_text, SelElecs, ...
  242. % low_FTPL_all{i_sub-1}, ...
  243. % param, paths_NASTD_ECoG);
  244. % disp(['-- GC computation for sub: ' sub_list{i_sub} ' for LOW FTPL finished after ' num2str(round(toc/60),2) ' min --'])
  245. % GCdata_highFTPL{i_sub} = ... %Compute GC for aggregated tones
  246. % NASTD_ECoG_Connectivity_CalculateGC_aggrtone_SelTrials ...
  247. % (sub_list, i_sub, ...
  248. % ToneDur_text, SelElecs, ...
  249. % high_FTPL_all{i_sub-1}, ...
  250. % param, paths_NASTD_ECoG);
  251. % disp(['-- GC computation for sub: ' sub_list{i_sub} ' for LOW FTPL finished after ' num2str(round(toc/60),2) ' min --'])
  252. % end
  253. label_outputdata1 = ['GCdata_n' num2str(length(vars.validSubjs)) '_' ...
  254. param.GC.ElecPairRegion '_' ...
  255. param.GC.InputDataType{1} param.GC.tone_aggregation_label '_' ...
  256. param.GC.epochdur_ms_label '_lowFTPL'];
  257. %save([path_outputdata label_outputdata1], 'GCdata_lowFTPL','-v7.3')
  258. GCdata_lowFTPL=load([path_outputdata label_outputdata1]);
  259. label_outputdata2 = ['GCdata_n' num2str(length(vars.validSubjs)) '_' ...
  260. param.GC.ElecPairRegion '_' ...
  261. param.GC.InputDataType{1} param.GC.tone_aggregation_label '_' ...
  262. param.GC.epochdur_ms_label '_highFTPL'];
  263. %save([path_outputdata label_outputdata2], 'GCdata_highFTPL','-v7.3')
  264. GCdata_highFTPL = load([path_outputdata label_outputdata2]);
  265. % Trialwise GC estimates
  266. % parfor i_sub = vars.validSubjs
  267. %
  268. % tic
  269. % GCdata{i_sub} = ... %Compute GC for each single tone and for each trial; used for control analysis checking how GC values differ for different trial-wise FTPL ratings; only run for tone 34
  270. % NASTD_ECoG_Connectivity_CalculateGC_aggrtone_trialwise ...
  271. % (sub_list, i_sub, ...
  272. % ToneDur_text, SelElecs, ...
  273. % param, paths_NASTD_ECoG);
  274. % disp(['-- GC computation for sub: ' sub_list{i_sub} ' finished after ' num2str(round(toc/60),2) ' min --'])
  275. %
  276. % end
  277. %save output
  278. % path_outputdata = ([paths_NASTD_ECoG.ECoGdata_Connectivity 'GC/']);
  279. % if (~exist(path_outputdata, 'dir')); mkdir(path_outputdata); end
  280. % label_outputdata = ['GCdata_n' num2str(length(vars.validSubjs)) '_' ...
  281. % param.GC.ElecPairRegion '_' ...
  282. % param.GC.InputDataType{1} param.GC.tone_aggregation_label '_' ...
  283. % param.GC.epochdur_ms_label '_trialwise_ensemnorm'];
  284. % %save([path_outputdata label_outputdata], 'GCdata','-v7.3')
  285. % load([path_outputdata label_outputdata], 'GCdata')
  286. %% Compare GC values for low vs. high FTPL ratings for parietal -> frontal during p34 using trialwise data
  287. %First make a GCdata for low FTPL ratings, average across trials,NASTD_ECoG_Connectivity_stat save GC.
  288. %Do the same for high FTP ratings, average across trials, save GC.
  289. %Pass both averaged GC through anatomical averaging script (NASTD_ECoG_Connectivity_PlotGC_statp32p33p34.m in Thomas' folder)
  290. % This will output 10 (source anat regions) x 10 (target anat regions) x 2
  291. % (TDs) arrays for the low-FTPL-GC and the high-FTPL-GC. Then we can select
  292. % parietal to frontal by indexing source anat region = 7 and target anat
  293. % region = 1 for each of them, and do the stats.
  294. % GCdata_FTPL = GCdata(2:9);
  295. % numSubjects = length(GCdata_FTPL);
  296. % FTPL_ratings = load([paths_NASTD_ECoG.Analysis_Behavior 'FTPLratings/Allsub_n8/Data/', 'Trialwise_FTPL_allsubs.mat']);
  297. % FTPL_ratings = FTPL_ratings.Trialwise_FTPL;
  298. % rows_all = strcmp(FTPL_ratings.ToneDur, 'all'); %Take ratings across both TD conditions
  299. % FTPL_all = FTPL_ratings(rows_all, :);
  300. % all_trialIDs = cell(numSubjects, 1);
  301. % for i_sub = 1:numSubjects
  302. % % Combine trial IDs across tone durations (1x2 cell)
  303. % all_trialIDs{i_sub} = [GCdata{i_sub}.info.trialIDs{1}; GCdata{i_sub}.info.trialIDs{2}];
  304. % end
  305. % sub_list_FTPL = sub_list(2:9);
  306. %
  307. % % Averaging over trialwise data for low-FTPL trials and for high-FTPL
  308. % % trials
  309. % for i_sub = 1:numSubjects
  310. % current_subID = sub_list_FTPL(i_sub);
  311. %
  312. % % Find all rows in FTPL_all for this subject
  313. % subj_rows = strcmp(FTPL_all.SubID, current_subID);
  314. %
  315. % % Get the FTPL ratings for this subject
  316. % ratings_subj = FTPL_all.FTPLrating(subj_rows);
  317. % median_subj = median(ratings_subj, 'omitnan');
  318. % trialIDs_subj = all_trialIDs{i_sub};
  319. %
  320. % % Create logical indices for low and high FTPL relative to
  321. % % subject-specific median of ratings
  322. % low_idx = ratings_subj < median_subj;
  323. % low_idx = FTPL_all.TrialNum(low_idx); % TrialIDs for low FTPL
  324. %
  325. % high_idx = ratings_subj > median_subj;
  326. % high_idx = FTPL_all.TrialNum(high_idx);
  327. %
  328. % % Find the Trial IDs for the GC data
  329. % trialIDs_GC_TD1 = GCdata_FTPL{i_sub}.info.trialIDs{1}; %Trial IDs of GC data for TD1
  330. % trialIDs_GC_TD2 = GCdata_FTPL{i_sub}.info.trialIDs{2}; %Trial IDs for GC data for TD2
  331. %
  332. % % Identify corresponding trials in GC data for low and high FTPL
  333. % % ratings
  334. % [~,match_idx_low_TD1] = ismember(low_idx, trialIDs_GC_TD1); % Finds corresponding trials in the GC data for TD1
  335. % idx_low_in_GC_TD1 = match_idx_low_TD1(match_idx_low_TD1 > 0);
  336. % [~, match_idx_low_TD2] = ismember(low_idx, trialIDs_GC_TD2); % Finds corresponding trials in the GC data for TD2
  337. % idx_low_in_GC_TD2 = match_idx_low_TD2(match_idx_low_TD2 > 0);
  338. %
  339. % [~, match_idx_high_TD1] = ismember(high_idx, trialIDs_GC_TD1); % Finds corresponding trials in the GC data for TD1
  340. % idx_high_in_GC_TD1 = match_idx_high_TD1(match_idx_high_TD1 > 0);
  341. % [~, match_idx_high_TD2] = ismember(high_idx, trialIDs_GC_TD2); % Finds corresponding trials in the GC data for TD2
  342. % idx_high_in_GC_TD2 = match_idx_high_TD2(match_idx_high_TD2 > 0);
  343. %
  344. % for i_effect = 1:length(GCdata_FTPL{i_sub}.temporalGC)
  345. % for i_TD = 1:length(GCdata_FTPL{i_sub}.temporalGC{i_effect})
  346. % if i_TD == 1
  347. % idx_low_in_GC = idx_low_in_GC_TD1;
  348. % idx_high_in_GC = idx_high_in_GC_TD1;
  349. % else
  350. % idx_low_in_GC = idx_low_in_GC_TD2;
  351. % idx_high_in_GC = idx_high_in_GC_TD2;
  352. % end
  353. %
  354. % % === TEMPORAL GC ===
  355. % temp_struct = GCdata_FTPL{i_sub}.temporalGC{i_effect}{i_TD};
  356. % GCdata_average_lowFTPL{i_sub}.temporalGC{i_effect}{i_TD}.source2target = ...
  357. % mean(temp_struct.source2target(:,:,:,idx_low_in_GC), 4, 'omitnan');
  358. % GCdata_average_lowFTPL{i_sub}.temporalGC{i_effect}{i_TD}.target2source = ...
  359. % mean(temp_struct.target2source(:,:,:,idx_low_in_GC), 4, 'omitnan');
  360. %
  361. % GCdata_average_highFTPL{i_sub}.temporalGC{i_effect}{i_TD}.source2target = ...
  362. % mean(temp_struct.source2target(:,:,:,idx_high_in_GC), 4, 'omitnan');
  363. % GCdata_average_highFTPL{i_sub}.temporalGC{i_effect}{i_TD}.target2source = ...
  364. % mean(temp_struct.target2source(:,:,:,idx_high_in_GC), 4, 'omitnan');
  365. %
  366. % % === PVAL TEMPORAL GC ===
  367. % pval_struct = GCdata_FTPL{i_sub}.pval_temporalGC{i_effect}{i_TD};
  368. % GCdata_average_lowFTPL{i_sub}.pval_temporalGC{i_effect}{i_TD}.source2target = ...
  369. % mean(pval_struct.source2target(:,:,:,idx_low_in_GC), 4, 'omitnan');
  370. % GCdata_average_lowFTPL{i_sub}.pval_temporalGC{i_effect}{i_TD}.target2source = ...
  371. % mean(pval_struct.target2source(:,:,:,idx_low_in_GC), 4, 'omitnan');
  372. %
  373. % GCdata_average_highFTPL{i_sub}.pval_temporalGC{i_effect}{i_TD}.source2target = ...
  374. % mean(pval_struct.source2target(:,:,:,idx_high_in_GC), 4, 'omitnan');
  375. % GCdata_average_highFTPL{i_sub}.pval_temporalGC{i_effect}{i_TD}.target2source = ...
  376. % mean(pval_struct.target2source(:,:,:,idx_high_in_GC), 4, 'omitnan');
  377. %
  378. % % === SPECTRAL GC ===
  379. % spec_struct = GCdata_FTPL{i_sub}.spectralGC{i_effect}{i_TD};
  380. % GCdata_average_lowFTPL{i_sub}.spectralGC{i_effect}{i_TD}.source2target = ...
  381. % mean(spec_struct.source2target(:,:,:,:,idx_low_in_GC), 5, 'omitnan');
  382. % GCdata_average_lowFTPL{i_sub}.spectralGC{i_effect}{i_TD}.target2source = ...
  383. % mean(spec_struct.target2source(:,:,:,:,idx_low_in_GC), 5, 'omitnan');
  384. %
  385. % GCdata_average_highFTPL{i_sub}.spectralGC{i_effect}{i_TD}.source2target = ...
  386. % mean(spec_struct.source2target(:,:,:,:,idx_high_in_GC), 5, 'omitnan');
  387. % GCdata_average_highFTPL{i_sub}.spectralGC{i_effect}{i_TD}.target2source = ...
  388. % mean(spec_struct.target2source(:,:,:,:,idx_high_in_GC), 5, 'omitnan');
  389. % end
  390. % end
  391. % GCdata_average_lowFTPL{i_sub}.info = GCdata_FTPL{i_sub}.info;
  392. % GCdata_average_lowFTPL{i_sub}.label_allelecs = GCdata_FTPL{i_sub}.label_allelecs;
  393. % GCdata_average_lowFTPL{i_sub}.ind_pairedelecs_from = GCdata_FTPL{i_sub}.ind_pairedelecs_from;
  394. % GCdata_average_lowFTPL{i_sub}.ind_pairedelecs_to = GCdata_FTPL{i_sub}.ind_pairedelecs_to;
  395. %
  396. % GCdata_average_highFTPL{i_sub}.info = GCdata_FTPL{i_sub}.info;
  397. % GCdata_average_highFTPL{i_sub}.label_allelecs = GCdata_FTPL{i_sub}.label_allelecs;
  398. % GCdata_average_highFTPL{i_sub}.ind_pairedelecs_from = GCdata_FTPL{i_sub}.ind_pairedelecs_from;
  399. % GCdata_average_highFTPL{i_sub}.ind_pairedelecs_to = GCdata_FTPL{i_sub}.ind_pairedelecs_to;
  400. % end
  401. % AnatReg_CatLabels = ... %Select which anatomical regions should be plotted
  402. % {'AntPFC'; ...
  403. % 'VentralT'; ...
  404. % 'SupParLob'};
  405. %
  406. % Gavg_tempGC_peranatreg_lowFTPL = NASTD_ECoG_Connectivity_ObtainGCByAnatRegions ...
  407. % (sub_list_FTPL, ...
  408. % GCdata_average_lowFTPL, ...
  409. % ToneDur_text, ...
  410. % SelElecs, AnatReg_CatLabels, ...
  411. % save_poststepFigs, ...
  412. % param, paths_NASTD_ECoG); %This will have the format, for each field, of i_effect cells, with format nSourceElecs x nTargetElecs x nTD
  413. %
  414. % Gavg_tempGC_peranatreg_highFTPL = NASTD_ECoG_Connectivity_ObtainGCByAnatRegions ...
  415. % (sub_list_FTPL, ...
  416. % GCdata_average_highFTPL, ...
  417. % ToneDur_text, ...
  418. % SelElecs, AnatReg_CatLabels, ...
  419. % save_poststepFigs, ...
  420. % param, paths_NASTD_ECoG); %This will have the format, for each field, of i_effect cells, with format nSourceElecs x nTargetElecs x nTD
  421. % Compute GC low vs high FTPL for Parietal > Frontal
  422. %
  423. % index_of_interest_source = 7; %Parietal
  424. % index_of_interest_target = 1; %Frontal
  425. %
  426. % GC_Par_to_Front_lowFTPL = nan(numSubjects, 1); % one entry per subject
  427. % GC_Par_to_Front_highFTPL = nan(numSubjects, 1); % one entry per subject
  428. %
  429. % GC_Par_to_Front_lowFTPL_all = {}; % Pool across 4 different effect types, average across TDs
  430. % GC_Par_to_Front_highFTPL_all = {};
  431. %
  432. % for i_sub = 1:numSubjects
  433. % all_GC_rows_low = [];
  434. % all_GC_rows_high = [];
  435. %
  436. % for i_effect = 1:length(GCdata_FTPL{i_sub}.temporalGC)
  437. % for i_TD = 1:length(GCdata_FTPL{i_sub}.temporalGC{i_effect})
  438. % % Get data and subject indices for this effect and TD
  439. % GCvals_low = Gavg_tempGC_peranatreg_lowFTPL.source2target{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  440. % subjIDs_low = Gavg_tempGC_peranatreg_lowFTPL.subject_index{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  441. %
  442. % if ~isempty(GCvals_low) && ~isempty(subjIDs_low)
  443. % % Find rows belonging to this subject
  444. % rows_low = find(subjIDs_low == i_sub);
  445. % if ~isempty(rows_low)
  446. % all_GC_rows_low = [all_GC_rows_low; GCvals_low(rows_low, :)];
  447. % end
  448. % end
  449. %
  450. % % Get data and subject indices for this effect and TD
  451. % GCvals_high = Gavg_tempGC_peranatreg_highFTPL.source2target{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  452. % subjIDs_high = Gavg_tempGC_peranatreg_highFTPL.subject_index{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  453. %
  454. % if ~isempty(GCvals_high) && ~isempty(subjIDs_high)
  455. % % Find rows belonging to this subject
  456. % rows_high = find(subjIDs_high == i_sub);
  457. % if ~isempty(rows_high)
  458. % all_GC_rows_high = [all_GC_rows_high; GCvals_high(rows_high, :)];
  459. % end
  460. % end
  461. % end
  462. % end
  463. %
  464. % if ~isempty(all_GC_rows_low)
  465. % GC_Par_to_Front_lowFTPL(i_sub,1) = mean(all_GC_rows_low, 1, 'omitnan');
  466. % else
  467. % GC_Par_to_Front_lowFTPL(i_sub,1) = NaN; % or [] if you prefer
  468. % end
  469. %
  470. % if ~isempty(all_GC_rows_high)
  471. % GC_Par_to_Front_highFTPL(i_sub,1) = mean(all_GC_rows_high, 1, 'omitnan');
  472. % else
  473. % GC_Par_to_Front_highFTPL(i_sub,1) = NaN; % or [] if you prefer
  474. % end
  475. % end
  476. %
  477. % % Do stats
  478. % [~, pval, ~, stats] = ttest(GC_Par_to_Front_lowFTPL, GC_Par_to_Front_highFTPL);
  479. % [pval, h, stats] = signrank(GC_Par_to_Front_lowFTPL, GC_Par_to_Front_highFTPL);
  480. %
  481. % % Plot
  482. % % Combine data
  483. % % all_data = [GC_Par_to_Front_lowFTPL(:); GC_Par_to_Front_highFTPL(:)];
  484. % % group = [ones(length(GC_Par_to_Front_lowFTPL),1); 2*ones(length(GC_Par_to_Front_highFTPL),1)];
  485. % all_data = [GC_Par_to_Front_lowFTPL(:); mean(GC_Par_to_Front_lowFTPL); GC_Par_to_Front_highFTPL(:); mean(GC_Par_to_Front_highFTPL)];
  486. % group = [ones(length(GC_Par_to_Front_lowFTPL)+1,1); 2*ones(length(GC_Par_to_Front_highFTPL)+1,1)];
  487. %
  488. % % Create boxplot
  489. % figure; hold on;
  490. % h = boxplot(all_data, group, 'Labels', {'Low FTPL', 'High FTPL'}, ...
  491. % 'Colors', 'k', 'Widths', 0.5);
  492. %
  493. % % Change box colors
  494. % boxColors = [0.2 0.6 1; 1 0.4 0.4]; % Blue, Red
  495. % boxes = findobj(gca, 'Tag', 'Box');
  496. % for j = 1:length(boxes)
  497. % patch(get(boxes(j), 'XData'), get(boxes(j), 'YData'), ...
  498. % boxColors(3-j,:), 'FaceAlpha', 0.5, 'EdgeColor', 'none');
  499. % end
  500. %
  501. % % Overlay paired data
  502. % for i = 1:length(GC_Par_to_Front_lowFTPL)
  503. % plot([1, 2], [GC_Par_to_Front_lowFTPL(i), GC_Par_to_Front_highFTPL(i)], '-o', ...
  504. % 'Color', [0.6 0.6 0.6], ...
  505. % 'MarkerFaceColor', 'k', ...
  506. % 'MarkerEdgeColor', 'none', ...
  507. % 'LineWidth', 1.2);
  508. % end
  509. %
  510. % plot([1, 2], [mean(GC_Par_to_Front_lowFTPL), mean(GC_Par_to_Front_highFTPL)], '-o', ...
  511. % 'Color', [0.6 0.6 0.6], ...
  512. % 'MarkerFaceColor', 'k', ...
  513. % 'MarkerEdgeColor', 'none', ...
  514. % 'LineWidth', 1.2);
  515. %
  516. % % Significance annotation
  517. % [~, pval] = ttest(GC_Par_to_Front_lowFTPL, GC_Par_to_Front_highFTPL);
  518. % y_max = max([GC_Par_to_Front_lowFTPL(:); GC_Par_to_Front_highFTPL(:)]) + 0.01;
  519. % plot([1, 2], [y_max, y_max], 'k', 'LineWidth', 1.5)
  520. %
  521. % if pval < 0.001
  522. % sig_label = '***';
  523. % elseif pval < 0.01
  524. % sig_label = '**';
  525. % elseif pval < 0.05
  526. % sig_label = '*';
  527. % else
  528. % sig_label = 'n.s.';
  529. % end
  530. % text(1.5, y_max + 0.005, sig_label, ...
  531. % 'FontSize', 16, ...
  532. % 'FontWeight', 'bold', ...
  533. % 'HorizontalAlignment', 'center');
  534. %
  535. % % Formatting
  536. % title('GC during p34 Parietal > Frontal');
  537. % ylabel('Average GC');
  538. % ylim([min([GC_Par_to_Front_lowFTPL; GC_Par_to_Front_highFTPL]) - 0.01, y_max + 0.02]);
  539. % set(gca, 'FontSize', 12);
  540. % box on;
  541. %
  542. % filename = ['boxplot_compare_GC_lowhigh_FTPL_Par_to_Front.png'];
  543. % figfile = ['/isilon/LFMI/VMdrive/Lua/NASTD/Figures/' filename];
  544. % saveas(gcf, figfile, 'png');
  545. %
  546. %
  547. % %% Computing stats for FTPL low vs high GC comparison across pairs from different effect-type pairings using TRIALWISE data
  548. % % Compute GC low vs high FTPL for Parietal > Frontal
  549. %
  550. % index_of_interest_source = 7; %Parietal
  551. % index_of_interest_target = 1; %Frontal
  552. % effectTypeNames = {'Pred_Pred','PE_PE','Pred_PE','PE_Pred'};
  553. %
  554. % GC_Par_to_Front_HighMinusLow = struct(); % Final output
  555. %
  556. % for i_effect = 1:length(GCdata_FTPL{1}.temporalGC)
  557. % effect_field = effectTypeNames{i_effect};
  558. % for i_TD = 1:length(GCdata_FTPL{1}.temporalGC{1})
  559. % if ~isfield(GC_Par_to_Front_HighMinusLow, effect_field)
  560. % GC_Par_to_Front_HighMinusLow.(effect_field) = struct();
  561. % end
  562. % if ~isfield(GC_Par_to_Front_HighMinusLow.(effect_field), sprintf('TD_%d', i_TD))
  563. % GC_Par_to_Front_HighMinusLow.(effect_field).(sprintf('TD_%d', i_TD)) = [];
  564. % end
  565. %
  566. % pooled_diffs = []; % temporary holder for this TD across all subjects
  567. %
  568. % for i_sub = 1:numSubjects
  569. % % LOW
  570. % GCvals_low = Gavg_tempGC_peranatreg_lowFTPL.source2target{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  571. % subjIDs_low = Gavg_tempGC_peranatreg_lowFTPL.subject_index{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  572. %
  573. % if ~isempty(GCvals_low) && ~isempty(subjIDs_low)
  574. % rows_low = (subjIDs_low == i_sub);
  575. % GC_low = GCvals_low(rows_low, :);
  576. % else
  577. % GC_low = NaN;
  578. % end
  579. %
  580. % % HIGH
  581. % GCvals_high = Gavg_tempGC_peranatreg_highFTPL.source2target{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  582. % subjIDs_high = Gavg_tempGC_peranatreg_highFTPL.subject_index{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  583. %
  584. % if ~isempty(GCvals_high) && ~isempty(subjIDs_high)
  585. % rows_high = (subjIDs_high == i_sub);
  586. % GC_high = GCvals_high(rows_high, :);
  587. % else
  588. % GC_high = NaN;
  589. % end
  590. %
  591. % if ~isempty(GC_low) && ~isempty(GC_high)
  592. % n_rows = min(size(GC_low,1), size(GC_high,1));
  593. % GC_diff = GC_high(1:n_rows, :) - GC_low(1:n_rows, :); % pairwise subtraction
  594. % pooled_diffs = [pooled_diffs; GC_diff]; % append
  595. % end
  596. % end
  597. % GC_Par_to_Front_HighMinusLow.(effect_field).(sprintf('TD_%d', i_TD)) = pooled_diffs;
  598. % end
  599. % end
  600. %
  601. % % Average across TDs
  602. % GC_all = cell(1, length(effectTypeNames));
  603. % pvals = zeros(1, length(effectTypeNames));
  604. % numEffects = numel(effectTypeNames);
  605. %
  606. % % Prepare data
  607. % for i = 1:length(effectTypeNames)
  608. % data_TD1 = GC_Par_to_Front_HighMinusLow.(effectTypeNames{i}).TD_1;
  609. % data_TD2 = GC_Par_to_Front_HighMinusLow.(effectTypeNames{i}).TD_2;
  610. %
  611. % % Average across TDs
  612. % avgData = mean([data_TD1(:), data_TD2(:)], 2, 'omitnan');
  613. % GC_all{i} = avgData;
  614. %
  615. % % t-test against zero
  616. % [~, p] = ttest(avgData);
  617. % pvals(i) = p;
  618. % end
  619. %
  620. % % Plot
  621. % effectNames_plot = {'Pred --> Pred', 'PE --> PE', 'Pred --> PE', 'PE --> Pred'};
  622. % figure; hold on; box on;
  623. % colors = lines(numEffects); % distinct colors for each cloud
  624. % rng(0); % for reproducible jitter
  625. %
  626. % for i = 1:numEffects
  627. % x = i + (rand(size(GC_all{i})) - 0.5) * 0.4; % add jitter
  628. % scatter(x, GC_all{i}, 25, ...
  629. % 'MarkerFaceColor', colors(i,:), ...
  630. % 'MarkerEdgeColor', 'k', ...
  631. % 'MarkerFaceAlpha', 0.6, ...
  632. % 'MarkerEdgeAlpha', 0.6);
  633. % end
  634. %
  635. % % Formatting
  636. % xlim([0.5, numEffects + 0.5]);
  637. % xticks(1:numEffects);
  638. % xticklabels(effectNames_plot);
  639. % xtickangle(20);
  640. % ylabel('GC Difference (High FTPL − Low FTPL)');
  641. % yline(0, '--k', 'LineWidth', 1);
  642. %
  643. % % Add exact p-values above each scatter cloud
  644. % yl = ylim;
  645. % extra_space = 0.1 * range(yl); % 10% extra space
  646. % ylim([yl(1) + 2 * extra_space, yl(2) + extra_space]);
  647. %
  648. % % Update y-limit variable for use in placing the p-values
  649. % yl = ylim;
  650. % text_y = yl(2) - 0.05 * range(yl);
  651. % for i = 1:numEffects
  652. % text(i, text_y, sprintf('p = %.3g', pvals(i)), ...
  653. % 'HorizontalAlignment', 'center', ...
  654. % 'FontSize', 11, 'FontWeight', 'bold');
  655. % end
  656. %
  657. % % Save figure
  658. % set(gcf, 'Color', 'w');
  659. %
  660. %
  661. % filename = ['boxplot_compare_GC_lowhigh_FTPL_Par_to_Front_allpairs.png'];
  662. % figfile = ['/isilon/LFMI/VMdrive/Lua/NASTD/Figures/' filename];
  663. % saveas(gcf, figfile, 'png');
  664. %
  665. %% Computing stats for FTPL low vs high GC comparison across pairs from different effect-type pairings using AVERAGED data
  666. % Compute GC low vs high FTPL for Parietal > Frontal
  667. AnatReg_CatLabels = ... %Select which anatomical regions should be plotted
  668. {'AntPFC'; ...
  669. 'VentralT'; ...
  670. 'SupParLob'};
  671. sub_list_FTPL = sub_list(2:9);
  672. Gavg_tempGC_peranatreg_lowFTPL = NASTD_ECoG_Connectivity_ObtainGCByAnatRegions ...
  673. (sub_list_FTPL, ...
  674. GCdata_lowFTPL.GCdata_lowFTPL(2:9), ...
  675. ToneDur_text, ...
  676. SelElecs, AnatReg_CatLabels, ...
  677. save_poststepFigs, ...
  678. param, paths_NASTD_ECoG); %This will have the format, for each field, of i_effect cells, with format nSourceElecs x nTargetElecs x nTD
  679. Gavg_tempGC_peranatreg_highFTPL = NASTD_ECoG_Connectivity_ObtainGCByAnatRegions ...
  680. (sub_list_FTPL, ...
  681. GCdata_highFTPL.GCdata_highFTPL(2:9), ...
  682. ToneDur_text, ...
  683. SelElecs, AnatReg_CatLabels, ...
  684. save_poststepFigs, ...
  685. param, paths_NASTD_ECoG); %This will have the format, for each field, of i_effect cells, with format nSourceElecs x nTargetElecs x nTD
  686. index_of_interest_source = 7; %Parietal
  687. index_of_interest_target = 1; %Frontal
  688. effectTypeNames = {'Pred_Pred','PE_PE','Pred_PE','PE_Pred'};
  689. GC_Par_to_Front_HighMinusLow = struct(); % Final output
  690. for i_effect = 1:length(GCdata_lowFTPL.GCdata_lowFTPL{2}.temporalGC)
  691. effect_field = effectTypeNames{i_effect};
  692. for i_TD = 1:length(GCdata_lowFTPL.GCdata_lowFTPL{2}.temporalGC{1})
  693. if ~isfield(GC_Par_to_Front_HighMinusLow, effect_field)
  694. GC_Par_to_Front_HighMinusLow.(effect_field) = struct();
  695. end
  696. if ~isfield(GC_Par_to_Front_HighMinusLow.(effect_field), sprintf('TD_%d', i_TD))
  697. GC_Par_to_Front_HighMinusLow.(effect_field).(sprintf('TD_%d', i_TD)) = [];
  698. end
  699. pooled_diffs = []; % temporary holder for this TD across all subjects
  700. for i_sub = 1:8
  701. % LOW
  702. GCvals_low = Gavg_tempGC_peranatreg_lowFTPL.source2target{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  703. subjIDs_low = Gavg_tempGC_peranatreg_lowFTPL.subject_index{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  704. if ~isempty(GCvals_low) && ~isempty(subjIDs_low)
  705. rows_low = (subjIDs_low == i_sub);
  706. GC_low = GCvals_low(rows_low, :);
  707. else
  708. GC_low = NaN;
  709. end
  710. % HIGH
  711. GCvals_high = Gavg_tempGC_peranatreg_highFTPL.source2target{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  712. subjIDs_high = Gavg_tempGC_peranatreg_highFTPL.subject_index{i_effect}{index_of_interest_source, index_of_interest_target, i_TD};
  713. if ~isempty(GCvals_high) && ~isempty(subjIDs_high)
  714. rows_high = (subjIDs_high == i_sub);
  715. GC_high = GCvals_high(rows_high, :);
  716. else
  717. GC_high = NaN;
  718. end
  719. if ~isempty(GC_low) && ~isempty(GC_high)
  720. n_rows = min(size(GC_low,1), size(GC_high,1));
  721. GC_diff = GC_high(1:n_rows, :) - GC_low(1:n_rows, :); % pairwise subtraction
  722. pooled_diffs = [pooled_diffs; GC_diff]; % append
  723. end
  724. end
  725. GC_Par_to_Front_HighMinusLow.(effect_field).(sprintf('TD_%d', i_TD)) = pooled_diffs;
  726. end
  727. end
  728. % Average across TDs
  729. GC_all = cell(1, length(effectTypeNames));
  730. pvals = zeros(1, length(effectTypeNames));
  731. numEffects = numel(effectTypeNames);
  732. % Prepare data
  733. for i = 1:length(effectTypeNames)
  734. data_TD1 = GC_Par_to_Front_HighMinusLow.(effectTypeNames{i}).TD_1;
  735. data_TD2 = GC_Par_to_Front_HighMinusLow.(effectTypeNames{i}).TD_2;
  736. % Average across TDs
  737. minLen = min(numel(data_TD1), numel(data_TD2));
  738. avgData = mean([data_TD1(1:minLen), data_TD2(1:minLen)], 2, 'omitnan');
  739. GC_all{i} = avgData;
  740. % t-test against zero
  741. [~, p] = ttest(avgData);
  742. pvals(i) = p;
  743. end
  744. % Plot
  745. effectNames_plot = {'Pred --> Pred', 'PE --> PE', 'Pred --> PE', 'PE --> Pred'};
  746. figure; hold on; box on;
  747. colors = lines(numEffects);
  748. rng(0);
  749. % Prepare data for boxplot
  750. allData = [];
  751. groupData = [];
  752. for i = 1:numEffects
  753. allData = [allData; GC_all{i}(:)];
  754. groupData = [groupData; repmat(i, numel(GC_all{i}), 1)];
  755. end
  756. % Overlay scatter points (lower alpha)
  757. for i = 1:numEffects
  758. x = i + (rand(size(GC_all{i})) - 0.5) * 0.4;
  759. scatter(x, GC_all{i}, 25, ...
  760. 'MarkerFaceColor', colors(i,:), ...
  761. 'MarkerEdgeColor', 'k', ...
  762. 'MarkerFaceAlpha', 0.3, ...
  763. 'MarkerEdgeAlpha', 0.3);
  764. % Mean line
  765. m = mean(GC_all{i}, 'omitnan');
  766. plot([i-0.3, i+0.3], [m, m], 'Color', colors(i,:), 'LineWidth', 3);
  767. end
  768. % Formatting
  769. xlim([0.5, numEffects + 0.5]);
  770. xticks(1:numEffects);
  771. xticklabels(effectNames_plot);
  772. xtickangle(20);
  773. ylabel('GC Difference (High FTPL > Low FTPL)');
  774. yline(0, '--k', 'LineWidth', 1);
  775. % Add exact p-values or significance stars
  776. ylim([-0.01, 0.02]);
  777. yl = ylim;
  778. text_y = yl(2) - 0.05 * range(yl);
  779. for i = 1:numEffects
  780. if pvals(i) < 0.001
  781. sigLabel = '***';
  782. elseif pvals(i) < 0.01
  783. sigLabel = '**';
  784. elseif pvals(i) < 0.05
  785. sigLabel = '*';
  786. else
  787. sigLabel = sprintf('p=%.3g', pvals(i));
  788. end
  789. text(i, text_y, sigLabel, ...
  790. 'HorizontalAlignment', 'center', ...
  791. 'FontSize', 12, 'FontWeight', 'bold', 'Color', 'k');
  792. end
  793. set(gcf, 'Color', 'w');
  794. filename = ['boxplot_compare_GC_lowhigh_FTPL_Par_to_Front_allpairs_avgData.png'];
  795. figfile = ['/isilon/LFMI/VMdrive/Lua/NASTD/Figures/' filename];
  796. saveas(gcf, figfile, 'png');
  797. %% Plot GC results
  798. AnatReg_CatLabels = ... %Select which anatomical regions should be plotted
  799. {'AntPFC'; ...
  800. 'VentralT'; ...
  801. 'SupParLob'};
  802. % AnatReg_CatLabels = ... %Select which anatomical regions should be plotted
  803. % {'AntPFC_IFG'; 'AntPFC_PrecentralG'; ...
  804. % 'VentralT_STG'; 'VentralT_MTG'; ...
  805. % 'SupParLob_PostcentralG'; 'SupParLob_SupramarginalG'};
  806. % AnatReg_CatLabels = ... %Select which anatomical regions should be plotted
  807. % {'AntPFC'; 'AntPFC_IFG'; 'AntPFC_PrecentralG'; ...
  808. % 'VentralT'; 'VentralT_STG'; 'VentralT_MTG'; ...
  809. % 'SupParLob'; 'SupParLob_PostcentralG'; 'SupParLob_SupramarginalG'; ...
  810. % 'OccipitalL'};
  811. %Single subject per electrode pairing
  812. % NASTD_ECoG_Connectivity_PlotGC_persub_aggrtone ...
  813. % (sub_list(vars.validSubjs), ...
  814. % ToneDur_text, ...
  815. % save_poststepFigs, ...
  816. % param, paths_NASTD_ECoG);
  817. % NASTD_ECoG_Connectivity_PlotGC_persub_pertone ...
  818. % (sub_list(vars.validSubjs), ...
  819. % ToneDur_text, InputDataType, label_ElecPairSel, ...
  820. % save_poststepFigs, ...
  821. % paths_NASTD_ECoG);
  822. %Single subject aggregated GC results
  823. % NASTD_ECoG_Connectivity_PlotGC_persub_aggrtoneanat ...
  824. % (sub_list(vars.validSubjs), ...
  825. % ToneDur_text, SelElecs, AnatReg_CatLabels, ...
  826. % save_poststepFigs, ...
  827. % param, paths_NASTD_ECoG);
  828. %Plot group-level aggregated GC results
  829. % NASTD_ECoG_Connectivity_PlotGC_allsub_aggrtone ...
  830. % (sub_list(vars.validSubjs), ...
  831. % ToneDur_text, SelElecs, AnatReg_CatLabels, ...
  832. % save_poststepFigs, ...
  833. % param, paths_NASTD_ECoG);
  834. NASTD_ECoG_Connectivity_PlotGC_allsub_aggrtone_median ...
  835. (sub_list(vars.validSubjs), ...
  836. ToneDur_text, SelElecs, AnatReg_CatLabels, ...
  837. save_poststepFigs, ...
  838. param, paths_NASTD_ECoG);
  839. %Plot GC output with statistics
  840. if strcmp(param.GC.tone_aggregation_label,'_30_31_32_33_34')
  841. NASTD_ECoG_Connectivity_PlotGC_statp30top32_vs_p33p34_lk ...
  842. (sub_list(vars.validSubjs), ...
  843. ToneDur_text, SelElecs, AnatReg_CatLabels, ...
  844. save_poststepFigs, ...
  845. param, paths_NASTD_ECoG);
  846. else
  847. NASTD_ECoG_Connectivity_PlotGC_statp1top31 ...
  848. (sub_list(vars.validSubjs), ...
  849. ToneDur_text, SelElecs, AnatReg_CatLabels, ...
  850. save_poststepFigs, ...
  851. param, paths_NASTD_ECoG);
  852. end
  853. %% 3) Compute Granger Causality (GC) during p34 for different PE effects
  854. addpath('/isilon/LFMI/VMdrive/Thomas/toolboxes/mvgc_v1.3/');
  855. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.01uncorr.mat') %p < 0.01 thresh,uncorr elec selection
  856. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.05uncorr.mat') %p < 0.05 thresh,uncorr elec selection
  857. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.025FDRcorr.mat') %p < 0.025 thresh, FDRcorr elec selection
  858. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_AllElecs.mat') % no thresh, all elec selection
  859. %%%load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.05uncorr_HighGamma.mat') %p < 0.05 thresh,uncorr elec selection
  860. % load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.01uncorr_HighGamma.mat') %p < 0.05 thresh,uncorr elec selection
  861. param.GC.fs = 512;
  862. param.GC.downsample = 0; %Cave: Downsampling lead to problems with tone sample selection
  863. if param.GC.downsample == 0
  864. param.GC.newfs = param.GC.fs;
  865. else
  866. param.GC.newfs = param.GC.fs/param.GC.downsample;
  867. end
  868. param.GC.nvars = 2;
  869. param.GC.regmode = 'OLS'; % VAR model estimation regression mode ('OLS', 'LWR' or empty for default
  870. param.GC.maxmorder = 50; % maximum model order for model order estimation, rule of thumb = number of samples per input data snippet, but not > 100
  871. param.GC.morder = 'AIC'; % model order to use ('actual', 'AIC', 'BIC' or supplied numerical value)
  872. param.GC.tstat = 'F'; % statistical test for MVGC: 'F' for Granger's F-test (default) or 'chi2' for Geweke's chi2 test
  873. param.GC.alpha = 0.05; % significance level for significance test
  874. param.GC.mhtc = 'FDRD'; % multiple hypothesis test correction (see routine 'significance')
  875. param.GC.ElecPairEffect = {'Pred_Pred','PE_PE','Pred_PE','PE_Pred'};
  876. param.GC.ElecPairRegion = 'AllRegions';
  877. param.GC.InputDataType = {'Broadband'}; %{'Broadband', 'HP05toLP30Hz', 'HighGamma_LogAmp'};
  878. param.GC.epochdur_ms = 'full'; %'full', 200, 100
  879. if strcmp(param.GC.epochdur_ms, 'full')
  880. param.GC.epochdur_ms_label = 'fullTW';
  881. else
  882. param.GC.epochdur_ms_label = [num2str(param.GC.epochdur_ms) 'msTW'];
  883. end
  884. for i_sub = vars.validSubjs
  885. tic
  886. GCdata{i_sub} = ...
  887. NASTD_ECoG_Connectivity_CalculateGC_PEeffect ...
  888. (sub_list, i_sub, ...
  889. ToneDur_text, SelElecs, ...
  890. param, paths_NASTD_ECoG);
  891. disp(['-- GC PE computation for sub: ' sub_list{i_sub} ' finished after ' num2str(round(toc/60),2) ' min --'])
  892. end
  893. %save output
  894. path_outputdata = ([paths_NASTD_ECoG.ECoGdata_Connectivity 'GC/PEeffect/']);
  895. if (~exist(path_outputdata, 'dir')); mkdir(path_outputdata); end
  896. label_outputdata = ['GCdataPEeffect_n' num2str(length(vars.validSubjs)) '_' ...
  897. param.GC.ElecPairRegion '_' ...
  898. param.GC.InputDataType{1} '_' ...
  899. param.GC.epochdur_ms_label '_ensemnorm'];
  900. save([path_outputdata label_outputdata], 'GCdata')
  901. % load([path_outputdata label_outputdata], 'GCdata')
  902. %Plot GC results
  903. AnatReg_CatLabels = ... %Select which anatomical regions should be plotted
  904. {'AntPFC'; ...
  905. 'VentralT'; ...
  906. 'SupParLob'};
  907. NASTD_ECoG_Connectivity_PlotGC_statPEeffect ...
  908. (sub_list(vars.validSubjs), ...
  909. ToneDur_text, SelElecs, AnatReg_CatLabels, ...
  910. save_poststepFigs, ...
  911. param, paths_NASTD_ECoG);
  912. %% 4) Plot and do statistics for electrode combinations between regions of the auditory hierarchy
  913. addpath('/isilon/LFMI/VMdrive/Lua/Temp2A/Temp2A_fMRI_pilot/toolboxes/spm12');
  914. load('/isilon/LFMI/VMdrive/Thomas//NaturalisticAuditorySequences_ToneDuration(NAS_TD)/ECoG/Analysis/Connectivity/ElecSelect/Allsub_n9/SelElecs_p0.05uncorr.mat') %p < 0.05 thresh,uncorr elec selection
  915. atlas_path = 'brodmann.nii';
  916. % Determine if any of the electrodes are located in one of the auditory
  917. % regions of interest
  918. % Classify each electrode as part of a Brodmann's area
  919. BA_areas_Pred = assign_BA_from_MNI(SelElecs.PredEffect.("Elec Coords"), atlas_path);
  920. BA_areas_PE = assign_BA_from_MNI(SelElecs.PEEffect.("Elec Coords"), atlas_path);
  921. % Define ROI map: Brodmann areas → auditory/cognitive labels
  922. roi_map = containers.Map( ...
  923. [41, 42, 44, 45, 8, 40, 6, 22], ...
  924. {'Auditory Cortex', ...
  925. 'Auditory Cortex', ...
  926. 'IFC Dorsal', ...
  927. 'IFC Ventral', ...
  928. 'dlPFC', ...
  929. 'IPL', ...
  930. 'PMC', ...
  931. 'STS'});
  932. % For Prediction electrodes
  933. roi_labels_pred = cell(size(BA_areas_Pred));
  934. for i = 1:length(BA_areas_Pred)
  935. roi_labels_pred{i} = get_roi_label(BA_areas_Pred(i), roi_map);
  936. end
  937. % For Prediction Error electrodes
  938. roi_labels_PE = cell(size(BA_areas_PE));
  939. for i = 1:length(BA_areas_PE)
  940. roi_labels_PE{i} = get_roi_label(BA_areas_PE(i), roi_map);
  941. end
  942. % Combine everything into one table
  943. SelElecs.PredEffect.BAlabel = roi_labels_pred;
  944. SelElecs.PEEffect.BAlabel = roi_labels_PE;
  945. % Also need to update SelElecs.Pairs for stats
  946. % === Update Pred_Pred with PredEffect ===
  947. predPairFields = fieldnames(SelElecs.Pairs.Pred_Pred.AllRegions.Pairs_perelec);
  948. predEffect = SelElecs.PredEffect;
  949. for i = 1:length(predPairFields)
  950. pairName = predPairFields{i};
  951. targetElecs = SelElecs.Pairs.Pred_Pred.AllRegions.Pairs_perelec.(pairName);
  952. BAlabels = cell(height(targetElecs), 1);
  953. for j = 1:height(targetElecs)
  954. elecLabel = targetElecs.("Electrode Label"){j};
  955. subjLabel = targetElecs.("Subject Label"){j};
  956. % Find matching row in PredEffect
  957. matchIdx = strcmp(predEffect{:,1}, elecLabel) & strcmp(predEffect{:,2}, subjLabel);
  958. if any(matchIdx)
  959. baLabel = predEffect{matchIdx,12}{1}; % Get BAlabel (12th column)
  960. else
  961. baLabel = 'NA';
  962. end
  963. BAlabels{j,1} = baLabel;
  964. end
  965. targetElecs.BAlabel = BAlabels; % Add as new column
  966. SelElecs.Pairs.Pred_Pred.AllRegions.Pairs_perelec.(pairName) = targetElecs; % Update
  967. end
  968. % === Update PE_PE with PEEffect ===
  969. pePairFields = fieldnames(SelElecs.Pairs.PE_PE.AllRegions.Pairs_perelec);
  970. peEffect = SelElecs.PEEffect;
  971. for i = 1:length(pePairFields)
  972. pairName = pePairFields{i};
  973. targetElecs = SelElecs.Pairs.PE_PE.AllRegions.Pairs_perelec.(pairName);
  974. BAlabels = cell(height(targetElecs), 1);
  975. for j = 1:height(targetElecs)
  976. elecLabel = targetElecs.("Electrode Label"){j};
  977. subjLabel = targetElecs.("Subject Label"){j};
  978. % Find matching row in PEEffect
  979. matchIdx = strcmp(peEffect{:,1}, elecLabel) & strcmp(peEffect{:,2}, subjLabel);
  980. if any(matchIdx)
  981. baLabel = peEffect{matchIdx,12}{1}; % Get BAlabel (12th column)
  982. else
  983. baLabel = 'NA';
  984. end
  985. BAlabels{j,1} = baLabel;
  986. end
  987. targetElecs.BAlabel = BAlabels; % Add as new column
  988. SelElecs.Pairs.PE_PE.AllRegions.Pairs_perelec.(pairName) = targetElecs; % Update
  989. end
  990. % Output a surface project of Brodmanns areas with only the desired ROIs
  991. % addpath '/isilon/LFMI/VMdrive/Lua/surfice_atlas-master'
  992. % desired_ROIs = [41, 42, 44, 45, 8, 40, 6, 22];
  993. % nii_nii2atlas_rois('brodmann.nii', 'mylut.lut', desired_ROIs);
  994. %% Extract GC values for each pair
  995. subs = sub_list(vars.validSubjs);
  996. param.GC = [];
  997. param.GC.fs = 512;
  998. param.GC.downsample = 0; %Cave: Downsampling lead to problems with tone sample selection
  999. if param.GC.downsample == 0
  1000. param.GC.newfs = param.GC.fs;
  1001. else
  1002. param.GC.newfs = param.GC.fs/param.GC.downsample;
  1003. end
  1004. param.GC.nvars = 2;
  1005. param.GC.regmode = 'OLS'; % VAR model estimation regression mode ('OLS', 'LWR' or empty for default
  1006. param.GC.maxmorder = 50; % maximum model order for model order estimation, rule of thumb = number of samples per input data snippet, but not > 100
  1007. % param.GC.morder = 'AIC'; % model order to use ('actual', 'AIC', 'BIC' or supplied numerical value)
  1008. param.GC.tstat = 'F'; % statistical test for MVGC: 'F' for Granger's F-test (default) or 'chi2' for Geweke's chi2 test
  1009. param.GC.alpha = 0.05; % significance level for significance test
  1010. param.GC.mhtc = 'FDRD'; % multiple hypothesis test correction (see routine 'significance')
  1011. %param.GC.ElecPairEffect = {'Pred_Pred','PE_PE','Pred_PE','PE_Pred'};
  1012. param.GC.ElecPairEffect = {'Pred_Pred','PE_PE'};
  1013. param.GC.ElecPairRegion = 'AllRegions';
  1014. param.GC.InputDataType = {'Broadband'}; %{'Broadband', 'HP05toLP30Hz', 'HighGamma_LogAmp'};
  1015. param.GC.tone_aggregation = {1, 6, 11, 16, 21, 26, 31};
  1016. param.GC.tone_aggregation = {2, 7, 12, 17, 22, 27, 32};
  1017. param.GC.tone_aggregation = {30, 31, 32, 33, 34};
  1018. param.GC.tone_aggregation_label = cellfun(@(c)[c],param.GC.tone_aggregation);
  1019. param.GC.tone_aggregation_label = num2str((param.GC.tone_aggregation_label),'_%d');
  1020. param.GC.tone_aggregation_label = erase(param.GC.tone_aggregation_label, ' ');
  1021. param.GC.epochdur_ms = 'full'; %'full', 200, 100
  1022. if strcmp(param.GC.epochdur_ms, 'full')
  1023. param.GC.epochdur_ms_label = 'fullTW';
  1024. else
  1025. param.GC.epochdur_ms_label = [num2str(param.GC.epochdur_ms) 'msTW'];
  1026. end
  1027. param.GC.ElecPairRegion = 'AllRegions';
  1028. param.GC.InputDataType = {'Broadband'}; %{'Broadband', 'HP05toLP30Hz', 'HighGamma_LogAmp'};
  1029. % Load in GC data
  1030. path_outputdata = ([paths_NASTD_ECoG.ECoGdata_Connectivity 'GC/']);
  1031. if (~exist(path_outputdata, 'dir')); mkdir(path_outputdata); end
  1032. label_outputdata = ['GCdata_n' num2str(length(vars.validSubjs)) '_' ...
  1033. param.GC.ElecPairRegion '_' ...
  1034. param.GC.InputDataType{1} param.GC.tone_aggregation_label '_' ...
  1035. param.GC.epochdur_ms_label '_ensemnorm'];
  1036. load([path_outputdata label_outputdata], 'GCdata')
  1037. %Add in BA label information to GCdata
  1038. % for i_sub = vars.validSubjs
  1039. % for i_effect = 1:2
  1040. % % Assign labels that correspond to ind_pairedelecs_from
  1041. % sub = subs(i_sub);
  1042. % if i_effect == 1
  1043. % effecttype = 'Pred';
  1044. % else
  1045. % effecttype = 'PE';
  1046. % end
  1047. % GCdata{i_sub}.BAlabels{i_effect} = MNI_coords_all.BAlabel(strcmp(MNI_coords_all.("Subject Label"), sub) & strcmp(MNI_coords_all.EffectType, effecttype),:);
  1048. % end
  1049. % end
  1050. % Now the GC results also have the BA labels for auditory cortex
  1051. %Plot GC results
  1052. AnatReg_CatLabels = {'Auditory Cortex', ... %Select which anatomical regions should be plotted
  1053. 'IFC Dorsal', ...
  1054. 'IFC Ventral', ...
  1055. 'dlPFC', ...
  1056. 'IPL', ...
  1057. 'PMC', ...
  1058. 'STS'};
  1059. %Extract GC per anat regions
  1060. NASTD_ECoG_Connectivity_BAregions_lk ...
  1061. (sub_list(vars.validSubjs), GCdata,...
  1062. ToneDur_text, SelElecs, AnatReg_CatLabels, ...
  1063. save_poststepFigs, ...
  1064. param, paths_NASTD_ECoG);
  1065. % GCdata = cell(1, 9); % Initialize output
  1066. %
  1067. % for i = 1:9
  1068. % % Start from GCdata_T1 and overwrite the field we want to average
  1069. % GCdata{i} = GCdata_T1{i};
  1070. %
  1071. % avg_tgc = cell(1, 4); % Correct shape: 1×4
  1072. %
  1073. % for j = 1:4
  1074. % avg_tgc{j} = cell(1, 2); % Each is a 1×2 cell
  1075. %
  1076. % for k = 1:2
  1077. % % Extract source2target matrices
  1078. % mat1 = GCdata_T1{i}.temporalGC{j}{k}.source2target;
  1079. % mat2 = GCdata_T2{i}.temporalGC{j}{k}.source2target;
  1080. %
  1081. % % Compute average
  1082. % avg_mat = (mat1 + mat2) / 2;
  1083. %
  1084. % % Copy one struct and overwrite source2target with the average
  1085. % avg_struct = GCdata_T1{i}.temporalGC{j}{k};
  1086. % avg_struct.source2target = avg_mat;
  1087. %
  1088. % % Save back
  1089. % avg_tgc{j}{k} = avg_struct;
  1090. % end
  1091. % end
  1092. %
  1093. % % Assign averaged temporalGC to output
  1094. % GCdata{i}.temporalGC = avg_tgc;
  1095. % end

NASTD_ECoG_Connectivity_Main_lk.m at commit 9cafa02, no license · at the source

Overview

Authors: Thomas J Baumgarten1,2, Lua Koenig1, Richard Hardstone1, Adeen Flinker3,4, Sasha Devore3, Daniel Friedman3, Patricia Dugan3, Orrin Devinsky3, Biyu J He1,3,4,5,6
  1. Neuroscience Institute, New York University Langone Health, New York, NY USA
  2. Institute of Clinical Neuroscience and Medical Psychology, Medical Faculty, Heinrich Heine University Düsseldorf, Düsseldorf, Germany
  3. Department of Neurology, New York University Langone Health, New York, NY USA
  4. Department of Biomedical Engineering, NYU Tandon School of Engineering, New York, NY USA
  5. Department of Neuroscience, New York University Langone Health, New York, NY USA
  6. Department of Radiology, New York University Langone Health, New York, NY USA
Institutions: NYU Langone Health (United States); Heinrich Heine University Düsseldorf (Germany); New York University (United States)
Journal: Nature communications, volume 17, issue 1, article 8459
Dates: received 10 March 2025; accepted 26 June 2026; published online 9 July 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41467-026-75359-0 · PMID 42426016 · PMCID PMC13478490 · OpenAlex W7167837097
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: EEG (modality), human (organism), cognitive (subfield)
Methods: Spectral & time-frequency, Connectivity, Statistics, Machine learning, Preprocessing, fMRI & imaging, Smoothing, state filtering, decompositions, Physiology & signal measures
Keywords: Perception, Cortex
MeSH: Anticipation, Psychological*, Auditory Perception*, Cerebral Cortex*, Electroencephalography*, Adult, Auditory Pathways, Brain Mapping, Female, Humans, Male, Middle Aged, Young Adult (* major topic)
Topic: Neuroscience and Music Perception (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Funding: EC | EU Framework Programme for Research and Innovation H2020 | H2020 Priority Excellent Science | H2020 Marie Skłodowska-Curie Actions (H2020 Excellent Science - Marie Skłodowska-Curie Actions) (795998)
Citations: not cited yet (Europe PMC); 53 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above, with 26 matches between paragraphs and lines of code.

BiyuHeLab/TimeForwardPrediction_iEEG_Baumgarten_Koenig

License: none: the authors keep all their rights
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 9cafa02247de275fa5b20745e861a6cccaf1bab7, 29 May 2026
Languages: MATLAB (279), R (1)
Size: 389 files, 280 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Statistics and Machine Learning Toolbox (61 files), fdr_bh (Benjamini-Hochberg FDR) (31 files), FieldTrip (27 files), FreeSurfer (21 files), Signal Processing Toolbox (21 files), Psychtoolbox (18 files), shadedErrorBar (14 files), SPM (2 files)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
281 files

Code availability statement

The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41467-026-75359-0.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 280 scripts, each with its path and the digest of its content;
  • 26 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability statement

The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

  • no repository, dataset or request procedure was recognized in it

Read it in the paper: doi.org/10.1038/s41467-026-75359-0.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 9 authors, 2 keywords, 12 MeSH terms, 1 funder, 48 references.

Cite

This paper

Baumgarten, T. J., Koenig, L., Hardstone, R., Flinker, A., Devore, S., Friedman, D., Dugan, P., Devinsky, O., & He, B. J. (2026). Neural mechanisms of time-forward predictions for naturalistic auditory tone sequences. Nature communications, 17(1), 8459. https://doi.org/10.1038/s41467-026-75359-0

BibTeX

@article{baumgarten2026neural,
author = {Baumgarten, Thomas J and Koenig, Lua and Hardstone, Richard and Flinker, Adeen and Devore, Sasha and Friedman, Daniel and Dugan, Patricia and Devinsky, Orrin and He, Biyu J},
title = {{Neural mechanisms of time-forward predictions for naturalistic auditory tone sequences}},
journal = {Nature communications},
year = {2026},
month = jul,
volume = {17},
number = {1},
pages = {8459},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/s41467-026-75359-0},
url = {https://doi.org/10.1038/s41467-026-75359-0},
pmid = {42426016},
pmcid = {PMC13478490}
}

RIS

TY - JOUR
AU - Baumgarten, Thomas J
AU - Koenig, Lua
AU - Hardstone, Richard
AU - Flinker, Adeen
AU - Devore, Sasha
AU - Friedman, Daniel
AU - Dugan, Patricia
AU - Devinsky, Orrin
AU - He, Biyu J
TI - Neural mechanisms of time-forward predictions for naturalistic auditory tone sequences
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/07/09
VL - 17
IS - 1
SP - 8459
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-75359-0
UR - https://doi.org/10.1038/s41467-026-75359-0
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-75359-0",
"type": "article-journal",
"title": "Neural mechanisms of time-forward predictions for naturalistic auditory tone sequences",
"container-title": "Nature communications",
"author": [
{
"family": "Baumgarten",
"given": "Thomas J"
},
{
"family": "Koenig",
"given": "Lua"
},
{
"family": "Hardstone",
"given": "Richard"
},
{
"family": "Flinker",
"given": "Adeen"
},
{
"family": "Devore",
"given": "Sasha"
},
{
"family": "Friedman",
"given": "Daniel"
},
{
"family": "Dugan",
"given": "Patricia"
},
{
"family": "Devinsky",
"given": "Orrin"
},
{
"family": "He",
"given": "Biyu J"
}
],
"container-title-short": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "8459",
"DOI": "10.1038/s41467-026-75359-0",
"PMID": "42426016",
"PMCID": "PMC13478490",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-75359-0",
"language": "en",
"issued": {
"date-parts": [
[
2026,
7,
9
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-73540-z [code]
Predictive acoustical processing in human cortical layers.
Journal: Nature communications
In common: FieldTrip, FreeSurfer, SPM, 2 other tools, cognitive, 10 references
[2] doi:10.1002/advs.77857 [code]
Brain Network Dynamics of Local and Global Predictive Processing in Aging.
Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)
In common: FieldTrip, SPM, Signal Processing Toolbox, 1 other tool, cognitive, 7 references
[3] doi:10.1038/s41467-026-73947-8 [code]
Frontal cortex organization supporting audiovisual processing during naturalistic viewing.
Journal: Nature communications
In common: cognitive, 3 references, 2 authors
[4] doi:10.7554/elife.108408 [code]
Frequency and laminar profile of feature-specific visual activity revealed by interleaved EEG-fMRI.
Journal: eLife
In common: FieldTrip, FreeSurfer, SPM, 2 other tools, EEG, 5 references
[5] doi:10.1371/journal.pbio.3003966 [code]
Behavioral engagement and stimulus regularities coordinate auditory-prefrontal network activity.
Journal: PLoS biology
In common: fdr_bh (Benjamini-Hochberg FDR), Statistics and Machine Learning Toolbox, 8 references
[6] doi:10.1126/sciadv.aec0518 [code]
Hybrid spatial organization and evidence for magnitude-independent neural coding of linguistic information during sentence production.
Journal: Science advances
In common: 3 references, 2 authors
[7] doi:10.1038/s41467-026-71151-2 [code]
Common and distinct neural correlates of social interaction processing and theory of mind in narratives.
Journal: Nature communications
In common: fdr_bh (Benjamini-Hochberg FDR), Psychtoolbox, FieldTrip, 4 other tools, cognitive, 1 reference
[8] doi:10.1038/s41593-026-02345-6 [code]
Human hippocampal ripples tune cortical responses based on predicted uncertainty.
Journal: Nature neuroscience
In common: FieldTrip, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, cognitive, 7 references
[9] doi:10.1162/imag.a.1218 [code]
Reliability and signal comparison of OPM-MEG, fMRI &amp; iEEG in a repeated movie viewing paradigm.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: fdr_bh (Benjamini-Hochberg FDR), FieldTrip, Statistics and Machine Learning Toolbox, 5 references
[10] doi:10.1371/journal.pcbi.1014563 [code]
Single pulse electrical stimulation in white matter modulates iEEG visual responses in human early visual cortex.
Journal: PLoS computational biology
In common: fdr_bh (Benjamini-Hochberg FDR), FreeSurfer, SPM, 2 other tools, EEG, 2 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.