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.

d2_taskPLS_recognition_erf.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_erf, [id,'_erf.mat']));
  28. for ind_option = 1:4%numel(conds.behavior)
  29. if ind_id == 1
  30. erpgroup.behavior.(conds.behavior{ind_option}) = erf.behavior{ind_option};
  31. erpgroup.behavior.(conds.behavior{ind_option}) = ...
  32. rmfield(erpgroup.behavior.(conds.behavior{ind_option}), {'powspctrm'});
  33. erpgroup.behavior.(conds.behavior{ind_option}).dimord = 'sub_chan_freq_time';
  34. end
  35. erpgroup.behavior.(conds.behavior{ind_option}).avg(ind_id,:,:,:) = erf.behavior{ind_option}.powspctrm;
  36. end
  37. end
  38. time = erpgroup.behavior.hit.time;
  39. freq = erpgroup.behavior.hit.freq;
  40. channels = erpgroup.behavior.hit.label;
  41. mergeddata = cat(5, erpgroup.behavior.hit.avg, ...
  42. erpgroup.behavior.miss.avg);
  43. num_chans = numel(channels);
  44. num_freqs = numel(freq);
  45. num_time = numel(time);
  46. num_subj_lst = [33];
  47. num_cond = 2;
  48. num_grp = 1;
  49. datamat_lst = cell(num_grp); lv_evt_list = [];
  50. indCount_cont = 1;
  51. indCount = 1;
  52. indGroup = 1;
  53. for indCond = 1:num_cond
  54. for indID = 1:num_subj_lst(indGroup)
  55. datamat_lst{indGroup}(indCount,:) = reshape(squeeze(mergeddata(indID,:,:,:,indCond)), [], 1);
  56. lv_evt_list(indCount_cont) = indCond;
  57. indCount = indCount+1;
  58. indCount_cont = indCount_cont+1;
  59. end
  60. end
  61. datamat_lst{indGroup}(isnan(datamat_lst{indGroup})) = 0;
  62. %% set PLS options and run PLS
  63. option = [];
  64. option.method = 1; % [1] | 2 | 3 | 4 | 5 | 6
  65. option.num_perm = 1000; %( single non-negative integer )
  66. option.num_split = 0; %( single non-negative integer )
  67. option.num_boot = 1000; % ( single non-negative integer )
  68. option.cormode = 0; % [0] | 2 | 4 | 6
  69. option.meancentering_type = 0;% [0] | 1 | 2 | 3
  70. option.boot_type = 'strat'; %['strat'] | 'nonstrat'
  71. result = pls_analysis(datamat_lst, num_subj_lst, num_cond, option);
  72. %% rearrange into fieldtrip structure
  73. lvdat = reshape(result.boot_result.compare_u(:,1), num_chans, num_freqs, num_time);
  74. %udat = reshape(result.u, num_chans, num_freqs, num_time);
  75. stat = [];
  76. stat.prob = lvdat;
  77. stat.dimord = 'chan_freq_time';
  78. stat.clusters = [];
  79. stat.clusters.prob = result.perm_result.sprob; % check for significance of LV
  80. stat.mask = lvdat > 3 | lvdat < -3;
  81. stat.cfg = option;
  82. stat.freq = freq;
  83. stat.time = time;
  84. save(fullfile(pn.data, 'd2_taskpls_erf.mat'),...
  85. 'stat', 'result', 'lvdat', 'lv_evt_list', 'num_chans', 'num_freqs', 'num_time')