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.

unfold_calculateSE.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. % loads unfold results, adds ufresult.data and calculates the
  2. % SE over trials for each subject
  3. function se = unfold_calculateSE(subj,phase)
  4. cd '/net/store/nbp/users/agert/itw'
  5. init_itw
  6. addpath('/net/store/nbp/users/agert/unfold')
  7. init_unfold
  8. projectFolder=['/net/store/nbp/projects/IntoTheWild'];
  9. filtType='causal';
  10. % time ranges for P100 and N170
  11. t_p100=[0.07 0.150];
  12. t_n170=[0.120 0.200];
  13. %% LOADING
  14. codingscheme = 'mashup';
  15. %% load ufresults
  16. ufPath = fullfile(projectFolder,['Daten/EEG/' phase '/unfold_' phase '/' filtType '/']);
  17. ufPath = fullfile(ufPath,['ufresult_subj' num2str(subj) ,'_allElec_' codingscheme '_-500-1000_regularized0.mat']);
  18. fprintf('\n \n loading subject %i \n',subj)
  19. d = load(ufPath);
  20. ufresult = d.ufresult;
  21. clear d; % make some space
  22. if strcmp(phase,'WLFO')
  23. ufam = uf_predictContinuous(ufresult,'predictAt',{{'sac_amplitude',[0.5 1 2.5 5 7.5 10]},{'fix_avgpos_y',linspace(500,1500,5)},{'fix_avgpos_x',linspace(900,3000,5)},{'samebox_1',1}});
  24. ufam = uf_addmarginal(ufam);
  25. elseif strcmp(phase,'Lab')
  26. ufam=ufresult;
  27. end
  28. %% load EEG data
  29. cfg = struct();
  30. cfg.subject = num2str(subj);
  31. cfg.filtering='causal';
  32. cfg.mainfolder = ['/net/store/nbp/projects/IntoTheWild/Daten/EEG/' phase '/VP' cfg.subject '/preprocessed/' cfg.filtering];
  33. cfg.file = ['3_ITW_' phase '_subj' cfg.subject '_channelrejTriggersXensor.set'];
  34. tmp = pop_loadset('filename',['2_ITW_' phase '_subj' cfg.subject '_bandpass_resample_deblank.set'],'filepath',cfg.mainfolder,'loadmode','info');
  35. tmp.chanlocs(find(strcmp({tmp.chanlocs.labels},'CzAmp2'))).labels = 'Iz';
  36. tmp=pop_chanedit(tmp, 'lookup','/net/store/nbp/projects/IntoTheWild/EEG_analysis/eeglab13_5_4b/plugins/dipfit2.3/standard_BESA/standard-10-5-cap385.elp');
  37. cfg.urchanlocs= tmp.chanlocs;
  38. cfg.avgref=1;
  39. cfg.saccade=1;
  40. cfg.regularize=0;
  41. tmp = load(fullfile(cfg.mainfolder,['6_ITW_' phase '_subj' cfg.subject '_ICAcleancont.mat']));
  42. cfg.badcomponents = tmp.comps_to_rej;
  43. cfg.timewin=[-0.5 1];
  44. %load EEG
  45. EEG = pop_loadset('filename',cfg.file,'filepath',cfg.mainfolder);
  46. EEG = pop_select(EEG,'nochannel',{'AUX1','AUX2'});
  47. % Load ICA and clean
  48. mod = loadmodout12(fullfile(cfg.mainfolder,'amica'));
  49. EEG.icaweights = mod.W;
  50. EEG.icasphere = mod.S;
  51. EEG.icawinv = [];EEG.icaact = [];EEG.icachansind = [];
  52. EEG = eeg_checkset(EEG);
  53. EEG = pop_subcomp(EEG,cfg.badcomponents);
  54. % interpolate missing channels
  55. % ET channels (Gaze etc.) not interpolated
  56. alldel = {'CzAmp2' 'BIP1' 'BIP2' 'BIP3' 'BIP4' 'BIP5' 'BIP6' 'BIP7' 'BIP8' 'AUX1' 'AUX2' 'AUX3' 'AUX4' 'AUX5' 'AUX6' 'AUX7' 'AUX8','TIME', 'L_GAZE_X', 'L_GAZE_Y', 'L_AREA','R_GAZE_X', 'R_GAZE_Y', 'R_AREA', 'INPUT', 'L-GAZE-X', 'L-GAZE-Y', 'L-AREA','R-GAZE-X', 'R-GAZE-Y', 'R-AREA', 'INPUT'};
  57. %remove VEOG from EEG, as there is no corresponding location
  58. EEG = pop_select(EEG, 'nochannel', {'VEOG'});
  59. if cfg.avgref
  60. %calculate avg ref
  61. EEG = pop_reref( EEG, []); %Participants’ averages were then re-referenced to a common average reference. (Rossion & Caharel, 2011)
  62. end
  63. %interpolate missing channels
  64. idxs = ~ismember({cfg.urchanlocs.labels},alldel);
  65. EEG= pop_interp(EEG,cfg.urchanlocs(idxs),'spherical');
  66. %% add the EEG data to the unfold data
  67. ufresult.data=EEG.data;
  68. clear EEG mod; % make some space
  69. %% find P100 and N170 peaks
  70. elecfind = @(x)find(strcmp(x,{ufresult.chanlocs.labels}));
  71. chan = [elecfind('PO8'),elecfind('P8'),elecfind('P7'),elecfind('PO7')];
  72. P100Start=find(ufresult.times>t_p100(1),1,'first');
  73. P100Stop=find(ufresult.times<t_p100(2),1,'last');
  74. N170Start=find(ufresult.times>t_n170(1),1,'first');
  75. N170Stop=find(ufresult.times<t_n170(2),1,'last');
  76. paramNames=ufresult.unfold.colnames;
  77. if strcmp(phase,'WLFO')
  78. [~,intPos] =find(ismember(paramNames,'(Intercept)'));
  79. elseif strcmp(phase,'Lab')
  80. [~,intPos] =find(ismember(paramNames,'2_(Intercept)'));
  81. end
  82. [~,currHFPos]=find(ismember(paramNames,'curr_HF'));
  83. ufFace=mean(ufam.beta(chan,:,intPos)+ufresult.beta(chan,:,currHFPos));
  84. ufObj =mean(ufam.beta(chan,:,intPos)-ufresult.beta(chan,:,currHFPos));
  85. clear ufam;% make some space
  86. [~,P100Face]=max(ufFace(P100Start:P100Stop));
  87. P100Face=P100Start+P100Face-1;
  88. [~,N170Face]=min(ufFace(N170Start:N170Stop));
  89. N170Face=N170Start-1+N170Face; %-1 as correction for shift by one position
  90. [~,P100Obj]=max(ufObj(P100Start:P100Stop));
  91. P100Obj=P100Start+P100Obj-1;
  92. [~,N170Obj]=min(ufObj(N170Start:N170Stop));
  93. N170Obj=N170Start-1+N170Obj; %-1 as correction for shift by one position
  94. %% calculate SE
  95. contrast = zeros(7,size(ufresult.unfold.beta_dc,2),size(ufresult.unfold.beta_dc,3));
  96. %y = b0==N1 + bHF==N1 - (b0==P1 + bHF==P1)
  97. contrast(1, N170Face,intPos) = 1;
  98. contrast(1, N170Face,currHFPos) = 1;
  99. contrast(2, P100Face,intPos) = (1);
  100. contrast(2, P100Face,currHFPos)= (1);
  101. %y = b0==N1 - bHF==N1 - (y = b0==P1 - bHF==P1)
  102. contrast(3, N170Obj,intPos) = 1;
  103. contrast(3, N170Obj,currHFPos) = -1;
  104. contrast(4, P100Obj,intPos) = (1);
  105. contrast(4, P100Obj,currHFPos)= (-1);
  106. contrast=uf_contrast_addmarginal(ufresult,contrast);
  107. %y = bHF==N1+ bHF==N1 - bHF==P1 - bHF==P1 - b0==P1 + b0==P1 + b0==N1 - b0==N1
  108. contrast(5, :,:) = contrast(1, :,:)-contrast(2, :,:); %N1Face - P1Face
  109. contrast(6, :,:) = contrast(3, :,:)-contrast(4, :,:); %N1Obje - P1Obje
  110. contrast(7, :,:) = contrast(5, :,:)-contrast(6, :,:); %P2PFace - P2Pobj
  111. tic
  112. [se] = uf_se(ufresult,'channels', chan,'contrast',contrast);
  113. toc
  114. save(['/net/store/nbp/projects/IntoTheWild/Daten/EEG/' phase '/unfold_' phase '/' filtType 'unfoldSE_subj' num2str(subj) '.mat'],'se')
  115. end
  116. %end