Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

c1_taskPLS_novelty_frontal_erp.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. % Set up EEG PLS for a task PLS using spectral power
  2. clear all; cla; clc;
  3. currentFile = mfilename('fullpath');
  4. [pathstr,~,~] = fileparts(currentFile);
  5. cd(fullfile(pathstr,'..'))
  6. rootpath = pwd;
  7. pn.data_eeg = fullfile(rootpath, '..', 'eegmp_preproc', 'data', 'outputs', 'eeg');
  8. pn.data_erp = fullfile(rootpath, 'data', 'erp');
  9. pn.data_erf = fullfile(rootpath, 'data', 'erf');
  10. pn.data = fullfile(rootpath, 'data', 'stats'); mkdir(pn.data);
  11. pn.tools = fullfile(rootpath, 'tools');
  12. addpath(fullfile(rootpath, '..', 'eegmp_preproc', 'tools', 'fieldtrip')); ft_defaults
  13. addpath(genpath(fullfile(pn.tools, '[MEG]PLS', 'MEGPLS_PIPELINE_v2.02b')))
  14. addpath(fullfile(pn.tools, 'BrewerMap'));
  15. addpath(fullfile(pn.tools, 'shadedErrorBar'));
  16. %% add seed for reproducibility
  17. rng(0, 'twister');
  18. %% load event info
  19. load(fullfile(pn.data_eeg, ['sub-001_task-xxxx_eeg_art.mat']), 'events');
  20. parameter = {'scene_category'; 'old'; 'behavior'; 'subsequent_memory'};
  21. for ind_param = 1:numel(parameter)
  22. conds.(parameter{ind_param}) = unique(events.(parameter{ind_param}));
  23. end
  24. %% load erp
  25. for ind_id = 1:33
  26. id = sprintf('sub-%03d', ind_id); disp(id)
  27. load(fullfile(pn.data_erp, [id,'_erp_bl.mat']));
  28. for ind_option = 1:numel(conds.old)
  29. if ind_id == 1
  30. erpgroup.old.(conds.old{ind_option}) = erp_bl.old{ind_option};
  31. erpgroup.old.(conds.old{ind_option}) = ...
  32. rmfield(erpgroup.old.(conds.old{ind_option}), {'avg', 'var', 'dof'});
  33. erpgroup.old.(conds.old{ind_option}).dimord = 'sub_chan_time';
  34. end
  35. % only include time points from 300 - 500 ms
  36. time = erpgroup.old.(conds.old{ind_option}).time;
  37. toi = time >0.3 & time <0.5;
  38. erpgroup.old.(conds.old{ind_option}).avg(ind_id,:,:) = erp_bl.old{ind_option}.avg(:,toi);
  39. end
  40. end
  41. time = erpgroup.old.old.time(toi);
  42. elec = erpgroup.old.old.elec;
  43. channels = erpgroup.old.old.label;
  44. mergeddata = cat(4, erpgroup.old.old.avg, ...
  45. erpgroup.old.new.avg);
  46. % identify frontal channels, and set everything else to zero
  47. idx_chans = startsWith(channels, 'F') | startsWith(channels, 'A') | startsWith(channels, 'C');% & ~startsWith(channels, 'CP');
  48. mergeddata(:, idx_chans==0,:,:) = 0;
  49. num_chans = numel(channels);
  50. num_freqs = 1;
  51. num_time = numel(time);
  52. num_subj_lst = [33];
  53. num_cond = 2;
  54. num_grp = 1;
  55. datamat_lst = cell(num_grp); lv_evt_list = [];
  56. indCount_cont = 1;
  57. indCount = 1;
  58. indGroup = 1;
  59. for indCond = 1:num_cond
  60. for indID = 1:num_subj_lst(indGroup)
  61. datamat_lst{indGroup}(indCount,:) = reshape(squeeze(mergeddata(indID,:,:,indCond)), [], 1);
  62. lv_evt_list(indCount_cont) = indCond;
  63. indCount = indCount+1;
  64. indCount_cont = indCount_cont+1;
  65. end
  66. end
  67. datamat_lst{indGroup}(isnan(datamat_lst{indGroup})) = 0;
  68. %% set PLS options and run PLS
  69. option = [];
  70. option.method = 1; % [1] | 2 | 3 | 4 | 5 | 6
  71. option.num_perm = 1000; %( single non-negative integer )
  72. option.num_split = 0; %( single non-negative integer )
  73. option.num_boot = 1000; % ( single non-negative integer )
  74. option.cormode = 0; % [0] | 2 | 4 | 6
  75. option.meancentering_type = 0;% [0] | 1 | 2 | 3
  76. option.boot_type = 'strat'; %['strat'] | 'nonstrat'
  77. result = pls_analysis(datamat_lst, num_subj_lst, num_cond, option);
  78. %% rearrange into fieldtrip structure
  79. lvdat = reshape(result.boot_result.compare_u(:,1), num_chans, num_freqs, num_time);
  80. %udat = reshape(result.u, num_chans, num_freqs, num_time);
  81. stat = [];
  82. stat.prob = lvdat;
  83. stat.dimord = 'chan_freq_time';
  84. stat.clusters = [];
  85. stat.clusters.prob = result.perm_result.sprob; % check for significance of LV
  86. stat.mask = lvdat > 3 | lvdat < -3;
  87. stat.cfg = option;
  88. stat.time = time;
  89. save(fullfile(pn.data, 'c1_taskpls_erp.mat'),...
  90. 'stat', 'result', 'lvdat', 'lv_evt_list', 'num_chans', 'num_freqs', 'num_time')