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.

collectUnfold_calculateTFCE.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. %% collectUnfold_calculateTFCE.m
  2. % This script collects all unfold data and calculates the TFCE
  3. cd '/net/store/nbp/users/agert/itw'
  4. init_itw
  5. projectFolder=['/net/store/nbp/projects/IntoTheWild'];
  6. codingscheme = 'mashup';
  7. filtType='causal';
  8. phase='WLFO';
  9. timewin=[-500 1000];
  10. %% Collecting unfold
  11. d2nd = [];
  12. for subj = [8 9 29:36 38:41 44 45 48 51:53]
  13. fPath = fullfile(projectFolder,['/Daten/EEG/' phase '/unfold_' phase '/' filtType '/']);
  14. fPath = fullfile(fPath,['ufresult_subj' num2str(subj) ,'_allElec_' codingscheme '_' num2str(timewin(1)) '-' num2str(timewin(2)) '_regularized0.mat']);
  15. try
  16. fprintf('loading subject %i \n',subj)
  17. d = load(fPath);
  18. ufresult=d.ufresult;
  19. ufresult = 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}});
  20. % I don't have to add marginals, as I am interested in the pure
  21. % betas = differences between conditions
  22. if strcmp(phase,'Lab') && subj==51 % sub 51 does not have predictore sacAmp -> adjust structure accordingly
  23. tmpBeta(:,:,1:11)=ufresult.beta(:,:,1:11);
  24. tmpBeta(:,:,12:17)=nan(128,length(ufresult.times),6);
  25. tmpBeta(:,:,18:24)=ufresult.beta(:,:,12:18);
  26. tmpBeta_nodc(:,:,1:11)=ufresult.beta_nodc(:,:,1:11);
  27. tmpBeta_nodc(:,:,12:17)=nan(128,length(ufresult.times),6);
  28. tmpBeta_nodc(:,:,18:24)=ufresult.beta_nodc(:,:,12:18);
  29. ufresult.beta=tmpBeta;
  30. ufresult.beta_nodc=tmpBeta_nodc;
  31. if ~isempty(d2nd)
  32. ufresult.param=d2nd.param;
  33. end
  34. end
  35. % first subject: initialize d2nd (2nd-level analysis)
  36. if isempty(d2nd)
  37. d2nd = ufresult;
  38. d2nd.unfold(1) = d2nd.unfold;
  39. d2nd.subject = subj;
  40. d2nd.chanlocs = ufresult.chanlocs;
  41. d2nd.codingscheme = codingscheme;
  42. else
  43. d2nd.unfold(end+1) = ufresult.unfold;
  44. d2nd.beta(:,:,:,end+1) = ufresult.beta;
  45. d2nd.beta_nodc(:,:,:,end+1) = ufresult.beta_nodc;
  46. d2nd.subject(end+1) = subj;
  47. end
  48. catch e
  49. display(['problem with subject ',num2str(subj), ': ' ,e.message])
  50. end
  51. end
  52. %% TFCE
  53. elecfind = @(x)find(strcmp(x,{d2nd.chanlocs.labels}));
  54. cfg = [];
  55. cfg.chan = 1:length(d2nd.chanlocs); % the other channels are eye-movement channels from the Eye-EEG toolbox
  56. cfg.blcorrect = 0;
  57. cfg.save = 1;
  58. ept_tfce_nb = ept_ChN2(d2nd.chanlocs,0);
  59. cfg.nperm=10000;
  60. cfgPlot = [];
  61. cfgPlot.highlighted_channel= [elecfind('PO8') elecfind('P8') elecfind('PO7') elecfind('P7')];
  62. cfgPlot.colormap = {{'div','RdYlBu'},'seq'};
  63. cfgPlot.topoalpha = 0.05; % where to put the significance dots?
  64. cfgPlot.individualcolorscale = 'row'; % different rows have very different interpretation
  65. cfgPlot.time = [-0.2 0.5]; % we will zoom in
  66. cfgPlot.n_topos = 14; %every 50 ms
  67. cfgPlot.quality = 100; % put higher for better quality
  68. paramNames={d2nd.param.name};
  69. cfg.effecttype = 'prev'; %'prev' or 'curr' - only relevant for HF
  70. paramlist = {'HF'};%HF,'interaction','samebox'};
  71. data=0;
  72. %%
  73. for param = paramlist
  74. switch param{1}
  75. case 'HF'
  76. [~,paramPos]=find(ismember(paramNames,[cfg.effecttype '_HF']));
  77. assert(~isempty(paramPos))
  78. data = squeeze(d2nd.beta(cfg.chan,:,paramPos,:));
  79. data=data*2; %because the data is effect coded
  80. case 'interaction'
  81. [~,paramPos]=find(ismember(paramNames,'humanface:prevhumanface'));
  82. assert(~isempty(paramPos))
  83. data = squeeze(d2nd.beta(cfg.chan,:,paramPos,:));
  84. data=data*2;
  85. case 'samebox'
  86. [~,paramPos]=find(ismember(paramNames,'samebox_1'));
  87. assert(~isempty(paramPos))
  88. data = squeeze(d2nd.beta(cfg.chan,:,paramPos,:));
  89. otherwise
  90. error('wrong condition')
  91. end
  92. if cfg.blcorrect
  93. data = bsxfun(@minus,data,mean(data(:,d2nd.times<0,:),2));
  94. end
  95. [res,info] = be_ept_tfce_diff(struct('nperm',cfg.nperm,'neighbours',ept_tfce_nb(cfg.chan,:)),permute(data,[3 1 2]));
  96. cfgPlot.pvalues = res.P_Values;
  97. TFCEresults.res=res;
  98. TFCEresults.info=info;
  99. TFCEresults.channels=d2nd.chanlocs;
  100. TFCEresults.times=d2nd.times;
  101. %% actual plotting
  102. tmpPVal = log10(res.P_Values); % change p-values to log-scale
  103. hA = plot_topobutter(cat(3,mean(data,3),tmpPVal),d2nd.times,d2nd.chanlocs,cfgPlot);
  104. hA.topo.colorbar{2}.XTick = log10([0.001 0.005 0.05]);
  105. hA.topo.colorbar{2}.TickLabels = [0.001 0.005 0.05];
  106. if strcmp(param,'interaction')
  107. figurename = [codingscheme ' ' param{1} ', iter:' num2str(cfg.nperm) ', time:' num2str(timewin(1)) ' to ' num2str(timewin(2))];
  108. elseif strcmp(param,'samebox') || strcmp(param,'boxn2')
  109. figurename = [codingscheme ' ' param{1} ', iter:' num2str(cfg.nperm) ', time:' num2str(timewin(1)) ' to ' num2str(timewin(2))];
  110. else
  111. figurename = [codingscheme ' main effect: ' cfg.effecttype ', iter:' num2str(cfg.nperm) ', time:' num2str(timewin(1)) ' to ' num2str(timewin(2))];
  112. end
  113. title(figurename)
  114. drawnow
  115. set(gcf,'Position',[5 515 2550 571])
  116. drawnow
  117. end