diff --git a/.DS_Store b/.DS_Store index 5008ddf..47829d4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/._spDist_neural_behav_corr_exclutri_individperm_noflipth_fig5.m* b/._spDist_neural_behav_corr_exclutri_individperm_noflipth_fig5.m* new file mode 100644 index 0000000..e8d3a8d Binary files /dev/null and b/._spDist_neural_behav_corr_exclutri_individperm_noflipth_fig5.m* differ diff --git a/spDist_channelRespAmp_GAT_Figure4.m b/spDist_channelRespAmp_GAT_suppFigure5.m similarity index 93% rename from spDist_channelRespAmp_GAT_Figure4.m rename to spDist_channelRespAmp_GAT_suppFigure5.m index 6426148..fa6b26f 100644 --- a/spDist_channelRespAmp_GAT_Figure4.m +++ b/spDist_channelRespAmp_GAT_suppFigure5.m @@ -8,7 +8,7 @@ % % TCS 8/19/2019 % -function spDist_channelRespAmp_GATdist_gh_082520(subj,sess,ROIs,which_vox) +function spDist_channelRespAmp_GAT_suppFigure5(subj,sess,ROIs,which_vox) tst_dir = 'spDist'; @@ -17,20 +17,18 @@ function spDist_channelRespAmp_GATdist_gh_082520(subj,sess,ROIs,which_vox) %root = spDist_loadRoot; if nargin < 1 - % subj = {'CC','MR','AY'} + subj = {'AY','CC','EK','KD','MR','SF','XL'}; end if nargin < 2 sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; - % sess = {{'spDistLong1','spDistLong2'},{'spDistLong1','spDistLong2'},{'spDistLong1','spDistLong2'}}; - % sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; end if nargin < 3 - ROIs = {'V1','V2','V3','V3AB','hV4','VO1','VO2','LO1','LO2','TO1','TO2','IPS0','IPS1','IPS2','IPS3','sPCS','iPCS'}; - + %ROIs = {'V1','V2','V3','V3AB','hV4','VO1','VO2','LO1','LO2','TO1','TO2','IPS0','IPS1','IPS2','IPS3','sPCS','iPCS'}; %change this back 111220 + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; end @@ -75,12 +73,8 @@ function spDist_channelRespAmp_GATdist_gh_082520(subj,sess,ROIs,which_vox) end - %delay_tpt_range = [1.5 3; 7 9; 15 16.5]; - delay_tpt_range = [3.75 5.25; 8 9.5; 10.5 12]; % updated to parallel new fig 4, aug 25 2020 - % delay_tpt_range = [1.5 3; 6 7.5; 10 12]; for use in spDist orig - - % delay_tpt_range = [1.5 6.5; 6.5 11.5; 11.5 16.5]; - % delay_tpt_range = [1.5 4;4 6.5;6.5 9;9 11.5;11.5 14; 14 16.5]; + + delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; delay_tpts_tmp = cell(size(delay_tpt_range,1),1); for dd = 1:size(delay_tpt_range,1) @@ -146,10 +140,7 @@ function spDist_channelRespAmp_GATdist_gh_082520(subj,sess,ROIs,which_vox) for fold_idx = 1:n_folds % ~~~~~~~ first, estimate IEM ~~~~~~~~~~ - - - - + % pick CV sets trn_runs = ones(length(unique(data.r_LORO)),1); @@ -330,9 +321,9 @@ function spDist_channelRespAmp_GATdist_gh_082520(subj,sess,ROIs,which_vox) % save with VE marker when which_vox < 1, otherwise, number of % vox if which_vox < 1 - fn2s = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan_VE%03.f_GATdist_fig4TPTS.mat',root,tst_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,n_chan,100*which_vox); + fn2s = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan_VE%03.f_GATdist_fig5TPTS.mat',root,tst_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,n_chan,100*which_vox); else - fn2s = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan_%ivox_GATdist_fig4TPTS.mat' ,root,tst_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,n_chan, which_vox); + fn2s = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan_%ivox_GATdist_fig5TPTS.mat' ,root,tst_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,n_chan, which_vox); end fprintf('saving to %s...\n',fn2s); diff --git a/spDist_channelRespAmp_GATdist.m b/spDist_channelRespAmp_GATdist.m index 5fe92b0..39d3e40 100644 --- a/spDist_channelRespAmp_GATdist.m +++ b/spDist_channelRespAmp_GATdist.m @@ -16,17 +16,16 @@ function spDist_channelRespAmp_GATdist(subj,sess,ROIs,which_vox) %root = spDist_loadRoot; if nargin < 1 - subj = {'CC'}; + subj = {'AY','CC','EK','KD','MR','SF','XL'}; end if nargin < 2 - sess = {{'spDist1','spDist2'}}; - + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; end if nargin < 3 - ROIs = {'V1','V2','V3','V3AB','hV4','VO1','VO2','LO1','LO2','TO1','TO2','IPS0','IPS1','IPS2','IPS3','sPCS','iPCS'}; - + % ROIs = {'V1','V2','V3','V3AB','hV4','VO1','VO2','LO1','LO2','TO1','TO2','IPS0','IPS1','IPS2','IPS3','sPCS','iPCS'}; + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; end @@ -301,9 +300,9 @@ function spDist_channelRespAmp_GATdist(subj,sess,ROIs,which_vox) % save with VE marker when which_vox < 1, otherwise, number of % vox if which_vox < 1 - fn2s = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan_VE%03.f_GATdist.mat',root,tst_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,n_chan,100*which_vox); + fn2s = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan_VE%03.f_GATdist_fig5.mat',root,tst_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,n_chan,100*which_vox); else - fn2s = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan_%ivox_GATdist.mat' ,root,tst_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,n_chan, which_vox); + fn2s = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan_%ivox_GATdist_fig5.mat' ,root,tst_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,n_chan, which_vox); end fprintf('saving to %s...\n',fn2s); diff --git a/spDist_fidelity_stats_shuf.m b/spDist_fidelity_stats_shuf.m index 610759b..8ed3138 100644 --- a/spDist_fidelity_stats_shuf.m +++ b/spDist_fidelity_stats_shuf.m @@ -30,6 +30,7 @@ sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; +% ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; func_suffix = 'surf'; cat_mode = 1; % if 1, look for catSess1Ses...SessN_ files, otherwise, just look for each session in turn @@ -422,9 +423,9 @@ myy = match_ylim(get(gcf,'Children')); set(mh(:),'YData',[min(myy(:,1)) max(myy(:,2))]); - +set(gcf,'Position',[109 372 989 168]); %for concat ROIs set(gcf,'Position',[185 745 1843 470]); - +set(gcf,'Position',[109 372 1843 470]); % NOTE: other aspects of plotting from MGSMap_fidelity_stats_shuf.m were % not edited, so can be copied/pasted from that file if desired diff --git a/spDist_neuralBehavCorr_figure5.m b/spDist_neuralBehavCorr_figure5.m new file mode 100644 index 0000000..6e12f25 --- /dev/null +++ b/spDist_neuralBehavCorr_figure5.m @@ -0,0 +1,1163 @@ +function spDist_neuralBehavCorr_figure5(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'AY','CC','EK','KD','MR','SF','XL'}; %alph + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +% seed random number generator + +rng(spDist_randSeed); + +%% load neural data +startidx = 1; +bidx =1; +WHICH_EXCL = [13 20 21 22]; +all_data_beh = []; +all_subj_beh= []; + +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + + %%%inserting + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + %fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + this_data.s_all = this_scored.ii_sess; + + thisbidx = bidx:(bidx+size(this_scored.ii_sess.trialinfo,1)-1); + + this_data.sess_all = sessidx; + all_data_beh= cat_struct(all_data_beh,this_data); + all_subj_beh(thisbidx,1) = ss; + + bidx =thisbidx(end)+1; + end + + startidx = thisidx(end)+1; + + clear data; + + end + +end + +all_data_beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_beh.s_all.excl_trial, 'UniformOutput',false)); +fprintf('neural and behave loaded...\n') + + +%% load recons, no flipping + +all_recons_noflip = all_recons{1}; % simply reiterate, we are NOT flipping a thing + + +delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; %updated on nov 092020 +myTR = 0.75; + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + + + +cond = [1 2]; % do no distractor, then distractor +store_b = nan(length(cond),length(ROIs),length(delay_tpts),length(subj),36); + + +figure; + +for cc= 1:length(cond) + + thisd = nan(length(cond),length(ROIs),length(delay_tpts),length(subj),36, length(angs)); + thisb = nan(1,length(subj)); + + for vv = 1:length(ROIs) + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + for nr =1:nruns + if cc ==1 %%%%%% NOTE THIS COLLECTS THREE TRIALS IN MGS CONDITION %%%% NEED TO FIX!!!! + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==1; + else + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; + end + + thisd(cc,vv,dd,ss,nr,:) = squeeze(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3)); + + thisb(ss) = atan2d(sum(mean(mean(all_recons_noflip(thisidx,:, delay_tpts{dd}),1),3).*sind(angs)),... + sum(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3).*cosd(angs))); + + store_b(cc,vv,dd,ss,nr) = thisb(ss); + + end + end + end + clear thisidx + clear thisb + + end + +end + +fprintf('neural bias computed ...\n') +%% organize beh data + +% which param should we collect? +dist_colors = spDist_condColors; + +params_of_interest = {'f_sacc'}; + +param_str = {'fsacc'}; + +mu = nan(2,length(subj),length(cond),36); % no subj performed > 36 runs +err = nan(2,length(subj),length(cond),36); +dtheta = nan(length(subj),length(cond),36); +drad = nan(length(subj),length(cond),36); +dtheta_poldeg = nan(length(subj),length(cond),36); + +for cc = 1:length(cond) + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + + for nr = 1:nruns + + if cc ==1 + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==1; + else + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; + end + err(1,ss,cc,nr) = std(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,2)); + mu(:,ss,cc,nr) = mean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); %mean of a single number = the number .. leaving this + tmp(1,:) = mean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + [dtheta(ss,cc,nr), drad(ss,cc,nr)]= cart2pol(tmp(1),tmp(2)); + dtheta_poldeg(ss,cc,nr) = dtheta(ss,cc,nr).*360/(2*pi); + + end + + + + end +end + +%% bias %% Figure 1F : Near Distractor trials: Bias, polar degrees + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; + +mu_bias = nan(1,1,2,length(subj)); % no subj performed > 36 runs + +drad_bias = []; +dtheta_bias = []; + +for pp =1:length(params_of_interest) + for bb =1 + for ss = 1:length(subj) + + tmpd = all_data_beh.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.use_trial==1 & all_data_beh.s_all.trialinfo(:,6)==0 & all_data_beh.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins, into tmpd ONLY + + thisidx = all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.use_trial==1 & all_data_beh.s_all.trialinfo(:,6)==0; %now, collect all jitters. + + % distractor bin x param x [radial; tangential] x subj + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); % use idx with all zero bin from flipped data + + [dtheta_bias, drad_bias] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + mu_bias(bb,pp,:,ss) = mean([drad_bias rad2deg(dtheta_bias)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd thisidx orig_y orig_y_flip + + + + end + + end +end + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thism_near = squeeze(mu_bias(:,pp,2,:))'; %this is the only condition that is information for this analysis. + plot(1+0.15,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); + plot(1,mean(thism_near,2),'o','MarkerSize',15,'Color',dist_colors(2,:),'MarkerFaceColor',dist_colors(2,:)); + hold on; + + tmpe = std(thism_near)/sqrt(length(subj)); + plot([1 1], mean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color',dist_colors(2,:)); + + %errorbar(1, mean(thism_near), [std(thism_near)/sqrt(length(subj))],'linewidth',2,'Color',cond_colors(2,:)) + title(param_str{pp}); + + + ylabel('Bias, Polar Angle (\circ), toward distractor'); +end +xlabel('Near Distractor') +xlim([0 2]) + +[h_bias_near p_bias_near,CI,STATS] = ttest(thism_near(1,:)') %t-test to determine if bias is different than zero +text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',p_bias_near),'color','k','fontsize',15) %filled + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) +%% Fgiure 5 B & C + +rho_group_theta = nan(length(cond),length(ROIs),1); +pval_group_theta = nan(length(cond),length(ROIs),1); +rho_theta = nan(length(subj),length(ROIs),1); +pval_theta = nan(length(subj),length(ROIs),1); +subj_col = lines(7); + +figure + +for ss = 1:length(subj) + hold on; + for cc = 2 % 1:length(cond) + + for vv = 1:length(ROIs) + + for dd = 3 % 1:length(delay_tpts) + + thisb_neural_tmp =[]; + thisb_behav_tmp =[]; + thisb_behav = []; + thisb_neural = []; + thisb_behav_poldegtmp =[]; + thisb_behav_poldeg =[]; + + + thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); + + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + subplot(1,length(ROIs),vv); hold on; + + scatter(thisb_neural,thisb_behav_poldeg,30,subj_col(ss,:),'filled','MarkerFaceAlpha',.4) + + title(ROIs{vv}) + lsline + set(gcf,'Position',[ -110 706 1882 624]) + + if vv==1 && ss ==7 + ylabel({'Polar angle \circ delta, target, sacc endpt', 'Epoch 3'}) + xlabel('Neural bias, Polar angle \circ') + else + end + [rho_theta(cc,ss,vv,dd), pval_theta(cc,ss,vv,dd)] = corr(thisb_neural', thisb_behav_poldeg'); + clear this neural thisb_behav_poldeg + end + + + end + + end + + + +end + + set(get(gcf,'Children'),'XLim',[-180 180],'YLim',[-25 25],'xtick',-180:90:180) %,'xtick',{'180','0','180'}, + + %% make group subplot - supp fig 5 A +% +% % squeeze over subj, collect each subj, all trials into one container +% rho_group_theta = nan(length(cond),length(ROIs),length(delay_tpts)); +% pval_group_theta = nan(length(cond),length(ROIs),length(delay_tpts)); +% +% subj_col = lines(7); +% +% figure +% +% +% hold on; +% +% for vv = 1:length(ROIs) +% for cc = 2 % 1:length(cond) +% +% for dd = 1:length(delay_tpts) +% +% thisb_neural_tmp =[]; +% thisb_behav_tmp =[]; +% thisb_behav = []; +% thisb_neural = []; +% thisb_behav_poldegtmp =[]; +% thisb_behav_poldeg =[]; +% +% for ss = 1:length(subj) +% thisb_neural_tmp(ss,:) = squeeze(store_b(cc,vv,dd,ss,:)); +% thisb_behav_tmp(ss,:)= squeeze(mu(2,ss,cc,:))'; +% thisb_behav_poldegtmp(ss,:)= dtheta_poldeg(ss,cc,:); +% +% end +% thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); +% thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); +% thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); +% +% subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; +% scatter(thisb_neural,thisb_behav_poldeg,30,dist_colors(cc,:),'filled','MarkerFaceAlpha',.4) +% title(ROIs{vv}) +% lsline +% set(gcf,'Position',[ -110 706 1882 624]) +% +% +% if vv==1 && ss ==1 +% ylabel({'Polar angle \circ delta, target, sacc endpt', 'Epoch 3'}) +% xlabel('Neural bias, Polar angle \circ') +% else +% end +% [rho_group_theta(cc,vv,dd), pval_group_theta(cc,vv,dd)] = corr(thisb_neural, thisb_behav_poldeg); +% clear this neural thisb_behav_poldeg +% end +% +% +% end +% +% +% +% +% end +% +% +% set(get(gcf,'Children'),'XLim',[-180 180],'YLim',[-25 25],'xtick',-180:90:180) + + %% supp fig 5 c +% +% store_fish_ztheta= []; +% pval_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +% rho_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +% fish_z_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +% +% figure +% for cc = 2 %1:length(cond) +% +% for vv=1:length(ROIs) +% +% for dd = 3 %1:length(delay_tpts) +% +% for ss = 1:length(subj) +% +% thisb_neural_tmp = []; +% thisb_behav_tmp = []; +% thisb_neural = []; +% thisb_behav = []; +% thisb_behav_poldegtmp =[]; +% thisb_behav_polradtmp =[]; +% thisb_behav_poldeg =[]; +% thisb_behav_polrad =[]; +% +% thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); +% thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; +% thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); +% +% +% thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); +% thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); +% +% thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); +% +% % +% % [rho_sg(cc,ss,vv,dd), pval_sg(cc,ss,vv,dd)] = corr(thisb_neural', thisb_behav'); +% % +% % fish_z(cc,ss,vv,dd) = atanh(rho_sg(cc,ss,vv,dd)); +% +% [rho_sg_theta(cc,ss,vv,dd), pval_sg_theta(cc,ss,vv,dd)] =corr(thisb_neural', thisb_behav_poldeg'); +% +% fish_z_theta(cc,ss,vv,dd) = atanh(rho_sg_theta(cc,ss,vv,dd)); % identical +% store_fish_ztheta = [store_fish_ztheta; atanh(rho_sg_theta(cc,ss,vv,dd)) cc ss vv dd ]; +% clear mysd +% end +% +% % +% +% hold on; +% +% plot(vv+0.15,fish_z_theta(cc,:,vv,dd),'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); +% hold on; +% my_sem_th = std(fish_z_theta(cc,:,vv,dd))/sqrt(length(subj)); +% plot(vv,mean(fish_z_theta(cc,:,vv,dd)), 'o', 'color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',10) +% plot(vv*[1 1],[mean(fish_z_theta(cc,:,vv,dd))+1.*my_sem_th, mean(fish_z_theta(cc,:,vv,dd))-1.*my_sem_th], '-', 'color',dist_colors(cc,:),'linewidth',2) +% %title(ROIs{vv}) +% ylim([-1 1]) +% xlim([0.05 12.5]) +% line([0 12.5], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') % geh add y =0 baseline +% set(gca,'Xtick',[0 1 2 3 4 5 6 7 8 9 10 11 12],'Xticklabel',{'','V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS',''},'XTickLabelRotation',45,'TickDir','out'); +% ylabel('Fisher Z-transformed Rho') +% +% set(gcf,'position',[ 549 724 499 571]) +% +% +% [h_th,p_th(cc,vv,dd),~,stats_th] = ttest(fish_z_theta(cc,:,vv,dd)); +% realT_th(cc,vv,dd) = stats_th.tstat; +% +% end +% +% end +% end + +%% figure 5c + +fish_theta_fig = figure('Name','fish_theta'); +store_fish_ztheta= []; +pval_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +rho_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +fish_z_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); + +figure +for cc = 2 %1:length(cond) + +for vv=1:length(ROIs) + + for dd = 3 %1:length(delay_tpts) + + for ss = 1:length(subj) + + thisb_neural_tmp = []; + thisb_behav_tmp = []; + thisb_neural = []; + thisb_behav = []; + thisb_behav_poldegtmp =[]; + thisb_behav_polradtmp =[]; + thisb_behav_poldeg =[]; + thisb_behav_polrad =[]; + + thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); + + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + + [rho_sg(cc,ss,vv,dd), pval_sg(cc,ss,vv,dd)] = corr(thisb_neural', thisb_behav'); + + fish_z(cc,ss,vv,dd) = atanh(rho_sg(cc,ss,vv,dd)); + + [rho_sg_theta(cc,ss,vv,dd), pval_sg_theta(cc,ss,vv,dd)] =corr(thisb_neural', thisb_behav_poldeg'); + + fish_z_theta(cc,ss,vv,dd) = atanh(rho_sg_theta(cc,ss,vv,dd)); % identical + store_fish_ztheta = [store_fish_ztheta; atanh(rho_sg_theta(cc,ss,vv,dd)) cc ss vv dd ]; + clear mysd + end + +% + + hold on; + plot(vv+0.15,fish_z_theta(cc,:,vv,dd),'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); + hold on; + my_sem_th = std(fish_z_theta(cc,:,vv,dd))/sqrt(length(subj)); + plot(vv,mean(fish_z_theta(cc,:,vv,dd)), 'o', 'color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',10) + plot(vv*[1 1],[mean(fish_z_theta(cc,:,vv,dd))+1.*my_sem_th, mean(fish_z_theta(cc,:,vv,dd))-1.*my_sem_th], '-', 'color',dist_colors(cc,:),'linewidth',2) + %title(ROIs{vv}) + ylim([-1 1]) + xlim([0.05 7.5]) + line([0 8], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') % geh add y =0 baseline + + % if vv==1 + set(gca,'Xtick',[0 1 2 3 4 5 6 7 8 ],'Xticklabel',{'','V1-V3','V3AB','hV4','LO1','IPS0-IPS1','IPS2-IPS3','sPCS',''},'XTickLabelRotation',45,'TickDir','out'); + ylabel('Fisher Z-transformed Rho') + %else + set(gcf,'position',[ 549 724 499 571]) + %end + + [h_th,p_th(cc,vv,dd),~,stats_th] = ttest(fish_z_theta(cc,:,vv,dd)); + realT_th(cc,vv,dd) = stats_th.tstat; + + end + +end +end +%% +%% +% % squeeze over subj, collect each subj, all trials into one container +% rho_group_theta = nan(length(cond),length(ROIs),1); +% pval_group_theta = nan(length(cond),length(ROIs),1); +% rho_theta = nan(length(subj),length(ROIs),1); +% pval_theta = nan(length(subj),length(ROIs),1); +% +% +% figure +% +% for ss = 1:length(subj) +% hold on; +% for cc = 2 % 1:length(cond) +% +% for vv = 1:length(ROIs) +% +% for dd = 3 % 1:length(delay_tpts) +% +% thisb_neural_tmp =[]; +% thisb_behav_tmp =[]; +% thisb_behav = []; +% thisb_neural = []; +% thisb_behav_poldegtmp =[]; +% thisb_behav_poldeg =[]; +% +% +% thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); +% thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; +% thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); +% +% +% thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); +% thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); +% thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); +% +% %subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; +% subplot(length(subj),length(ROIs),(ss-1)*length(ROIs)+vv); hold on; +% %subplot(1,length(ROIs),vv); hold on; +% scatter(thisb_neural,thisb_behav_poldeg,30,subj_colors(ss,:),'filled','MarkerFaceAlpha',.4) +% +% title(ROIs{vv}) +% lsline +% set(gcf,'Position',[ -110 706 1882 624]) +% % xlim([-180 180]) +% %ylim([-25 25]) +% +% +% +% if vv==1 && ss ==7 +% ylabel({'Polar angle \circ delta, target, sacc endpt', 'Epoch 3'}) +% xlabel('Neural bias, Polar angle \circ') +% else +% end +% [rho_theta(cc,ss,vv,dd), pval_theta(cc,ss,vv,dd)] = corr(thisb_neural', thisb_behav_poldeg'); +% clear this neural thisb_behav_poldeg +% end +% +% +% end +% +% +% +% +% end +% +% +% +% end +% set(get(gcf,'Children'),'XLim',[-180 180],'YLim',[-25 25]) +% + + + +%% supplmental figure 5 + + +% fish_theta_fig = figure('Name','fish_theta'); +% store_fish_ztheta= []; +% pval_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +% rho_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +% fish_z_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +% +% figure +% for cc = 2 %1:length(cond) +% +% for vv=1:length(ROIs) +% +% for dd = 3 %1:length(delay_tpts) +% +% for ss = 1:length(subj) +% +% thisb_neural_tmp = []; +% thisb_behav_tmp = []; +% thisb_neural = []; +% thisb_behav = []; +% thisb_behav_poldegtmp =[]; +% thisb_behav_polradtmp =[]; +% thisb_behav_poldeg =[]; +% thisb_behav_polrad =[]; +% +% thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); +% thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; +% thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); +% +% +% thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); +% thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); +% +% thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); +% +% +% [rho_sg(cc,ss,vv,dd), pval_sg(cc,ss,vv,dd)] = corr(thisb_neural', thisb_behav'); +% +% fish_z(cc,ss,vv,dd) = atanh(rho_sg(cc,ss,vv,dd)); +% +% [rho_sg_theta(cc,ss,vv,dd), pval_sg_theta(cc,ss,vv,dd)] =corr(thisb_neural', thisb_behav_poldeg'); +% +% fish_z_theta(cc,ss,vv,dd) = atanh(rho_sg_theta(cc,ss,vv,dd)); % identical +% store_fish_ztheta = [store_fish_ztheta; atanh(rho_sg_theta(cc,ss,vv,dd)) cc ss vv dd ]; +% clear mysd +% end +% +% % +% +% hold on; +% plot(vv+0.15,fish_z_theta(cc,:,vv,dd),'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); +% hold on; +% my_sem_th = std(fish_z_theta(cc,:,vv,dd))/sqrt(length(subj)); +% plot(vv,mean(fish_z_theta(cc,:,vv,dd)), 'o', 'color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',10) +% plot(vv*[1 1],[mean(fish_z_theta(cc,:,vv,dd))+1.*my_sem_th, mean(fish_z_theta(cc,:,vv,dd))-1.*my_sem_th], '-', 'color',dist_colors(cc,:),'linewidth',2) +% %title(ROIs{vv}) +% ylim([-1 1]) +% xlim([0.05 7.5]) +% line([0 8], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') % geh add y =0 baseline +% +% % if vv==1 +% set(gca,'Xtick',[0 1 2 3 4 5 6 7 8 ],'Xticklabel',{'','V1-V3','V3AB','hV4','LO1','IPS0-IPS1','IPS2-IPS3','sPCS',''},'XTickLabelRotation',45,'TickDir','out'); +% ylabel('Fisher Z-transformed Rho') +% %else +% set(gcf,'position',[ 549 724 499 571]) +% %end +% +% [h_th,p_th(cc,vv,dd),~,stats_th] = ttest(fish_z_theta(cc,:,vv,dd)); +% realT_th(cc,vv,dd) = stats_th.tstat; +% +% end +% +% end +% end +%% +% +y_var = store_fish_ztheta(:,1); +cond_var = store_fish_ztheta(:,2); %condition +subj_var = store_fish_ztheta(:,3); %subject +roi_var = store_fish_ztheta(:,4); %roi +epoch_var = store_fish_ztheta(:,5); %epoch + +% perform real T test + + for vv =1:length(ROIs) + for cc =1:length(cond) + for ee = 1:3 + thisidx = roi_var ==vv & cond_var ==cc & epoch_var ==ee; + y_shuf =y_var(thisidx); %these are already shuffled, see above + [~,~,~,stats] = ttest(y_shuf); + real_t(vv,cc,ee) = stats.tstat; + + clear thisidx y_shuf + end + end + end + +% perform true 1-way anova + + +f_real_one = []; +p_real_one = []; + + + y = y_var; + thissubj = subj_var; + thisroi = roi_var; + [f_real_one, pval_real_one] = RMAOV1_gh([y,thisroi,thissubj],0.05); + clear thisroiidx y thiscond thissubj thisepoch + + +% +% +% clear cond_var roi_var epoch_var subj_var y_var +% +% y_var = store_fish_ztheta(:,1); %fish z +% cond_var = store_fish_ztheta(:,2); %condition +% subj_var = store_fish_ztheta(:,3); %subject +% roi_var = store_fish_ztheta(:,4); %roi +% epoch_var = store_fish_ztheta(:,5); %epoch +% +% % 1-way +% +% f_real_one = []; +% pval_real_one =[]; +% +% for cc =1:length(cond) +% for vv =1:length(ROIs) +% +% thisroiidx = roi_var==vv & cond_var==cc; +% y = y_var(thisroiidx); +% +% thissubj = subj_var(thisroiidx); +% thisepoch = epoch_var(thisroiidx); +% +% [f_real_one(cc,vv), pval_real_one(cc,vv)] = RMAOV1_gh([y,thisepoch,thissubj],0.05); +% clear thisroiidx y thissubj thisepoch +% +% end +% end +% +% +% clear cond_var roi_var epoch_var subj_var y_var +% check the usage of 'random' per the grouping var +%%%%%%%%%%%%%%%%%%%%%%%%% PERM TEST # 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% we're permuting two measures here, linear bias and ciruclar bias, open +iter = 1000; +t_iter =cell(length(ROIs),iter); +p_iter =cell(length(ROIs),iter); +f_store_iter_2 = nan(length(ROIs),iter,3); +fish_zthstore_perm =[]; +fish_zthperm = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +shuff_Tth =nan(length(cond),length(ROIs),length(delay_tpts),iter); +rho_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +pval_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); + + +for xx = 1:iter + + if xx == 1 + fprintf('starting @ %s \n',datestr(now,'HH:MM:SS')) + tic + elseif xx == 2 + toc + elseif xx == 3 + toc + elseif xx == iter/4 + fprintf('quarter-way ...\n') + toc + elseif xx == iter/2 + fprintf('halfway ...\n') + toc + else + end + + for cc = 2 %1:length(cond) + for vv=1:length(ROIs) + + for dd = 3 %1:length(delay_tpts) + + for ss = 1:length(subj) + thisb_neural_tmp_perm = []; + thisb_behav_tmp_perm = []; + thisb_behav_perm = []; + thisb_neural_perm = []; + thisb_behav_poldegtmp = []; + thisb_behav_poldegperm = []; + thisb_neural_poldegperm = []; + shuff_btheta =[]; + shuff_ntheta =[]; + + + thisb_neural_tmp_perm (1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp_perm (1,:)= squeeze(mu(2,ss,cc,:))'; + + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); %this obv cant change across ROI, delay, lose two dimens (vv,dd) here + + + thisb_behav_poldegperm = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp_perm)); + + thisb_neural_poldegperm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm)); + + % do the shuffle + shuff_btheta = thisb_behav_poldegperm; %reload these each time + shuff_ntheta = thisb_neural_poldegperm; + subjidxth = find(shuff_btheta); + shuff_bidxth = randperm(length(subjidxth))'; + shuff_btheta(subjidxth) = shuff_btheta(shuff_bidxth); %insert shuffled subj indices into bdata (note : in this case, bdata is ONLY this subj. just jumbling idx) + + bthdata = shuff_btheta(subjidxth); + nthdata = shuff_ntheta(subjidxth); + + [rho_permth(cc,ss,vv,dd,xx), pval_permth(cc,ss,vv,dd,xx)] = corr(nthdata',bthdata'); + fish_zthperm(cc,ss,vv,dd,xx) = atanh(rho_permth(cc,ss,vv,dd,xx)); + + + fish_zthstore_perm =[fish_zthstore_perm; fish_zthperm(cc,ss,vv,dd,xx) cc ss vv dd xx]; + + + clear thisidx subjidxth shuff_bidxth shuff_btheta shuff_ntheta bthdata nthdata + end + + [h,p,~,statsth] = ttest(fish_zthperm(cc,:,vv,dd,xx)); + shuff_Tth(cc,vv,dd,xx) = statsth.tstat; + + end + end + end +end + + + +% collect original perm pvalues + +p_th_twotail =nan(length(cond),length(ROIs),length(delay_tpts)); +p_th_onetail =nan(length(cond),length(ROIs),length(delay_tpts)); + +pfdr_th_twotail =[]; +pmask_th_twotail =[]; +pmask_th_onetail =[]; +pfdr_th_onetail =[]; + +p_th_twotaile = []; +p_th_onetaile = []; +pmask_th_twotaile = []; +pmask_th_onetaile = []; +pfdr_th_twotaile = []; +pfdr_th_onetaile = []; + + +tdistpolbias = figure('Name','tdistpolbias'); + +realT_col = lines(3); +for cc =1:length(cond) + for dd = 1:length(delay_tpts) + for vr = 1:length(ROIs) + + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_Tth(cc,vr,dd,:))) + line([realT_th(cc,vr,dd) realT_th(cc,vr,dd)], [0 max(ylim)],'LineWidth',0.75,'color',realT_col(dd,:)) + p_th_twotail(cc,vr,dd) = 2 * min ( mean( shuff_Tth(cc,vr,dd,:) <= realT_th(cc,vr,dd) ), mean ( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd))); + p_th_onetail(cc,vr,dd) = mean( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd) ); + title(ROIs{vr}) + end + + [pfdr_th_twptail(cc,:,dd), pmask_th_twotail(cc,:,dd)] = fdr(p_th_twotail(cc,:,dd),0.05); % this is two tail + [pfdr_th_onetail(cc,:,dd), pmask_th_onetail(cc,:,dd)] = fdr(p_th_onetail(cc,:,dd),0.05); %one tail + + + end + +end + + +% +% two-way anova perm for each ROI? + % correct across epochs? + + test = squeeze(p_th_onetail(2,:,3)); + + [fdrout, maskout] = fdr(test,0.05) + + +tmp = [squeeze(p_th_onetail(2,:,1)); squeeze(p_th_onetail(2,:,2)); squeeze(p_th_onetail(2,:,3))] + +[fdrout, maskout] = fdr(tmp,0.05); + + +%% hold off on other perms for now - 102920 + + + + +y_var = fish_zthstore_perm(:,1); +cond_var = fish_zthstore_perm(:,2); +subj_var = fish_zthstore_perm(:,3); +roi_var = fish_zthstore_perm(:,4); +epoch_var = fish_zthstore_perm(:,5); +iter_var = fish_zthstore_perm(:,6); + + +% +% for zz =1:iter +% +% for vv = 1:length(ROIs) +% +% +% thisroiidx = roi_var ==vv & iter_var == zz; +% y_shuf = y_var(thisroiidx); %these are already shuffled, see above +% thisepoch = epoch_var(thisroiidx); +% thiscond =cond_var(thisroiidx); +% thissubj=subj_var(thisroiidx); +% +% [p_iter{vv,zz},t_iter{vv,zz},~] = anovan(y_shuf,{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'},'display','off'); +% [f_store_iter_2(vv,zz,:)] = RMAOV2_gh([y_shuf,thisepoch,thiscond,thissubj],0.05); +% +% clear thisroiidx thisepoch thiscond thissubj y_shuf +% +% end +% end +toc + +for zz =1:iter + + + thisidx = iter_var == zz; + y_shuf = y_var(thisidx); %these are already shuffled, see above + thisroi = roi_var(thisidx); + thissubj=subj_var(thisidx); + + % [p_iter{vv,zz},t_iter{vv,zz},~] = anovan(y_shuf,{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'},'display','off'); + % [f_store_iter_2(vv,zz,:)] = RMAOV2_gh([y_shuf,thisepoch,thiscond,thissubj],0.05); + + [f_store_iter_1(zz,:)] = RMAOV1_gh([y_shuf,thisroi,thissubj],0.05); + clear thisroiidx thisepoch thiscond thissubj y_shuf + +end + +% visualize + +% iv_str_rm ={'epoch','cond','epoch*cond'}; +% which_effect_rm = [1 2 3]; +% exact_store_tmp=[]; +% exact_store_rm_2 =nan(length(ROIs),length(which_effect_rm)); +% +% for vv =1:length(ROIs) +% figure('name','2-way perm; RMAOV2') +% +% for ww =1:length(which_effect_rm) +% extract_vals=[]; +% for ii=1:iter +% extract_vals = [extract_vals; f_store_iter_2(vv,ii,which_effect_rm(ww))]; +% end +% hold on; +% +% subplot(1,length(which_effect_rm),ww) +% histogram(extract_vals) +% line([f_real(vv,which_effect_rm(ww)) f_real(vv,which_effect_rm(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') +% title(iv_str_rm{which_effect_rm(ww)},'Interpreter','none'); +% % exact_p = sum(extract_vals >= f_real(vv,which_effect_rm(ww)))/iter; +% exact_p = 2 * min ( sum(extract_vals >= f_real(vv,which_effect_rm(ww)))/iter, sum(extract_vals <= f_real(vv,which_effect_rm(ww)))/iter ); +% +% text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) +% exact_store_rm_2(vv,ww) = [exact_store_tmp; exact_p]; +% clear exact_p +% sgtitle(ROIs{vv}) +% title(iv_str_rm{ww}) +% if ww ==1 +% xlabel('T-stat') +% ylabel('Frequency of T-stat') +% else +% end +% +% end +% end +% +% % one-way anova perm +% for xx=1:iter +% for cc =1:length(cond) +% for vv =1:length(ROIs) +% +% thisroiidx = roi_var==vv & cond_var==cc & iter_var ==xx; +% y = y_var(thisroiidx); +% thissubj = subj_var(thisroiidx); +% thisepoch = epoch_var(thisroiidx); +% +% [f_real_one_perm(cc,vv,xx)] = RMAOV1_gh([y,thisepoch,thissubj],0.05); +% clear thisroiidx y thissubj thisepoch +% +% end +% end +% end +% +% % visualize 1--way result +% +iv_str_rm ={'epoch'}; +which_effect_rm = 1; +exact_store_tmp = []; +exact_store_rm_1 =nan(length(ROIs),length(which_effect_rm)); + + +for cc =2 + figure('name','1-way perm; RMAOV1') + extract_vals= []; + for ii= 1:iter + extract_vals = [extract_vals; f_store_iter_1(ii)]; + end + + + subplot(1,2,cc) + hold on; + histogram(extract_vals) + line([f_real_one f_real_one], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str_rm{which_effect_rm(1)},'Interpreter','none'); + exact_p = sum(extract_vals >= f_real_one)/iter; + + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) + exact_store_rm_1 = [exact_store_tmp; exact_p]; + clear exact_p + title(iv_str_rm{1}) + xlabel('T-stat') + ylabel('Frequency of T-stat') + + +end + + +[p_fdr_one_out p_fdrthresh_one] = fdr(exact_store_rm_1,0.05) + + +% do ttest for each roi,epoch,condition + +for xx =1:iter + for vv =1:length(ROIs) + for cc =1:length(cond) + for ee = 1:3 + thisidx = roi_var ==vv & cond_var ==cc & epoch_var ==ee & iter_var == xx; + y_shuf =y_var(thisidx); %these are already shuffled, see above + [~,~,~,stats] = ttest(y_shuf); + shuff_t(vv,cc,ee,xx) = stats.tstat; + + clear thisidx y_shuf + end + end + end +end +fprintf('done') + +% pvals + +for cc =1:length(cond) + for ee = 1:3 + for vv =1:length(ROIs) + + pval_twotail(cc,vv,ee) = 2 * min(mean(shuff_t(vv,cc,ee,:) <= real_t(vv,cc,ee)), mean(shuff_t(vv,cc,ee,:) >= real_t(vv,cc,ee))); + pval_onetail(cc,vv,ee) = mean(shuff_t(vv,cc,ee,:) >= real_t(vv,cc,ee)); + + end + [pval_fdrthresh_twotail(cc,:,ee), pval_th_twotail_mask(cc,:,ee)] = fdr(pval_th_twotail(cc,:,ee),0.05); % this is two tail + [pval_fdrthresh_onetail(cc,:,ee), pval_th_onetail_mask(cc,:,ee)] = fdr(pval_th_onetail(cc,:,ee),0.05); %one tail + + end +end + + + + +fprintf('done') + +fn2s = sprintf('%s/%s_corr/neurbehcorr_concatROIs_fsacc_%iiterperm_%s.mat',root,task_dir,iter,datestr(now,'mmddyyyyHHMM')); +save(fn2s); +fprintf('saving to %s...\n',fn2s); +end + diff --git a/spDist_neuralBehavCorr_suppFigure5.m b/spDist_neuralBehavCorr_suppFigure5.m new file mode 100644 index 0000000..10fa831 --- /dev/null +++ b/spDist_neuralBehavCorr_suppFigure5.m @@ -0,0 +1,645 @@ +function spDist_neuralBehavCorr_suppFigure5(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'AY','CC','EK','KD','MR','SF','XL'}; %alph + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +% seed random number generator + +rng(spDist_randSeed); + +%% load neural data +startidx = 1; +bidx =1; +WHICH_EXCL = [13 20 21 22]; +all_data_beh = []; +all_subj_beh= []; + +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + + %%%inserting + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + %fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + this_data.s_all = this_scored.ii_sess; + + thisbidx = bidx:(bidx+size(this_scored.ii_sess.trialinfo,1)-1); + + this_data.sess_all = sessidx; + all_data_beh= cat_struct(all_data_beh,this_data); + all_subj_beh(thisbidx,1) = ss; + + bidx =thisbidx(end)+1; + end + + startidx = thisidx(end)+1; + + clear data; + + end + +end + +all_data_beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_beh.s_all.excl_trial, 'UniformOutput',false)); +fprintf('neural and behave loaded...\n') + + +%% load recons, no flipping + +all_recons_noflip = all_recons{1}; % simply reiterate, we are NOT flipping a thing + + +delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; %updated on nov 092020 +myTR = 0.75; + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + + + +cond = [1 2]; % do no distractor, then distractor +store_b = nan(length(cond),length(ROIs),length(delay_tpts),length(subj),36); + + +figure; + +for cc= 1:length(cond) + + thisd = nan(length(cond),length(ROIs),length(delay_tpts),length(subj),36, length(angs)); + thisb = nan(1,length(subj)); + + for vv = 1:length(ROIs) + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + for nr =1:nruns + if cc ==1 %%%%%% NOTE THIS COLLECTS THREE TRIALS IN MGS CONDITION %%%% NEED TO FIX!!!! + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==1; + else + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; + end + + thisd(cc,vv,dd,ss,nr,:) = squeeze(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3)); + + thisb(ss) = atan2d(sum(mean(mean(all_recons_noflip(thisidx,:, delay_tpts{dd}),1),3).*sind(angs)),... + sum(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3).*cosd(angs))); + + store_b(cc,vv,dd,ss,nr) = thisb(ss); + + end + end + end + clear thisidx + clear thisb + + end + +end + +fprintf('neural bias computed ...\n') +%% organize beh data + +% which param should we collect? +dist_colors = spDist_condColors; + +params_of_interest = {'f_sacc'}; + +param_str = {'fsacc'}; + +mu = nan(2,length(subj),length(cond),36); % no subj performed > 36 runs +err = nan(2,length(subj),length(cond),36); +dtheta = nan(length(subj),length(cond),36); +drad = nan(length(subj),length(cond),36); +dtheta_poldeg = nan(length(subj),length(cond),36); + +for cc = 1:length(cond) + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + + for nr = 1:nruns + + if cc ==1 + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==1; + else + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; + end + err(1,ss,cc,nr) = std(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,2)); + mu(:,ss,cc,nr) = mean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); %mean of a single number = the number .. leaving this + tmp(1,:) = mean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + [dtheta(ss,cc,nr), drad(ss,cc,nr)]= cart2pol(tmp(1),tmp(2)); + dtheta_poldeg(ss,cc,nr) = dtheta(ss,cc,nr).*360/(2*pi); + + end + + + + end +end + + +%% supp Figure 5 A : all subj scatter plot + +rho_theta = nan(length(cond),length(ROIs),length(delay_tpts)); +pval_theta = nan(length(cond),length(ROIs),length(delay_tpts)); + + +figure + + hold on; + + for vv = 1:length(ROIs) + for cc = 2 % 1:length(cond) + + for dd = 3 % 1:length(delay_tpts) + + thisb_neural_tmp =[]; + thisb_behav_tmp =[]; + thisb_behav = []; + thisb_neural = []; + thisb_behav_poldegtmp =[]; + thisb_behav_poldeg =[]; + + for ss = 1:length(subj) + thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); + + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + %subplot(1,length(ROIs),vv); + subplot(length(subj),length(ROIs),(ss-1)*length(ROIs)+vv); hold on; + %scatter(thisb_neural,thisb_behav_poldeg,30,dist_colors(cc,:),'filled','MarkerFaceAlpha',.4) + scatter(thisb_neural,thisb_behav_poldeg,30,'k') + title(ROIs{vv}) + h= lsline + set(h,'linewidth',2) + clear h + if vv==1 && ss ==7 + ylabel({'Polar angle \circ delta, target, sacc endpt', 'Epoch 3'}) + xlabel('Neural bias, Polar angle \circ') + + + % set(get(gcf,'Children'),'YLim',[-30 30],'ytick',-30:15:30,'yticklabel',{'-30','-15','0','15','30'},'xtick',-180:90:180,'xticklabel',{'-180','-90','0','90','180'}) + else + %set(get(gcf,'Children'),'YLim',[-30 30],'xtick',-180:90:180,'xticklabel',{'','','','',''}, 'yticklabel',{'','',''}) + end + [rho_theta(cc,vv,ss,dd), pval_theta(cc,vv,ss,dd)] = corr(thisb_neural', thisb_behav_poldeg'); + %set(get(gcf,'Children'),'XLim',[-180:180],'YLim',[-30 30],'xtick',-180:90:180) + % set(gca,'YLim',[-30 30],'xtick',-180:90:180) + set(get(gcf,'Children'),'XLim',[-180 180],'xtick',-180:90:180,'YLim',[-30 30]) + text(max(xlim)-(.8*max(xlim)),max(ylim)-(1.9*max(ylim)),sprintf('r = %.2f',rho_theta(cc,vv,ss,dd)),'FontSize',10) + clear this neural thisb_behav_poldeg this_behav_tmp this_neural_tmp l + end + end + + + end + + + + + end + set(gcf,'Position',[-196 184 2168 1103]) + + + + %% supp Figure 5B : all subj fisher-z transformed rho, all ROIs + +store_fish_ztheta= []; +% pval_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +% rho_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +% fish_z_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); + +pval_sg_theta = nan(length(cond),length(subj),length(ROIs),1); +rho_sg_theta = nan(length(cond),length(subj),length(ROIs),1); +fish_z_theta = nan(length(cond),length(subj),length(ROIs),1); + +figure +for cc = 2 %1:length(cond) + +for vv=1:length(ROIs) + + for dd = 3 %1:length(delay_tpts) + + for ss = 1:length(subj) + + thisb_neural_tmp = []; + thisb_behav_tmp = []; + thisb_neural = []; + thisb_behav = []; + thisb_behav_poldegtmp =[]; + thisb_behav_polradtmp =[]; + thisb_behav_poldeg =[]; + thisb_behav_polrad =[]; + + thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); + + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + + [rho_sg_theta(cc,ss,vv,dd), pval_sg_theta(cc,ss,vv,dd)] =corr(thisb_neural', thisb_behav_poldeg'); + + fish_z_theta(cc,ss,vv,dd) = atanh(rho_sg_theta(cc,ss,vv,dd)); % identical + store_fish_ztheta = [store_fish_ztheta; atanh(rho_sg_theta(cc,ss,vv,dd)) cc ss vv dd ]; + clear mysd + end + + + + hold on; + plot(vv+0.15,fish_z_theta(cc,:,vv,dd),'o','MarkerSize',5,'Color',[0.3 0.3 0.3]); + hold on; + my_sem_th = std(fish_z_theta(cc,:,vv,dd))/sqrt(length(subj)); + + plot(vv,mean(fish_z_theta(cc,:,vv,dd)), 'o', 'color','k','markersize',10) + plot(vv*[1 1],[mean(fish_z_theta(cc,:,vv,dd))+1.*my_sem_th, mean(fish_z_theta(cc,:,vv,dd))-1.*my_sem_th], '-', 'color','k','linewidth',2) + xlim([0.05 12.5]) + line([0 12.5], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') % geh add y =0 baseline + set(gca,'Xtick',[1 2 3 4 5 6 7 8 9 10 11],'Xticklabel',{'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'},'XTickLabelRotation',45,'TickDir','out'); % + ylabel('Memory Error & Decoded WM Position Correlation (Z)') + + set(gcf,'position',[ 549 724 499 571]) + + + [h_th,p_th(cc,vv,dd),~,stats_th] = ttest(fish_z_theta(cc,:,vv,dd)); + realT_th(cc,vv,dd) = stats_th.tstat; + + end + +end +end + + +%% STATS + +y_var = store_fish_ztheta(:,1); +cond_var = store_fish_ztheta(:,2); %condition +subj_var = store_fish_ztheta(:,3); %subject +roi_var = store_fish_ztheta(:,4); %roi +epoch_var = store_fish_ztheta(:,5); %epoch + +% perform real T test + + for vv =1:length(ROIs) + for cc =1:length(cond) + for dd = 1:3 + thisidx = roi_var ==vv & cond_var ==cc & epoch_var == dd; + y_shuf =y_var(thisidx); %these are already shuffled, see above + [~,~,~,stats] = ttest(y_shuf); + real_t(vv,cc,dd) = stats.tstat; + + clear thisidx y_shuf + end + end + end + +% perform true 1-way anova +f_real_one = []; +p_real_one = []; + + +y = y_var; +thissubj = subj_var; +thisroi = roi_var; +[f_real_one, pval_real_one] = RMAOV1_gh([y,thisroi,thissubj],0.05); +clear thisroiidx y thiscond thissubj thisepoch + + +%%%%%%%%%%%%%%%%%%%%%%%%% PERM TEST # 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% we're permuting two measures here, linear bias and ciruclar bias, open +iter = 1000; +t_iter =cell(length(ROIs),iter); +p_iter =cell(length(ROIs),iter); +f_store_iter_2 = nan(length(ROIs),iter,3); +fish_zthstore_perm =[]; +fish_zthperm = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +shuff_Tth =nan(length(cond),length(ROIs),length(delay_tpts),iter); +rho_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +pval_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); + + +for xx = 1:iter + + if xx == 1 + fprintf('starting @ %s \n',datestr(now,'HH:MM:SS')) + tic + elseif xx == 2 + toc + elseif xx == 3 + toc + elseif xx == iter/4 + fprintf('quarter-way ...\n') + toc + elseif xx == iter/2 + fprintf('halfway ...\n') + toc + else + end + + for cc = 2 %1:length(cond) + for vv=1:length(ROIs) + + for dd = 3 %1:length(delay_tpts) + + for ss = 1:length(subj) + thisb_neural_tmp_perm = []; + thisb_behav_tmp_perm = []; + thisb_behav_perm = []; + thisb_neural_perm = []; + thisb_behav_poldegtmp = []; + thisb_behav_poldegperm = []; + thisb_neural_poldegperm = []; + shuff_btheta =[]; + shuff_ntheta =[]; + + + thisb_neural_tmp_perm (1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp_perm (1,:)= squeeze(mu(2,ss,cc,:))'; + + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); %this obv cant change across ROI, delay, lose two dimens (vv,dd) here + + + thisb_behav_poldegperm = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp_perm)); + + thisb_neural_poldegperm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm)); + + % do the shuffle + shuff_btheta = thisb_behav_poldegperm; %reload these each time + shuff_ntheta = thisb_neural_poldegperm; + subjidxth = find(shuff_btheta); + shuff_bidxth = randperm(length(subjidxth))'; + shuff_btheta(subjidxth) = shuff_btheta(shuff_bidxth); %insert shuffled subj indices into bdata (note : in this case, bdata is ONLY this subj. just jumbling idx) + + bthdata = shuff_btheta(subjidxth); + nthdata = shuff_ntheta(subjidxth); + + [rho_permth(cc,ss,vv,dd,xx), pval_permth(cc,ss,vv,dd,xx)] = corr(nthdata',bthdata'); + fish_zthperm(cc,ss,vv,dd,xx) = atanh(rho_permth(cc,ss,vv,dd,xx)); + + + fish_zthstore_perm =[fish_zthstore_perm; fish_zthperm(cc,ss,vv,dd,xx) cc ss vv dd xx]; + + + clear thisidx subjidxth shuff_bidxth shuff_btheta shuff_ntheta bthdata nthdata + end + + [h,p,~,statsth] = ttest(fish_zthperm(cc,:,vv,dd,xx)); + shuff_Tth(cc,vv,dd,xx) = statsth.tstat; + + end + end + end +end + + + +% collect original perm pvalues + +p_th_twotail =nan(length(cond),length(ROIs),length(delay_tpts)); +p_th_onetail =nan(length(cond),length(ROIs),length(delay_tpts)); + +pfdr_th_twotail =[]; +pmask_th_twotail =[]; +pmask_th_onetail =[]; +pfdr_th_onetail =[]; + + + + +tdistpolbias = figure('Name','tdistpolbias'); + +realT_col = lines(3); +for cc =1:length(cond) + for dd = 1:length(delay_tpts) + for vr = 1:length(ROIs) + + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_Tth(cc,vr,dd,:))) + line([realT_th(cc,vr,dd) realT_th(cc,vr,dd)], [0 max(ylim)],'LineWidth',0.75,'color',realT_col(dd,:)) + p_th_twotail(cc,vr,dd) = 2 * min ( mean( shuff_Tth(cc,vr,dd,:) <= realT_th(cc,vr,dd) ), mean ( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd))); + p_th_onetail(cc,vr,dd) = mean( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd) ); + title(ROIs{vr}) + end + + [pfdr_th_twptail(cc,:,dd), pmask_th_twotail(cc,:,dd)] = fdr(p_th_twotail(cc,:,dd),0.05); % this is two tail + [pfdr_th_onetail(cc,:,dd), pmask_th_onetail(cc,:,dd)] = fdr(p_th_onetail(cc,:,dd),0.05); %one tail + + + end + +end + +% stats table +ta = table(ROIs',p_th_onetail(2,:,3)'); %specifically collecting the epoch, condition, ROI we are concerned with +ta.Properties.VariableNames={'ROIs','Dist_POST'} + +% do 1-way ANOVA permutation with collected permuted correlations +y_var = fish_zthstore_perm(:,1); +cond_var = fish_zthstore_perm(:,2); +subj_var = fish_zthstore_perm(:,3); +roi_var = fish_zthstore_perm(:,4); +epoch_var = fish_zthstore_perm(:,5); +iter_var = fish_zthstore_perm(:,6); + + +% one-way anova perm +for zz =1:iter + + + thisidx = iter_var == zz; + y_shuf = y_var(thisidx); %these are already shuffled, see above + thisroi = roi_var(thisidx); + thissubj = subj_var(thisidx); + + [f_store_iter_1(zz,:)] = RMAOV1_gh([y_shuf,thisroi,thissubj],0.05); + clear thisroiidx thisepoch thiscond thissubj y_shuf + +end + + +% visualize 1-way result + +iv_str_rm ={'epoch'}; +which_effect_rm = 1; +exact_store_tmp = []; +exact_store_rm_1 =nan(length(ROIs),length(which_effect_rm)); + + figure('name','1-way perm; RMAOV1') +for cc = 2 %1:length(cond) + + extract_vals= []; + for ii= 1:iter + extract_vals = [extract_vals; f_store_iter_1(ii)]; + end + + + subplot(1,2,cc) + hold on; + histogram(extract_vals) + line([f_real_one f_real_one], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str_rm{which_effect_rm(1)},'Interpreter','none'); + exact_p = sum(extract_vals >= f_real_one(which_effect_rm(1)))/iter; + + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) + exact_store_rm_1 = [exact_store_tmp; exact_p]; + clear exact_p + title(iv_str_rm{1}) + xlabel('T-stat') + ylabel('Frequency of T-stat') + + +end + + + + +fprintf('done') + +fn2s = sprintf('%s/%s_corr/neurbehcorr_concatROIs_fsacc_%iiterperm_%s.mat',root,task_dir,iter,datestr(now,'mmddyyyyHHMM')); +save(fn2s); +fprintf('saving to %s...\n',fn2s); +end + diff --git a/spDist_neural_behav_corr.m b/spDist_neural_behav_corr.m new file mode 100644 index 0000000..56924a9 --- /dev/null +++ b/spDist_neural_behav_corr.m @@ -0,0 +1,496 @@ + +function spDist_neural_behav_corr(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'CC','KD','AY','MR','XL','SF','EK'}; + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1','V2','V3','V3AB','hV4','VO1','VO2','LO1','LO2','TO1','TO2','IPS0','IPS1','IPS2','IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + + + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + + +%% load neural data +startidx = 1; + +WHICH_EXCL = [13 20 22]; +all_data_beh = []; +all_subj_b=[]; + +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + + %%%inserting + for sessidx = 1:length(sess{ss}) + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + %fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + this_data.s_all = this_scored.ii_sess; + this_data.sess_all = sessidx; + all_data_beh= cat_struct(all_data_beh,this_data); + %all_subj_b(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = ss; + %all_r_b(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1)),1) = (this_data.sess_all*100+this_data.s_all.r_num); + + end + %%%% + + + startidx = thisidx(end)+1; + + clear data; + + end + +end +all_data_beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_beh.s_all.excl_trial, 'UniformOutput',false)); + +%% behav import +% subj = {'CC','KD','AY','MR','XL','SF','EK'}; +% sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed +% +% +% WHICH_EXCL = [13 20 22]; +% if ismember(WHICH_EXCL,13) +% which_excl_str ={'broken fix'}; +% elseif ismember(WHICH_EXCL,[13 20]) +% which_excl_str ={'broken fix','no sacc'}; +% elseif ismember(WHICH_EXCL, [13 20 21]) +% which_excl_str ={'broken fix','no sacc','i sacc too small/short'}; +% elseif ismember(WHICH_EXCL, [13 20 22]) +% which_excl_str ={'broken fix','no sacc','i sacc err too lg'}; +% elseif ismember(WHICH_EXCL, [13 20 21 22]) +% which_excl_str ={'broken fix','no sacc','i sacc too small/short','i sacc err too lg'}; +% else +% error('which exclusion criteria have you chosen?') +% end +% +% % first-digit: +% % - 1 - trial-level exclusion (bad drift correction [11], calibration [12], or delay- +% % fixation break [13] +% % - 2 - primary saccade exclusion (no primary sacc [20]; too small/short [21] bi, large error [22]ei) +% +% %21 bad initial saccade (duration/amplitude outside range) +% % 22 iniital saccade error +% +% +% % concatenate ALL subject data +% all_subj_b = nan(1000*length(subj),1); +% +% all_data_b = []; +% all_data_bn =[]; +% startidx = 1; +% bnidx =1; +% for ss = 1:length(subj) +% for sessidx = 1:length(sess{ss}) +% +% +% fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); +% fprintf('Loading scored eye data from %s\n',fn); +% this_scored = load(fn); +% +% this_data.s_all = this_scored.ii_sess; +% this_data.sess_all = sessidx; +% +% this_subj = ss; +% +% all_data_b = cat_struct(all_data_b,this_data); +% all_subj_b(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = this_subj; +% all_r_b(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1)),1) = (this_data.sess_all*100+this_data.s_all.r_num); +% +% %all_data_bn is only used wrt to collecting indices on neural data +% %keeps track of which trials were thrown out for various reasons, +% %duplicated per looping subj from ROI +% all_data_bn(bnidx:(bnidx-1+(size(this_scored.ii_sess.trialinfo,1)*length(ROIs))),1) = repmat( ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), this_data.s_all.excl_trial, 'UniformOutput',false) ), length(ROIs),1); +% +% bnidx = bnidx + size(this_scored.ii_sess.trialinfo,1)*length(ROIs); +% startidx = startidx+size(this_scored.ii_sess.trialinfo,1); +% clear this_subj this_data; +% end +% end +% +% +% all_subj_b = all_subj_b(1:(startidx-1)); +% all_data_b.subj_all = all_subj_b; +% +% % determine which trials to include +% % first, narrow based on saccade preprocessing/scoring exclusions +% all_data_b.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_b.s_all.excl_trial, 'UniformOutput',false)); +% all_data_b.use_trial(all_data_b.s_all.f_sacc_err>8) = 0; %exclude trials with errors > 10 deg +% all_data_b.use_trial(all_data_b.s_all.i_sacc_err>8) = 0; +% %all_data_b.use_trial(ismember(all_data_b.s_all.r_num, [8,12,14]) & all_subj_b==3) = 0; %3 here specifically refers to subj 3 above (AY), see spDist_eyeDataNotes for +% % drop trials with very short (< 100 ms) or very long RT (> 1 s) +% %all_data_b.use_trial(all_data_b.s_all.i_sacc_rt<0.1 | all_data_b.s_all.i_sacc_rt>1.0) = 0; + + + +%% align like distractor bins (and flip/average) 1D near only +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly +% new code +% flip negative angles + + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this matches all_conds(:,6) (relative distractor angle bin) + +flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +all_recons_flipped(flipidx,:) = fliplr(all_recons_flipped(flipidx,:)); + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj),36); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); + + +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + for nr =1:nruns + + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss,nr) = thisb(ss); + end + end + + + end + clear thisidx + clear thisb + clear thisd +end + + + + +%% organize beh data + +% % which param should we collect? +% params_of_interest = {'f_sacc'}; +% param_str = {'f sacc'}; +% +% mu = nan(2,length(subj),36); % no subj performed > 36 runs +% err = nan(2,length(subj),36); +% +% for ss = 1:length(subj) +% +% nruns = 0; +% +% % get one example set of trials +% ru = unique(all_r_b(all_subj_b==ss)); +% +% % figure out how many runs we have for that subj, add to total +% nruns = nruns+length(ru); +% for nr = 1:nruns +% %%%%%%% NOT EXCLUDING ON BASIS OF USE_TRIAL %%%%%%%%%% +% tmpidx = all_r_b==ru(nr) & all_subj_b==ss & all_data_b.s_all.trialinfo(:,1)==2 & all_data_b.s_all.trialinfo(:,6)==0 & all_data_b.s_all.trialinfo(:,10) < 0; %negative CW jitter +% orig_y = all_data_b.s_all.(params_of_interest{1})(tmpidx,2); +% +% if isempty(orig_y) +% thisorigidx = all_r_b==ru(nr) & all_subj_b==ss & all_data_b.s_all.trialinfo(:,1)==2 & all_data_b.s_all.trialinfo(:,6)==0; % skip trying to flip anything if the zero bin trial in this run is not < 0 jitter +% % if isempty(thisorigidx) %what if the zero bin trial is unusable? +% % err(1,ss,nr) = nan; +% % mu(:,ss,nr) = nan; +% % else +% err(1,ss,nr) = nanstd(all_data_b.s_all.(params_of_interest{1})(thisorigidx,2)); +% mu(:,ss,nr) = nanmean( all_data_b.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); +% %end +% else +% orig_y_flip = orig_y*-1; % in this run, the zero trial was usuable, and jitter <0, and we flipped it +% all_data_b.s_all.(params_of_interest{1})(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins. +% thisorigidx = all_r_b==ru(nr) & all_subj_b==ss & all_data_b.s_all.trialinfo(:,1)==2 & all_data_b.s_all.trialinfo(:,6)==0; %now, collect all jitters. +% err(1,ss,nr) = nanstd(all_data_b.s_all.(params_of_interest{1})(thisorigidx,2)); %lets just take the y-component here. cant STD over 1 number +% mu(:,ss,nr) = nanmean( all_data_b.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); +% end +% +% end +% +% end +% +% +% % squeeze over subj, collect each subj, all trials into one container +% pval_group=[]; +% rho_group =[]; +% +% figure ; +% for vv=1:length(ROIs) +% thisb_neural_tmp =[]; +% thisb_behav_tmp =[]; +% for ss = 1:length(subj) +% +% thisb_neural_tmp(ss,:) = squeeze(store_b(1,vv,ss,:)); +% thisb_behav_tmp(ss,:)= squeeze(mu(2,ss,:))'; +% end +% +% thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); %exclude outliers +% thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); %use if no exclu +% +% subplot(1,length(ROIs),vv); hold on; +% scatter(thisb_neural,thisb_behav,30,'filled','MarkerFaceAlpha',.3) +% +% h = lsline; +% h.LineWidth =2; +% if vv==1 +% xlabel('Polar angle \circ, Neural bias') +% ylabel('DVA, saccadic tangential mean error') +% set(gca,'Xtick',[-180:90:180],'xticklabel',{'180','90','0','90','180'},'xticklabelrotation',45,'TickDir','out') +% +% else +% set(gca,'Xtick',[-180:90:180],'xticklabel',{'','','','',''},'TickDir','out') +% +% +% end +% title(ROIs{vv}) +% [rho_group(vv), pval_group(vv)] =corr(thisb_neural, thisb_behav); +% clear thisb_neural thisb_behav h +% %end +% +% end +% +% set(gcf,'Position',[15 1052 2542 286]) +% [pfdr(:) pmask(:)]= fdr(pval_group(:),0.05); +% +% all_trials = table(ROIs',rho_group', pval_group',pmask'); +% all_trials.Properties.VariableNames={'ROIs', 'rho', 'pval','surviveFDR'} +% +% +% +% fprintf('done') +%% organize beh data + +% which param should we collect? +params_of_interest = {'f_sacc'}; +param_str = {'f sacc'}; + +mu = nan(2,length(subj),36); % no subj performed > 36 runs +err = nan(2,length(subj),36); + +for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + + for nr = 1:nruns + %%%%%%% NOT EXCLUDING ON BASIS OF USE_TRIAL %%%%%%%%%% + tmpidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0 & all_data_beh.s_all.trialinfo(:,10) < 0; %negative CW jitter + % + orig_y = all_data_beh.s_all.(params_of_interest{1})(tmpidx,2); + + % if isempty(orig_y) + %if isempty(thisorigidx) %what if the zero bin trial is unusable? + % err(1,ss,nr) = nan; + % mu(:,ss,nr) = nan; + % else + % err(1,ss,nr) = nanstd(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,2)); + % mu(:,ss,nr) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + % end + % else + orig_y_flip = orig_y*-1; % in this run, the zero trial was usuable, and jitter <0, and we flipped it + all_data_beh.s_all.(params_of_interest{1})(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins. + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; %now, collect all jitters. + err(1,ss,nr) = nanstd(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,2)); %lets just take the y-component here. cant STD over 1 number + mu(:,ss,nr) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + end + + + +end + + + % squeeze over subj, collect each subj, all trials into one container + pval_group=[]; + rho_group =[]; + + figure ; + for vv=1:length(ROIs) + thisb_neural_tmp =[]; + thisb_behav_tmp =[]; + for ss = 1:length(subj) + + thisb_neural_tmp(ss,:) = squeeze(store_b(1,vv,ss,:)); + thisb_behav_tmp(ss,:)= squeeze(mu(2,ss,:))'; + end + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); %exclude outliers + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); %use if no exclu + + subplot(1,length(ROIs),vv); hold on; + scatter(thisb_neural,thisb_behav,30,'filled','MarkerFaceAlpha',.3) + + h = lsline; + h.LineWidth =2; + if vv==1 + xlabel('Polar angle \circ, Neural bias') + ylabel('DVA, saccadic tangential mean error') + set(gca,'Xtick',[-180:90:180],'xticklabel',{'180','90','0','90','180'},'xticklabelrotation',45,'TickDir','out') + + else + set(gca,'Xtick',[-180:90:180],'xticklabel',{'','','','',''},'TickDir','out') + + + end + title(ROIs{vv}) + [rho_group(vv), pval_group(vv)] =corr(thisb_neural, thisb_behav); + clear thisb_neural thisb_behav h + %end + + end + + set(gcf,'Position',[15 1052 2542 286]) + [pfdr(:) pmask(:)]= fdr(pval_group(:),0.05); + + all_trials = table(ROIs',rho_group', pval_group',pmask'); + all_trials.Properties.VariableNames={'ROIs', 'rho', 'pval','surviveFDR'} + + + + fprintf('done') + + +end + + + + + + + + diff --git a/spDist_neural_behav_corr_exclutri_individperm_noflipth.m b/spDist_neural_behav_corr_exclutri_individperm_noflipth.m new file mode 100644 index 0000000..8852cf4 --- /dev/null +++ b/spDist_neural_behav_corr_exclutri_individperm_noflipth.m @@ -0,0 +1,651 @@ +function spDist_neural_behav_corr_exclutri_individperm_noflipth(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'CC','KD','AY','MR','XL','SF','EK'}; + % subj = {'AY','CC','EK','KD','MR','SF','XL'}; %alph + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + %ROIs = {'V1V2V3','V3AB','IPS0IPS1','IPS2IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +% seed random number generator: +rng(spDist_randSeed); + +%% load neural data +startidx = 1; +bidx =1; +WHICH_EXCL = [13 20 21 22]; +all_data_beh = []; +all_subj_beh=[]; + +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + + %%%inserting + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + %fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + this_data.s_all = this_scored.ii_sess; + + thisbidx = bidx:(bidx+size(this_scored.ii_sess.trialinfo,1)-1); + + this_data.sess_all = sessidx; + all_data_beh= cat_struct(all_data_beh,this_data); + all_subj_beh(thisbidx,1) = ss; + + bidx =thisbidx(end)+1; + end + + startidx = thisidx(end)+1; + + clear data; + + end + +end +all_data_beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_beh.s_all.excl_trial, 'UniformOutput',false)); +fprintf('neural and behave loaded...\n') + +% visualize all_data_beh.use_trial, make sure the pattern repeats exactly +% across all ROIs +% for ss=1:length(subj) +% figure +% for vv = 1:length(ROIs) +% hold on; +% thisidx = all_subj==ss & all_ROIs ==vv; +% myd = all_data_beh.use_trial(thisidx); +% subplot(1,length(ROIs),vv) +% imagesc(myd) +% clear myd thisidx +% end +% end +% + + +%% load recons, no flipping + +all_recons_noflip = all_recons{1}; + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i\n', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot = [0]; % just one, zero bin +store_b = nan(length(cond_to_plot),length(ROIs),length(subj),36); + + +figure; + +for ff = 1:length(cond_to_plot) + thisd = nan(length(ROIs),length(subj),36, length(angs)); + + thisb = nan(1,length(subj)); + for vv = 1:length(ROIs) + + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + for nr =1:nruns + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; + + %thisidx = all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; + + thisd(vv,ss,nr,:) = squeeze(mean(mean(all_recons_noflip(thisidx,:,tpts_to_plot),1),3)); + + thisb(ss) = atan2d(sum(mean(mean(all_recons_noflip(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_noflip(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + + store_b(ff,vv,ss,nr) = thisb(ss); + + end + end + + + end + clear thisidx + clear thisb + clear thisd +end + +fprintf('neural bias computed ...\n') +%% organize beh data + +% which param should we collect? + +params_of_interest = {'f_sacc'}; +param_str = {'f sacc'}; + +mu = nan(2,length(subj),36); % no subj performed > 36 runs +err = nan(2,length(subj),36); +dtheta = nan(length(subj),36); +drad = nan(length(subj),36); +dtheta_poldeg = nan(length(subj),36); + + +for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + + for nr = 1:nruns + + % thisorigidx = all_ROIs ==1 & all_r==ru(nr) & all_subj_beh==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; %now, collect all jitters. + + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; + + err(1,ss,nr) = nanstd(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,2)); + mu(:,ss,nr) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); %mean of a single number = the number .. leaving this + tmp(1,:) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + [dtheta(ss,nr), drad(ss,nr)]= cart2pol(tmp(1),tmp(2)); + dtheta_poldeg(ss,nr) = dtheta(ss,nr).*360/(2*pi); + + end + + + +end + + +% squeeze over subj, collect each subj, all trials into one container +rho_group = nan(length(ROIs),1); +rho_group_theta = nan(length(ROIs),1); +pval_group = nan(length(ROIs),1); +pval_group_theta = nan(length(ROIs),1); + +bn_corr = figure('Name','behneurcorr'); + +bn_corr_theta = figure('Name','behneurcorrtheta'); + +bn_corr_theta2sd = figure('Name','behneurcorrtheta2sd'); + +for vv=1:length(ROIs) + + thisb_neural_tmp =[]; + thisb_behav_tmp =[]; + thisb_behav = []; + thisb_neural = []; + thisb_behav_poldegtmp =[]; + thisb_behav_polradtmp =[]; + thisb_behav_poldeg =[]; + % thisb_behav_polrad =[]; + + for ss = 1:length(subj) + thisb_neural_tmp(ss,:) = squeeze(store_b(1,vv,ss,:)); + thisb_behav_tmp(ss,:)= squeeze(mu(2,ss,:))'; + thisb_behav_poldegtmp(ss,:)= dtheta_poldeg(ss,:); + % thisb_behav_polradtmp(ss,:)= dtheta(ss,:); + end + %thisidx = ~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8; +% +% thisb_behavt = thisb_behav_tmp(thisidx); %exclude outliers +% thisb_neuralt = thisb_neural_tmp(thisidx); %use if no exclu +% thisb_behav_poldegt = thisb_behav_poldegtmp(thisidx); +% thisb_behav_polradt = thisb_behav_polradtmp(thisidx); + +% % thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); %exclude outliers +% % thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); %use if no exclu +% % thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); +% % thisb_behav_polrad = thisb_behav_polradtmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); %exclude outliers + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); %use if no exclu + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + + mysd = std(thisb_behav_poldeg); + thisb_behav_poldeg2sd = thisb_behav_poldegtmp( ~isnan(thisb_behav_tmp) & abs(thisb_behav_poldegtmp) <= 2 * mysd); + thisb_neural_poldeg2sd = thisb_neural_tmp( ~isnan(thisb_behav_tmp) & abs(thisb_behav_poldegtmp) <= 2 * mysd); + + [rho_group_theta2sd(vv), pval_group_theta2sd(vv)] =corr(thisb_neural_poldeg2sd, thisb_behav_poldeg2sd); + fish_z_theta2sd(vv) = atanh(rho_group_theta2sd(vv)); + + + set(0, 'CurrentFigure', bn_corr_theta2sd) + subplot(1,length(ROIs),vv); + scatter(thisb_neural_poldeg2sd, thisb_behav_poldeg2sd ,30,'filled','MarkerFaceAlpha',.3) + h = lsline; + h.LineWidth =2; + [rho_group(vv), pval_group(vv)] = corr(thisb_neural, thisb_behav); + set(gcf,'Position',[15 1052 2542 286]) + if vv==1 + ylabel('DVA, sacc endpt') + xlabel('Neural bias, Polar angle \circ') + else + end + + + + set(0, 'CurrentFigure', bn_corr) + subplot(1,length(ROIs),vv); + scatter(thisb_neural,thisb_behav,30,'filled','MarkerFaceAlpha',.3) + h = lsline; + h.LineWidth =2; + [rho_group(vv), pval_group(vv)] = corr(thisb_neural, thisb_behav); + set(gcf,'Position',[15 1052 2542 286]) + if vv==1 + ylabel('DVA, sacc endpt') + xlabel('Neural bias, Polar angle \circ') + else + end + + set(0, 'CurrentFigure', bn_corr_theta) + subplot(1,length(ROIs),vv); + scatter(thisb_neural,thisb_behav_poldeg,30,'filled','MarkerFaceAlpha',.3) + h = lsline; + h.LineWidth =2; + title(ROIs{vv}) + set(gcf,'Position',[15 1052 2542 286]) + if vv==1 + ylabel('Polar angle \circ delta, target, sacc endpt') + xlabel('Neural bias, Polar angle \circ') + else + end + [rho_group_theta(vv), pval_group_theta(vv)] = corr(thisb_neural, thisb_behav_poldeg); + + +end +grouprho = figure('Name','grouprho'); +plot(rho_group,'-') +hold on; +plot(rho_group_theta,'--') +legend('rho,linear', 'rho,polar') + +%% corr on individual subj, convert to z, t-test + +fish_fig = figure('Name','fish'); + +fish_theta_fig = figure('Name','fish_theta'); + +subjrho = figure('Name','subjrho'); + +pval_sg = nan(length(subj),length(ROIs)); +rho_sg = nan(length(subj),length(ROIs)); +fish_z = nan(length(subj),length(ROIs)); +pval_sg_theta = nan(length(subj),length(ROIs)); +rho_sg_theta = nan(length(subj),length(ROIs)); +fish_z_theta = nan(length(subj),length(ROIs)); + +for vv=1:length(ROIs) + + for ss = 1:length(subj) + thisb_neural_tmp = []; + thisb_behav_tmp = []; + thisb_neural = []; + thisb_behav = []; + thisb_behav_poldegtmp =[]; + thisb_behav_polradtmp =[]; + thisb_behav_poldeg =[]; + thisb_behav_polrad =[]; + + thisb_neural_tmp(1,:) = squeeze(store_b(1,vv,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,:); +% +% thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); %exclude outliers +% thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); %use if no exclu +% +% thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp) & thisb_behav_tmp > -8 & thisb_behav_tmp < 8); +% +% + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); %exclude outliers + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); %use if no exclu + + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + + mysd = std(thisb_behav_poldeg); + thisb_behav_poldeg2sd = thisb_behav_poldegtmp( ~isnan(thisb_behav_tmp) & abs(thisb_behav_poldegtmp) <= 2 * mysd); + thisb_neural_poldeg2sd = thisb_neural_tmp( ~isnan(thisb_behav_tmp) & abs(thisb_behav_poldegtmp) <= 2 * mysd); + + [rho_sg_theta2sd(ss,vv), pval_sg_theta2sd(ss,vv)] =corr(thisb_neural_poldeg2sd', thisb_behav_poldeg2sd'); + fish_z_theta2sd(ss,vv) = atanh(rho_sg_theta2sd(ss,vv)); + + + [rho_sg(ss,vv), pval_sg(ss,vv)] = corr(thisb_neural', thisb_behav'); + + fish_z(ss,vv) = atanh(rho_sg(ss,vv)); + + [rho_sg_theta(ss,vv), pval_sg_theta(ss,vv)] =corr(thisb_neural', thisb_behav_poldeg'); + + fish_z_theta(ss,vv) = atanh(rho_sg_theta(ss,vv)); % identical + + clear mysd + end + + set(0, 'CurrentFigure', fish_fig) + subplot(1,length(ROIs),vv) + plot(1,fish_z(:,vv),'bo','markerfacecolor','b','markersize',5) + hold on; + my_sem = std(fish_z(:,vv))/sqrt(length(subj)); + ylim([-.4 .7]) + errorbar(1,mean(fish_z(:,vv)),my_sem,'ko','markerfacecolor','k','markersize',10) + title(ROIs{vv}) + + [h,p(vv),~,stats] = ttest(fish_z(:,vv)); + realT(vv) = stats.tstat; + ylabel('Fisher-Z') + + set(0, 'CurrentFigure', fish_theta_fig) + subplot(1,length(ROIs),vv) + plot(1,fish_z_theta(:,vv),'bo','markerfacecolor','b','markersize',5) + hold on; + my_sem_th = std(fish_z_theta(:,vv))/sqrt(length(subj)); + errorbar(1,mean(fish_z_theta(:,vv)),my_sem_th,'ko','markerfacecolor','k','markersize',10) + title(ROIs{vv}) + ylim([-.4 .7]) + [h_th,p_th(vv),~,stats_th] = ttest(fish_z_theta(:,vv)); + realT_th(vv) = stats_th.tstat; + + + set(0, 'CurrentFigure', subjrho) + subplot(1,length(ROIs),vv) + plot(1:7,rho_sg(:,vv),'-') + hold on; + plot(1:7,rho_sg_theta(:,vv),'--') + if vv== length(ROIs) + legend('rho,linear', 'rho,polar') + else + end + + + +end + + +%%%%%%%%%%%%%%%%%%%%%%%%% PERM TEST %%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% we're permuting two measures here, linear bias and ciruclar bias, open +% all variables up front +iter = 10000; +fish_zperm = nan(length(subj),length(ROIs),iter); +fish_zthperm = nan(length(subj),length(ROIs),iter); +shuff_T =nan(length(ROIs),iter); +shuff_Tth =nan(length(ROIs),iter); +rho_perm = nan(length(subj),length(ROIs),iter); +pval_perm = nan(length(subj),length(ROIs),iter); +rho_permth = nan(length(subj),length(ROIs),iter); +pval_permth = nan(length(subj),length(ROIs),iter); + + +for xx = 1:iter + + if xx == 1 + fprintf('doing shuffle ...\n') + tic + elseif xx == iter/2 + fprintf('halfway ...\n') + toc + else + end + + for vv=1:length(ROIs) + + for ss = 1:length(subj) + thisb_neural_tmp_perm = []; + thisb_behav_tmp_perm = []; + thisb_behav_perm = []; + thisb_neural_perm = []; + shuff_bdata = []; + shuff_ndata = []; + thisb_behav_poldegtmp =[]; + thisb_behav_poldegperm =[]; + thisb_neural_poldegperm =[]; + shuff_btheta =[]; + shuff_ntheta =[]; + + + thisb_neural_tmp_perm (1,:) = squeeze(store_b(1,vv,ss,:)); + thisb_behav_tmp_perm (1,:)= squeeze(mu(2,ss,:))'; + + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,:); + %thisb_behav_polradtmp(1,:)= dtheta(ss,:); + +% thisb_behav_perm = thisb_behav_tmp_perm (~isnan(thisb_behav_tmp_perm) & thisb_behav_tmp_perm > -8 & thisb_behav_tmp_perm < 8); %exclude outliers +% thisb_neural_perm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm) & thisb_behav_tmp_perm > -8 & thisb_behav_tmp_perm < 8); %use if no exclu +% +% thisb_behav_poldegperm = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp_perm) & thisb_behav_tmp_perm > -8 & thisb_behav_tmp_perm < 8); +% thisb_neural_poldegperm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm) & thisb_behav_tmp_perm > -8 & thisb_behav_tmp_perm < 8); + + + thisb_behav_perm = thisb_behav_tmp_perm (~isnan(thisb_behav_tmp_perm) ); %exclude outliers + thisb_neural_perm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm)); %use if no exclu + + thisb_behav_poldegperm = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp_perm)); + + + + %thisb_behav_poldegperm = thisb_behav_poldegtmp(~isnan(thisb_behav_poldegtmp)); + % thisb_neural_poldegperm = thisb_neural_tmp_perm(~isnan(thisb_behav_poldegtmp)); + thisb_neural_poldegperm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm)); + + % do the shuffle + + shuff_bdata = thisb_behav_perm; %reload these each time + shuff_ndata = thisb_neural_perm; + subjidx = find(shuff_bdata); + shuff_bidx = randperm(length(subjidx))'; + shuff_bdata(subjidx) = shuff_bdata(shuff_bidx); %insert shuffled subj indices into bdata (note : in this case, bdata is ONLY this subj. just jumbling idx) + + bdata = shuff_bdata(subjidx); + ndata = shuff_ndata(subjidx); + + [rho_perm(ss,vv,xx), pval_perm(ss,vv,xx)] = corr(ndata',bdata'); %1st output is RHO, 2nd is pval + fish_zperm(ss,vv,xx) = atanh(rho_perm(ss,vv,xx)); + + shuff_btheta = thisb_behav_poldegperm; %reload these each time + shuff_ntheta = thisb_neural_poldegperm; + subjidxth = find(shuff_btheta); + shuff_bidxth = randperm(length(subjidxth))'; + shuff_btheta(subjidxth) = shuff_btheta(shuff_bidxth); %insert shuffled subj indices into bdata (note : in this case, bdata is ONLY this subj. just jumbling idx) + + bthdata = shuff_btheta(subjidxth); + nthdata = shuff_ntheta(subjidxth); + + [rho_permth(ss,vv,xx), pval_permth(ss,vv,xx)] = corr(nthdata',bthdata'); + fish_zthperm(ss,vv,xx) = atanh(rho_permth(ss,vv,xx)); + + clear thisidx subjidx shuff_bidx shuff_nidx shuff_bdata shuff_ndata bdata ndata subjidxth shuff_bidxth shuff_btheta shuff_ntheta bthdata nthdata + end + + [h,p,~,statsz] = ttest(fish_zperm(:,vv,xx)); + shuff_T(vv,xx) = statsz.tstat; + + [h,p,~,statsth] = ttest(fish_zthperm(:,vv,xx)); + shuff_Tth(vv,xx) = statsth.tstat; + + end +end + +p_twotail =nan(length(ROIs),1); +p_onetail =nan(length(ROIs),1); +p_th_twotail =nan(length(ROIs),1); +p_th_onetail =nan(length(ROIs),1); +pmask_twotail = []; +pfdr_twotail = []; +pfdr_onetail = []; +pmask_onetail = []; +pfdr_th_twotail =[]; +pmask_th_twotail =[]; +pmask_th_onetail =[]; +pfdr_th_onetail =[]; + +tdistlinbias = figure('Name','tdistlinbias'); +for vr = 1:length(ROIs) + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_T)) + line([realT(vr) realT(vr)], [0 max(ylim)],'LineWidth',0.75,'color','r') + p_twotail(vr) = 2 * min ( mean( shuff_T(vr,:) <= realT(vr) ), mean ( shuff_T(vr,:) >= realT(vr))); + p_onetail(vr) = mean( shuff_T(vr,:) >= realT(vr) ); + title(ROIs{vr}) +end + + +[pfdr_twotail, pmask_twotail] = fdr(p_twotail(:),0.05); +[pfdr_onetail, pmask_onetail] = fdr(p_onetail(:),0.05); + + +tdistpolbias = figure('Name','tdistpolbias'); +for vr = 1:length(ROIs) + + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_Tth)) + line([realT_th(vr) realT_th(vr)], [0 max(ylim)],'LineWidth',0.75,'color','r') + p_th_twotail(vr) = 2 * min ( mean( shuff_Tth(vr,:) <= realT_th(vr) ), mean ( shuff_Tth(vr,:) >= realT_th(vr))); + p_th_onetail(vr) = mean( shuff_Tth(vr,:) >= realT_th(vr) ); + title(ROIs{vr}) +end + + +[pfdr_th_twotail, pmask_th_twotail] = fdr(p_th_twotail(:),0.05); +[pfdr_th_onetail, pmask_th_onetail] = fdr(p_th_onetail(:),0.05); + +% one last plot, t-dists overlaid + +tdistlinpolbias = figure('Name','tdistlinpolbias'); + +for vr = 1:length(ROIs) + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_T)) + line([realT(vr) realT(vr)], [0 max(ylim)],'LineWidth',0.75,'color','r') + hold on; + histogram(sort(shuff_Tth)) + line([realT_th(vr) realT_th(vr)], [0 max(ylim)],'LineWidth',0.75,'color','b') + + title(ROIs{vr}) + if vr ==length(ROIs) + legend('lin tval', 'pol tval') + else + end + +end + + +fprintf('done') +end + diff --git a/spDist_neural_behav_corr_exclutri_individperm_noflipth_concat.m b/spDist_neural_behav_corr_exclutri_individperm_noflipth_concat.m new file mode 100644 index 0000000..eeb64c9 --- /dev/null +++ b/spDist_neural_behav_corr_exclutri_individperm_noflipth_concat.m @@ -0,0 +1,676 @@ +function spDist_neural_behav_corr_exclutri_individperm_noflipth_concat(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'CC','KD','AY','MR','XL','SF','EK'}; + % subj = {'AY','CC','EK','KD','MR','SF','XL'}; %alph + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + % ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +% seed random number generator: +rng(spDist_randSeed); + +%% load neural data +startidx = 1; +bidx =1; +WHICH_EXCL = [13 20 21 22]; +all_data_beh = []; +all_subj_beh=[]; + +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + + %%%inserting + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + %fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + this_data.s_all = this_scored.ii_sess; + + thisbidx = bidx:(bidx+size(this_scored.ii_sess.trialinfo,1)-1); + + this_data.sess_all = sessidx; + all_data_beh= cat_struct(all_data_beh,this_data); + all_subj_beh(thisbidx,1) = ss; + + bidx =thisbidx(end)+1; + end + + startidx = thisidx(end)+1; + + clear data; + + end + +end +all_data_beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_beh.s_all.excl_trial, 'UniformOutput',false)); +fprintf('neural and behave loaded...\n') + +% visualize all_data_beh.use_trial, make sure the pattern repeats exactly +% across all ROIs +% for ss=1:length(subj) +% figure +% for vv = 1:length(ROIs) +% hold on; +% thisidx = all_subj==ss & all_ROIs ==vv; +% myd = all_data_beh.use_trial(thisidx); +% subplot(1,length(ROIs),vv) +% imagesc(myd) +% clear myd thisidx +% end +% end +% + + +%% load recons, no flipping + +all_recons_noflip = all_recons{1}; % simply reiterate, we are NOT flipping a thing + +%fprintf('chaotic tpt range grl') +%delay_tpt_range = [3.75 5.25; 7.5 9; 10.5 12]; +delay_tpt_range = [0 .75; .75 1.5; 1.5 2.25; 2.25 3; 3 3.75; 3.75 4.5; 4.5 5.25; 5.25 6; 6 6.75; 6.75 7.5; 7.5 8.25; 8.25 9; 9 9.75; 9.75 10.5; 10.5 11.25; 11.25 12;] +myTR = 0.75; + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + + + +cond = [1 2]; % do no distractor, then distractor +store_b = nan(length(cond),length(ROIs),length(subj),36); + + +figure; + +for cc= 1:length(cond) + + thisd = nan(length(cond),length(ROIs),length(delay_tpts),length(subj),36, length(angs)); + thisb = nan(1,length(subj)); + + for vv = 1:length(ROIs) + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + for nr =1:nruns + if cc ==1 + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==1; + else + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; + end + + thisd(cc,vv,dd,ss,nr,:) = squeeze(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3)); + + thisb(ss) = atan2d(sum(mean(mean(all_recons_noflip(thisidx,:, delay_tpts{dd}),1),3).*sind(angs)),... + sum(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3).*cosd(angs))); + + store_b(cc,vv,dd,ss,nr) = thisb(ss); + + end + end + end + clear thisidx + clear thisb + + end + +end + +fprintf('neural bias computed ...\n') +%% organize beh data + +% which param should we collect? +dist_colors = [ 0.7100 0.2128 0.4772; 0 0 1]; % red - no dist, blue - dist + +params_of_interest = {'f_sacc'}; + +param_str = {'fsacc'}; + +mu = nan(2,length(subj),length(cond),36); % no subj performed > 36 runs +err = nan(2,length(subj),length(cond),36); +dtheta = nan(length(subj),length(cond),36); +drad = nan(length(subj),length(cond),36); +dtheta_poldeg = nan(length(subj),length(cond),36); + +for cc = 1:length(cond) + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + + for nr = 1:nruns + + if cc ==1 + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==1; + else + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; + + end + err(1,ss,cc,nr) = nanstd(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,2)); + mu(:,ss,cc,nr) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); %mean of a single number = the number .. leaving this + tmp(1,:) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + [dtheta(ss,cc,nr), drad(ss,cc,nr)]= cart2pol(tmp(1),tmp(2)); + dtheta_poldeg(ss,cc,nr) = dtheta(ss,cc,nr).*360/(2*pi); + + end + + + + end +end + +% squeeze over subj, collect each subj, all trials into one container +rho_group = nan(length(cond),length(ROIs),1); +rho_group_theta = nan(length(cond),length(ROIs),1); +pval_group = nan(length(cond),length(ROIs),1); +pval_group_theta = nan(length(cond),length(ROIs),1); + +% bn_corr = figure('Name','behneurcorr'); +% +bn_corr_theta_nodist = figure('Name','behneurcorrthetanodist'); +bn_corr_theta_dist = figure('Name','behneurcorrthetadist'); +bn_corr_theta_both = figure('Name','behneurcorrthetaboth'); + +% grouprho = figure('Name','grouprho'); + +for cc = 1:length(cond) + +for vv=1:length(ROIs) + + for dd =1:length(delay_tpts) + thisb_neural_tmp =[]; + thisb_behav_tmp =[]; + thisb_behav = []; + thisb_neural = []; + thisb_behav_poldegtmp =[]; + thisb_behav_polradtmp =[]; + thisb_behav_poldeg =[]; + + for ss = 1:length(subj) + thisb_neural_tmp(ss,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(ss,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(ss,:)= dtheta_poldeg(ss,cc,:); + end + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + +% set(0, 'CurrentFigure', bn_corr) +% subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; +% scatter(thisb_neural,thisb_behav,30,dist_colors(cc,:),'filled','MarkerFaceAlpha',.3) +% h = lsline; +% h.LineWidth =2; +% [rho_group(cc,vv,dd), pval_group(cc,vv,dd)] = corr(thisb_neural, thisb_behav); +% set(gcf,'Position',[15 1052 2542 286]) +% if vv==1 && cc ==1 && dd ==1 +% ylabel('DVA, sacc endpt') +% xlabel('Neural bias, Polar angle \circ') +% else +% end +% clear h +% + if cc ==1 + set(0, 'CurrentFigure', bn_corr_theta_nodist) + subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; + scatter(thisb_neural,thisb_behav_poldeg,30,dist_colors(cc,:),'filled','MarkerFaceAlpha',.3) + elseif cc ==2 + set(0, 'CurrentFigure', bn_corr_theta_dist) + subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; + scatter(thisb_neural,thisb_behav_poldeg,30,dist_colors(cc,:),'filled','MarkerFaceAlpha',.3) + end + q = lsline; + q.LineWidth =2; + clear q + title(ROIs{vv}) + set(gcf,'Position',[ -110 706 1882 624]) + if vv==1 && dd==1 + ylabel('Epoch 1') + elseif vv==1 && dd==2 + ylabel('Epoch 2') + elseif vv==1 && dd ==3 + ylabel({'Polar angle \circ delta, target, sacc endpt', 'Epoch 3'}) + xlabel('Neural bias, Polar angle \circ') + else + end + [rho_group_theta(cc,vv,dd), pval_group_theta(cc,vv,dd)] = corr(thisb_neural, thisb_behav_poldeg); + + +% + set(0, 'CurrentFigure', bn_corr_theta_both) + subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; + scatter(thisb_neural,thisb_behav_poldeg,30,dist_colors(cc,:),'filled','MarkerFaceAlpha',.1) + title(ROIs{vv}) + lsline + set(gcf,'Position',[ -110 706 1882 624]) + if vv==1 && dd==1 + ylabel('Epoch 1') + elseif vv==1 && dd==2 + ylabel('Epoch 1') + elseif vv==1 && dd ==3 + ylabel({'Polar angle \circ delta, target, sacc endpt', 'Epoch 3'}) + xlabel('Neural bias, Polar angle \circ') + else + end + [rho_group_theta(cc,vv,dd), pval_group_theta(cc,vv,dd)] = corr(thisb_neural, thisb_behav_poldeg); + + end + + +% set(0, 'CurrentFigure', grouprho) +% subplot(1,length(ROIs),vv) +% plot(squeeze(rho_group(cc,vv,:)),'-','color',dist_colors(cc,:)) +% hold on; +% plot(squeeze(rho_group_theta(cc,vv,:)),'--','color',dist_colors(cc,:)) +% legend('rho,linear', 'rho,polar') + + + + + +end + + + +end + +% grouprho = figure('Name','grouprho'); +% plot(rho_group,'-') +% hold on; +% plot(rho_group_theta,'--') +% legend('rho,linear', 'rho,polar') + +%% corr on individual subj, convert to z, t-test + +% fish_fig = figure('Name','fish'); +% +fish_theta_fig = figure('Name','fish_theta'); +% +% subjrho = figure('Name','subjrho'); +p=[]; + +pval_sg = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +rho_sg = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +fish_z = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +pval_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +rho_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +fish_z_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); + +for cc = 1:length(cond) + +for vv=1:length(ROIs) + + for dd = 1:length(delay_tpts) + + for ss = 1:length(subj) + + thisb_neural_tmp = []; + thisb_behav_tmp = []; + thisb_neural = []; + thisb_behav = []; + thisb_behav_poldegtmp =[]; + thisb_behav_polradtmp =[]; + thisb_behav_poldeg =[]; + thisb_behav_polrad =[]; + + thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); + + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); %exclude outliers + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); %use if no exclu + + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + + [rho_sg(cc,ss,vv,dd), pval_sg(cc,ss,vv,dd)] = corr(thisb_neural', thisb_behav'); + + fish_z(cc,ss,vv,dd) = atanh(rho_sg(cc,ss,vv,dd)); + + [rho_sg_theta(cc,ss,vv,dd), pval_sg_theta(cc,ss,vv,dd)] =corr(thisb_neural', thisb_behav_poldeg'); + + fish_z_theta(cc,ss,vv,dd) = atanh(rho_sg_theta(cc,ss,vv,dd)); % identical + + clear mysd + end +% +% set(0, 'CurrentFigure', fish_fig) +% subplot(1,length(ROIs),vv); hold on; +% plot(dd,fish_z(cc,:,vv,dd),'o','color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',1) +% hold on; +% my_sem = std(fish_z(cc,:,vv,dd))/sqrt(length(subj)); +% ylim([-.4 .7]) +% errorbar(dd,mean(fish_z(cc,:,vv,dd)),my_sem,'o','color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',7) +% title(ROIs{vv}) +% xlim([0.05 3.5]) + [h,p(cc,vv,dd),~,stats] = ttest(fish_z(cc,:,vv,dd)); + realT(cc,vv,dd) = stats.tstat; + %ylabel('Fisher-Z') + + set(0, 'CurrentFigure', fish_theta_fig) + subplot(1,length(ROIs),vv); hold on; + plot(dd,fish_z_theta(cc,:,vv,dd),'o','color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',4) + hold on; + my_sem_th = std(fish_z_theta(cc,:,vv,dd))/sqrt(length(subj)); + %errorbar(dd,mean(fish_z_theta(cc,:,vv,dd)),my_sem_th,'o','color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',7) + plot(dd,mean(fish_z_theta(cc,:,vv,dd)), 'o', 'color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',8) + plot(dd*[1 1],[mean(fish_z_theta(cc,:,vv,dd))+1.*my_sem_th, mean(fish_z_theta(cc,:,vv,dd))-1.*my_sem_th], '-', 'color',dist_colors(cc,:),'linewidth',1) + title(ROIs{vv}) + ylim([-1 1]) + xlim([0.05 3.5]) + if vv==1 + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','Epoch 1','Epoch 2','Epoch 3',''},'XTickLabelRotation',45,'TickDir','out'); + ylabel('Fisher-Z Corr') + else + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out'); + end + + [h_th,p_th(cc,vv,dd),~,stats_th] = ttest(fish_z_theta(cc,:,vv,dd)); + realT_th(cc,vv,dd) = stats_th.tstat; + +% +% set(0, 'CurrentFigure', subjrho) +% subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; +% pl(1) = plot(1:7,rho_sg(cc,:,vv,dd),'-','color',dist_colors(cc,:)) +% hold on; +% pl(2) = plot(1:7,rho_sg_theta(cc,:,vv,dd),'--','color',dist_colors(cc,:)) +% if vv==1 && dd==1 && cc ==1 +% title(ROIs{vv}) +% elseif vv==1 && dd ==3 && cc==1 +% ylabel('untransformed Rho') +% set(gca,'Xtick',[0 1 2 3 4 5 6 7],'Xticklabel',{'','1','2','3','4','5','6','7',''},'XTickLabelRotation',45,'TickDir','out'); +% elseif vv==length(ROIs) && dd==3 && cc==2 +% legend(pl,'rho,linear', 'rho,polar') +% end +% + end + +end +end + +%%%%%%%%%%%%%%%%%%%%%%%%% PERM TEST%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% we're permuting two measures here, linear bias and ciruclar bias, open +iter = 10000; +fish_zperm = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +fish_zthperm = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +shuff_T =nan(length(cond),length(ROIs),length(delay_tpts),iter); +shuff_Tth =nan(length(cond),length(ROIs),length(delay_tpts),iter); +rho_perm = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +pval_perm = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +rho_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +pval_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); + + +for xx = 1:iter + + if xx == 1 + fprintf('doing shuffle ...\n') + tic + elseif xx == iter/2 + fprintf('halfway ...\n') + toc + else + end + for cc = 1:length(cond) + for vv=1:length(ROIs) + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + thisb_neural_tmp_perm = []; + thisb_behav_tmp_perm = []; + thisb_behav_perm = []; + thisb_neural_perm = []; + shuff_bdata = []; + shuff_ndata = []; + thisb_behav_poldegtmp =[]; + thisb_behav_poldegperm =[]; + thisb_neural_poldegperm =[]; + shuff_btheta =[]; + shuff_ntheta =[]; + + + thisb_neural_tmp_perm (1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp_perm (1,:)= squeeze(mu(2,ss,cc,:))'; + + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); %this obv cant change across ROI, delay, lose two dimens (vv,dd) here + + thisb_behav_perm = thisb_behav_tmp_perm (~isnan(thisb_behav_tmp_perm) ); %exclude outliers + thisb_neural_perm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm)); %use if no exclu + + thisb_behav_poldegperm = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp_perm)); + + thisb_neural_poldegperm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm)); + + % do the shuffle + + shuff_bdata = thisb_behav_perm; %reload these each time + shuff_ndata = thisb_neural_perm; + subjidx = find(shuff_bdata); + shuff_bidx = randperm(length(subjidx))'; + shuff_bdata(subjidx) = shuff_bdata(shuff_bidx); %insert shuffled subj indices into bdata (note : in this case, bdata is ONLY this subj. just jumbling idx) + + bdata = shuff_bdata(subjidx); + ndata = shuff_ndata(subjidx); + + [rho_perm(cc,ss,vv,dd,xx), pval_perm(cc,ss,vv,dd,xx)] = corr(ndata',bdata'); %1st output is RHO, 2nd is pval + fish_zperm(cc,ss,vv,dd,xx) = atanh(rho_perm(cc,ss,vv,dd,xx)); + + shuff_btheta = thisb_behav_poldegperm; %reload these each time + shuff_ntheta = thisb_neural_poldegperm; + subjidxth = find(shuff_btheta); + shuff_bidxth = randperm(length(subjidxth))'; + shuff_btheta(subjidxth) = shuff_btheta(shuff_bidxth); %insert shuffled subj indices into bdata (note : in this case, bdata is ONLY this subj. just jumbling idx) + + bthdata = shuff_btheta(subjidxth); + nthdata = shuff_ntheta(subjidxth); + + [rho_permth(cc,ss,vv,dd,xx), pval_permth(cc,ss,vv,dd,xx)] = corr(nthdata',bthdata'); + fish_zthperm(cc,ss,vv,dd,xx) = atanh(rho_permth(cc,ss,vv,dd,xx)); + + clear thisidx subjidx shuff_bidx shuff_nidx shuff_bdata shuff_ndata bdata ndata subjidxth shuff_bidxth shuff_btheta shuff_ntheta bthdata nthdata + end + + [h,p,~,statsz] = ttest(fish_zperm(cc,:,vv,dd,xx)); + shuff_T(cc,vv,dd,xx) = statsz.tstat; + + [h,p,~,statsth] = ttest(fish_zthperm(cc,:,vv,dd,xx)); + shuff_Tth(cc,vv,dd,xx) = statsth.tstat; + end + end + end +end +p_twotail =nan(length(cond),length(ROIs),length(delay_tpts)); +p_onetail =nan(length(cond),length(ROIs),length(delay_tpts)); +p_th_twotail =nan(length(cond),length(ROIs),length(delay_tpts)); +p_th_onetail =nan(length(cond),length(ROIs),length(delay_tpts)); +pmask_twotail = []; +pfdr_twotail = []; +pfdr_onetail = []; +pmask_onetail = []; +pfdr_th_twotail =[]; +pmask_th_twotail =[]; +pmask_th_onetail =[]; +pfdr_th_onetail =[]; + +tdistlinbias = figure('Name','tdistlinbias'); +for cc = 1:length(cond) +for dd =1:length(delay_tpts) +for vr = 1:length(ROIs) + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_T)) + line([realT(cc,vr,dd) realT(cc,vr,dd)], [0 max(ylim)],'LineWidth',0.75,'color','r') + p_twotail(cc,vr,dd) = 2 * min ( mean( shuff_T(cc,vr,dd,:) <= realT(vr) ), mean ( shuff_T(cc,vr,dd,:) >= realT(cc,vr,dd))); + p_onetail(cc,vr,dd) = mean( shuff_T(cc,vr,dd,:) >= realT(cc,vr,dd) ); + title(ROIs{vr}) +end + +[pfdr_twotail(cc,:,dd), pmask_twotail(cc,:,dd)] = fdr(p_twotail(cc,:,dd),0.05); +[pfdr_onetail(cc,:,dd), pmask_onetail(cc,:,dd)] = fdr(p_onetail(cc,:,dd),0.05); + +end +end + + + +tdistpolbias = figure('Name','tdistpolbias'); +for cc =1:length(cond) +for dd = 1:length(delay_tpts) +for vr = 1:length(ROIs) + + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_Tth(cc,vr,dd,:))) + line([realT_th(cc,vr,dd) realT_th(cc,vr,dd)], [0 max(ylim)],'LineWidth',0.75,'color','r') + p_th_twotail(cc,vr,dd) = 2 * min ( mean( shuff_Tth(cc,vr,dd,:) <= realT_th(cc,vr,dd) ), mean ( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd))); + p_th_onetail(cc,vr,dd) = mean( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd) ); + title(ROIs{vr}) +end + + +[pfdr_th_twotail(cc,:,dd), pmask_th_twotail(cc,:,dd)] = fdr(p_th_twotail(cc,:,dd),0.05); +[pfdr_th_onetail(cc,:,dd), pmask_th_onetail(cc,:,dd)] = fdr(p_th_onetail(cc,:,dd),0.05); +end +end + +fprintf('done') + +%fn2s = sprintf('%s/%s_corr/neurbehcorr_fsacc_%iter.mat',root,task_dir,iter); + +%save(fn2s); + + + % fprintf('saving to %s...\n',fn2s); +end + diff --git a/spDist_neural_behav_corr_exclutri_individperm_noflipth_fig5.m* b/spDist_neural_behav_corr_exclutri_individperm_noflipth_fig5.m* new file mode 100644 index 0000000..1ba8d59 --- /dev/null +++ b/spDist_neural_behav_corr_exclutri_individperm_noflipth_fig5.m* @@ -0,0 +1,802 @@ +function spDist_neural_behav_corr_exclutri_individperm_noflipth_fig5(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + %subj = {'CC','KD','AY','MR','XL','SF','EK'}; + subj = {'AY','CC','EK','KD','MR','SF','XL'}; %alph + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + % ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +% seed random number generator + +rng(spDist_randSeed); + +%% load neural data +startidx = 1; +bidx =1; +WHICH_EXCL = [13 20 21 22]; +all_data_beh = []; +all_subj_beh= []; + +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + + %%%inserting + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + %fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + this_data.s_all = this_scored.ii_sess; + + thisbidx = bidx:(bidx+size(this_scored.ii_sess.trialinfo,1)-1); + + this_data.sess_all = sessidx; + all_data_beh= cat_struct(all_data_beh,this_data); + all_subj_beh(thisbidx,1) = ss; + + bidx =thisbidx(end)+1; + end + + startidx = thisidx(end)+1; + + clear data; + + end + +end + +all_data_beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_beh.s_all.excl_trial, 'UniformOutput',false)); +fprintf('neural and behave loaded...\n') + + +%% load recons, no flipping + +all_recons_noflip = all_recons{1}; % simply reiterate, we are NOT flipping a thing + + +delay_tpt_range = [3.75 5.25; 7.5 9; 10.5 12]; +myTR = 0.75; + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + + + +cond = [1 2]; % do no distractor, then distractor +store_b = nan(length(cond),length(ROIs),length(subj),36); + + +figure; + +for cc= 1:length(cond) + + thisd = nan(length(cond),length(ROIs),length(delay_tpts),length(subj),36, length(angs)); + thisb = nan(1,length(subj)); + + for vv = 1:length(ROIs) + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + for nr =1:nruns + if cc ==1 %%%%%% NOTE THIS COLLECTS THREE TRIALS IN MGS CONDITION %%%% NEED TO FIX!!!! + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==1; + else + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; + end + + thisd(cc,vv,dd,ss,nr,:) = squeeze(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3)); + + thisb(ss) = atan2d(sum(mean(mean(all_recons_noflip(thisidx,:, delay_tpts{dd}),1),3).*sind(angs)),... + sum(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3).*cosd(angs))); + + store_b(cc,vv,dd,ss,nr) = thisb(ss); + + end + end + end + clear thisidx + clear thisb + + end + +end + +fprintf('neural bias computed ...\n') +%% organize beh data + +% which param should we collect? +dist_colors = spDist_condColors; + +params_of_interest = {'f_sacc'}; + +param_str = {'fsacc'}; + +mu = nan(2,length(subj),length(cond),36); % no subj performed > 36 runs +err = nan(2,length(subj),length(cond),36); +dtheta = nan(length(subj),length(cond),36); +drad = nan(length(subj),length(cond),36); +dtheta_poldeg = nan(length(subj),length(cond),36); + +for cc = 1:length(cond) + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + + for nr = 1:nruns + + if cc ==1 + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==1; + else + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; + end + err(1,ss,cc,nr) = nanstd(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,2)); + mu(:,ss,cc,nr) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); %mean of a single number = the number .. leaving this + tmp(1,:) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + [dtheta(ss,cc,nr), drad(ss,cc,nr)]= cart2pol(tmp(1),tmp(2)); + dtheta_poldeg(ss,cc,nr) = dtheta(ss,cc,nr).*360/(2*pi); + + end + + + + end +end + +% squeeze over subj, collect each subj, all trials into one container +rho_group_theta = nan(length(cond),length(ROIs),1); +pval_group_theta = nan(length(cond),length(ROIs),1); +rho_theta = nan(length(subj),length(ROIs),1); +pval_theta = nan(length(subj),length(ROIs),1); + +bn_corr_theta_dist = figure('Name','behneurcorrthetadist'); +bn_corr_theta_both = figure('Name','behneurcorrthetaboth'); +figure + +for ss = 6 %1:length(subj) + hold on; + for cc = 2% 1:length(cond) + + for vv = 1:length(ROIs) + + for dd = 3 % 1:length(delay_tpts) + + thisb_neural_tmp =[]; + thisb_behav_tmp =[]; + thisb_behav = []; + thisb_neural = []; + thisb_behav_poldegtmp =[]; + thisb_behav_poldeg =[]; + + + thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); + + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + %subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; + %subplot(length(subj),length(ROIs),(ss-1)*length(ROIs)+vv); hold on; + subplot(1,length(ROIs),vv); hold on; + scatter(thisb_neural,thisb_behav_poldeg,30,dist_colors(cc,:),'filled','MarkerFaceAlpha',.4) + + title(ROIs{vv}) + lsline + set(gcf,'Position',[ -110 706 1882 624]) + % xlim([-180 180]) + %ylim([-25 25]) + + + + if vv==1 && ss ==7 + ylabel({'Polar angle \circ delta, target, sacc endpt', 'Epoch 3'}) + xlabel('Neural bias, Polar angle \circ') + else + end + [rho_theta(ss,vv,dd), pval_theta(ss,vv,dd)] = corr(thisb_neural', thisb_behav_poldeg'); + clear this neural thisb_behav_poldeg + end + + + end + + + + + end + set(get(gcf,'Children'),'XLim',[-180 180],'YLim',[-25 25]) + + +end + + +%% corr on individual subj, convert to z, t-test + +fish_theta_fig = figure('Name','fish_theta'); +store_fish_ztheta= []; +pval_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +rho_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +fish_z_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); + +for cc = 2 %1:length(cond) + +for vv=1:length(ROIs) + + for dd = 1:length(delay_tpts) + + for ss = 1:length(subj) + + thisb_neural_tmp = []; + thisb_behav_tmp = []; + thisb_neural = []; + thisb_behav = []; + thisb_behav_poldegtmp =[]; + thisb_behav_polradtmp =[]; + thisb_behav_poldeg =[]; + thisb_behav_polrad =[]; + + thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); + + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + + [rho_sg(cc,ss,vv,dd), pval_sg(cc,ss,vv,dd)] = corr(thisb_neural', thisb_behav'); + + fish_z(cc,ss,vv,dd) = atanh(rho_sg(cc,ss,vv,dd)); + + [rho_sg_theta(cc,ss,vv,dd), pval_sg_theta(cc,ss,vv,dd)] =corr(thisb_neural', thisb_behav_poldeg'); + + fish_z_theta(cc,ss,vv,dd) = atanh(rho_sg_theta(cc,ss,vv,dd)); % identical + store_fish_ztheta = [store_fish_ztheta; atanh(rho_sg_theta(cc,ss,vv,dd)) cc ss vv dd ]; + clear mysd + end + +% + set(0, 'CurrentFigure', fish_theta_fig) + subplot(1,length(ROIs),vv); hold on; + plot(dd,fish_z_theta(cc,:,vv,dd),'o','color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',3) + hold on; + my_sem_th = std(fish_z_theta(cc,:,vv,dd))/sqrt(length(subj)); + plot(dd,mean(fish_z_theta(cc,:,vv,dd)), 'o', 'color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',8) + plot(dd*[1 1],[mean(fish_z_theta(cc,:,vv,dd))+1.*my_sem_th, mean(fish_z_theta(cc,:,vv,dd))-1.*my_sem_th], '-', 'color',dist_colors(cc,:),'linewidth',1) + title(ROIs{vv}) + ylim([-1 1]) + xlim([0.05 3.5]) + if vv==1 + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','Epoch 1','Epoch 2','Epoch 3',''},'XTickLabelRotation',45,'TickDir','out'); + ylabel('Fisher-Z Corr') + else + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out'); + end + + [h_th,p_th(cc,vv,dd),~,stats_th] = ttest(fish_z_theta(cc,:,vv,dd)); + realT_th(cc,vv,dd) = stats_th.tstat; + + end + +end +end +% +% y_var = store_fish_ztheta(:,1); %fish z +% cond_var = store_fish_ztheta(:,2); %condition +% subj_var = store_fish_ztheta(:,3); %subject +% roi_var = store_fish_ztheta(:,4); %roi +% epoch_var = store_fish_ztheta(:,5); %epoch +% +% % perform real T test +% +% for vv =1:length(ROIs) +% for cc =1:length(cond) +% for ee = 1:3 +% thisidx = roi_var ==vv & cond_var ==cc & epoch_var ==ee; +% y_shuf =y_var(thisidx); %these are already shuffled, see above +% [~,~,~,stats] = ttest(y_shuf); +% real_t(vv,cc,ee) = stats.tstat; +% +% clear thisidx y_shuf +% end +% end +% end +% % perform true 2-way anova +% +% p_real = {}; +% +% f_real = []; +% +% for vv =1:length(ROIs) +% +% thisroiidx = roi_var==vv; +% y = y_var(thisroiidx); +% thiscond= cond_var(thisroiidx); +% thissubj = subj_var(thisroiidx); +% thisepoch = epoch_var(thisroiidx); +% [f_real(vv,:)] = RMAOV2_gh([y,thisepoch,thiscond,thissubj],0.05); +% clear thisroiidx y thiscond thissubj thisepoch +% +% end +% +% +% clear cond_var roi_var epoch_var subj_var y_var +% +% y_var = store_fish_ztheta(:,1); %fish z +% cond_var = store_fish_ztheta(:,2); %condition +% subj_var = store_fish_ztheta(:,3); %subject +% roi_var = store_fish_ztheta(:,4); %roi +% epoch_var = store_fish_ztheta(:,5); %epoch +% +% % 1-way +% +% f_real_one = []; +% pval_real_one =[]; +% +% for cc =1:length(cond) +% for vv =1:length(ROIs) +% +% thisroiidx = roi_var==vv & cond_var==cc; +% y = y_var(thisroiidx); +% +% thissubj = subj_var(thisroiidx); +% thisepoch = epoch_var(thisroiidx); +% +% [f_real_one(cc,vv), pval_real_one(cc,vv)] = RMAOV1_gh([y,thisepoch,thissubj],0.05); +% clear thisroiidx y thissubj thisepoch +% +% end +% end +% +% +% clear cond_var roi_var epoch_var subj_var y_var +% check the usage of 'random' per the grouping var +%%%%%%%%%%%%%%%%%%%%%%%%% PERM TEST # 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% we're permuting two measures here, linear bias and ciruclar bias, open +iter = 1000; +t_iter =cell(length(ROIs),iter); +p_iter =cell(length(ROIs),iter); +f_store_iter_2 = nan(length(ROIs),iter,3); +fish_zthstore_perm =[]; +fish_zthperm = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +shuff_Tth =nan(length(cond),length(ROIs),length(delay_tpts),iter); +rho_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +pval_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); + + +for xx = 1:iter + + if xx == 1 + fprintf('starting @ %s \n',datestr(now,'HH:MM:SS')) + tic + elseif xx == 2 + toc + elseif xx == 3 + toc + elseif xx == iter/4 + fprintf('quarter-way ...\n') + toc + elseif xx == iter/2 + fprintf('halfway ...\n') + toc + else + end + + for cc = 1:length(cond) + for vv=1:length(ROIs) + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + thisb_neural_tmp_perm = []; + thisb_behav_tmp_perm = []; + thisb_behav_perm = []; + thisb_neural_perm = []; + thisb_behav_poldegtmp = []; + thisb_behav_poldegperm = []; + thisb_neural_poldegperm = []; + shuff_btheta =[]; + shuff_ntheta =[]; + + + thisb_neural_tmp_perm (1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp_perm (1,:)= squeeze(mu(2,ss,cc,:))'; + + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); %this obv cant change across ROI, delay, lose two dimens (vv,dd) here + + + thisb_behav_poldegperm = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp_perm)); + + thisb_neural_poldegperm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm)); + + % do the shuffle + shuff_btheta = thisb_behav_poldegperm; %reload these each time + shuff_ntheta = thisb_neural_poldegperm; + subjidxth = find(shuff_btheta); + shuff_bidxth = randperm(length(subjidxth))'; + shuff_btheta(subjidxth) = shuff_btheta(shuff_bidxth); %insert shuffled subj indices into bdata (note : in this case, bdata is ONLY this subj. just jumbling idx) + + bthdata = shuff_btheta(subjidxth); + nthdata = shuff_ntheta(subjidxth); + + [rho_permth(cc,ss,vv,dd,xx), pval_permth(cc,ss,vv,dd,xx)] = corr(nthdata',bthdata'); + fish_zthperm(cc,ss,vv,dd,xx) = atanh(rho_permth(cc,ss,vv,dd,xx)); + + + % fish_zthstore_perm =[fish_zthstore_perm; fish_zthperm(cc,ss,vv,dd,xx) cc ss vv dd xx]; + + + clear thisidx subjidxth shuff_bidxth shuff_btheta shuff_ntheta bthdata nthdata + end + + [h,p,~,statsth] = ttest(fish_zthperm(cc,:,vv,dd,xx)); + shuff_Tth(cc,vv,dd,xx) = statsth.tstat; + + end + end + end +end + + + +% collect original perm pvalues + +p_th_twotail =nan(length(cond),length(ROIs),length(delay_tpts)); +p_th_onetail =nan(length(cond),length(ROIs),length(delay_tpts)); + +pfdr_th_twotail =[]; +pmask_th_twotail =[]; +pmask_th_onetail =[]; +pfdr_th_onetail =[]; + +p_th_twotaile = []; +p_th_onetaile = []; +pmask_th_twotaile = []; +pmask_th_onetaile = []; +pfdr_th_twotaile = []; +pfdr_th_onetaile = []; + + +tdistpolbias = figure('Name','tdistpolbias'); + +realT_col = lines(3); +for cc =1:length(cond) + for dd = 1:length(delay_tpts) + for vr = 1:length(ROIs) + + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_Tth(cc,vr,dd,:))) + line([realT_th(cc,vr,dd) realT_th(cc,vr,dd)], [0 max(ylim)],'LineWidth',0.75,'color',realT_col(dd,:)) + p_th_twotail(cc,vr,dd) = 2 * min ( mean( shuff_Tth(cc,vr,dd,:) <= realT_th(cc,vr,dd) ), mean ( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd))); + p_th_onetail(cc,vr,dd) = mean( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd) ); + title(ROIs{vr}) + end + + [pfdr_th_twptail(cc,:,dd), pmask_th_twotail(cc,:,dd)] = fdr(p_th_twotail(cc,:,dd),0.05); % this is two tail + [pfdr_th_onetail(cc,:,dd), pmask_th_onetail(cc,:,dd)] = fdr(p_th_onetail(cc,:,dd),0.05); %one tail + + + end + +end + + +% +% two-way anova perm for each ROI? + % correct across epochs? + + + +tmp = [squeeze(p_th_onetail(:,:,1)); squeeze(p_th_onetail(:,:,2)); squeeze(p_th_onetail(:,:,3))] + +[fdrout, maskout] = fdr(tmp,0.05); + + +%% hold off on other perms for now - 102920 + + + + +y_var = fish_zthstore_perm(:,1); +cond_var = fish_zthstore_perm(:,2); +subj_var = fish_zthstore_perm(:,3); +roi_var = fish_zthstore_perm(:,4); +epoch_var = fish_zthstore_perm(:,5); +iter_var = fish_zthstore_perm(:,6); + + + +for zz =1:iter + + for vv = 1:length(ROIs) + + + thisroiidx = roi_var ==vv & iter_var == zz; + y_shuf = y_var(thisroiidx); %these are already shuffled, see above + thisepoch = epoch_var(thisroiidx); + thiscond =cond_var(thisroiidx); + thissubj=subj_var(thisroiidx); + + [p_iter{vv,zz},t_iter{vv,zz},~] = anovan(y_shuf,{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'},'display','off'); + [f_store_iter_2(vv,zz,:)] = RMAOV2_gh([y_shuf,thisepoch,thiscond,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj y_shuf + + end +end +toc + +% visualize + +iv_str_rm ={'epoch','cond','epoch*cond'}; +which_effect_rm = [1 2 3]; +exact_store_tmp=[]; +exact_store_rm_2 =nan(length(ROIs),length(which_effect_rm)); + +for vv =1:length(ROIs) + figure('name','2-way perm; RMAOV2') + + for ww =1:length(which_effect_rm) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; f_store_iter_2(vv,ii,which_effect_rm(ww))]; + end + hold on; + + subplot(1,length(which_effect_rm),ww) + histogram(extract_vals) + line([f_real(vv,which_effect_rm(ww)) f_real(vv,which_effect_rm(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str_rm{which_effect_rm(ww)},'Interpreter','none'); + % exact_p = sum(extract_vals >= f_real(vv,which_effect_rm(ww)))/iter; + exact_p = 2 * min ( sum(extract_vals >= f_real(vv,which_effect_rm(ww)))/iter, sum(extract_vals <= f_real(vv,which_effect_rm(ww)))/iter ); + + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) + exact_store_rm_2(vv,ww) = [exact_store_tmp; exact_p]; + clear exact_p + sgtitle(ROIs{vv}) + title(iv_str_rm{ww}) + if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + + end +end + +% one-way anova perm +for xx=1:iter +for cc =1:length(cond) +for vv =1:length(ROIs) + + thisroiidx = roi_var==vv & cond_var==cc & iter_var ==xx; + y = y_var(thisroiidx); + thissubj = subj_var(thisroiidx); + thisepoch = epoch_var(thisroiidx); + + [f_real_one_perm(cc,vv,xx)] = RMAOV1_gh([y,thisepoch,thissubj],0.05); + clear thisroiidx y thissubj thisepoch + +end +end +end + +% visualize 1--way result + +iv_str_rm ={'epoch'}; +which_effect_rm = 1; +exact_store_tmp = []; +exact_store_rm_1 =nan(length(ROIs),length(which_effect_rm)); + +for vv =1:length(ROIs) + figure('name','2-way perm; RMAOV2') +for cc =1:length(cond) + + extract_vals= []; + for ii= 1:iter + extract_vals = [extract_vals; f_real_one_perm(cc,vv,ii)]; + end + + + subplot(1,2,cc) + hold on; + histogram(extract_vals) + line([f_real_one(cc,vv) f_real(cc,vv)], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str_rm{which_effect_rm(1)},'Interpreter','none'); + % exact_p = sum(extract_vals >= f_real(vv,which_effect_rm(ww)))/iter; + exact_p = 2 * min ( sum(extract_vals >= f_real_one(cc,vv))/iter, sum(extract_vals <= f_real_one(cc,vv))/iter ); + + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) + exact_store_rm_1(vv,1) = [exact_store_tmp; exact_p]; + clear exact_p + sgtitle(ROIs{vv}) + title(iv_str_rm{1}) + xlabel('T-stat') + ylabel('Frequency of T-stat') + + +end +end + + + + +% do ttest for each roi,epoch,condition + +for xx =1:iter + for vv =1:length(ROIs) + for cc =1:length(cond) + for ee = 1:3 + thisidx = roi_var ==vv & cond_var ==cc & epoch_var ==ee & iter_var == xx; + y_shuf =y_var(thisidx); %these are already shuffled, see above + [~,~,~,stats] = ttest(y_shuf); + shuff_t(vv,cc,ee,xx) = stats.tstat; + + clear thisidx y_shuf + end + end + end +end +fprintf('done') + +% pvals + +for cc =1:length(cond) + for ee = 1:3 + for vv =1:length(ROIs) + + pval_twotail(cc,vv,ee) = 2 * min(mean(shuff_t(vv,cc,ee,:) <= real_t(vv,cc,ee)), mean(shuff_t(vv,cc,ee,:) >= real_t(vv,cc,ee))); + pval_onetail(cc,vv,ee) = mean(shuff_t(vv,cc,ee,:) >= real_t(vv,cc,ee)); + + end + [pval_fdrthresh_twotail(cc,:,ee), pval_th_twotail_mask(cc,:,ee)] = fdr(pval_th_twotail(cc,:,ee),0.05); % this is two tail + [pval_fdrthresh_onetail(cc,:,ee), pval_th_onetail_mask(cc,:,ee)] = fdr(pval_th_onetail(cc,:,ee),0.05); %one tail + + end +end + + + + +fprintf('done') + +fn2s = sprintf('%s/%s_corr/neurbehcorr_concatROIs_fsacc_%iiterperm_%s.mat',root,task_dir,iter,datestr(now,'mmddyyyyHHMM')); +save(fn2s); +fprintf('saving to %s...\n',fn2s); +end + diff --git a/spDist_neural_behav_corr_exclutri_individperm_noflipth_stats.m b/spDist_neural_behav_corr_exclutri_individperm_noflipth_stats.m new file mode 100644 index 0000000..32fe9c8 --- /dev/null +++ b/spDist_neural_behav_corr_exclutri_individperm_noflipth_stats.m @@ -0,0 +1,791 @@ +function spDist_neural_behav_corr_exclutri_individperm_noflipth_stats(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + %subj = {'CC','KD','AY','MR','XL','SF','EK'}; + subj = {'AY','CC','EK','KD','MR','SF','XL'}; %alph + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + % ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +% seed random number generator + +rng(spDist_randSeed); + +%% load neural data +startidx = 1; +bidx =1; +WHICH_EXCL = [13 20 21 22]; +all_data_beh = []; +all_subj_beh= []; + +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + + %%%inserting + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + %fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + this_data.s_all = this_scored.ii_sess; + + thisbidx = bidx:(bidx+size(this_scored.ii_sess.trialinfo,1)-1); + + this_data.sess_all = sessidx; + all_data_beh= cat_struct(all_data_beh,this_data); + all_subj_beh(thisbidx,1) = ss; + + bidx =thisbidx(end)+1; + end + + startidx = thisidx(end)+1; + + clear data; + + end + +end + +all_data_beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_beh.s_all.excl_trial, 'UniformOutput',false)); +fprintf('neural and behave loaded...\n') + + +%% load recons, no flipping + +all_recons_noflip = all_recons{1}; % simply reiterate, we are NOT flipping a thing + + +delay_tpt_range = [3.75 5.25; 7.5 9; 10.5 12]; +myTR = 0.75; + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + + + +cond = [1 2]; % do no distractor, then distractor +store_b = nan(length(cond),length(ROIs),length(subj),36); + + +figure; + +for cc= 1:length(cond) + + thisd = nan(length(cond),length(ROIs),length(delay_tpts),length(subj),36, length(angs)); + thisb = nan(1,length(subj)); + + for vv = 1:length(ROIs) + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + for nr =1:nruns + if cc ==1 %%%%%% NOTE THIS COLLECTS THREE TRIALS IN MGS CONDITION %%%% NEED TO FIX!!!! + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==1; + else + thisidx = all_data_beh.use_trial==1 & all_r ==ru(nr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; + end + + thisd(cc,vv,dd,ss,nr,:) = squeeze(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3)); + + thisb(ss) = atan2d(sum(mean(mean(all_recons_noflip(thisidx,:, delay_tpts{dd}),1),3).*sind(angs)),... + sum(mean(mean(all_recons_noflip(thisidx,:,delay_tpts{dd}),1),3).*cosd(angs))); + + store_b(cc,vv,dd,ss,nr) = thisb(ss); + + end + end + end + clear thisidx + clear thisb + + end + +end + +fprintf('neural bias computed ...\n') +%% organize beh data + +% which param should we collect? +dist_colors = spDist_condColors; + +params_of_interest = {'f_sacc'}; + +param_str = {'fsacc'}; + +mu = nan(2,length(subj),length(cond),36); % no subj performed > 36 runs +err = nan(2,length(subj),length(cond),36); +dtheta = nan(length(subj),length(cond),36); +drad = nan(length(subj),length(cond),36); +dtheta_poldeg = nan(length(subj),length(cond),36); + +for cc = 1:length(cond) + for ss = 1:length(subj) + + nruns = 0; + + % get one example set of trials + ru = unique(all_r(all_subj==ss)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + + for nr = 1:nruns + + if cc ==1 + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==1; + else + thisorigidx = all_data_beh.use_trial==1 & all_ROIs ==1 & all_r==ru(nr) & all_subj==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; + end + err(1,ss,cc,nr) = nanstd(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,2)); + mu(:,ss,cc,nr) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); %mean of a single number = the number .. leaving this + tmp(1,:) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + [dtheta(ss,cc,nr), drad(ss,cc,nr)]= cart2pol(tmp(1),tmp(2)); + dtheta_poldeg(ss,cc,nr) = dtheta(ss,cc,nr).*360/(2*pi); + + end + + + + end +end + +% squeeze over subj, collect each subj, all trials into one container +rho_group_theta = nan(length(cond),length(ROIs),1); +pval_group_theta = nan(length(cond),length(ROIs),1); + +bn_corr_theta_dist = figure('Name','behneurcorrthetadist'); +bn_corr_theta_both = figure('Name','behneurcorrthetaboth'); + +for cc = 1:length(cond) + +for vv=1:length(ROIs) + + for dd =1:length(delay_tpts) + thisb_neural_tmp =[]; + thisb_behav_tmp =[]; + thisb_behav = []; + thisb_neural = []; + thisb_behav_poldegtmp =[]; + thisb_behav_poldeg =[]; + + for ss = 1:length(subj) + thisb_neural_tmp(ss,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(ss,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(ss,:)= dtheta_poldeg(ss,cc,:); + end + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + set(0, 'CurrentFigure', bn_corr_theta_dist) + subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; + scatter(thisb_neural,thisb_behav_poldeg,30,dist_colors(cc,:),'filled','MarkerFaceAlpha',.1) + title(ROIs{vv}) + lsline + set(gcf,'Position',[ -110 706 1882 624]) + if vv==1 && dd==1 + ylabel('Epoch 1') + elseif vv==1 && dd==2 + ylabel('Epoch 2') + elseif vv==1 && dd ==3 + ylabel({'Polar angle \circ delta, target, sacc endpt', 'Epoch 3'}) + xlabel('Neural bias, Polar angle \circ') + else + end +end + [rho_group_theta(cc,vv,dd), pval_group_theta(cc,vv,dd)] = corr(thisb_neural, thisb_behav_poldeg); + + end + + + + +end + + + +end + + +%% corr on individual subj, convert to z, t-test + +%fish_theta_fig = figure('Name','fish_theta'); + +store_fish_ztheta= []; +pval_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +rho_sg_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); +fish_z_theta = nan(length(cond),length(subj),length(ROIs),length(delay_tpts)); + +for cc = 1:length(cond) + +for vv=1:length(ROIs) + + for dd = 1:length(delay_tpts) + + for ss = 1:length(subj) + + thisb_neural_tmp = []; + thisb_behav_tmp = []; + thisb_neural = []; + thisb_behav = []; + thisb_behav_poldegtmp =[]; + thisb_behav_polradtmp =[]; + thisb_behav_poldeg =[]; + thisb_behav_polrad =[]; + + thisb_neural_tmp(1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp(1,:)= squeeze(mu(2,ss,cc,:))'; + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); + + + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural_tmp(~isnan(thisb_behav_tmp)); + + thisb_behav_poldeg = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp)); + + + [rho_sg(cc,ss,vv,dd), pval_sg(cc,ss,vv,dd)] = corr(thisb_neural', thisb_behav'); + + fish_z(cc,ss,vv,dd) = atanh(rho_sg(cc,ss,vv,dd)); + + [rho_sg_theta(cc,ss,vv,dd), pval_sg_theta(cc,ss,vv,dd)] =corr(thisb_neural', thisb_behav_poldeg'); + + fish_z_theta(cc,ss,vv,dd) = atanh(rho_sg_theta(cc,ss,vv,dd)); % identical + store_fish_ztheta = [store_fish_ztheta; atanh(rho_sg_theta(cc,ss,vv,dd)) cc ss vv dd ]; + clear mysd + end + +% +% set(0, 'CurrentFigure', fish_theta_fig) +% subplot(1,length(ROIs),vv); hold on; +% plot(dd,fish_z_theta(cc,:,vv,dd),'o','color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',4) +% hold on; +% my_sem_th = std(fish_z_theta(cc,:,vv,dd))/sqrt(length(subj)); +% plot(dd,mean(fish_z_theta(cc,:,vv,dd)), 'o', 'color',dist_colors(cc,:),'markerfacecolor',dist_colors(cc,:),'markersize',8) +% plot(dd*[1 1],[mean(fish_z_theta(cc,:,vv,dd))+1.*my_sem_th, mean(fish_z_theta(cc,:,vv,dd))-1.*my_sem_th], '-', 'color',dist_colors(cc,:),'linewidth',1) +% title(ROIs{vv}) +% ylim([-1 1]) +% xlim([0.05 3.5]) +% if vv==1 +% set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','Epoch 1','Epoch 2','Epoch 3',''},'XTickLabelRotation',45,'TickDir','out'); +% ylabel('Fisher-Z Corr') +% else +% set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out'); +% end + + [h_th,p_th(cc,vv,dd),~,stats_th] = ttest(fish_z_theta(cc,:,vv,dd)); + realT_th(cc,vv,dd) = stats_th.tstat; + + end + +end +end +% +% y_var = store_fish_ztheta(:,1); %fish z +% cond_var = store_fish_ztheta(:,2); %condition +% subj_var = store_fish_ztheta(:,3); %subject +% roi_var = store_fish_ztheta(:,4); %roi +% epoch_var = store_fish_ztheta(:,5); %epoch +% +% % perform real T test +% +% for vv =1:length(ROIs) +% for cc =1:length(cond) +% for ee = 1:3 +% thisidx = roi_var ==vv & cond_var ==cc & epoch_var ==ee; +% y_shuf =y_var(thisidx); %these are already shuffled, see above +% [~,~,~,stats] = ttest(y_shuf); +% real_t(vv,cc,ee) = stats.tstat; +% +% clear thisidx y_shuf +% end +% end +% end +% % perform true 2-way anova +% +% p_real = {}; +% +% f_real = []; +% +% for vv =1:length(ROIs) +% +% thisroiidx = roi_var==vv; +% y = y_var(thisroiidx); +% thiscond= cond_var(thisroiidx); +% thissubj = subj_var(thisroiidx); +% thisepoch = epoch_var(thisroiidx); +% [f_real(vv,:)] = RMAOV2_gh([y,thisepoch,thiscond,thissubj],0.05); +% clear thisroiidx y thiscond thissubj thisepoch +% +% end +% +% +% clear cond_var roi_var epoch_var subj_var y_var +% +% y_var = store_fish_ztheta(:,1); %fish z +% cond_var = store_fish_ztheta(:,2); %condition +% subj_var = store_fish_ztheta(:,3); %subject +% roi_var = store_fish_ztheta(:,4); %roi +% epoch_var = store_fish_ztheta(:,5); %epoch +% +% % 1-way +% +% f_real_one = []; +% pval_real_one =[]; +% +% for cc =1:length(cond) +% for vv =1:length(ROIs) +% +% thisroiidx = roi_var==vv & cond_var==cc; +% y = y_var(thisroiidx); +% +% thissubj = subj_var(thisroiidx); +% thisepoch = epoch_var(thisroiidx); +% +% [f_real_one(cc,vv), pval_real_one(cc,vv)] = RMAOV1_gh([y,thisepoch,thissubj],0.05); +% clear thisroiidx y thissubj thisepoch +% +% end +% end +% +% +% clear cond_var roi_var epoch_var subj_var y_var +% check the usage of 'random' per the grouping var +%%%%%%%%%%%%%%%%%%%%%%%%% PERM TEST # 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% we're permuting two measures here, linear bias and ciruclar bias, open +iter = 1000; +t_iter =cell(length(ROIs),iter); +p_iter =cell(length(ROIs),iter); +f_store_iter_2 = nan(length(ROIs),iter,3); +fish_zthstore_perm =[]; +fish_zthperm = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +shuff_Tth =nan(length(cond),length(ROIs),length(delay_tpts),iter); +rho_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); +pval_permth = nan(length(cond),length(subj),length(ROIs),length(delay_tpts),iter); + + +for xx = 1:iter + + if xx == 1 + fprintf('starting @ %s \n',datestr(now,'HH:MM:SS')) + tic + elseif xx == 2 + toc + elseif xx == 3 + toc + elseif xx == iter/4 + fprintf('quarter-way ...\n') + toc + elseif xx == iter/2 + fprintf('halfway ...\n') + toc + else + end + + for cc = 1:length(cond) + for vv=1:length(ROIs) + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + thisb_neural_tmp_perm = []; + thisb_behav_tmp_perm = []; + thisb_behav_perm = []; + thisb_neural_perm = []; + thisb_behav_poldegtmp = []; + thisb_behav_poldegperm = []; + thisb_neural_poldegperm = []; + shuff_btheta =[]; + shuff_ntheta =[]; + + + thisb_neural_tmp_perm (1,:) = squeeze(store_b(cc,vv,dd,ss,:)); + thisb_behav_tmp_perm (1,:)= squeeze(mu(2,ss,cc,:))'; + + thisb_behav_poldegtmp(1,:)= dtheta_poldeg(ss,cc,:); %this obv cant change across ROI, delay, lose two dimens (vv,dd) here + + + thisb_behav_poldegperm = thisb_behav_poldegtmp(~isnan(thisb_behav_tmp_perm)); + + thisb_neural_poldegperm = thisb_neural_tmp_perm (~isnan(thisb_behav_tmp_perm)); + + % do the shuffle + shuff_btheta = thisb_behav_poldegperm; %reload these each time + shuff_ntheta = thisb_neural_poldegperm; + subjidxth = find(shuff_btheta); + shuff_bidxth = randperm(length(subjidxth))'; + shuff_btheta(subjidxth) = shuff_btheta(shuff_bidxth); %insert shuffled subj indices into bdata (note : in this case, bdata is ONLY this subj. just jumbling idx) + + bthdata = shuff_btheta(subjidxth); + nthdata = shuff_ntheta(subjidxth); + + [rho_permth(cc,ss,vv,dd,xx), pval_permth(cc,ss,vv,dd,xx)] = corr(nthdata',bthdata'); + fish_zthperm(cc,ss,vv,dd,xx) = atanh(rho_permth(cc,ss,vv,dd,xx)); + + + % fish_zthstore_perm =[fish_zthstore_perm; fish_zthperm(cc,ss,vv,dd,xx) cc ss vv dd xx]; + + + clear thisidx subjidxth shuff_bidxth shuff_btheta shuff_ntheta bthdata nthdata + end + + [h,p,~,statsth] = ttest(fish_zthperm(cc,:,vv,dd,xx)); + shuff_Tth(cc,vv,dd,xx) = statsth.tstat; + + end + end + end +end + + + +% collect original perm pvalues + +p_th_twotail =nan(length(cond),length(ROIs),length(delay_tpts)); +p_th_onetail =nan(length(cond),length(ROIs),length(delay_tpts)); + +pfdr_th_twotail =[]; +pmask_th_twotail =[]; +pmask_th_onetail =[]; +pfdr_th_onetail =[]; + +p_th_twotaile = []; +p_th_onetaile = []; +pmask_th_twotaile = []; +pmask_th_onetaile = []; +pfdr_th_twotaile = []; +pfdr_th_onetaile = []; + + +tdistpolbias = figure('Name','tdistpolbias'); + +realT_col = lines(3); +for cc =1:length(cond) + for dd = 1:length(delay_tpts) + for vr = 1:length(ROIs) + + hold on; + subplot(1,length(ROIs),vr) + histogram(sort(shuff_Tth(cc,vr,dd,:))) + line([realT_th(cc,vr,dd) realT_th(cc,vr,dd)], [0 max(ylim)],'LineWidth',0.75,'color',realT_col(dd,:)) + p_th_twotail(cc,vr,dd) = 2 * min ( mean( shuff_Tth(cc,vr,dd,:) <= realT_th(cc,vr,dd) ), mean ( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd))); + p_th_onetail(cc,vr,dd) = mean( shuff_Tth(cc,vr,dd,:) >= realT_th(cc,vr,dd) ); + title(ROIs{vr}) + end + + [pfdr_th_twptail(cc,:,dd), pmask_th_twotail(cc,:,dd)] = fdr(p_th_twotail(cc,:,dd),0.05); % this is two tail + [pfdr_th_onetail(cc,:,dd), pmask_th_onetail(cc,:,dd)] = fdr(p_th_onetail(cc,:,dd),0.05); %one tail + + + end + +end + + +% +% two-way anova perm for each ROI? + % correct across epochs? + + + +tmp = [squeeze(p_th_onetail(:,:,1)); squeeze(p_th_onetail(:,:,2)); squeeze(p_th_onetail(:,:,3))] + +[fdrout, maskout] = fdr(tmp,0.05); + + +%% hold off on other perms for now - 102920 + + + + +y_var = fish_zthstore_perm(:,1); +cond_var = fish_zthstore_perm(:,2); +subj_var = fish_zthstore_perm(:,3); +roi_var = fish_zthstore_perm(:,4); +epoch_var = fish_zthstore_perm(:,5); +iter_var = fish_zthstore_perm(:,6); + + + +for zz =1:iter + + for vv = 1:length(ROIs) + + + thisroiidx = roi_var ==vv & iter_var == zz; + y_shuf = y_var(thisroiidx); %these are already shuffled, see above + thisepoch = epoch_var(thisroiidx); + thiscond =cond_var(thisroiidx); + thissubj=subj_var(thisroiidx); + + [p_iter{vv,zz},t_iter{vv,zz},~] = anovan(y_shuf,{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'},'display','off'); + [f_store_iter_2(vv,zz,:)] = RMAOV2_gh([y_shuf,thisepoch,thiscond,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj y_shuf + + end +end +toc + +% visualize + +iv_str_rm ={'epoch','cond','epoch*cond'}; +which_effect_rm = [1 2 3]; +exact_store_tmp=[]; +exact_store_rm_2 =nan(length(ROIs),length(which_effect_rm)); + +for vv =1:length(ROIs) + figure('name','2-way perm; RMAOV2') + + for ww =1:length(which_effect_rm) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; f_store_iter_2(vv,ii,which_effect_rm(ww))]; + end + hold on; + + subplot(1,length(which_effect_rm),ww) + histogram(extract_vals) + line([f_real(vv,which_effect_rm(ww)) f_real(vv,which_effect_rm(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str_rm{which_effect_rm(ww)},'Interpreter','none'); + % exact_p = sum(extract_vals >= f_real(vv,which_effect_rm(ww)))/iter; + exact_p = 2 * min ( sum(extract_vals >= f_real(vv,which_effect_rm(ww)))/iter, sum(extract_vals <= f_real(vv,which_effect_rm(ww)))/iter ); + + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) + exact_store_rm_2(vv,ww) = [exact_store_tmp; exact_p]; + clear exact_p + sgtitle(ROIs{vv}) + title(iv_str_rm{ww}) + if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + + end +end + +% one-way anova perm +for xx=1:iter +for cc =1:length(cond) +for vv =1:length(ROIs) + + thisroiidx = roi_var==vv & cond_var==cc & iter_var ==xx; + y = y_var(thisroiidx); + thissubj = subj_var(thisroiidx); + thisepoch = epoch_var(thisroiidx); + + [f_real_one_perm(cc,vv,xx)] = RMAOV1_gh([y,thisepoch,thissubj],0.05); + clear thisroiidx y thissubj thisepoch + +end +end +end + +% visualize 1--way result + +iv_str_rm ={'epoch'}; +which_effect_rm = 1; +exact_store_tmp = []; +exact_store_rm_1 =nan(length(ROIs),length(which_effect_rm)); + +for vv =1:length(ROIs) + figure('name','2-way perm; RMAOV2') +for cc =1:length(cond) + + extract_vals= []; + for ii= 1:iter + extract_vals = [extract_vals; f_real_one_perm(cc,vv,ii)]; + end + + + subplot(1,2,cc) + hold on; + histogram(extract_vals) + line([f_real_one(cc,vv) f_real(cc,vv)], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str_rm{which_effect_rm(1)},'Interpreter','none'); + % exact_p = sum(extract_vals >= f_real(vv,which_effect_rm(ww)))/iter; + exact_p = 2 * min ( sum(extract_vals >= f_real_one(cc,vv))/iter, sum(extract_vals <= f_real_one(cc,vv))/iter ); + + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) + exact_store_rm_1(vv,1) = [exact_store_tmp; exact_p]; + clear exact_p + sgtitle(ROIs{vv}) + title(iv_str_rm{1}) + xlabel('T-stat') + ylabel('Frequency of T-stat') + + +end +end + + + + +% do ttest for each roi,epoch,condition + +for xx =1:iter + for vv =1:length(ROIs) + for cc =1:length(cond) + for ee = 1:3 + thisidx = roi_var ==vv & cond_var ==cc & epoch_var ==ee & iter_var == xx; + y_shuf =y_var(thisidx); %these are already shuffled, see above + [~,~,~,stats] = ttest(y_shuf); + shuff_t(vv,cc,ee,xx) = stats.tstat; + + clear thisidx y_shuf + end + end + end +end +fprintf('done') + +% pvals + +for cc =1:length(cond) + for ee = 1:3 + for vv =1:length(ROIs) + + pval_twotail(cc,vv,ee) = 2 * min(mean(shuff_t(vv,cc,ee,:) <= real_t(vv,cc,ee)), mean(shuff_t(vv,cc,ee,:) >= real_t(vv,cc,ee))); + pval_onetail(cc,vv,ee) = mean(shuff_t(vv,cc,ee,:) >= real_t(vv,cc,ee)); + + end + [pval_fdrthresh_twotail(cc,:,ee), pval_th_twotail_mask(cc,:,ee)] = fdr(pval_th_twotail(cc,:,ee),0.05); % this is two tail + [pval_fdrthresh_onetail(cc,:,ee), pval_th_onetail_mask(cc,:,ee)] = fdr(pval_th_onetail(cc,:,ee),0.05); %one tail + + end +end + + + + +fprintf('done') + +fn2s = sprintf('%s/%s_corr/neurbehcorr_concatROIs_fsacc_%iiterperm_%s.mat',root,task_dir,iter,datestr(now,'mmddyyyyHHMM')); +save(fn2s); +fprintf('saving to %s...\n',fn2s); +end + diff --git a/spDist_neural_behav_corr_sess.m b/spDist_neural_behav_corr_sess.m new file mode 100644 index 0000000..b36276e --- /dev/null +++ b/spDist_neural_behav_corr_sess.m @@ -0,0 +1,558 @@ +function spDist_neural_behav_corr_sess(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'CC','KD','AY','MR','XL','SF','EK'}; + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + % ROIs = {'V1','V2','V3','V3AB','hV4','VO1','VO2','LO1','LO2','TO1','TO2','IPS0','IPS1','IPS2','IPS3','sPCS'}; + ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'} +end + + +func_suffix = 'surf'; + +cat_mode = 1; % if 1, look for catSess1Ses...SessN_ files, otherwise, just look for each session in turn + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + +plot_tpts = 7:15; % for a plot where we average reconstructions over a fixed time window + +dist_time = 4.5; % onset at 4 s + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + + + + + + +%% load neural data +startidx = 1; +bidx =1; +WHICH_EXCL = [13 20 21 22]; +all_data_beh = []; +all_subj_beh=[]; + +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + + %%%inserting + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + %fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + this_data.s_all = this_scored.ii_sess; + + thisbidx = bidx:(bidx+size(this_scored.ii_sess.trialinfo,1)-1); + + this_data.sess_all = sessidx; + all_data_beh= cat_struct(all_data_beh,this_data); + all_subj_beh(thisbidx,1) = ss; + all_sess_beh(thisbidx,1) = sessidx; + %all_r_b(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1)),1) = (this_data.sess_all*100+this_data.s_all.r_num); + + bidx =thisbidx(end)+1; + end + %%%% + + + startidx = thisidx(end)+1; + + clear data; + + end + +end +all_data_beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data_beh.s_all.excl_trial, 'UniformOutput',false)); +fprintf('pause') +%% behav import +% subj = {'CC','KD','AY','MR','XL','SF','EK'}; +% sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed +% +% +% WHICH_EXCL = [13 20 21 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. +% if ismember(WHICH_EXCL,13) +% which_excl_str ={'broken fix'}; +% elseif ismember(WHICH_EXCL,[13 20]) +% which_excl_str ={'broken fix','no sacc'}; +% elseif ismember(WHICH_EXCL, [13 20 21]) +% which_excl_str ={'broken fix','no sacc','i sacc too small/short'}; +% elseif ismember(WHICH_EXCL, [13 20 22]) +% which_excl_str ={'broken fix','no sacc','i sacc err too lg'}; +% elseif ismember(WHICH_EXCL, [13 20 21 22]) +% which_excl_str ={'broken fix','no sacc','i sacc too small/short','i sacc err too lg'}; +% else +% error('which exclusion criteria have you chosen?') +% end +% +% % first-digit: +% % - 1 - trial-level exclusion (bad drift correction [11], calibration [12], or delay- +% % fixation break [13] +% % - 2 - primary saccade exclusion (no primary sacc [20]; too small/short [21] bi, large error [22]ei) +% +% %21 bad initial saccade (duration/amplitude outside range) +% % 22 iniital saccade error +% +% +% % concatenate ALL subject data +% all_subj_beh = nan(1000*length(subj),1); +% +% all_data.beh = []; +% all_data.behn =[]; +% startidx = 1; +% bnidx =1; +% for ss = 1:length(subj) +% for sessidx = 1:length(sess{ss}) +% +% +% fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); +% fprintf('Loading scored eye data from %s\n',fn); +% this_scored = load(fn); +% +% this_data.s_all = this_scored.ii_sess; +% this_data.sess_all = sessidx; +% +% this_subj = ss; +% +% all_data.beh = cat_struct(all_data.beh,this_data); +% all_subj_beh(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = this_subj; +% all_r_b(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1)),1) = (this_data.sess_all*100+this_data.s_all.r_num); +% +% all_data.behn(bnidx:(bnidx-1+(size(this_scored.ii_sess.trialinfo,1)*length(ROIs))),1) = repmat( ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), this_data.s_all.excl_trial, 'UniformOutput',false) ), length(ROIs),1); +% all_sess_b(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1)),1) = this_data.sess_all; +% +% bnidx = bnidx + size(this_scored.ii_sess.trialinfo,1)*length(ROIs); +% startidx = startidx+size(this_scored.ii_sess.trialinfo,1); +% clear this_subj this_data; +% end +% end +% +% +% all_subj_beh = all_subj_beh(1:(startidx-1)); +% all_data.beh.subj_all = all_subj_beh; +% +% % determine which trials to include +% % first, narrow based on saccade preprocessing/scoring exclusions +% all_data.beh.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data.beh.s_all.excl_trial, 'UniformOutput',false)); +% all_data.beh.use_trial(all_data.beh.s_all.f_sacc_err>10) = 0; %exclude trials with errors > 10 deg +% all_data.beh.use_trial(all_data.beh.s_all.i_sacc_err>10) = 0; +% %all_data.beh.use_trial(ismember(all_data.beh.s_all.r_num, [8,12,14]) & all_subj_beh==3) = 0; %3 here specifically refers to subj 3 above (AY), see spDist_eyeDataNotes for +% % drop trials with very short (< 100 ms) or very long RT (> 1 s) +% %all_data.beh.use_trial(all_data.beh.s_all.i_sacc_rt<0.1 | all_data.beh.s_all.i_sacc_rt>1.0) = 0; +% + + +%% align like distractor bins (and flip/average) 1D near only +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly +% new code +% flip negative angles +% + +%roi_str= {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this matches all_conds(:,6) (relative distractor angle bin) + +flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +all_recons_flipped(flipidx,:) = fliplr(all_recons_flipped(flipidx,:)); + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +sprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj),2); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); +sessions =[1 2]; + +figure +test_store =[]; +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + subplot(length(cond_to_plot),length(ROIs),(ff-1)*length(ROIs)+vv); hold on; + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + + for ss = 1:length(subj) + + + for sh =1:length(sessions) + thisidx = all_data_beh.use_trial==1 & all_sess ==sessions(sh) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; % %this needs to be further checked.. all_data.behn==1; + + % thisidx = all_sess ==sessions(sh) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 ; % %this needs to be further checked.. all_data.behn==1; + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss,sh) = thisb(ss); + test_store = [test_store; thisb(ss) vv ss sh]; + end + end + + + end + clear thisidx + clear thisb + clear thisd +end + +% y_tmp = test_store(:,1); +% roi_var_tmp = test_store(:,2); +% subj_var_tmp = test_store(:,3); +% +% y = y_tmp(~isnan(y_tmp)); +% roi_var = roi_var_tmp(~isnan(y_tmp)); +% subj_var = subj_var_tmp(~isnan(y_tmp)); + + +[f_out] = RMAOV1_gh([test_store(:,1), test_store(:,2), test_store(:,3)]); +RMAOV1([test_store(:,1), test_store(:,2), test_store(:,3)]) +%RMAOV1([y, roi_var, subj_var]) + +for tt =1:size(store_b,1) %condition = 1, near; +for rr =1:length(ROIs) +[H(tt,rr), P(tt,rr), CI, STATS] = ttest(store_b(tt,rr,:)); +t_real = STATS.tstat; +clear STATS CI +end +[p_fdr(tt,:) p_masked(tt,:)] = fdr(P(tt,:),0.05); + +end +corrected_pval = P <= p_fdr; +set(gcf,'Position',[15 1052 2542 286]) + +%% organize beh data +distractor_bins = unique(all_data.beh.s_all.trialinfo(all_data.beh.s_all.trialinfo(:,1)~=1,6)); +distractor_spacing = 360/length(distractor_bins); + +flip_bins = [1 2 3]; %which distractor bins should we "flip" the Y in order to collapse across CW/CCW distractors? + + +cond_str = {'No distractor','Distractor'}; + + +params_of_interest = {'f_sacc'}; +param_str = {'f sacc'}; + + +subj_col = lines(7); +mu = nan(2,length(subj)); % no subj performed > 36 runs +err = nan(2,length(subj)); + +for ss = 1:length(subj) + + + for sh = 1:length(sessions) + %%%%%%% NOT EXCLUDING ON BASIS OF USE_TRIAL %%%%%%%%%% + % tmpidx = all_sess_beh==sessions(sh) & all_subj_beh==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0 & all_data_beh.s_all.trialinfo(:,10) < 0; %negative CW jitter +% + tmpidx = all_data_beh.use_trial==1 & all_sess_beh==sessions(sh) & all_subj_beh==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0 & all_data_beh.s_all.trialinfo(:,10) < 0; %negative CW jitter + + orig_y = all_data_beh.s_all.(params_of_interest{1})(tmpidx,2); + orig_y_flip = orig_y*-1; + all_data_beh.s_all.(params_of_interest{1})(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins. + + thisorigidx = all_data_beh.use_trial==1 & all_sess_beh== sessions(sh) & all_subj_beh==ss & all_data_beh.s_all.trialinfo(:,1)==2 & all_data_beh.s_all.trialinfo(:,6)==0; %now, collect all jitters. + + % distractor bin x param x [radial; tangential] x subj + err(:,ss,sh) = nanstd(all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), [], 1 ); % this wont work here bc we're working with + mu(:,ss,sh) = nanmean( all_data_beh.s_all.(params_of_interest{1})(thisorigidx,:), 1 ); + + end + + +end + +%plot just the behav bias +figure +subplot(1,length(params_of_interest),1); hold on; +for ss = 1:length(subj) + thism_near = squeeze(mu(2,ss,:))'; %this is the only condition that is information for this analysis. + plot(ss,thism_near,'o','MarkerSize',5, 'Color',subj_col(ss,:),'markerfacecolor',subj_col(ss,:)); + hold on; + plot(ss,nanmean(thism_near),'o','MarkerSize',8, 'Color',subj_col(ss,:),'markerfacecolor',subj_col(ss,:)); + set(gca,'xlim',[0.5 length(subj)+0.5], 'xtick',[1:length(subj)],'xticklabel', [1:length(subj)]) + clear thism_near +end +title('mu') +ylabel('DVA, tangential mean error') +xlabel('subj') + +figure +for vv=1:length(ROIs) + subplot(1,length(ROIs),vv); hold on; + for ss = 1:length(subj) + thism_near = squeeze(store_b(1,vv,ss,:))'; %this is the only condition that is information for this analysis. + plot(ss,thism_near,'o','MarkerSize',3, 'Color',subj_col(ss,:),'markerfacecolor',subj_col(ss,:)); + hold on; + plot(ss,nanmean(thism_near),'o','MarkerSize',8, 'Color',subj_col(ss,:),'markerfacecolor',subj_col(ss,:)); + set(gca,'xlim',[-0.5 length(subj)+0.5], 'xtick',[1:length(subj)],'xticklabel', [1:length(subj)]) + + end + ylim([-180 180]) + title(ROIs{vv}) + if vv==1 + ylabel('polar angle') + xlabel('subj') + else + end + +end + %group avg, simple + + figure + thism_near_tmp = squeeze(mu(2,:,:)); %this is the only condition that is information for this analysis. + thism_near = [thism_near_tmp(:,1); thism_near_tmp(:,2)]; + + plot(1,thism_near,'o','MarkerSize',3, 'Color',subj_col(ss,:),'markerfacecolor',[.5 .5 .5]); + hold on; + plot(1,nanmean(thism_near),'o','MarkerSize',8, 'Color',subj_col(ss,:),'markerfacecolor',[.5 .5 .5]); + tmpe = std(thism_near)/sqrt(length(subj)); + plot(1*[1 1],nanmean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color','k'); + + if vv==1 + ylabel('DVA, mu') + xlabel('subj') + else + end + + [h,p]= ttest(thism_near) + + title('Bias') +% $ fig + figure ; + for vv=1:length(ROIs) + + subplot(1,length(ROIs),vv); hold on; + thisb_neural_tmp = squeeze(store_b(1,vv,:,:)); %this is the only condition that is information for this analysis. + thisb_neural = [thisb_neural_tmp(:,1); thisb_neural_tmp(:,2)]; + thisb_behav_tmp = squeeze(mu(2,:,:)); %this is the only condition that is information for this analysis. + thisb_behav =[thisb_behav_tmp(:,1); thisb_behav_tmp(:,2)]; + + %thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + %thisb_neural = thisb_neural(~isnan(thisb_behav_tmp)); %need to trim based on behav, nan's are unavoidable + plot(thisb_neural,thisb_behav,'o','markerface',subj_col(ss,:),'markerfacecolor',subj_col(ss,:)) + lsline + if vv==1 && ss ==7 + xlabel('Polar angle \circ, Neural bias') + ylabel('DVA, saccadic tangential mean error (Bias)') + set(gca,'Xtick',[-180:90:180],'Xticklabel',{'180','90','0','90','180'},'xticklabelrotation',45,'TickDir','out') + else + set(gca,'xtick',[-180:90:180],'xticklabel',{'','','','',''},'TickDir','out') + end + title(ROIs{vv}) + [rho(vv), pval(vv)] =corr(thisb_neural, thisb_behav) + clear thisb_neural thisb_behav thisb_behav_tmp thisb_neural_tmp + end + + %do corr using ERR + figure ; + for vv=1:length(ROIs) + + subplot(1,length(ROIs),vv); hold on; + thisb_neural_tmp = squeeze(store_b(1,vv,:,:)); %this is the only condition that is information for this analysis. + thisb_behav_tmp = squeeze(err(1,:,:)); %this is the only condition that is information for this analysis. + thisb_neural = [thisb_neural_tmp(:,1); thisb_neural_tmp(:,2)]; + thisb_behav = [thisb_behav_tmp(:,1); thisb_behav_tmp(:,2)]; + + + %thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + %thisb_neural = thisb_neural(~isnan(thisb_behav_tmp)); %need to trim based on behav, nan's are unavoidable + + plot(thisb_behav,thisb_neural,'o','markerface',subj_col(ss,:),'markerfacecolor',subj_col(ss,:)) + lsline + if vv==1 && ss ==7 + xlabel('Polar angle \circ, Neural bias') + ylabel('DVA, saccadic tangential STD error') + set(gca,'ytick',[-180:90:180],'yticklabel',{'180','90','0','90','180'},'yticklabelrotation',45,'TickDir','out') + set(gca,'xtick',[-2:0.5:2],'yticklabelrotation',45,'TickDir','out') + + else + set(gca,'ytick',[-180:90:180],'xticklabel',{'','','','',''},'TickDir','out') + set(gca,'xtick',[-2:0.5:2],'yticklabelrotation',45,'TickDir','out') + + + end + title(ROIs{vv}) + [rho(vv), pval(vv)] =corr(thisb_neural, thisb_behav) + clear thisb_neural thisb_behav + end + +%group avg over runs + figure ; + for vv=1:length(ROIs) + + for ss = 1:length(subj) + subplot(1,length(ROIs),vv); hold on; + thisb_neural = squeeze(store_b(1,vv,ss,:)); %this is the only condition that is information for this analysis. + thisb_behav= squeeze(mu(2,ss,:)); %this is the only condition that is information for this analysis. + thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp)); + thisb_neural = thisb_neural(~isnan(thisb_behav_tmp)); %need to trim based on behav, nan's are unavoidable + + plot(thisb_neural,thisb_behav,'o','markerface',subj_col(ss,:),'markerfacecolor',subj_col(ss,:)) + lsline + if vv==1 + xlabel('Polar angle \circ, Neural bias') + ylabel('DVA, saccadic tangential mean error') + set(gca,'Xtick',[-180:90:180],'xticklabel',{'180','90','0','90','180'},'xticklabelrotation',45,'TickDir','out') + + else + set(gca,'Xtick',[-180:90:180],'xticklabel',{'','','','',''},'TickDir','out') + + + end + title(ROIs{vv}) + [rho_group(vv), pval_group(vv)] =corr(thisb_neural, thisb_behav) + clear thisb_neural thisb_behav + end + end + + figure ; + for vv=1:length(ROIs) + + %for ss = 1:length(subj) + subplot(1,length(ROIs),vv); hold on; + thisb_neural = squeeze(nanmean(store_b(1,vv,:,:),4)); %this is the only condition that is information for this analysis. + thisb_behav= squeeze(nanmean(mu(2,:,:),3))'; %this is the only condition that is information for this analysis. + % thisb_behav = thisb_behav_tmp(~isnan(thisb_behav_tmp))'; + %thisb_neural = thisb_neural(~isnan(thisb_behav_tmp)); %need to trim based on behav, nan's are unavoidable + + plot(thisb_neural,thisb_behav,'o','markerface',subj_col(ss,:),'markerfacecolor',subj_col(ss,:)) + lsline + if vv==1 + xlabel('Polar angle \circ, Neural bias') + ylabel('DVA, saccadic tangential mean error') + set(gca,'Xtick',[-180:90:180],'xticklabel',{'180','90','0','90','180'},'xticklabelrotation',45,'TickDir','out') + + else + set(gca,'Xtick',[-180:90:180],'xticklabel',{'','','','',''},'TickDir','out') + + + end + title(ROIs{vv}) + [rho_group(vv), pval_group(vv)] =corr(thisb_neural, thisb_behav) + clear thisb_neural thisb_behav + %end + end + + figure; imagesc(rho) + ylabel('ROI') + set(gca,'Ytick',[1:1:length(ROIs)],'Yticklabel',{'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}) + title('Trial-by-trial correlations, f sacc bias & neural bias') + caxis([-1 1]) + colorbar + fprintf('done') + + +end + + diff --git a/spDist_neural_bias.m b/spDist_neural_bias.m new file mode 100644 index 0000000..73b1296 --- /dev/null +++ b/spDist_neural_bias.m @@ -0,0 +1,688 @@ +% spDist_pilot_plotReconstructions_thruTime_gh.m +% adapted from MGSMap_plotReconstructions_cv_thruTime1.m +% +% for plotting WM reconstructions during trials with/without spatial +% distractor, plotting distractor-aligned reconstructions, and sorting +% trials based on relative distractor position + +% for plotting cross-validated WM reconstructions from mapping task, +% computed using MGSMap_channelRespAmp* scripts +% +% TODO: extend to compareReconstruction, which can load multiple sets of +% sessions per subj, and will compare across sessions (and/or across sets +% of tpts, etc... - only one set of comparisons at a time?) + +function spDist_neural_bias(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'CC','KD','AY','MR','XL','SF','EK'}; + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + +cat_mode = 1; % if 1, look for catSess1Ses...SessN_ files, otherwise, just look for each session in turn + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + +plot_tpts = 7:15; % for a plot where we average reconstructions over a fixed time window + +dist_time = 4.5; % onset at 4 s + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +delay_tpt_range = [3.75 5.25; 7.5 9; 10.5 12]; + + + +% for fidelity timecourses +tmpcolors = lines(7); + +ROI_colors = [repmat(tmpcolors(1,:),3,1); % V1, V2, V3 + tmpcolors(4,:); % V3AB + tmpcolors(1,:); % hV4 + repmat(tmpcolors(3,:),1,1); % VO1 + repmat(tmpcolors(1,:),2,1); % LO1/2 + + repmat(tmpcolors(2,:),2,1); % TO1-2 + + repmat(tmpcolors(5,:),2,1); % IPS0-1 + repmat(tmpcolors(6,:),2,1); % IPS2-3 + tmpcolors(7,:); % sPCS + ]; % iPCS (color 1...) + + +%% load data +startidx = 1; +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + if cat_mode == 1 + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + startidx = thisidx(end)+1; + + clear data; + + else + + + for sess_idx = 1:length(sess{ss}) + % build fn + fn = sprintf('%swmChoose_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_cv_thruTime1.mat',root,subj{ss},sess{ss}{sess_idx},ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*numel(sess)*size(data.recons,1); + + all_recons = nan(nblankt,size(data.recons,2),size(data.recons,3)); + all_conds = nan(nblankt,size(data.c_map,2)); + + all_fidelity = nan(nblankt,size(data.recons,3)); % timecoruse of fidelity + + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + angs = data.angs; + tpts = data.delay_tpts; + + all_r2 = nan(length(ROIs),length(tpts),length(subj)); + + end + + + if sess_idx == 1 + tmp_r2 = nan(length(tpts),length(sess{ss})); % average acorss sessions... + end + + thisidx = startidx:(startidx+size(data.c_map,1)-1); + + + all_recons(thisidx,:,:) = data.recons; + all_fidelity(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons,2)); + + + all_conds(thisidx,:) = data.c_map; + + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = sess_idx; + + tmp_r2(:,sess_idx) = squeeze(mean(mean(data.r2_all,1),2)); + + startidx = thisidx(end)+1; + + clear data; + + end + + + end + end + +end + + +%% align like distractor bins (and flip/average) 1D near only +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly +% new code +% flip negative angles +% + +roi_str= {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this rel wil only match 0 bin trials, bc ang difference there is +% only the jitter, not bin dist + +flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +all_recons_flipped(flipidx,:,:) = fliplr(all_recons_flipped(flipidx,:,:)); % updated this oct 20 + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); + +figure +test_store =[]; +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + subplot(length(cond_to_plot),length(ROIs),(ff-1)*length(ROIs)+vv); hold on; + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0; + + %thatidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & + %all_conds(:,6)==2 & this_rel > 0; % figure % this is geh checking things, on 10/21/20 + %thisd2(:,:,ss) = squeeze(mean(all_recons_flipped(thatidx,:,:),1)).'; + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss) = thisb(ss); + test_store = [test_store; thisb(ss) vv ss]; + end + + hold on + t = mean(thisd((tpts_to_plot),:,:),1); + myd_sem = nanstd(t,[],3) /sqrt(length(subj)); +% figure % this is geh checking things, on 10/21/20 +% for sbj = 1:7 +% hold on; plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,sbj),3),1),'LineWidth',2,'color',cond_colors(ff,:)) +% hold on; plot(linspace(-180,180,90),mean(mean(thisd2(tpts_to_plot,:,sbj),3),1),'LineWidth',2,'color','r') % pos +% end + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3),1),'LineWidth',2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + btwn_d = [mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem fliplr(mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem)]; + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_d,cond_colors(ff,:),'facealpha',0.4); + mybias_sem = std(store_b(ff,vv,:)) /sqrt(length(subj)); + line([mean(store_b(ff,vv,:),3) mean(store_b(ff,vv,:),3)], [0 2], 'color','k','linewidth',1,'linestyle','-') + hold on; + btwn_b=[mean(store_b(ff,vv,:),3)-1*mybias_sem fliplr(mean(store_b(ff,vv,:),3)+1*mybias_sem)]; + plot([mean(store_b(ff,vv,:),3)-1*mybias_sem mean(store_b(ff,vv,:),3)-1*mybias_sem], [0 2],'r-.','linewidth',0.5) + plot([mean(store_b(ff,vv,:),3)+1*mybias_sem mean(store_b(ff,vv,:),3)+1*mybias_sem], [0 2],'r-.','linewidth',0.5) + fill([btwn_b(1) btwn_b(1) btwn_b(2) btwn_b(2)], [0 2 2 0],'r','facealpha',0.2); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + plot([min(xlim) max(xlim)], [0 0], '-', 'color', [.2 .2 .2]) + x = linspace(-180,180,90); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + + if ff == 1 && vv ==1 + title(ROIs{vv}); + + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','90','0','90','180'},'XTickLabelRotation',45,'TickDir','out'); + xlabel('Polar angle (\circ)'); + ylabel('Near Distractor'); + else + title(ROIs{vv}); + set(gca,'XTick',-180:90:180,'XTickLabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out') + + end + ylim([-.8 2]) + xlim([-180 180]); + + + end + clear thisidx + clear thisb + clear thisd +end + + +%store_b dimens +% 1: near distractor +% 2: ROI +% 3: subj +% do rm anova + + +%[f_out] = RMAOV1_gh([test_store(:,1), test_store(:,2), test_store(:,3)]) +%RMAOV1([test_store(:,1), test_store(:,2), test_store(:,3)]) + +for tt =1:size(store_b,1) %condition = 1, near; +for rr =1:length(ROIs) +[H(tt,rr), P(tt,rr), CI, STATS] = ttest(store_b(tt,rr,:)); +t_real(rr) = STATS.tstat; +%fprintf('%s p=%i, t-score =%i, df=%i,sd=%i,mean =', ROIs{rr}, P(tt,rr),STATS.tstat,STATS.df,STATS.sd,mean(store_b(tt,rr,:),3)) +clear STATS CI +end +[p_fdr(tt,:) p_masked(tt,:)] = fdr(P(tt,:),0.05); + +end +corrected_pval = P <= p_fdr; +set(gcf,'Position',[15 1052 2542 286]) +%do RM ANOVA to check for differences among offset conditions +%% shuffle +% align like distractor bins (and flip/average) 1D near only +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly + + +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0]; %which trial type? +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); +bshuff_store=[]; +iter = 1000; +data_store =nan(iter,length(angs),length(subj)); +tic +for xx = 1:iter + + +for ff = 1:length(cond_to_plot) + + for vv = 1:length(ROIs) + + thisdata = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj),iter); %recon data + thisb = nan(1,length(subj),iter); %computed bias + %all_recons_tmp = all_recons{1}; + %all_recons_flipped = all_recons{1}; + for ss = 1:length(subj) + %thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + + + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0; %this is collecting all cw/ccw trials + findidx = find(thisidx); + tmp= randperm(length(findidx))'; + shuff_idx = findidx(tmp); + flipidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 & this_rel<0; %collect just cw trials, want to flip this many trials + nflip = size(find(flipidx),1); % how many trials are truly cw? a # + tmp_flip = shuff_idx(1:nflip,1); % flip the correct # of trial labels, but ranomly chosen from the shuffled 0 label idx, + all_recons_tmp = all_recons{1}; + all_recons_flipped = all_recons{1}; + flip_log = zeros(length(flipidx),1); + flip_log(tmp_flip,1) = 1; % needs to actually be 'logical' not ones, zeros.. + a =logical(flip_log); + all_recons_flipped(a,:,:) = fliplr(all_recons_tmp(a,:,:)); + thisdata = all_recons_flipped(shuff_idx,:,tpts_to_plot); %now access recon that have been randomly flipped with 0 label shuffled + data_store(xx,:,ss) = mean(mean(thisdata,1),3); + thisb(vv,ss,xx) = atan2d(sum(mean(mean(thisdata,1),3).*sind(angs)), sum(mean(mean(thisdata,1),3).*cosd(angs))); %compute bias using shuffling cw/ccw trials + + bshuff_store = [bshuff_store; xx thisb(ss) vv ss]; + clear thisdatat shuff_idx tmpd thisidx all_recons_flipped flip_log tmp_log all_recons_tmp tmp_flip n_flip flip_idx + + end + [~, P(vv,xx), ~, stats] = ttest(thisb(vv,:,xx)); + t_stat_shuff(vv,xx) = stats.tstat; + + end + + clear thisb + + +end +end + +toc +fprintf('shuffling done') + + +set(gcf,'Position',[15 1052 2542 286]) +for vv =1:length(ROIs) +condcompare_pval(vv) = mean(t_stat_shuff(vv,:)>=t_real(1,vv)); +end +condcompare_fdrthresh = fdr(condcompare_pval(:),0.05) + +%% align like distractor bins (and flip/average) 1D FOR ALL BINS, first near, then far +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly +% new code +% flip negative angles +% +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this matches all_conds(:,6) (relative distractor angle bin) + +flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +all_recons_flipped(flipidx,:) = fliplr(all_recons_flipped(flipidx,:)); + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) <= t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0 1 2 3]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); + +figure +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + subplot(length(cond_to_plot),length(ROIs),(ff-1)*length(ROIs)+vv); hold on; + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + for ss = 1:length(subj) + if ff ==1 + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0; + else + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & (all_conds(:,6)==cond_to_plot(ff)*-1 |all_conds(:,6)==cond_to_plot(ff)*1) ; + end + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss) = thisb(ss); + end + + hold on + t = mean(thisd((tpts_to_plot),:,:),1); + myd_sem = nanstd(t,[],3) /sqrt(length(subj)); + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3),1),'LineWidth',2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + btwn_d = [mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem fliplr(mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem)]; + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_d,cond_colors(ff,:),'facealpha',0.4); + mybias_sem = std(store_b(ff,vv,:)) /sqrt(length(subj)); + line([mean(store_b(ff,vv,:),3) mean(store_b(ff,vv,:),3)], [0 2], 'color','k','linewidth',1,'linestyle','-') + hold on; + btwn_b=[mean(store_b(ff,vv,:),3)-1*mybias_sem fliplr(mean(store_b(ff,vv,:),3)+1*mybias_sem)]; + plot([mean(store_b(ff,vv,:),3)-1*mybias_sem mean(store_b(ff,vv,:),3)-1*mybias_sem], [0 2],'r-.','linewidth',0.5) + plot([mean(store_b(ff,vv,:),3)+1*mybias_sem mean(store_b(ff,vv,:),3)+1*mybias_sem], [0 2],'r-.','linewidth',0.5) + fill([btwn_b(1) btwn_b(1) btwn_b(2) btwn_b(2)], [0 2 2 0],'r','facealpha',0.2); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + plot([min(xlim) max(xlim)], [0 0], '-', 'color', [.2 .2 .2]) + x = linspace(-180,180,90); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + + if ff == 1 + title(ROIs{vv}); + end + + set(gca,'XTick',-180:40:180,'XTickLabelRotation',45,'TickDir','out') + + xlabel('Polar angle (\circ)'); + + if ff ==1 + ylabel('Near Distractor'); + elseif ff==2 + ylabel('Bin 1,D-offset ~50'); + elseif ff==3 + ylabel('Bin 2,D-offset ~100'); + elseif ff==4 + ylabel('Bin 3,D-offset ~150'); + end + + ylim([-.8 2]) + + set(gca,'XTickLabel',{'-180','-140','-100','-60','-20','20','60','100','140','180'}); + + xlim([-180 180]); + + + end + clear thisidx + clear thisb + clear thisd +end + + +%store_b dimens +% 1: near or far distractor +% 2: ROI +% 3: subj + +for tt =1:size(store_b,1) %condition = 1, near; 2, far +for rr =1:length(ROIs) +[H(tt,rr), P(tt,rr), CI, STATS] = ttest(store_b(tt,rr,:)); +fprintf('%s p=%i, t-score =%i, df=%i,sd=%i,mean =', ROIs{rr}, P(tt,rr),STATS.tstat,STATS.df,STATS.sd,mean(store_b(tt,rr,:),3)) +clear STATS +end +[p_fdr(tt,:) p_masked(tt,:)] = fdr(P(tt,:),0.05); +end +corrected_pval = P <= p_fdr; +set(gcf,'Position',[210 817 2168 521]) +%do RM ANOVA to check for differences among offset conditions + +the_y= mean(store_b,3)'; +the_y = [the_y(:,2); the_y(:,3); the_y(:,4)]; %just look at bins 1,2,3 for now +the_iv= [ones(size(store_b,2),1); 2*ones(size(store_b,2),1); 3*ones(size(store_b,2),1)]; +roi = [1 2 3 4 5 6 7 8 9]'; %depends on length of ROIs +the_roi =[roi; roi; roi]; + x = [the_y the_iv the_roi]; + RMAOV1(x,0.05) + + +%% +roi_str = {'V1','V2','V3','V3AB','IPS0','IPS1','IPS2','IPS3','sPCS'}; +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this matches all_conds(:,6) (relative distractor angle bin) + +%flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +%all_recons_flipped(flipidx,:) = fliplr(all_recons_flipped(flipidx,:)); + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) <= t_range_to_plot_subset(2); + + +cond_to_plot =[1 2]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); + +figure +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + subplot(length(cond_to_plot),length(ROIs),(ff-1)*length(ROIs)+vv);hold on; + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + for ss = 1:length(subj) + if ff==1 + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==-2 & this_rel< 0; %cw + else + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==2 & this_rel> 0; %ccw + end + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss) = thisb(ss); + end + + hold on + t = mean(thisd((tpts_to_plot),:,:),1); + myd_sem = nanstd(t,[],3) /sqrt(length(subj)); + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3),1),'LineWidth',2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + btwn_d = [mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem fliplr(mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem)]; + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_d,cond_colors(ff,:),'facealpha',0.4) + mybias_sem = std(store_b(ff,vv,:)) /sqrt(length(subj)); + line([mean(store_b(ff,vv,:),3) mean(store_b(ff,vv,:),3)], [0 2], 'color','k','linewidth',1,'linestyle','-') + hold on; + btwn_b=[mean(store_b(ff,vv,:),3)-1*mybias_sem fliplr(mean(store_b(ff,vv,:),3)+1*mybias_sem)]; + plot([mean(store_b(ff,vv,:),3)-1*mybias_sem mean(store_b(ff,vv,:),3)-1*mybias_sem], [0 2],'r-.','linewidth',0.5) + plot([mean(store_b(ff,vv,:),3)+1*mybias_sem mean(store_b(ff,vv,:),3)+1*mybias_sem], [0 2],'r-.','linewidth',0.5) + fill([btwn_b(1) btwn_b(1) btwn_b(2) btwn_b(2)], [0 2 2 0],'r','facealpha',0.2) + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + plot([min(xlim) max(xlim)], [0 0], '-', 'color', [.2 .2 .2]) + x = linspace(-180,180,90); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + + if ff == 1 + title(ROIs{vv}); + end + + set(gca,'XTick',-180:40:180,'XTickLabelRotation',45,'TickDir','out') + + xlabel('Polar angle (\circ)'); + + if ff ==1 + ylabel('Near Distractor'); + else + ylabel('Far Distractor'); + end + + ylim([-.8 2]) + + set(gca,'XTickLabel',{'-180','-140','-100','-60','-20','20','60','100','140','180'}); + set(gca,'YTickLabel') + xlim([-180 180]); + + + end + clear thisidx + clear thisb + clear thisd +end + + +%store_b dimens +% 1: near or far distractor +% 2: ROI +% 3: subj + +for tt =1:size(store_b,1) %condition = 1, near; 2, far +for rr =1:length(ROIs) +[H(tt,rr), P(tt,rr), CI, STATS] = ttest(store_b(tt,rr,:)); +fprintf('\n%s p=%i, t-score =%i, df=%i,sd=%i,mean =', ROIs{rr}, P(tt,rr),STATS.tstat,STATS.df,STATS.sd,mean(store_b(tt,rr,:),3)) +clear STATS +end +[p_fdr(tt,:) p_masked(tt,:)] = fdr(P(tt,:),0.05); +corrected_pval_pass(tt,:) = P(tt,:) <= p_fdr; +end + + + + + +set(gcf,'Position',[ 220 1058 1760 194]); + + diff --git a/spDist_neural_bias_perm.m b/spDist_neural_bias_perm.m new file mode 100644 index 0000000..2995f06 --- /dev/null +++ b/spDist_neural_bias_perm.m @@ -0,0 +1,428 @@ +% spDist_neural_bias.m + +function spDist_neural_bias_perm(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'CC','KD','AY','MR','XL','SF','EK'}; + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + +cat_mode = 1; % if 1, look for catSess1Ses...SessN_ files, otherwise, just look for each session in turn + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + +plot_tpts = 7:15; % for a plot where we average reconstructions over a fixed time window + +dist_time = 4.5; % onset at 4 s + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +delay_tpt_range = [3.75 5.25; 7.5 9; 10.5 12]; + + + +% for fidelity timecourses +tmpcolors = lines(7); + +ROI_colors = [repmat(tmpcolors(1,:),3,1); % V1, V2, V3 + tmpcolors(4,:); % V3AB + tmpcolors(1,:); % hV4 + repmat(tmpcolors(3,:),1,1); % VO1 + repmat(tmpcolors(1,:),2,1); % LO1/2 + + repmat(tmpcolors(2,:),2,1); % TO1-2 + + repmat(tmpcolors(5,:),2,1); % IPS0-1 + repmat(tmpcolors(6,:),2,1); % IPS2-3 + tmpcolors(7,:); % sPCS + ]; % iPCS (color 1...) + + +%% load data +startidx = 1; +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + if cat_mode == 1 + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + startidx = thisidx(end)+1; + + clear data; + + else + + + for sess_idx = 1:length(sess{ss}) + % build fn + fn = sprintf('%swmChoose_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_cv_thruTime1.mat',root,subj{ss},sess{ss}{sess_idx},ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*numel(sess)*size(data.recons,1); + + all_recons = nan(nblankt,size(data.recons,2),size(data.recons,3)); + all_conds = nan(nblankt,size(data.c_map,2)); + + all_fidelity = nan(nblankt,size(data.recons,3)); % timecoruse of fidelity + + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + angs = data.angs; + tpts = data.delay_tpts; + + all_r2 = nan(length(ROIs),length(tpts),length(subj)); + + end + + + if sess_idx == 1 + tmp_r2 = nan(length(tpts),length(sess{ss})); % average acorss sessions... + end + + thisidx = startidx:(startidx+size(data.c_map,1)-1); + + + all_recons(thisidx,:,:) = data.recons; + all_fidelity(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons,2)); + + + all_conds(thisidx,:) = data.c_map; + + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = sess_idx; + + tmp_r2(:,sess_idx) = squeeze(mean(mean(data.r2_all,1),2)); + + startidx = thisidx(end)+1; + + clear data; + + end + + + end + end + +end + + +%% align like distractor bins (and flip/average) 1D near only - TRUTH +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly +% new code +% flip negative angles +% + +roi_str= {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this matches all_conds(:,6) (relative distractor angle bin) + +flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +all_recons_flipped(flipidx,:) = fliplr(all_recons_flipped(flipidx,:)); + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); + +figure +test_store =[]; +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + subplot(length(cond_to_plot),length(ROIs),(ff-1)*length(ROIs)+vv); hold on; + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0; + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss) = thisb(ss); + test_store = [test_store; thisb(ss) vv ss]; + end + + hold on + t = mean(thisd((tpts_to_plot),:,:),1); + myd_sem = nanstd(t,[],3) /sqrt(length(subj)); + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3),1),'LineWidth',2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + btwn_d = [mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem fliplr(mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem)]; + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_d,cond_colors(ff,:),'facealpha',0.4); + mybias_sem = std(store_b(ff,vv,:)) /sqrt(length(subj)); + line([mean(store_b(ff,vv,:),3) mean(store_b(ff,vv,:),3)], [0 2], 'color','k','linewidth',1,'linestyle','-') + hold on; + btwn_b=[mean(store_b(ff,vv,:),3)-1*mybias_sem fliplr(mean(store_b(ff,vv,:),3)+1*mybias_sem)]; + plot([mean(store_b(ff,vv,:),3)-1*mybias_sem mean(store_b(ff,vv,:),3)-1*mybias_sem], [0 2],'r-.','linewidth',0.5) + plot([mean(store_b(ff,vv,:),3)+1*mybias_sem mean(store_b(ff,vv,:),3)+1*mybias_sem], [0 2],'r-.','linewidth',0.5) + fill([btwn_b(1) btwn_b(1) btwn_b(2) btwn_b(2)], [0 2 2 0],'r','facealpha',0.2); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + plot([min(xlim) max(xlim)], [0 0], '-', 'color', [.2 .2 .2]) + x = linspace(-180,180,90); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + + if ff == 1 && vv ==1 + title(ROIs{vv}); + + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','90','0','90','180'},'XTickLabelRotation',45,'TickDir','out'); + xlabel('Polar angle (\circ)'); + ylabel('Near Distractor'); + else + title(ROIs{vv}); + set(gca,'XTick',-180:90:180,'XTickLabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out') + + end + ylim([-.8 2]) + xlim([-180 180]); + + + end + clear thisidx + clear thisb + clear thisd +end + + +%store_b dimens +% 1: near distractor +% 2: ROI +% 3: subj +% do rm anova + + +[f_out] = RMAOV1_gh([test_store(:,1), test_store(:,2), test_store(:,3)]) +RMAOV1([test_store(:,1), test_store(:,2), test_store(:,3)]) + +for tt =1:size(store_b,1) %condition = 1, near; +for rr =1:length(ROIs) +[H(tt,rr), P(tt,rr), CI, STATS] = ttest(store_b(tt,rr,:)); +t_real(rr) = STATS.tstat; +%fprintf('%s p=%i, t-score =%i, df=%i,sd=%i,mean =', ROIs{rr}, P(tt,rr),STATS.tstat,STATS.df,STATS.sd,mean(store_b(tt,rr,:),3)) +clear STATS CI +end +[p_fdr(tt,:) p_masked(tt,:)] = fdr(P(tt,:),0.05); + +end +corrected_pval = P <= p_fdr; +set(gcf,'Position',[15 1052 2542 286]) +%do RM ANOVA to check for differences among offset conditions +%% shuffle on basis of 0 trial, flip random # (length cw trials), compute bias and recon, store +% align like distractor bins (and flip/average) 1D near only +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly + + +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0]; %which trial type? +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); +bshuff_store=[]; +iter = 1; +data_store =nan(iter,length(angs),length(subj)); +tic +for xx = 1:iter + + +for ff = 1:length(cond_to_plot) + + for vv = 1:length(ROIs) + + thisdata = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj),iter); %recon data + thisb = nan(1,length(subj),iter); %computed bias + %all_recons_tmp = all_recons{1}; + %all_recons_flipped = all_recons{1}; + for ss = 1:length(subj) + %thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + + + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0; %this is collecting all cw/ccw trials + findidx = find(thisidx); + tmp= randperm(length(findidx))'; + shuff_idx = findidx(tmp); + flipidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 & this_rel<0; %collect just cw trials, want to flip this many trials + nflip = size(find(flipidx),1); % how many trials are truly cw? a # + tmp_flip = shuff_idx(1:nflip,1); % flip the correct # of trial labels, but ranomly chosen from the shuffled 0 label idx, + all_recons_tmp = all_recons{1}; + all_recons_flipped = all_recons{1}; + flip_log = zeros(length(flipidx),1); + flip_log(tmp_flip,1) = 1; % needs to actually be 'logical' not ones, zeros.. + a =logical(flip_log); + all_recons_flipped(a,:,:) = fliplr(all_recons_tmp(a,:,:)); + thisdata = all_recons_flipped(shuff_idx,:,tpts_to_plot); %now access recon that have been randomly flipped with 0 label shuffled + data_store(xx,:,ss) = mean(mean(thisdata,1),3); + thisb(vv,ss,xx) = atan2d(sum(mean(mean(thisdata,1),3).*sind(angs)), sum(mean(mean(thisdata,1),3).*cosd(angs))); %compute bias using shuffling cw/ccw trials + + bshuff_store = [bshuff_store; xx thisb(ss) vv ss]; + clear thisdatat shuff_idx tmpd thisidx all_recons_flipped flip_log tmp_log all_recons_tmp tmp_flip n_flip flip_idx + + end + [~, P(vv,xx), ~, stats] = ttest(thisb(vv,:,xx)); + t_stat_shuff(vv,xx) = stats.tstat; + + end + + clear thisb + + +end +end + +toc +fprintf('shuffling done') + + +set(gcf,'Position',[15 1052 2542 286]) +for vv =1:length(ROIs) +condcompare_pval(vv) = mean(t_stat_shuff(vv,:)>=t_real(1,vv)); +end +condcompare_fdrthresh = fdr(condcompare_pval(:),0.05) +end + diff --git a/spDist_neural_bias_sess.m b/spDist_neural_bias_sess.m new file mode 100644 index 0000000..7965001 --- /dev/null +++ b/spDist_neural_bias_sess.m @@ -0,0 +1,812 @@ +% spDist_pilot_plotReconstructions_thruTime_gh.m +% adapted from MGSMap_plotReconstructions_cv_thruTime1.m +% +% for plotting WM reconstructions during trials with/without spatial +% distractor, plotting distractor-aligned reconstructions, and sorting +% trials based on relative distractor position + +% for plotting cross-validated WM reconstructions from mapping task, +% computed using MGSMap_channelRespAmp* scripts +% +% TODO: extend to compareReconstruction, which can load multiple sets of +% sessions per subj, and will compare across sessions (and/or across sets +% of tpts, etc... - only one set of comparisons at a time?) + +function spDist_neural_bias_sess(subj,sess,ROIs) + +root = spDist_loadRoot; + + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'CC','KD','AY','MR','XL','SF','EK'}; + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + +cat_mode = 1; % if 1, look for catSess1Ses...SessN_ files, otherwise, just look for each session in turn + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + +plot_tpts = 7:15; % for a plot where we average reconstructions over a fixed time window + +dist_time = 4.5; % onset at 4 s + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +delay_tpt_range = [3.75 5.25; 7.5 9; 10.5 12]; + + + +% for fidelity timecourses +tmpcolors = lines(7); + +ROI_colors = [repmat(tmpcolors(1,:),3,1); % V1, V2, V3 + tmpcolors(4,:); % V3AB + tmpcolors(1,:); % hV4 + repmat(tmpcolors(3,:),1,1); % VO1 + repmat(tmpcolors(1,:),2,1); % LO1/2 + + repmat(tmpcolors(2,:),2,1); % TO1-2 + + repmat(tmpcolors(5,:),2,1); % IPS0-1 + repmat(tmpcolors(6,:),2,1); % IPS2-3 + tmpcolors(7,:); % sPCS + ]; % iPCS (color 1...) + + +%% load data +startidx = 1; +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + if cat_mode == 1 + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecourse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + end + + + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + + all_r(thisidx,1) = (data.sess_all*100+data.r_all)'; + startidx = thisidx(end)+1; + + clear data; + + else + + + for sess_idx = 1:length(sess{ss}) + % build fn + fn = sprintf('%swmChoose_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_cv_thruTime1.mat',root,subj{ss},sess{ss}{sess_idx},ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*numel(sess)*size(data.recons,1); + + all_recons = nan(nblankt,size(data.recons,2),size(data.recons,3)); + all_conds = nan(nblankt,size(data.c_map,2)); + + all_fidelity = nan(nblankt,size(data.recons,3)); % timecoruse of fidelity + + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + angs = data.angs; + tpts = data.delay_tpts; + + all_r2 = nan(length(ROIs),length(tpts),length(subj)); + + end + + + if sess_idx == 1 + tmp_r2 = nan(length(tpts),length(sess{ss})); % average acorss sessions... + end + + thisidx = startidx:(startidx+size(data.c_map,1)-1); + + + all_recons(thisidx,:,:) = data.recons; + all_fidelity(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons,2)); + + + all_conds(thisidx,:) = data.c_map; + + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = sess_idx; + + tmp_r2(:,sess_idx) = squeeze(mean(mean(data.r2_all,1),2)); + + startidx = thisidx(end)+1; + + clear data; + + end + + + end + end + +end + + +%% align like distractor bins (and flip/average) 1D near only +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly +% new code +% flip negative angles +% + +roi_str= {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this matches all_conds(:,6) (relative distractor angle bin) + +flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +all_recons_flipped(flipidx,:) = fliplr(all_recons_flipped(flipidx,:)); + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); + +figure +test_store =[]; +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + subplot(length(cond_to_plot),length(ROIs),(ff-1)*length(ROIs)+vv); hold on; + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0; + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss) = thisb(ss); + test_store = [test_store; thisb(ss) vv ss]; + end + + hold on + t = mean(thisd((tpts_to_plot),:,:),1); + myd_sem = nanstd(t,[],3) /sqrt(length(subj)); + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3),1),'LineWidth',2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + btwn_d = [mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem fliplr(mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem)]; + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_d,cond_colors(ff,:),'facealpha',0.4); + mybias_sem = std(store_b(ff,vv,:)) /sqrt(length(subj)); + line([mean(store_b(ff,vv,:),3) mean(store_b(ff,vv,:),3)], [0 2], 'color','k','linewidth',1,'linestyle','-') + hold on; + btwn_b=[mean(store_b(ff,vv,:),3)-1*mybias_sem fliplr(mean(store_b(ff,vv,:),3)+1*mybias_sem)]; + plot([mean(store_b(ff,vv,:),3)-1*mybias_sem mean(store_b(ff,vv,:),3)-1*mybias_sem], [0 2],'r-.','linewidth',0.5) + plot([mean(store_b(ff,vv,:),3)+1*mybias_sem mean(store_b(ff,vv,:),3)+1*mybias_sem], [0 2],'r-.','linewidth',0.5) + fill([btwn_b(1) btwn_b(1) btwn_b(2) btwn_b(2)], [0 2 2 0],'r','facealpha',0.2); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + plot([min(xlim) max(xlim)], [0 0], '-', 'color', [.2 .2 .2]) + x = linspace(-180,180,90); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + + if ff == 1 && vv ==1 + title(ROIs{vv}); + + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','90','0','90','180'},'XTickLabelRotation',45,'TickDir','out'); + xlabel('Polar angle (\circ)'); + ylabel('Near Distractor'); + else + title(ROIs{vv}); + set(gca,'XTick',-180:90:180,'XTickLabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out') + + end + ylim([-.8 2]) + xlim([-180 180]); + + + end + clear thisidx + clear thisb + clear thisd +end + + +%store_b dimens +% 1: near distractor +% 2: ROI +% 3: subj +% do rm anova + + +[f_out] = RMAOV1_gh([test_store(:,1), test_store(:,2), test_store(:,3)]) +RMAOV1([test_store(:,1), test_store(:,2), test_store(:,3)]) + +for tt =1:size(store_b,1) %condition = 1, near; +for rr =1:length(ROIs) +[H(tt,rr), P(tt,rr), CI, STATS] = ttest(store_b(tt,rr,:)); +t_real(rr) = STATS.tstat; +%fprintf('%s p=%i, t-score =%i, df=%i,sd=%i,mean =', ROIs{rr}, P(tt,rr),STATS.tstat,STATS.df,STATS.sd,mean(store_b(tt,rr,:),3)) +clear STATS CI +end +[p_fdr(tt,:) p_masked(tt,:)] = fdr(P(tt,:),0.05); + +end +corrected_pval = P <= p_fdr; +set(gcf,'Position',[15 1052 2542 286]) +%do RM ANOVA to check for differences among offset conditions +%% shuffle +% align like distractor bins (and flip/average) 1D near only +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly + + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) < t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0]; %which trial type? +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); +bshuff_store=[]; +iter = 1000; +data_store =nan(length(ROIs),iter,length(subj),length(angs)); +sns = [1 2]; + +tic +for xx = 1:iter + + +for ff = 1:length(cond_to_plot) + + for vv = 1:length(ROIs) + + thisdata = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj),iter); %recon data + thisb = nan(1,length(subj),iter); %computed bias + %all_recons_tmp = all_recons{1}; + %all_recons_flipped = all_recons{1}; + for ss = 1:length(subj) + %thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + %for sh =1:length(sns) + + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0; %this is collecting all cw/ccw trials + findidx = find(thisidx); + tmp= randperm(length(findidx))'; + shuff_idx = findidx(tmp); + flipidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 & this_rel<0; %collect just cw trials, want to flip this many trials + nflip = size(find(flipidx),1); % how many trials are truly cw? a # + tmp_flip = shuff_idx(1:nflip,1); % flip the correct # of trial labels, but ranomly chosen from the shuffled 0 label idx, + all_recons_tmp = all_recons{1}; + all_recons_flipped = all_recons{1}; + flip_log = zeros(length(flipidx),1); + flip_log(tmp_flip,1) = 1; % needs to actually be 'logical' not ones, zeros.. + a =logical(flip_log); + all_recons_flipped(a,:,:) = fliplr(all_recons_tmp(a,:,:)); + thisdata = all_recons_flipped(shuff_idx,:,tpts_to_plot); %now access recon that have been randomly flipped with 0 label shuffled + data_store(vv,xx,ss,:) = mean(mean(thisdata,1),3); + thisb(vv,ss,xx) = atan2d(sum(mean(mean(thisdata,1),3).*sind(angs)), sum(mean(mean(thisdata,1),3).*cosd(angs))); %compute bias using shuffling cw/ccw trials + + bshuff_store = [bshuff_store; xx thisb(ss) vv ss]; + clear thisdatat shuff_idx tmpd thisidx all_recons_flipped flip_log tmp_log all_recons_tmp tmp_flip n_flip flip_idx + + % end + end + [~, P(vv,xx), ~, stats] = ttest(thisb(vv,:,xx)); + t_stat_shuff(vv,xx) = stats.tstat; + + end + + clear thisb + + +end +end + +toc +fprintf('shuffling done') + + +set(gcf,'Position',[15 1052 2542 286]) +for vv =1:length(ROIs) +condcompare_pval(vv) = mean(t_stat_shuff(vv,:)>=t_real(1,vv)); +end +condcompare_fdrthresh = fdr(condcompare_pval(:),0.05) + +figure; +hold on; +for vv =1:length(ROIs) + subplot(1,length(ROIs),vv) + plot(linspace(-180,180,90),squeeze(mean(mean(data_store(vv,:,:,:),2),3))) +end + +%% t-test between condition during each epoch against shuffled null +% +% to shuffle: +% - compute n_runs fidelity for each condition for each subj +% - shuffle labels of *these data* 1000 times, then average across +% condition/subj, compute null T distribution; compute p against this +% (two-tailed) (TODO) + + +% figure out how many total runs... (hack...) +n_runs= 0; +for ss = 1:length(subj) + % get one example set of trials + ru = unique(all_data(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + n_runs= n_runs+length(ru); + clear tu; +end + + +% store 'real' T (ROI x epoch) +fidelity_condcompare_realT = nan(length(ROIs),size(delay_tpt_range,1)); + +% store iter shuffled T's (ROI x epoch x iter) +fidelity_condcompare_shufT = nan(length(ROIs),size(delay_tpt_range,1),iter); + +fprintf('Computing null T-dist for condition comparison w/ in epochs\n'); + +for vv = 1:length(ROIs) + + for tt = 1:size(n_runs) + + fprintf('%s, trial %i\n',ROIs{vv},tt); + tic; + thisd = nan(length(subj),2); + + for ss = 1:length(subj) + for cc = 1:2 %this should be cw/ccw idx + + if cc ==1 + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 & tmp_rel < 0; %cw + elseif cc ==2 + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0 & tmp_rel > 0; %ccw + end + thisb(cc,ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))) + test_store = [test_store; thisb(ss) tt vv cc ss]; + clear thisidx; + end + end + + % compute real T + [~,~,~,thisstats] = ttest(thisb(:)); + fidelity_condcompare_realT(vv,tt) = thisstats.tstat; clear thisstats thisd; + + % create a data structure we can shuffle: for each subj/ROI/cond, + % n_runs datapoints + data_ru = nan(nruns,1); + labels_ru = nan(nruns,2); % condition, subj + + tmpidx = 1; % where to put this run.... + + for ss = 1:length(subj) + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + for rr = 1:length(ru) + for cc = 1:2 + thisidx = all_r==ru(rr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==cc; + data_ru( tmpidx) = mean( mean( all_fidelity(thisidx,delay_tpts{tt},1) , 2), 1 ); + labels_ru(tmpidx,:) = [cc ss]; + tmpidx = tmpidx+1; + end + end + end + + + % iter times.. + for ii = 1:iter + + tmpdata = nan(size(data_ru)); + + % within each subj, shuffle condition labels + for ss = 1:length(subj) + % logical indices for this subject, across runs + thisidx = labels_ru(:,2)==ss; + + % list of numerical indices - plug data in here + subjidx = find(thisidx); + + % used to shuffle subjidx + shufidx = randperm(length(subjidx)); + + % tmpdata will have data, shuffled wrt condition label, for + % each subj + tmpdata(subjidx) = data_ru(subjidx(shufidx)); + + clear thisidx subjidx shufidx; + end + + + % generate data structure for T-test (average across + % runs within condition label within each subj) + thisd = nan(length(subj),2); + for ss = 1:length(subj) + for cc = 1:2 + thisidx = labels_ru(:,1)==cc & labels_ru(:,2)==ss; + thisd(ss,cc) = mean( tmpdata(thisidx), 1 ); % mean across *shuffled* data + clear thisidx; + end + end + + % compute shuffled T + [~,~,~,thisstats] = ttest(thisd(:,1),thisd(:,2)); + fidelity_condcompare_shufT(vv,ii) = thisstats.tstat; clear thisstats + + clear thisd tmpdata; + + end + toc; + end + +end + + +% compute p-values (ROIs x epochs) +fidelity_condcompare_pval = 2 * min(mean(fidelity_condcompare_shufT<=fidelity_condcompare_realT,3), mean(fidelity_condcompare_shufT>=fidelity_condcompare_realT,3)); +fidelity_condcompare_fdrthresh = fdr(fidelity_condcompare_pval(:),0.05); + +%% align like distractor bins (and flip/average) 1D FOR ALL BINS, first near, then far +% goal here is to align cw/ccw distractor bins and flip one set to match +% - for 0-bin, need to determine which trials are CW/CCW and flip +% accordingly +% new code +% flip negative angles +% +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this matches all_conds(:,6) (relative distractor angle bin) + +flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +all_recons_flipped(flipidx,:) = fliplr(all_recons_flipped(flipidx,:)); + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) <= t_range_to_plot_subset(2); +fprintf('using delay tpts = %i to %i', t_range_to_plot_subset(1), t_range_to_plot_subset(2)) + +cond_to_plot =[0 1 2 3]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); + +figure +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + subplot(length(cond_to_plot),length(ROIs),(ff-1)*length(ROIs)+vv); hold on; + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + for ss = 1:length(subj) + if ff ==1 + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==0; + else + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & (all_conds(:,6)==cond_to_plot(ff)*-1 |all_conds(:,6)==cond_to_plot(ff)*1) ; + end + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss) = thisb(ss); + end + + hold on + t = mean(thisd((tpts_to_plot),:,:),1); + myd_sem = nanstd(t,[],3) /sqrt(length(subj)); + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3),1),'LineWidth',2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + btwn_d = [mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem fliplr(mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem)]; + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_d,cond_colors(ff,:),'facealpha',0.4); + mybias_sem = std(store_b(ff,vv,:)) /sqrt(length(subj)); + line([mean(store_b(ff,vv,:),3) mean(store_b(ff,vv,:),3)], [0 2], 'color','k','linewidth',1,'linestyle','-') + hold on; + btwn_b=[mean(store_b(ff,vv,:),3)-1*mybias_sem fliplr(mean(store_b(ff,vv,:),3)+1*mybias_sem)]; + plot([mean(store_b(ff,vv,:),3)-1*mybias_sem mean(store_b(ff,vv,:),3)-1*mybias_sem], [0 2],'r-.','linewidth',0.5) + plot([mean(store_b(ff,vv,:),3)+1*mybias_sem mean(store_b(ff,vv,:),3)+1*mybias_sem], [0 2],'r-.','linewidth',0.5) + fill([btwn_b(1) btwn_b(1) btwn_b(2) btwn_b(2)], [0 2 2 0],'r','facealpha',0.2); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + plot([min(xlim) max(xlim)], [0 0], '-', 'color', [.2 .2 .2]) + x = linspace(-180,180,90); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + + if ff == 1 + title(ROIs{vv}); + end + + set(gca,'XTick',-180:40:180,'XTickLabelRotation',45,'TickDir','out') + + xlabel('Polar angle (\circ)'); + + if ff ==1 + ylabel('Near Distractor'); + elseif ff==2 + ylabel('Bin 1,D-offset ~50'); + elseif ff==3 + ylabel('Bin 2,D-offset ~100'); + elseif ff==4 + ylabel('Bin 3,D-offset ~150'); + end + + ylim([-.8 2]) + + set(gca,'XTickLabel',{'-180','-140','-100','-60','-20','20','60','100','140','180'}); + + xlim([-180 180]); + + + end + clear thisidx + clear thisb + clear thisd +end + + +%store_b dimens +% 1: near or far distractor +% 2: ROI +% 3: subj + +for tt =1:size(store_b,1) %condition = 1, near; 2, far +for rr =1:length(ROIs) +[H(tt,rr), P(tt,rr), CI, STATS] = ttest(store_b(tt,rr,:)); +fprintf('%s p=%i, t-score =%i, df=%i,sd=%i,mean =', ROIs{rr}, P(tt,rr),STATS.tstat,STATS.df,STATS.sd,mean(store_b(tt,rr,:),3)) +clear STATS +end +[p_fdr(tt,:) p_masked(tt,:)] = fdr(P(tt,:),0.05); +end +corrected_pval = P <= p_fdr; +set(gcf,'Position',[210 817 2168 521]) +%do RM ANOVA to check for differences among offset conditions + +the_y= mean(store_b,3)'; +the_y = [the_y(:,2); the_y(:,3); the_y(:,4)]; %just look at bins 1,2,3 for now +the_iv= [ones(size(store_b,2),1); 2*ones(size(store_b,2),1); 3*ones(size(store_b,2),1)]; +roi = [1 2 3 4 5 6 7 8 9]'; %depends on length of ROIs +the_roi =[roi; roi; roi]; + x = [the_y the_iv the_roi]; + RMAOV1(x,0.05) + + +%% +roi_str = {'V1','V2','V3','V3AB','IPS0','IPS1','IPS2','IPS3','sPCS'}; +cond_colors = [0 0 1;.3 .6 .1 ; .3 .6 .1 ; .3 .6 .1]; +%tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) <= t_range_to_plot(2); +% look for all trials where <> is < 0, flipLR the reconstruction + +tmprel = all_angs(:,2) - all_angs(:,1); +this_rel = mod((tmprel+180), 360)-180; +% sign of this matches all_conds(:,6) (relative distractor angle bin) + +%flipidx = this_rel<0; +all_recons_flipped = all_recons{1}; +%all_recons_flipped(flipidx,:) = fliplr(all_recons_flipped(flipidx,:)); + +t_range_to_plot_subset = [10.5 12]; +tpts_to_plot = (tpts*myTR) >= t_range_to_plot_subset(1) & (tpts*myTR) <= t_range_to_plot_subset(2); + + +cond_to_plot =[1 2]; +store_b = nan(length(cond_to_plot),length(ROIs),length(subj)); +P = nan(length(cond_to_plot),length(ROIs)); +H = nan(length(cond_to_plot),length(ROIs)); + +figure +for ff = 1:length(cond_to_plot) + for vv = 1:length(ROIs) + subplot(length(cond_to_plot),length(ROIs),(ff-1)*length(ROIs)+vv);hold on; + thisd = nan(size(all_recons{1},3),size(all_recons_flipped,2),length(subj)); %recon data + thisb = nan(1,length(subj)); %computed bias + for ss = 1:length(subj) + if ff==1 + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==-2 & this_rel< 0; %cw + else + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2 & all_conds(:,6)==2 & this_rel> 0; %ccw + end + thisd(:,:,ss) = squeeze(mean(all_recons_flipped(thisidx,:,:),1)).'; + thisb(ss) = atan2d(sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*sind(angs)),... + sum(mean(mean(all_recons_flipped(thisidx,:,tpts_to_plot),1),3).*cosd(angs))); + store_b(ff,vv,ss) = thisb(ss); + end + + hold on + t = mean(thisd((tpts_to_plot),:,:),1); + myd_sem = nanstd(t,[],3) /sqrt(length(subj)); + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3),1),'LineWidth',2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + hold on; + plot(linspace(-180,180,90),mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem,'-','LineWidth',.2,'color',cond_colors(ff,:)) + btwn_d = [mean(mean(thisd(tpts_to_plot,:,:),3))+1.*myd_sem fliplr(mean(mean(thisd(tpts_to_plot,:,:),3))-1.*myd_sem)]; + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_d,cond_colors(ff,:),'facealpha',0.4) + mybias_sem = std(store_b(ff,vv,:)) /sqrt(length(subj)); + line([mean(store_b(ff,vv,:),3) mean(store_b(ff,vv,:),3)], [0 2], 'color','k','linewidth',1,'linestyle','-') + hold on; + btwn_b=[mean(store_b(ff,vv,:),3)-1*mybias_sem fliplr(mean(store_b(ff,vv,:),3)+1*mybias_sem)]; + plot([mean(store_b(ff,vv,:),3)-1*mybias_sem mean(store_b(ff,vv,:),3)-1*mybias_sem], [0 2],'r-.','linewidth',0.5) + plot([mean(store_b(ff,vv,:),3)+1*mybias_sem mean(store_b(ff,vv,:),3)+1*mybias_sem], [0 2],'r-.','linewidth',0.5) + fill([btwn_b(1) btwn_b(1) btwn_b(2) btwn_b(2)], [0 2 2 0],'r','facealpha',0.2) + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + plot([min(xlim) max(xlim)], [0 0], '-', 'color', [.2 .2 .2]) + x = linspace(-180,180,90); + line([0 0], [-.8 max(ylim)], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + + if ff == 1 + title(ROIs{vv}); + end + + set(gca,'XTick',-180:40:180,'XTickLabelRotation',45,'TickDir','out') + + xlabel('Polar angle (\circ)'); + + if ff ==1 + ylabel('Near Distractor'); + else + ylabel('Far Distractor'); + end + + ylim([-.8 2]) + + set(gca,'XTickLabel',{'-180','-140','-100','-60','-20','20','60','100','140','180'}); + set(gca,'YTickLabel') + xlim([-180 180]); + + + end + clear thisidx + clear thisb + clear thisd +end + + +%store_b dimens +% 1: near or far distractor +% 2: ROI +% 3: subj + +for tt =1:size(store_b,1) %condition = 1, near; 2, far +for rr =1:length(ROIs) +[H(tt,rr), P(tt,rr), CI, STATS] = ttest(store_b(tt,rr,:)); +fprintf('\n%s p=%i, t-score =%i, df=%i,sd=%i,mean =', ROIs{rr}, P(tt,rr),STATS.tstat,STATS.df,STATS.sd,mean(store_b(tt,rr,:),3)) +clear STATS +end +[p_fdr(tt,:) p_masked(tt,:)] = fdr(P(tt,:),0.05); +corrected_pval_pass(tt,:) = P(tt,:) <= p_fdr; +end + + + + + +set(gcf,'Position',[ 220 1058 1760 194]); + + diff --git a/spDist_plotEyeData_Figure1_102020.m b/spDist_plotEyeData_Figure1_102020.m new file mode 100644 index 0000000..c3e10b6 --- /dev/null +++ b/spDist_plotEyeData_Figure1_102020.m @@ -0,0 +1,965 @@ + +%spDist_plotEyeData.m +% in the actual task, cyan = distractor, magenta = no distractor +% dependencies: misc_util, RMAOV1 + +root = spDist_loadRoot; + +%load raw subject data +subj = {'KD','CC','AY','MR','XL','EK','SF'}; +%sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist2'},{'spDist1','spDist2'},{'spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed + +sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed + +WHICH_EXCL = [13 20 21 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. +if ismember(WHICH_EXCL,13) + which_excl_str ={'broken fix'}; +elseif ismember(WHICH_EXCL,[13 20]) + which_excl_str ={'broken fix','no sacc'}; +elseif ismember(WHICH_EXCL, [13 20 21]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short'}; +elseif ismember(WHICH_EXCL, [13 20 22]) + which_excl_str ={'broken fix','no sacc','i sacc err too lg'}; +elseif ismember(WHICH_EXCL, [13 20 21 22]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short','i sacc err too lg'}; +else + error('which exclusion criteria have you chosen?') +end + +% first-digit: +% - 1 - trial-level exclusion (bad drift correction [11], calibration [12], or delay- +% fixation break [13] +% - 2 - primary saccade exclusion (no primary sacc [20]; too small/short [21] bi, large error [22]ei) + +%21 bad initial saccade (duration/amplitude outside range) +% 22 iniital saccade error + + +% concatenate ALL subject data +all_subj = nan(1000*length(subj),1); + +all_data = []; + +startidx = 1; + +for ss = 1:length(subj) + for sessidx = 1:length(sess{ss}) + + + % fn = sprintf('%s/spDist_behav_82719/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + + this_data.s_all = this_scored.ii_sess; + this_data.sess_all = sessidx; + + this_subj = ss; + + all_data = cat_struct(all_data,this_data); + all_subj(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = this_subj; + + startidx = startidx+size(this_scored.ii_sess.trialinfo,1); + + clear this_subj this_data; + end +end + + +all_subj = all_subj(1:(startidx-1)); +all_data.subj_all = all_subj; + +% determine which trials to include +% first, narrow based on saccade preprocessing/scoring exclusions +all_data.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data.s_all.excl_trial, 'UniformOutput',false)); +all_data.use_trial(all_data.s_all.f_sacc_err>10) = 0; %exclude trials with errors > 10 deg +all_data.use_trial(all_data.s_all.i_sacc_err>10) = 0; +all_data.use_trial(ismember(all_data.s_all.r_num, [8,12,14]) & all_subj==3) = 0; %3 here specifically refers to subj 3 above (AY), see spDist_eyeDataNotes for +%drop trials with very short (< 100 ms) or very long RT (> 1 s) +all_data.use_trial(all_data.s_all.i_sacc_rt<0.1 | all_data.s_all.i_sacc_rt>1.0) = 0; + +%% organize data +distractor_bins = unique(all_data.s_all.trialinfo(all_data.s_all.trialinfo(:,1)~=1,6)); +distractor_spacing = 360/length(distractor_bins); + +flip_bins = [1 2 3]; %which distractor bins should we "flip" the Y in order to collapse across CW/CCW distractors? + +%initialize storage cells +all_err = cell(3,1); +all_mu = cell(3,1); +all_rt = cell(3,1); + +cond_str = {'No distractor','Distractor'}; +cond_colors = lines(3); + +params_of_interest = {'f_sacc'}; +param_str = {}; + + +% first, error for no-distractor trials +tmp_err = nan(1,length(params_of_interest),2,length(subj)); % initial, final +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); % initial, final +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = nanstd( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(1,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = nanstd([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(1,pp,:,ss) = nanmean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + end +end + +all_err{1} = tmp_err; % 1st cell of all err and all mu = no distractor +all_mu{1} = tmp_mu; %note: the first index of all_ is NO DIST +all_mupol{1} = tmp_mupol; +all_errpol{1} = tmp_errpol; + +clear tmp_err tmp_mu tmp_errpol tmp_mupol; + +tmp_err = nan(1,length(params_of_interest),2,length(subj)); +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_cw = nan(1,length(params_of_interest),2,length(subj)); +tmp_ccw = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + + for bb =1 %placeholder, not relevant here bc we're collecting bin zero, but want to keep dimens same size as when we collect others + + for pp = 1:length(params_of_interest) + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0 & all_data.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = all_data.s_all.(params_of_interest{pp})(tmpidx,2); + orig_y_flip = orig_y*-1; + all_data.s_all.(params_of_interest{pp})(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins. + + thisorigidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; %now, collect all jitters. + + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = nanstd( all_data.s_all.(params_of_interest{pp})(thisorigidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisorigidx,:), 1 ); + + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisorigidx,1), all_data.s_all.(params_of_interest{pp})(thisorigidx,2)); + tmp_errpol(bb,pp,:,ss) = nanstd([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisorigidx,1), all_data.s_all.(params_of_interest{pp})(thisorigidx,2)); + tmp_mupol(bb,pp,:,ss) = nanmean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_err dtheta_err + end + end +end + +all_err{2} = tmp_err; +all_mu{2} = tmp_mu; +all_mupol{2} = tmp_mupol; +all_errpol{2} = tmp_errpol; + +clear tmp_err tmp_mu tmp_mupol tmp_errpol; + +%put other bins in +flip_bins =[1 2 3]; +tmp_err = nan(length(flip_bins),length(params_of_interest),2,length(subj)); +tmp_mu = nan(length(flip_bins),length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + for bb = 1:length(flip_bins) + for pp = 1:length(params_of_interest) + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==(flip_bins(bb)*-1); + orig_y = all_data.s_all.(params_of_interest{pp})(tmpidx,2); + orig_y_flip = orig_y*-1; + all_data.s_all.(params_of_interest{pp})(tmpidx,2) = orig_y_flip; % the y flip is inserted for CW bins. + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)==flip_bins(bb) | all_data.s_all.trialinfo(:,6)==flip_bins(bb)*-1); + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = nanstd( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = nanstd([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = nanmean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_err dtheta_err + + end + end +end + +all_err{3} = tmp_err; +all_mu{3} = tmp_mu; +all_mupol{3} = tmp_mupol; +all_errpol{3} = tmp_errpol; +clear tmp_err tmp_mu tmp_errpol tmpmupol; + +% create a new container for _alldist +tmp_err = nan(1,length(params_of_interest),2,length(subj)); % initial, final +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); % initial, final +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = nanstd( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(1,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = nanstd([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(1,pp,:,ss) = nanmean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_err dtheta_err + end +end + +all_err_alldist{1} = tmp_err; +all_mu_alldist{1} = tmp_mu; +all_errpol_alldist{1} = tmp_errpol; +all_mupol_alldist{1} = tmp_mupol; +clear tmp_err tmp_mu tmp_errpol tmpmupol; + +% first, error for no-distractor trials +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); % initial, final +params_of_interest = {'i_sacc_rt'}; +param_str = {'RT'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{1} = tmp_rt; +clear tmp_rt +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); % initial, final + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx),1); %cw + + end + +end + +all_rt{2} = tmp_rt; +flip_bins =[1 2 3]; +tmp_rt = nan(length(flip_bins),length(params_of_interest),1,length(subj)); % initial, final +for ss = 1:length(subj) + for bb = 1:length(flip_bins) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)==flip_bins(bb) | all_data.s_all.trialinfo(:,6)==flip_bins(bb)*-1); + + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_rt(bb,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + + end + end +end + +all_rt{3} = tmp_rt; + +% new container for _alldist + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); % initial, final +params_of_interest = {'i_sacc_rt'}; +param_str = {'RT'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt_alldist{1} =tmp_rt; + + + +%% no dist, near, far +% directly compare error for no distractor, near distractor +% trials (subplot for each param); averaged over radial/tang... + +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;]; % 1 = red, no dist; 2 = blue, dist +cond_str = {'Distractor Absent','Near Dist','Far Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(length(all_err),length(subj)); %collect this error + for ii = 1:length(all_err) + + thise(ii,:) = mean(mean(all_err{ii}(:,pp,:,:),3),1); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + for ii = 1:length(all_err) + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + clear tmpe + end + + xlim([0 length(all_err)+1]); + + set(gca,'XTick',1:length(all_err),'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, \circ)'); + end + title(param_str{pp}); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end +clear tmpe +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) +%% Figure 1D : Precision, Distractor Absent vs. Distractor Present (all distractor bins collapsed) + +% directly compare avg sd for no distractor, near distractor +% trials, final sacc only ; averaged over radial/tang... + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;]; %red, blue +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thise(ii,:) = squeeze(mean(all_err{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + elseif ii ==2 + thise(ii,:) = squeeze(mean(all_err_alldist{1}(:,pp,:,:),3)); % this "all_err_alldist" container is used bc all_err separates near vs. far dists. Simplified w this {} where all dist trials are within a single cell + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + for ii = 1:2 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 3]); + + set(gca,'XTick',2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, \circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + [p, h]= ttest(thise(1,:)',thise(2,:)') + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + +%ylim([0 1.5]) +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); +%%ll bins +% +% %directly compare avg sd for no distractor, near distractor +% %trials, final sacc only ; averaged over radial/tang... +% +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1; 0 0 1;]; %red, blue +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_err{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + else + thise([ii:5],:)= squeeze(mean(all_err{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + % plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + end + set(gca,'XTick',2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd,\circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + [p, h]= ttest(thise(1,:)',thise(2,:)') + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + +%ylim([0 1.5]) + +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); +%% no dist, near, far + +% directly compare avg sd for no distractor, near distractor +% trials, final sacc only ; averaged over radial/tang... + +% params_of_interest = {'f_sacc'}; +% param_str = {'final sacc'}; +% cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;]; %red, blue +% cond_str = {'No distractor','Near dist','Far dist'}; + +% new avg sd in polar angle,deg, all bins +% +% %directly compare avg sd for no distractor, near distractor +% %trials, final sacc only ; averaged over radial/tang... +% +% params_of_interest = {'f_sacc'}; +% param_str = {'final sacc'}; +% cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1; 0 0 1;]; %red, blue +% cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; +% +% figure; +% +% for pp = 1:length(params_of_interest) +% +% subplot(1,length(params_of_interest),pp); hold on; +% +% % distractor cond x subj +% thise = nan(5,length(subj)); %collect this error +% +% for ii = 1:length(all_errpol) +% if ii == 1 || ii ==2 +% thise(ii,:) = squeeze(mean(all_errpol{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins +% else +% thise([ii:5],:)= squeeze(mean(all_errpol{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins +% +% end +% end +% +% plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); +% % plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); +% +% for ii = 1:5 +% hold on; +% tmpe = std(thise(ii,:))/sqrt(length(subj)); +% plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); +% plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); +% end +% +% xlim([0 6]); +% end +% set(gca,'XTick',2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); +% xlabel('Condition'); +% if pp == 1 +% ylabel('Precision (avg sd, polar \circ)'); +% end +% title(param_str{pp}); +% set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); +% +% the_y = [thise(1,:)';thise(2,:)';]; +% the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; +% subj = [1 2 3 4 5 6 7]'; +% the_subj =[subj;subj;]; +% x = [the_y the_iv the_subj]; +% [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA +% RMAOV1(x,0.05) +% +% [p, h]= ttest(thise(1,:)',thise(2,:)') +% text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled +% +% %ylim([0 1.5]) +% +% set(gcf,'position',[ 549 724 499 571]) +% match_ylim(get(gcf,'Children')); +% %% no dist, near, far +% +% % directly compare avg sd for no distractor, near distractor +% % trials, final sacc only ; averaged over radial/tang... +% +% params_of_interest = {'f_sacc'}; +% param_str = {'final sacc'}; +% cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;]; %red, blue +% cond_str = {'No distractor','Near dist','Far dist'}; +% +% figure; +% +% for pp = 1:length(params_of_interest) +% +% subplot(1,length(params_of_interest),pp); hold on; +% +% % distractor cond x subj +% thise = nan(3,length(subj)); %collect this error +% +% for ii = 1:length(all_errpol) +% % thise(ii,:) = mean(mean(all_err{ii}(:,pp,:,:),3),1); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins +% if ii == 1 || ii ==2 +% thise(ii,:) = squeeze(mean(all_errpol{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins +% else +% thise(ii,:)= mean(squeeze(mean(all_errpol{ii}(:,pp,:,:),3))); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins +% %all dist trials are lumped into a single index, then averaged +% end +% end +% +% plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); +% % plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); +% +% for ii = 1:3 +% hold on; +% tmpe = std(thise(ii,:))/sqrt(length(subj)); +% plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); +% plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); +% +% clear tmpe +% end +% +% xlim([0 4]); +% end +% xlabel('Condition'); +% if pp == 1 +% ylabel('Precision (avg sd, polar \circ)'); +% end +% title(param_str{pp}); +% set(gca,'XTick',1:3,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); +% +% the_y = [thise(1,:)';thise(2,:)';thise(3,:)']; +% the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);3*ones(length(thise(1,:)'),1);]; +% subj = [1 2 3 4 5 6 7]'; +% the_subj =[subj;subj;subj]; +% x = [the_y the_iv the_subj]; +% [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA +% RMAOV1(x,0.05) +% +% text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled +% +% +% +% set(gcf,'position',[ 549 724 499 571]) +% match_ylim(get(gcf,'Children')); +%% new +%% Figure 1D : Precision, Distractor Absent vs. Distractor Present (all distractor bins collapsed) + +% % directly compare avg sd for no distractor, near distractor +% % trials, final sacc only ; averaged over radial/tang... +% +% params_of_interest = {'f_sacc'}; +% param_str = {'final sacc'}; +% cond_colors = [0.7100 0.2128 0.4772;0 0 1;]; %red, blue +% cond_str = {'Distractor Absent','Distractor Present'}; +% +% figure; +% +% for pp = 1:length(params_of_interest) +% +% subplot(1,length(params_of_interest),pp); hold on; +% +% % distractor cond x subj +% thise = nan(2,length(subj)); %collect this error +% for ii = 1:2 +% if ii ==1 +% thise(ii,:) = squeeze(mean(all_errpol{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin +% elseif ii ==2 +% thise(ii,:) = squeeze(mean(all_errpol_alldist{1}(:,pp,:,:),3)); % this "all_err_alldist" container is used bc all_err separates near vs. far dists. Simplified w this {} where all dist trials are within a single cell +% end +% end +% +% plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); +% plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); +% for ii = 1:2 +% hold on; +% tmpe = std(thise(ii,:))/sqrt(length(subj)); +% plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); +% plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); +% +% clear tmpe +% end +% +% xlim([0 3]); +% +% set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); +% xlabel('Condition'); +% if pp == 1 +% ylabel('Precision (avg sd, polar \circ)'); +% end +% title(param_str{pp}); +% set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); +% +% the_y = [thise(1,:)';thise(2,:)';]; +% the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; +% subj = [1 2 3 4 5 6 7]'; +% the_subj =[subj;subj;]; +% x = [the_y the_iv the_subj]; +% [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA +% RMAOV1(x,0.05) +% +% [p, h]= ttest(thise(1,:)',thise(2,:)') +% text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled +% +% %ylim([0 1.5]) +% end +% set(gcf,'position',[ 549 724 499 571]) +% match_ylim(get(gcf,'Children')); +%% REPORTED STATS ONLY - PRECISION, Distractor Absent, Abs(Bin) Distractor Present (4-level RM ANOVA) +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; +%(F(2,4) = 2.081, p = 0.1148 +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_err) + % thise(ii,:) = mean(mean(all_err{ii}(:,pp,:,:),3),1); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_err{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + else + thise([ii:5],:)= squeeze(mean(all_err{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('comp Precision (avg sd, \circ)'); + end + title(param_str{pp}); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + RMAOV1(x,0.05) %one-way RM ANOVA + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + +% %% RT, no dist to all_dist +% +% +% params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +% param_str = {'RT'}; +% cond_colors = [0.7100 0.2128 0.4772;0 0 1;]; +% cond_str = {'Distractor Absent','Distractor Present'}; +% +% figure; +% +% for pp = 1:length(params_of_interest) +% +% subplot(1,length(params_of_interest),pp); hold on; +% +% % distractor cond x subj +% thise = nan(2,length(subj)); %collect this error +% for ii = 1:2 +% if ii ==1 +% thise(ii,:) = squeeze(mean(all_rt{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin +% elseif ii ==2 +% thise(ii,:) = squeeze(mean(all_rt_alldist{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin +% end +% end +% +% +% +% plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); +% plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); +% for ii = 1:2 +% hold on; +% tmpe = std(thise(ii,:))/sqrt(length(subj)); +% plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); +% plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); +% end +% +% xlim([0 3]); +% +% set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); +% xlabel('Condition'); +% if pp == 1 +% ylabel('RT (seconds)'); +% end +% title(param_str{pp}); +% +% the_y = [thise(1,:)';thise(2,:)';]; +% the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; +% subj = [1 2 3 4 5 6 7]'; +% the_subj =[subj;subj;] +% x = [the_y the_iv the_subj]; +% [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA +% RMAOV1(x,0.05) +% text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled +% +% +% end +% set(gcf,'position',[ 549 724 499 571]) +% match_ylim(get(gcf,'Children')); +% %% RT by bin +% +% params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +% param_str = {'RT'}; +% cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +% cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; +% +% figure; +% +% for pp = 1:length(params_of_interest) +% +% subplot(1,length(params_of_interest),pp); hold on; +% +% % distractor cond x subj +% thise = nan(5,length(subj)); %collect this error +% for ii = 1:length(all_rt) +% if ii == 1 || ii ==2 +% thise(ii,:) = squeeze(mean(all_rt{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins +% +% else +% thise([ii:5],:)= squeeze(mean(all_rt{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins +% +% end +% end +% +% plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); +% plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); +% for ii = 1:5 +% hold on; +% tmpe = std(thise(ii,:))/sqrt(length(subj)); +% plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); +% plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); +% end +% +% xlim([0 6]); +% +% set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); +% xlabel('Condition'); +% if pp == 1 +% ylabel('RT'); +% end +% title(param_str{pp}); +% +% the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; +% the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; +% subj = [1 2 3 4 5 6 7]'; +% the_subj =[subj;subj;subj;subj;subj]; +% x = [the_y the_iv the_subj]; +% [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA +% RMAOV1(x,0.05) +% text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled +% +% +% end +% +% match_ylim(get(gcf,'Children')); +% +% %% Figure 1E : RT +% +% cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; %colors for illustrator +% params_of_interest = {'i_sacc_rt'}; +% param_str = {'RT'}; +% +% figure; +% +% for pp = 1:length(params_of_interest) +% +% subplot(1,length(params_of_interest),pp); hold on; +% +% % nbins x nsubj +% thisnod_rt = squeeze(all_rt{1}(1,pp,1,:))'; +% thisnear_dist = squeeze(all_rt{2}(:,pp,1,:))'; +% thisfar_dist = mean(squeeze(all_rt{3}(:,pp,1,:))); +% thisrt= [thisnod_rt; thisnear_dist; thisfar_dist]; +% plot(1:length(flip_bins),thisrt,'-','color',[.2 .2 .2]); +% +% for ii = 1:size(thisrt,1) +% tmpe = std(thisrt(ii,:))/sqrt(length(subj)); +% plot(ii*[1 1],mean(thisrt(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); +% plot(ii,mean(thisrt(ii,:)),'o','LineWidth',1.5,'color',cond_colors(ii,:),'markerfacecolor',cond_colors(ii,:),'MarkerSize',10); +% end +% title(param_str{pp}); +% xlabel('Distractor Condition'); +% +% if pp == 1 +% ylabel('RT'); +% +% end +% set(gca,'XTick',[1 2 3],'Xticklabels',({'No Distractor', 'Near Distractor','Far Distractor'}), 'TickDir','out','XTickLabelRotation',45) +% the_RT = [thisrt(1,:)'; thisrt(2,:)'; thisrt(3,:)']; %use for just dist +% the_ivRT =[ones(length(thisrt(1,:)'),1); 2*ones(length(thisrt(2,:)'),1); 3*ones(length(thisrt(3,:)'),1);]; %use for just dist +% the_subj =[subj;subj;subj;]; +% x = [the_RT the_ivRT the_subj]; +% RMAOV1(x,0.05) +% end +% match_ylim(get(gcf,'Children')); +% xlim([0 size(thisrt,1)+1]); +% +%% Figure 1F : Bias +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thism_near = squeeze(all_mu{2}(:,pp,2,:))'; %this is the only condition that is information for this analysis. + plot(1,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); + plot(1,mean(thism_near,2),'o','MarkerSize',15,'Color',cond_colors(2,:),'MarkerFaceColor',cond_colors(2,:)); + hold on; + + tmpe = std(thism_near)/sqrt(length(subj)); + plot([1 1], mean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(2,:)); + + %errorbar(1, mean(thism_near), [std(thism_near)/sqrt(length(subj))],'linewidth',2,'Color',cond_colors(2,:)) + title(param_str{pp}); + + + ylabel('Memory Bias, toward distractor (\circ)'); +end +xlabel('Near Distractor'); + +[h_bias_near p_bias_near,CI,STATS] = ttest(thism_near(1,:)') %t-test to determine if bias is different than zero +text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',p_bias_near),'color','k','fontsize',15) %filled + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + +% %% Figure 1F : Bias %% NEW%% +% params_of_interest = {'f_sacc'}; +% param_str = {'final sacc'}; +% +% figure; +% +% for pp = 1:length(params_of_interest) +% +% subplot(1,length(params_of_interest),pp); hold on; +% +% % nbins x nsubj +% thism_near = squeeze(all_mupol{2}(:,pp,2,:))'; %this is the only condition that is information for this analysis. +% plot(1,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); +% plot(1,mean(thism_near,2),'o','MarkerSize',15,'Color',cond_colors(2,:),'MarkerFaceColor',cond_colors(2,:)); +% hold on; +% +% tmpe = std(thism_near)/sqrt(length(subj)); +% plot([1 1], mean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(2,:)); +% +% %errorbar(1, mean(thism_near), [std(thism_near)/sqrt(length(subj))],'linewidth',2,'Color',cond_colors(2,:)) +% title(param_str{pp}); +% +% +% ylabel('Memory Bias, toward distractor (polar \circ)'); +% end +% xlabel('Near Distractor'); +% +% [h_bias_near p_bias_near,CI,STATS] = ttest(thism_near(1,:)') %t-test to determine if bias is different than zero +% text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',p_bias_near),'color','k','fontsize',15) %filled +% +% match_ylim(get(gcf,'Children')); +%set(gcf,'position',[ 549 724 499 571]) diff --git a/spDist_plotEyeData_Figure1_102920.m b/spDist_plotEyeData_Figure1_102920.m new file mode 100644 index 0000000..cccf950 --- /dev/null +++ b/spDist_plotEyeData_Figure1_102920.m @@ -0,0 +1,783 @@ + +%spDist_plotEyeData.m +% in the actual task, cyan = distractor, magenta = no distractor +% dependencies: misc_util, RMAOV1 + +root = spDist_loadRoot; + +%load raw subject data + +subj = {'AY','CC','EK','KD','MR','SF','XL'}; + +sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed + +scatterplot_1BC = 0; % plot portions of figure that take quite a while? y/n + +WHICH_EXCL = [13 20 21 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. +if ismember(WHICH_EXCL,13) + which_excl_str ={'broken fix'}; +elseif ismember(WHICH_EXCL,[13 20]) + which_excl_str ={'broken fix','no sacc'}; +elseif ismember(WHICH_EXCL, [13 20 21]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short'}; +elseif ismember(WHICH_EXCL, [13 20 22]) + which_excl_str ={'broken fix','no sacc','i sacc err too lg'}; +elseif ismember(WHICH_EXCL, [13 20 21 22]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short','i sacc err too lg'}; +else + error('which exclusion criteria have you chosen?') +end + +% first-digit: +% - 1 - trial-level exclusion (bad drift correction [11], calibration [12], or delay- +% fixation break [13] +% - 2 - primary saccade exclusion (no primary sacc [20]; too small/short [21] bi, large error [22]ei) + +%21 bad initial saccade (duration/amplitude outside range) +% 22 iniital saccade error + + +% concatenate ALL subject data +all_subj = nan(1000*length(subj),1); + +all_data = []; + +startidx = 1; + +for ss = 1:length(subj) + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + + this_data.s_all = this_scored.ii_sess; + this_data.sess_all = sessidx; + + this_subj = ss; + + all_data = cat_struct(all_data,this_data); + all_subj(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = this_subj; + + startidx = startidx+size(this_scored.ii_sess.trialinfo,1); + + clear this_subj this_data; + end +end + + +all_subj = all_subj(1:(startidx-1)); +all_data.subj_all = all_subj; + +% determine which trials to include +% first, narrow based on saccade preprocessing/scoring exclusions +all_data.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data.s_all.excl_trial, 'UniformOutput',false)); + +% seed random number generator: +rng(spDist_randSeed); + + +%% organize data +distractor_bins = unique(all_data.s_all.trialinfo(all_data.s_all.trialinfo(:,1)~=1,6)); +distractor_spacing = 360/length(distractor_bins); + +%initialize storage cells +all_err = cell(3,1); +all_mu = cell(3,1); +all_rt = cell(3,1); + + +params_of_interest = {'f_sacc'}; + +% first, error for no-distractor trials +tmp_err = nan(1,length(params_of_interest),2,length(subj)); % condition x param x dimen of param (2) x subj +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(1,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(1,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + end +end +% no distractor std +all_err{1} = tmp_err; % 1st cell of all err and all mu = no distractor +all_mu{1} = tmp_mu; %note: the first index of all_ is NO DIST +all_mupol{1} = tmp_mupol; +all_errpol{1} = tmp_errpol; + +clear tmp_err tmp_mu tmp_errpol tmp_mupol; + +% shuffle zero bin flipping 1000 times. +iter =1000; +tmp_mupol = nan(1,length(params_of_interest),2,length(subj),iter); +for xx =1:iter +for ss = 1:length(subj) + + for bb =1 %placeholder, keep dimens same size as when we collect others + + for pp = 1:length(params_of_interest) + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + + + orig_y = tmpd(tmpidx,2); + n_flip =round(length(orig_y)/2); + orig_y(1:n_flip) = orig_y(1:n_flip)*-1; + + tmpd(tmpidx,2) = orig_y; + + + + [dtheta_mu, drad_mu] = cart2pol(tmpd(tmpidx,1), tmpd(tmpidx,2)); + tmp_mupol(bb,pp,:,ss,xx) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear drad_mu dtheta_mu tmpd tmpidx orig_y n_flip + end + end +end +end +all_mupol_shuf{1} = tmp_mupol; +% collect and store random zero bin trials +tmp_cw = nan(1,length(params_of_interest),2,length(subj)); +tmp_ccw = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + + for bb =1 %placeholder, keep dimens same size as when we collect others + + for pp = 1:length(params_of_interest) + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0 & all_data.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins, into tmpd ONLY + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; %now, collect all jitte + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); % use idx with all zero bin from flipped data + + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd thisidx orig_y orig_y_flip + end + end +end +%%%%%%%% + + + +all_err{2} = tmp_err; +all_mu{2} = tmp_mu; +all_mupol{2} = tmp_mupol; +all_errpol{2} = tmp_errpol; + +clear tmp_err tmp_mu tmp_mupol tmp_errpol; + +%put other distractor bins in - we will collect on this basis, and .*-1 for +%like bins +bins = [1 2 3]; +tmp_err = nan(length(bins),length(params_of_interest),2,length(subj)); +tmp_mu = nan(length(bins),length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + for bb = 1:length(bins) + for pp = 1:length(params_of_interest) + + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==(bins(bb)*-1); + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % the y flip is inserted for CW bins. + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)==bins(bb) | all_data.s_all.trialinfo(:,6)==bins(bb)*-1); + + + % distractor bin x param x [radial; tangential] x subj + + + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); %us thisidx, which collects both bin_n & bin_-n, only on the tmpd data which contains flipped y-vals on cw trials + + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); %we're only going to be using the theta dimen here + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later (x,y) indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd tmpd thisidx orig_y orig_y_flip + + end + end +end + +all_err{3} = tmp_err; +all_mu{3} = tmp_mu; +all_mupol{3} = tmp_mupol; +all_errpol{3} = tmp_errpol; +clear tmp_err tmp_mu tmp_errpol tmpmupol; + +% create a new container for _alldist - for precision only +tmp_err = nan(1,length(params_of_interest),2,length(subj)); +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); + +for pp = 1:length(params_of_interest) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + + clear dtheta_err drad_err + end +end + +all_err_alldist{1} = tmp_err; +all_errpol_alldist{1} = tmp_errpol; +clear tmp_err tmp_errpol + +% first, RT for no-distractor trials + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +params_of_interest = {'i_sacc_rt'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{1} = tmp_rt; +clear tmp_rt + +% RT for near dist +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{2} = tmp_rt; +bins = [1 2 3]; +tmp_rt = nan(length(bins),length(params_of_interest),1,length(subj)); % # conditions x # params x dimen of param x subj + +for ss = 1:length(subj) + for bb = 1:length(bins) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)== bins(bb) | all_data.s_all.trialinfo(:,6)== bins(bb)*-1); + + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_rt(bb,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + + end + end +end + +all_rt{3} = tmp_rt; + +% RT for _alldist + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); +params_of_interest = {'i_sacc_rt'}; +param_str = {'RT'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % all distractor x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt_alldist{1} =tmp_rt; + +if scatterplot_1BC ==1 + +%% Figure 1B : Example participant eye-trace + +dist_colors = [0.7100 0.2128 0.4772; 0 0 1;]; %1 is red, no distractor, 2 is blue (near distractor), 3 is green (far distractor) +figure; +hold on; +xdat_to_plot = [1 2 3 4 5 6 7 8 9 10]; % these are the annotations from our eye-data output, marking the distinct epochs of the task +dist_cond =[1 2]; + +for cc = 1:length(dist_cond) + thisidx = find(all_data.use_trial==1 & all_data.subj_all ==2 & all_data.s_all.trialinfo(:,1) == dist_cond(cc)); %subj should be 'CC' + + for tt = 1:length(thisidx) + figure(1) + %transform the cartesian X,Y coords we have for the trace and put + %it in polar + [tmpth,tmpr] = cart2pol(all_data.s_all.X{thisidx(tt)},all_data.s_all.Y{thisidx(tt)}); + + % change th, keeping r the same, based on th of all_data.s_all.targ + [adjth,~] = cart2pol(all_data.s_all.targ(thisidx(tt),1),all_data.s_all.targ(thisidx(tt),2)); + + [aligned_x,~] = pol2cart(tmpth-adjth,tmpr); % we're not using y here, just x + + aligned_x = aligned_x(ismember(all_data.s_all.XDAT{thisidx(tt)},xdat_to_plot)); + + if cc ==1 %no distractor + + this_t = (1:length(aligned_x))/500; % time in seconds (how many samples were taken / frequency of recording device) + subplot(2,1,1) + plot(this_t,aligned_x,'-','LineWidth',0.3,'Color', dist_colors(cc,:)); + ylim([-18 18]); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + set(gca,'YTick',[-12 0 12],'TickDir','out'); + hold on; + set(gcf,'Renderer','painters') + else + aligned_x = aligned_x.*-1; % for visualization purposes, flip the trace of the distractor condition to be mirrored over the x-axis + this_t = (1:length(aligned_x))/500; % time in seconds (how many samples were taken / frequency of recording device) + subplot(2,1,1) + plot(this_t,aligned_x,'-','LineWidth',0.3,'Color',[dist_colors(2,:) 0.5000]) %dist_colors(cc,:)); + ylim([-18 18]); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + set(gca,'YTick',[-12 0 12],'TickDir','out'); + hold on; + set(gcf,'Renderer','painters') + + end + + if tt ==1 + %for this subject, this trial, this epoch, turn XDAT marker on + epoch_1_condc = all_data.s_all.XDAT{thisidx(tt)} ==1 ; % distractor cue, store the entire epoch in a variable + epoch_2_targ = all_data.s_all.XDAT{thisidx(tt)} ==2; % targets + epoch_3_d1 = all_data.s_all.XDAT{thisidx(tt)}==3; % delay 1 + epoch_4_dist = all_data.s_all.XDAT{thisidx(tt)} ==4; % distractor + epoch_5_d2 = all_data.s_all.XDAT{thisidx(tt)} ==5; % delay 2 + epoch_6_go = all_data.s_all.XDAT{thisidx(tt)}==6; % response + epoch_7_fb = all_data.s_all.XDAT{thisidx(tt)}==7; %feedback + epoch_8_iti = all_data.s_all.XDAT{thisidx(tt)}==8; % waiting for subj to respond + + %epoch 9 = distractor feed-back (no eye-movement) + %epoch 10 = ITI + subplot(2,1,2) + hold on; + plot(this_t,epoch_1_condc+6,'k-','LineWidth',3); + plot(this_t,epoch_2_targ+4,'k-','LineWidth',3); + plot(this_t,epoch_4_dist+2,'k-','LineWidth',3); + plot(this_t,epoch_6_go,'k-','LineWidth',3); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + yticks([1 3 5 7]) + yticklabels({'Response','Distractor', 'Target','Condition Cue'}) + xlabel('Time relative to delay onset (s)'); + ylabel('Trial Epoch') + set(gcf,'Renderer','painters') + else + end + clear aligned_x this_t tmpth tmpr + end +end + +set(gcf,'Renderer','painters') +set(gcf,'position',[ 1000 626 1147 712]) +xlabel('Time relative to delay onset (s)'); +ylabel('Eye position (DVA)'); + +%% Figure 1C : Aligned Saccadic Endpoints; Distractor Absent, Distractor Present + +dist_colors = spDist_condColors; % 1= RED = no distractor; 2 =blue = DISTRACTOR + +figure; +params_of_interest= {'f_sacc'}; % what fields do we want to plot? + +dist_bins = [1 2]; %1 = no dist, 2 = dist + +for pp = 1:length(params_of_interest) + + for dd =1:length(dist_bins) + + if dist_bins(dd) == 1 + thisidx = all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + x = all_data.s_all.(params_of_interest{pp})(thisidx,1); + y = all_data.s_all.(params_of_interest{pp})(thisidx,2); + y_save = nanmean(y); + + elseif dist_bins(dd) == 2 + + thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + x = all_data.s_all.(params_of_interest{pp})(thisidx,1); + y = all_data.s_all.(params_of_interest{pp})(thisidx,2); + y_save = nanmean(y); + + end + + if dd ==1 + subplot(1,2,1) + title('Distractor Absent') + elseif dd==2 + subplot(1,2,2) + title('Distractor Present') + end + hold on; + scatter(x,y,30,dist_colors(dd,:),'filled','MarkerFaceAlpha',.2) + scatter(mean(x),mean(y),30,'k','filled') + hold on; + plot([3 15], [0 0],'--','linewidth',1,'color',[.1 .1 .1]) + clear tmpy + clear thisidx + ylim([-6 6]) + xlim([3 15]) + xticks([3:1:15]) + yticks([-6:1:6]) + xticklabels([3:15]) + yticklabels([-6:6]) + axis equal + end +end + +set(gcf,'Renderer','painters') +match_ylim(get(gcf,'Children')) +else + +%% Figure 1D : Precision, Distractor Absent vs. Distractor Present (all distractor bins collapsed), polar deg + +% directly compare avg sd for no distractor, near distractor, far +% distractor +% trials, final sacc only ; averaged over radial/tang... + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = spDist_condColors; %red, blue +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thise(ii,:) = squeeze(all_errpol{1}(:,pp,2,:)); % DO NOT mean over 3rd dimension here, look only at the 'y' component + elseif ii ==2 + thise(ii,:) = squeeze(all_errpol_alldist{1}(:,pp,2,:)); % this "all_err_alldist" container is used bc all_err separates near vs. far dists. Simplified w this {} where all dist trials are within a single cell + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:2 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + + clear tmpe + end + + xlim([0 3]); + + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error, Polar Angle (\circ)'); % + end + title(param_str{pp}); + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + [h,p,ci,stats] = ttest(thise(1,:)',thise(2,:)') % compare no dist, dist + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + +%ylim([0 1.5]) +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + + + +%% RT : No distractor, all distractor bins collapsed (seconds) + + +params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +param_str = {'RT'}; +cond_colors = spDist_condColors; +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thisrt = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thisrt(ii,:) = squeeze(mean(all_rt{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + elseif ii ==2 + thisrt(ii,:) = squeeze(mean(all_rt_alldist{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + end + end + + plot(1:size(thisrt,1),thisrt,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:2 + hold on; + tmpe = std(thisrt(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thisrt(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thisrt(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 3]); + + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('RT (seconds)'); + end + title(param_str{pp}); + + the_y = [thisrt(1,:)';thisrt(2,:)';]; + the_iv =[ones(length(thisrt(1,:)'),1); 2*ones(length(thisrt(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj = [subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + [h_rt,p_rt,ci_rt,stats_rt] = ttest(thisrt(1,:)',thisrt(2,:)') + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + + %% Figure 1F : Near Distractor trials: Bias, polar degrees + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thism_near = squeeze(all_mupol{2}(:,pp,2,:))'; %this is the only condition that is information for this analysis. + plot(1+0.15,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); + plot(1,mean(thism_near,2),'o','MarkerSize',15,'Color',cond_colors(2,:),'MarkerFaceColor',cond_colors(2,:)); + hold on; + + tmpe = std(thism_near)/sqrt(length(subj)); + plot([1 1], mean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(2,:)); + + %errorbar(1, mean(thism_near), [std(thism_near)/sqrt(length(subj))],'linewidth',2,'Color',cond_colors(2,:)) + title(param_str{pp}); + + + ylabel('Bias, Polar Angle (\circ), toward distractor'); +end +xlabel('Near Distractor') +xlim([0 2]) + +[h_bias_near p_bias_near,CI,STATS] = ttest(thism_near(1,:)') %t-test to determine if bias is different than zero +text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',p_bias_near),'color','k','fontsize',15) %filled +t_real = STATS.tstat; +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%% insert shuffling bias test +for xx = 1:iter +for pp = 1:length(params_of_interest) + + + thism_near = squeeze(all_mupol_shuf{1}(:,pp,2,:,xx)); %this is the only condition that is information for this analysis. + + [~,~,~,stats] = ttest(thism_near); + t_shuf(xx) = stats.tstat; + clear stats thism_near +end +end +fprintf('pause') + + +bias_pval = 2 * min(mean(t_shuf<=t_real), mean(t_shuf>=t_real)); % no pvals are greater than real + + +%% +%%%%%%%%%%%%%%%%%% SUPPLEMENATARY FIGURE 1 A %%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% REPORTED STATS ONLY - PRECISION, Distractor Absent, Distractor Present Abs(Bin) +% STATS ARE ONLY ON Distractor Present (4-level RM ANOVA) : polar deg +% updated 110620 with only y-component +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_errpol{ii}(:,pp,2,:))'; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + else + thise([ii:5],:)= squeeze(all_errpol{ii}(:,pp,2,:)) ; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error, Polar Angle (\circ)'); + end + title(param_str{pp}); + + + the_y = [thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; % do not use no distractor condition here + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;]; + x = [the_y the_iv the_subj]; + RMAOV1(x,0.05) %one-way RM ANOVA + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%%%%%%%%%%%%%%%%%% SUPPLEMENATARY FIGURE 1 B %%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% REPORTED STATS ONLY RT :Distractor Absent, Distractor Present abs(bins) + +params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +param_str = {'RT'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + for ii = 1:length(all_rt) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_rt{ii}(:,pp,:,:))'; + + else + thise([ii:5],:)= squeeze(all_rt{ii}(:,pp,:,:)); + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('RT'); + end + title(param_str{pp}); + + the_y = [thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + set(gcf,'position',[549 724 499 571]) + +end + +end + +fprintf('behave done') +%c/p to illustrator, scale by %60 diff --git a/spDist_plotEyeData_Figure1_102920.m~ b/spDist_plotEyeData_Figure1_102920.m~ new file mode 100644 index 0000000..cccf950 --- /dev/null +++ b/spDist_plotEyeData_Figure1_102920.m~ @@ -0,0 +1,783 @@ + +%spDist_plotEyeData.m +% in the actual task, cyan = distractor, magenta = no distractor +% dependencies: misc_util, RMAOV1 + +root = spDist_loadRoot; + +%load raw subject data + +subj = {'AY','CC','EK','KD','MR','SF','XL'}; + +sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed + +scatterplot_1BC = 0; % plot portions of figure that take quite a while? y/n + +WHICH_EXCL = [13 20 21 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. +if ismember(WHICH_EXCL,13) + which_excl_str ={'broken fix'}; +elseif ismember(WHICH_EXCL,[13 20]) + which_excl_str ={'broken fix','no sacc'}; +elseif ismember(WHICH_EXCL, [13 20 21]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short'}; +elseif ismember(WHICH_EXCL, [13 20 22]) + which_excl_str ={'broken fix','no sacc','i sacc err too lg'}; +elseif ismember(WHICH_EXCL, [13 20 21 22]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short','i sacc err too lg'}; +else + error('which exclusion criteria have you chosen?') +end + +% first-digit: +% - 1 - trial-level exclusion (bad drift correction [11], calibration [12], or delay- +% fixation break [13] +% - 2 - primary saccade exclusion (no primary sacc [20]; too small/short [21] bi, large error [22]ei) + +%21 bad initial saccade (duration/amplitude outside range) +% 22 iniital saccade error + + +% concatenate ALL subject data +all_subj = nan(1000*length(subj),1); + +all_data = []; + +startidx = 1; + +for ss = 1:length(subj) + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + + this_data.s_all = this_scored.ii_sess; + this_data.sess_all = sessidx; + + this_subj = ss; + + all_data = cat_struct(all_data,this_data); + all_subj(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = this_subj; + + startidx = startidx+size(this_scored.ii_sess.trialinfo,1); + + clear this_subj this_data; + end +end + + +all_subj = all_subj(1:(startidx-1)); +all_data.subj_all = all_subj; + +% determine which trials to include +% first, narrow based on saccade preprocessing/scoring exclusions +all_data.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data.s_all.excl_trial, 'UniformOutput',false)); + +% seed random number generator: +rng(spDist_randSeed); + + +%% organize data +distractor_bins = unique(all_data.s_all.trialinfo(all_data.s_all.trialinfo(:,1)~=1,6)); +distractor_spacing = 360/length(distractor_bins); + +%initialize storage cells +all_err = cell(3,1); +all_mu = cell(3,1); +all_rt = cell(3,1); + + +params_of_interest = {'f_sacc'}; + +% first, error for no-distractor trials +tmp_err = nan(1,length(params_of_interest),2,length(subj)); % condition x param x dimen of param (2) x subj +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(1,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(1,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + end +end +% no distractor std +all_err{1} = tmp_err; % 1st cell of all err and all mu = no distractor +all_mu{1} = tmp_mu; %note: the first index of all_ is NO DIST +all_mupol{1} = tmp_mupol; +all_errpol{1} = tmp_errpol; + +clear tmp_err tmp_mu tmp_errpol tmp_mupol; + +% shuffle zero bin flipping 1000 times. +iter =1000; +tmp_mupol = nan(1,length(params_of_interest),2,length(subj),iter); +for xx =1:iter +for ss = 1:length(subj) + + for bb =1 %placeholder, keep dimens same size as when we collect others + + for pp = 1:length(params_of_interest) + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + + + orig_y = tmpd(tmpidx,2); + n_flip =round(length(orig_y)/2); + orig_y(1:n_flip) = orig_y(1:n_flip)*-1; + + tmpd(tmpidx,2) = orig_y; + + + + [dtheta_mu, drad_mu] = cart2pol(tmpd(tmpidx,1), tmpd(tmpidx,2)); + tmp_mupol(bb,pp,:,ss,xx) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear drad_mu dtheta_mu tmpd tmpidx orig_y n_flip + end + end +end +end +all_mupol_shuf{1} = tmp_mupol; +% collect and store random zero bin trials +tmp_cw = nan(1,length(params_of_interest),2,length(subj)); +tmp_ccw = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + + for bb =1 %placeholder, keep dimens same size as when we collect others + + for pp = 1:length(params_of_interest) + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0 & all_data.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins, into tmpd ONLY + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; %now, collect all jitte + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); % use idx with all zero bin from flipped data + + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd thisidx orig_y orig_y_flip + end + end +end +%%%%%%%% + + + +all_err{2} = tmp_err; +all_mu{2} = tmp_mu; +all_mupol{2} = tmp_mupol; +all_errpol{2} = tmp_errpol; + +clear tmp_err tmp_mu tmp_mupol tmp_errpol; + +%put other distractor bins in - we will collect on this basis, and .*-1 for +%like bins +bins = [1 2 3]; +tmp_err = nan(length(bins),length(params_of_interest),2,length(subj)); +tmp_mu = nan(length(bins),length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + for bb = 1:length(bins) + for pp = 1:length(params_of_interest) + + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==(bins(bb)*-1); + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % the y flip is inserted for CW bins. + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)==bins(bb) | all_data.s_all.trialinfo(:,6)==bins(bb)*-1); + + + % distractor bin x param x [radial; tangential] x subj + + + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); %us thisidx, which collects both bin_n & bin_-n, only on the tmpd data which contains flipped y-vals on cw trials + + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); %we're only going to be using the theta dimen here + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later (x,y) indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd tmpd thisidx orig_y orig_y_flip + + end + end +end + +all_err{3} = tmp_err; +all_mu{3} = tmp_mu; +all_mupol{3} = tmp_mupol; +all_errpol{3} = tmp_errpol; +clear tmp_err tmp_mu tmp_errpol tmpmupol; + +% create a new container for _alldist - for precision only +tmp_err = nan(1,length(params_of_interest),2,length(subj)); +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); + +for pp = 1:length(params_of_interest) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + + clear dtheta_err drad_err + end +end + +all_err_alldist{1} = tmp_err; +all_errpol_alldist{1} = tmp_errpol; +clear tmp_err tmp_errpol + +% first, RT for no-distractor trials + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +params_of_interest = {'i_sacc_rt'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{1} = tmp_rt; +clear tmp_rt + +% RT for near dist +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{2} = tmp_rt; +bins = [1 2 3]; +tmp_rt = nan(length(bins),length(params_of_interest),1,length(subj)); % # conditions x # params x dimen of param x subj + +for ss = 1:length(subj) + for bb = 1:length(bins) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)== bins(bb) | all_data.s_all.trialinfo(:,6)== bins(bb)*-1); + + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_rt(bb,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + + end + end +end + +all_rt{3} = tmp_rt; + +% RT for _alldist + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); +params_of_interest = {'i_sacc_rt'}; +param_str = {'RT'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % all distractor x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt_alldist{1} =tmp_rt; + +if scatterplot_1BC ==1 + +%% Figure 1B : Example participant eye-trace + +dist_colors = [0.7100 0.2128 0.4772; 0 0 1;]; %1 is red, no distractor, 2 is blue (near distractor), 3 is green (far distractor) +figure; +hold on; +xdat_to_plot = [1 2 3 4 5 6 7 8 9 10]; % these are the annotations from our eye-data output, marking the distinct epochs of the task +dist_cond =[1 2]; + +for cc = 1:length(dist_cond) + thisidx = find(all_data.use_trial==1 & all_data.subj_all ==2 & all_data.s_all.trialinfo(:,1) == dist_cond(cc)); %subj should be 'CC' + + for tt = 1:length(thisidx) + figure(1) + %transform the cartesian X,Y coords we have for the trace and put + %it in polar + [tmpth,tmpr] = cart2pol(all_data.s_all.X{thisidx(tt)},all_data.s_all.Y{thisidx(tt)}); + + % change th, keeping r the same, based on th of all_data.s_all.targ + [adjth,~] = cart2pol(all_data.s_all.targ(thisidx(tt),1),all_data.s_all.targ(thisidx(tt),2)); + + [aligned_x,~] = pol2cart(tmpth-adjth,tmpr); % we're not using y here, just x + + aligned_x = aligned_x(ismember(all_data.s_all.XDAT{thisidx(tt)},xdat_to_plot)); + + if cc ==1 %no distractor + + this_t = (1:length(aligned_x))/500; % time in seconds (how many samples were taken / frequency of recording device) + subplot(2,1,1) + plot(this_t,aligned_x,'-','LineWidth',0.3,'Color', dist_colors(cc,:)); + ylim([-18 18]); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + set(gca,'YTick',[-12 0 12],'TickDir','out'); + hold on; + set(gcf,'Renderer','painters') + else + aligned_x = aligned_x.*-1; % for visualization purposes, flip the trace of the distractor condition to be mirrored over the x-axis + this_t = (1:length(aligned_x))/500; % time in seconds (how many samples were taken / frequency of recording device) + subplot(2,1,1) + plot(this_t,aligned_x,'-','LineWidth',0.3,'Color',[dist_colors(2,:) 0.5000]) %dist_colors(cc,:)); + ylim([-18 18]); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + set(gca,'YTick',[-12 0 12],'TickDir','out'); + hold on; + set(gcf,'Renderer','painters') + + end + + if tt ==1 + %for this subject, this trial, this epoch, turn XDAT marker on + epoch_1_condc = all_data.s_all.XDAT{thisidx(tt)} ==1 ; % distractor cue, store the entire epoch in a variable + epoch_2_targ = all_data.s_all.XDAT{thisidx(tt)} ==2; % targets + epoch_3_d1 = all_data.s_all.XDAT{thisidx(tt)}==3; % delay 1 + epoch_4_dist = all_data.s_all.XDAT{thisidx(tt)} ==4; % distractor + epoch_5_d2 = all_data.s_all.XDAT{thisidx(tt)} ==5; % delay 2 + epoch_6_go = all_data.s_all.XDAT{thisidx(tt)}==6; % response + epoch_7_fb = all_data.s_all.XDAT{thisidx(tt)}==7; %feedback + epoch_8_iti = all_data.s_all.XDAT{thisidx(tt)}==8; % waiting for subj to respond + + %epoch 9 = distractor feed-back (no eye-movement) + %epoch 10 = ITI + subplot(2,1,2) + hold on; + plot(this_t,epoch_1_condc+6,'k-','LineWidth',3); + plot(this_t,epoch_2_targ+4,'k-','LineWidth',3); + plot(this_t,epoch_4_dist+2,'k-','LineWidth',3); + plot(this_t,epoch_6_go,'k-','LineWidth',3); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + yticks([1 3 5 7]) + yticklabels({'Response','Distractor', 'Target','Condition Cue'}) + xlabel('Time relative to delay onset (s)'); + ylabel('Trial Epoch') + set(gcf,'Renderer','painters') + else + end + clear aligned_x this_t tmpth tmpr + end +end + +set(gcf,'Renderer','painters') +set(gcf,'position',[ 1000 626 1147 712]) +xlabel('Time relative to delay onset (s)'); +ylabel('Eye position (DVA)'); + +%% Figure 1C : Aligned Saccadic Endpoints; Distractor Absent, Distractor Present + +dist_colors = spDist_condColors; % 1= RED = no distractor; 2 =blue = DISTRACTOR + +figure; +params_of_interest= {'f_sacc'}; % what fields do we want to plot? + +dist_bins = [1 2]; %1 = no dist, 2 = dist + +for pp = 1:length(params_of_interest) + + for dd =1:length(dist_bins) + + if dist_bins(dd) == 1 + thisidx = all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + x = all_data.s_all.(params_of_interest{pp})(thisidx,1); + y = all_data.s_all.(params_of_interest{pp})(thisidx,2); + y_save = nanmean(y); + + elseif dist_bins(dd) == 2 + + thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + x = all_data.s_all.(params_of_interest{pp})(thisidx,1); + y = all_data.s_all.(params_of_interest{pp})(thisidx,2); + y_save = nanmean(y); + + end + + if dd ==1 + subplot(1,2,1) + title('Distractor Absent') + elseif dd==2 + subplot(1,2,2) + title('Distractor Present') + end + hold on; + scatter(x,y,30,dist_colors(dd,:),'filled','MarkerFaceAlpha',.2) + scatter(mean(x),mean(y),30,'k','filled') + hold on; + plot([3 15], [0 0],'--','linewidth',1,'color',[.1 .1 .1]) + clear tmpy + clear thisidx + ylim([-6 6]) + xlim([3 15]) + xticks([3:1:15]) + yticks([-6:1:6]) + xticklabels([3:15]) + yticklabels([-6:6]) + axis equal + end +end + +set(gcf,'Renderer','painters') +match_ylim(get(gcf,'Children')) +else + +%% Figure 1D : Precision, Distractor Absent vs. Distractor Present (all distractor bins collapsed), polar deg + +% directly compare avg sd for no distractor, near distractor, far +% distractor +% trials, final sacc only ; averaged over radial/tang... + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = spDist_condColors; %red, blue +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thise(ii,:) = squeeze(all_errpol{1}(:,pp,2,:)); % DO NOT mean over 3rd dimension here, look only at the 'y' component + elseif ii ==2 + thise(ii,:) = squeeze(all_errpol_alldist{1}(:,pp,2,:)); % this "all_err_alldist" container is used bc all_err separates near vs. far dists. Simplified w this {} where all dist trials are within a single cell + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:2 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + + clear tmpe + end + + xlim([0 3]); + + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error, Polar Angle (\circ)'); % + end + title(param_str{pp}); + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + [h,p,ci,stats] = ttest(thise(1,:)',thise(2,:)') % compare no dist, dist + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + +%ylim([0 1.5]) +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + + + +%% RT : No distractor, all distractor bins collapsed (seconds) + + +params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +param_str = {'RT'}; +cond_colors = spDist_condColors; +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thisrt = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thisrt(ii,:) = squeeze(mean(all_rt{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + elseif ii ==2 + thisrt(ii,:) = squeeze(mean(all_rt_alldist{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + end + end + + plot(1:size(thisrt,1),thisrt,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:2 + hold on; + tmpe = std(thisrt(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thisrt(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thisrt(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 3]); + + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('RT (seconds)'); + end + title(param_str{pp}); + + the_y = [thisrt(1,:)';thisrt(2,:)';]; + the_iv =[ones(length(thisrt(1,:)'),1); 2*ones(length(thisrt(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj = [subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + [h_rt,p_rt,ci_rt,stats_rt] = ttest(thisrt(1,:)',thisrt(2,:)') + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + + %% Figure 1F : Near Distractor trials: Bias, polar degrees + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thism_near = squeeze(all_mupol{2}(:,pp,2,:))'; %this is the only condition that is information for this analysis. + plot(1+0.15,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); + plot(1,mean(thism_near,2),'o','MarkerSize',15,'Color',cond_colors(2,:),'MarkerFaceColor',cond_colors(2,:)); + hold on; + + tmpe = std(thism_near)/sqrt(length(subj)); + plot([1 1], mean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(2,:)); + + %errorbar(1, mean(thism_near), [std(thism_near)/sqrt(length(subj))],'linewidth',2,'Color',cond_colors(2,:)) + title(param_str{pp}); + + + ylabel('Bias, Polar Angle (\circ), toward distractor'); +end +xlabel('Near Distractor') +xlim([0 2]) + +[h_bias_near p_bias_near,CI,STATS] = ttest(thism_near(1,:)') %t-test to determine if bias is different than zero +text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',p_bias_near),'color','k','fontsize',15) %filled +t_real = STATS.tstat; +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%% insert shuffling bias test +for xx = 1:iter +for pp = 1:length(params_of_interest) + + + thism_near = squeeze(all_mupol_shuf{1}(:,pp,2,:,xx)); %this is the only condition that is information for this analysis. + + [~,~,~,stats] = ttest(thism_near); + t_shuf(xx) = stats.tstat; + clear stats thism_near +end +end +fprintf('pause') + + +bias_pval = 2 * min(mean(t_shuf<=t_real), mean(t_shuf>=t_real)); % no pvals are greater than real + + +%% +%%%%%%%%%%%%%%%%%% SUPPLEMENATARY FIGURE 1 A %%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% REPORTED STATS ONLY - PRECISION, Distractor Absent, Distractor Present Abs(Bin) +% STATS ARE ONLY ON Distractor Present (4-level RM ANOVA) : polar deg +% updated 110620 with only y-component +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_errpol{ii}(:,pp,2,:))'; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + else + thise([ii:5],:)= squeeze(all_errpol{ii}(:,pp,2,:)) ; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error, Polar Angle (\circ)'); + end + title(param_str{pp}); + + + the_y = [thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; % do not use no distractor condition here + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;]; + x = [the_y the_iv the_subj]; + RMAOV1(x,0.05) %one-way RM ANOVA + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%%%%%%%%%%%%%%%%%% SUPPLEMENATARY FIGURE 1 B %%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% REPORTED STATS ONLY RT :Distractor Absent, Distractor Present abs(bins) + +params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +param_str = {'RT'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + for ii = 1:length(all_rt) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_rt{ii}(:,pp,:,:))'; + + else + thise([ii:5],:)= squeeze(all_rt{ii}(:,pp,:,:)); + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('RT'); + end + title(param_str{pp}); + + the_y = [thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + set(gcf,'position',[549 724 499 571]) + +end + +end + +fprintf('behave done') +%c/p to illustrator, scale by %60 diff --git a/spDist_plotEyeData_Figure1_111320.m b/spDist_plotEyeData_Figure1_111320.m new file mode 100644 index 0000000..ad9a9ca --- /dev/null +++ b/spDist_plotEyeData_Figure1_111320.m @@ -0,0 +1,833 @@ + +%spDist_plotEyeData.m +% in the actual task, cyan = distractor, magenta = no distractor +% dependencies: misc_util, RMAOV1 + +root = spDist_loadRoot; + +%load raw subject data + +subj = {'AY','CC','EK','KD','MR','SF','XL'}; + +sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed + +scatterplot_1BC = 0; % plot portions of figure that take quite a while? y/n + +WHICH_EXCL = [13 20 21 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. +if ismember(WHICH_EXCL,13) + which_excl_str ={'broken fix'}; +elseif ismember(WHICH_EXCL,[13 20]) + which_excl_str ={'broken fix','no sacc'}; +elseif ismember(WHICH_EXCL, [13 20 21]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short'}; +elseif ismember(WHICH_EXCL, [13 20 22]) + which_excl_str ={'broken fix','no sacc','i sacc err too lg'}; +elseif ismember(WHICH_EXCL, [13 20 21 22]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short','i sacc err too lg'}; +else + error('which exclusion criteria have you chosen?') +end + +% first-digit: +% - 1 - trial-level exclusion (bad drift correction [11], calibration [12], or delay- +% fixation break [13] +% - 2 - primary saccade exclusion (no primary sacc [20]; too small/short [21] bi, large error [22]ei) + +%21 bad initial saccade (duration/amplitude outside range) +% 22 iniital saccade error + + +% concatenate ALL subject data +all_subj = nan(1000*length(subj),1); + +all_data = []; + +startidx = 1; + +for ss = 1:length(subj) + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + + this_data.s_all = this_scored.ii_sess; + this_data.sess_all = sessidx; + + this_subj = ss; + + all_data = cat_struct(all_data,this_data); + all_subj(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = this_subj; + + startidx = startidx+size(this_scored.ii_sess.trialinfo,1); + + clear this_subj this_data; + end +end + + +all_subj = all_subj(1:(startidx-1)); +all_data.subj_all = all_subj; + +% determine which trials to include +% first, narrow based on saccade preprocessing/scoring exclusions +all_data.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data.s_all.excl_trial, 'UniformOutput',false)); + + +%% organize data +distractor_bins = unique(all_data.s_all.trialinfo(all_data.s_all.trialinfo(:,1)~=1,6)); +distractor_spacing = 360/length(distractor_bins); + +%initialize storage cells +all_err = cell(3,1); +all_mu = cell(3,1); +all_rt = cell(3,1); + + +params_of_interest = {'f_sacc'}; + +% first, error for no-distractor trials +tmp_err = nan(1,length(params_of_interest),2,length(subj)); % condition x param x dimen of param (2) x subj +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(1,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(1,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + end +end +% no distractor std +all_err{1} = tmp_err; % 1st cell of all err and all mu = no distractor +all_mu{1} = tmp_mu; %note: the first index of all_ is NO DIST +all_mupol{1} = tmp_mupol; +all_errpol{1} = tmp_errpol; + +clear tmp_err tmp_mu tmp_errpol tmp_mupol; +% +% tmp_err = nan(1,length(params_of_interest),2,length(subj)); +% tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +% tmp_cw = nan(1,length(params_of_interest),2,length(subj)); +% tmp_ccw = nan(1,length(params_of_interest),2,length(subj)); +% tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +% tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); +% +% for ss = 1:length(subj) +% +% for bb =1 %placeholder, keep dimens same size as when we collect others +% +% for pp = 1:length(params_of_interest) +% tmpd = all_data.s_all.(params_of_interest{pp}); +% tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; +% +% +% orig_y = tmpd(tmpidx,2); +% n_tflip = [1:round(length(orig_y)/2)]; %how many trials are there? flip half. make it a 1:number vector +% flip_y = -1.*orig_y(n_tflip); +% tmpd(tmpidx,2) = flip_y +% +% orig_y_flip = orig_y*-1; +% tmpd(tmpidx,2) = orig_y_flip; +% +% +% % distractor bin x param x [radial; tangential] x subj +% tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); +% tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); % use idx with all zero bin from flipped data +% +% [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); +% tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); +% [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); +% tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing +% +% clear dtheta_err drad_err drad_mu dtheta_mu tmpd thisidx orig_y orig_y_flip +% end +% end +% end +% %%% inserting +% collect and store random zero bin trials +tmp_cw = nan(1,length(params_of_interest),2,length(subj)); +tmp_ccw = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + + for bb =1 %placeholder, keep dimens same size as when we collect others + + for pp = 1:length(params_of_interest) + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0 & all_data.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins, into tmpd ONLY + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; %now, collect all jitters. + + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); % use idx with all zero bin from flipped data + + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd thisidx orig_y orig_y_flip + end + end +end +%%%%%%%% + + + +all_err{2} = tmp_err; +all_mu{2} = tmp_mu; +all_mupol{2} = tmp_mupol; +all_errpol{2} = tmp_errpol; + +clear tmp_err tmp_mu tmp_mupol tmp_errpol; + +%put other distractor bins in - we will collect on this basis, and .*-1 for +%like bins +bins = [1 2 3]; +tmp_err = nan(length(bins),length(params_of_interest),2,length(subj)); +tmp_mu = nan(length(bins),length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + for bb = 1:length(bins) + for pp = 1:length(params_of_interest) + + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==(bins(bb)*-1); + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % the y flip is inserted for CW bins. + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)==bins(bb) | all_data.s_all.trialinfo(:,6)==bins(bb)*-1); + + + % distractor bin x param x [radial; tangential] x subj + + + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); %us thisidx, which collects both bin_n & bin_-n, only on the tmpd data which contains flipped y-vals on cw trials + + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); %we're only going to be using the theta dimen here + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later (x,y) indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd tmpd thisidx orig_y orig_y_flip + + end + end +end + +all_err{3} = tmp_err; +all_mu{3} = tmp_mu; +all_mupol{3} = tmp_mupol; +all_errpol{3} = tmp_errpol; +clear tmp_err tmp_mu tmp_errpol tmpmupol; + +% create a new container for _alldist - for precision only +tmp_err = nan(1,length(params_of_interest),2,length(subj)); +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +%tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for pp = 1:length(params_of_interest) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + + clear dtheta_err drad_err + end +end + +all_err_alldist{1} = tmp_err; +all_errpol_alldist{1} = tmp_errpol; +clear tmp_err tmp_errpol + +% first, RT for no-distractor trials + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +params_of_interest = {'i_sacc_rt'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{1} = tmp_rt; +clear tmp_rt + +% RT for near dist +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{2} = tmp_rt; +bins = [1 2 3]; +tmp_rt = nan(length(bins),length(params_of_interest),1,length(subj)); % # conditions x # params x dimen of param x subj + +for ss = 1:length(subj) + for bb = 1:length(bins) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)== bins(bb) | all_data.s_all.trialinfo(:,6)== bins(bb)*-1); + + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_rt(bb,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + + end + end +end + +all_rt{3} = tmp_rt; + +% RT for _alldist + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); +params_of_interest = {'i_sacc_rt'}; +param_str = {'RT'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % all distractor x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt_alldist{1} =tmp_rt; + +if scatterplot_1BC ==1 + +%% Figure 1B : Example participant eye-trace + +dist_colors = [0.7100 0.2128 0.4772; 0 0 1;]; %1 is red, no distractor, 2 is blue (near distractor), 3 is green (far distractor) +figure; +hold on; +xdat_to_plot = [1 2 3 4 5 6 7 8 9 10]; % these are the annotations from our eye-data output, marking the distinct epochs of the task +dist_cond =[1 2]; + +for cc = 1:length(dist_cond) + thisidx = find(all_data.use_trial==1 & all_data.subj_all ==2 & all_data.s_all.trialinfo(:,1) == dist_cond(cc)); %subj should be 'CC' + + for tt = 1:length(thisidx) + figure(1) + %transform the cartesian X,Y coords we have for the trace and put + %it in polar + [tmpth,tmpr] = cart2pol(all_data.s_all.X{thisidx(tt)},all_data.s_all.Y{thisidx(tt)}); + + % change th, keeping r the same, based on th of all_data.s_all.targ + [adjth,~] = cart2pol(all_data.s_all.targ(thisidx(tt),1),all_data.s_all.targ(thisidx(tt),2)); + + [aligned_x,~] = pol2cart(tmpth-adjth,tmpr); % we're not using y here, just x + + aligned_x = aligned_x(ismember(all_data.s_all.XDAT{thisidx(tt)},xdat_to_plot)); + + if cc ==1 %no distractor + + this_t = (1:length(aligned_x))/500; % time in seconds (how many samples were taken / frequency of recording device) + subplot(2,1,1) + plot(this_t,aligned_x,'-','LineWidth',0.3,'Color', dist_colors(cc,:)); + ylim([-18 18]); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + set(gca,'YTick',[-12 0 12],'TickDir','out'); + hold on; + set(gcf,'Renderer','painters') + else + aligned_x = aligned_x.*-1; % for visualization purposes, flip the trace of the distractor condition to be mirrored over the x-axis + this_t = (1:length(aligned_x))/500; % time in seconds (how many samples were taken / frequency of recording device) + subplot(2,1,1) + plot(this_t,aligned_x,'-','LineWidth',0.3,'Color',[dist_colors(2,:) 0.5000]) %dist_colors(cc,:)); + ylim([-18 18]); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + set(gca,'YTick',[-12 0 12],'TickDir','out'); + hold on; + set(gcf,'Renderer','painters') + + end + + if tt ==1 + %for this subject, this trial, this epoch, turn XDAT marker on + epoch_1_condc = all_data.s_all.XDAT{thisidx(tt)} ==1 ; % distractor cue, store the entire epoch in a variable + epoch_2_targ = all_data.s_all.XDAT{thisidx(tt)} ==2; % targets + epoch_3_d1 = all_data.s_all.XDAT{thisidx(tt)}==3; % delay 1 + epoch_4_dist = all_data.s_all.XDAT{thisidx(tt)} ==4; % distractor + epoch_5_d2 = all_data.s_all.XDAT{thisidx(tt)} ==5; % delay 2 + epoch_6_go = all_data.s_all.XDAT{thisidx(tt)}==6; % response + epoch_7_fb = all_data.s_all.XDAT{thisidx(tt)}==7; %feedback + epoch_8_iti = all_data.s_all.XDAT{thisidx(tt)}==8; % waiting for subj to respond + + %epoch 9 = distractor feed-back (no eye-movement) + %epoch 10 = ITI + subplot(2,1,2) + hold on; + plot(this_t,epoch_1_condc+6,'k-','LineWidth',3); + plot(this_t,epoch_2_targ+4,'k-','LineWidth',3); + plot(this_t,epoch_4_dist+2,'k-','LineWidth',3); + plot(this_t,epoch_6_go,'k-','LineWidth',3); + xlim([0 15]) + xticks([0 1.5 6 13.5]) + xticklabels({'-1.5','0','4.5','12'}) + yticks([1 3 5 7]) + yticklabels({'Response','Distractor', 'Target','Condition Cue'}) + xlabel('Time relative to delay onset (s)'); + ylabel('Trial Epoch') + set(gcf,'Renderer','painters') + else + end + clear aligned_x this_t tmpth tmpr + end +end + +set(gcf,'Renderer','painters') +set(gcf,'position',[ 1000 626 1147 712]) +xlabel('Time relative to delay onset (s)'); +ylabel('Eye position (DVA)'); + +%% Figure 1C : Aligned Saccadic Endpoints; Distractor Absent, Distractor Present + +dist_colors = spDist_condColors; % 1= RED = no distractor; 2 =blue = DISTRACTOR + +figure; +params_of_interest= {'f_sacc'}; % what fields do we want to plot? + +dist_bins = [1 2]; %1 = no dist, 2 = dist + +for pp = 1:length(params_of_interest) + + for dd =1:length(dist_bins) + + if dist_bins(dd) == 1 + thisidx = all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + x = all_data.s_all.(params_of_interest{pp})(thisidx,1); + y = all_data.s_all.(params_of_interest{pp})(thisidx,2); + y_save = nanmean(y); + + elseif dist_bins(dd) == 2 + + thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + x = all_data.s_all.(params_of_interest{pp})(thisidx,1); + y = all_data.s_all.(params_of_interest{pp})(thisidx,2); + y_save = nanmean(y); + + end + + if dd ==1 + subplot(1,2,1) + title('Distractor Absent') + elseif dd==2 + subplot(1,2,2) + title('Distractor Present') + end + hold on; + scatter(x,y,30,dist_colors(dd,:),'filled','MarkerFaceAlpha',.2) + scatter(mean(x),mean(y),30,'k','filled') + hold on; + plot([3 15], [0 0],'--','linewidth',1,'color',[.1 .1 .1]) + clear tmpy + clear thisidx + ylim([-6 6]) + xlim([3 15]) + xticks([3:1:15]) + yticks([-6:1:6]) + xticklabels([3:15]) + yticklabels([-6:6]) + axis equal + end +end + +set(gcf,'Renderer','painters') +match_ylim(get(gcf,'Children')) +else + +%% Figure 1D : Precision, Distractor Absent vs. Distractor Present (all distractor bins collapsed), polar deg + +% directly compare avg sd for no distractor, near distractor, far +% distractor +% trials, final sacc only ; averaged over radial/tang... + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = spDist_condColors; %red, blue +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thise(ii,:) = squeeze(all_errpol{1}(:,pp,1,:)); % DO NOT mean over 3rd dimension here, look only at the 'y' component + elseif ii ==2 + thise(ii,:) = squeeze(all_errpol_alldist{1}(:,pp,1,:)); % this "all_err_alldist" container is used bc all_err separates near vs. far dists. Simplified w this {} where all dist trials are within a single cell + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:2 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + + clear tmpe + end + + xlim([0 3]); + + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error, Polar Angle (\circ)'); % + end + title(param_str{pp}); + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + [h,p,ci,stats] = ttest(thise(1,:)',thise(2,:)') % compare no dist, dist + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + +%ylim([0 1.5]) +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + + + +%% RT : No distractor, all distractor bins collapsed (seconds) + + +params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +param_str = {'RT'}; +cond_colors = spDist_condColors; +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thisrt = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thisrt(ii,:) = squeeze(mean(all_rt{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + elseif ii ==2 + thisrt(ii,:) = squeeze(mean(all_rt_alldist{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + end + end + + plot(1:size(thisrt,1),thisrt,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:2 + hold on; + tmpe = std(thisrt(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thisrt(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thisrt(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 3]); + + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('RT (seconds)'); + end + title(param_str{pp}); + + the_y = [thisrt(1,:)';thisrt(2,:)';]; + the_iv =[ones(length(thisrt(1,:)'),1); 2*ones(length(thisrt(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj = [subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + [h_rt,p_rt,ci_rt,stats_rt] = ttest(thisrt(1,:)',thisrt(2,:)') + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + + %% Figure 1F : Near Distractor trials: Bias, polar degrees + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thism_near = squeeze(all_mupol{2}(:,pp,1,:))'; %this is the only condition that is information for this analysis. + plot(1+0.15,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); + plot(1,mean(thism_near,2),'o','MarkerSize',15,'Color',cond_colors(2,:),'MarkerFaceColor',cond_colors(2,:)); + hold on; + + tmpe = std(thism_near)/sqrt(length(subj)); + plot([1 1], mean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(2,:)); + + %errorbar(1, mean(thism_near), [std(thism_near)/sqrt(length(subj))],'linewidth',2,'Color',cond_colors(2,:)) + title(param_str{pp}); + + + ylabel('Bias, Polar Angle (\circ), toward distractor'); +end +xlabel('Near Distractor') +xlim([0 2]) + +[h_bias_near p_bias_near,CI,STATS] = ttest(thism_near(1,:)') %t-test to determine if bias is different than zero +text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',p_bias_near),'color','k','fontsize',15) %filled + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) +%% inserting +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_mupol) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_mupol{ii}(:,pp,1,:))'; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + else + thise([ii:5],:)= squeeze(all_mupol{ii}(:,pp,1,:)) ; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + thise = thise-12; + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error, Ecc'); + end + title(param_str{pp}); + + + the_y = [thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; % do not use no distractor condition here + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;]; + x = [the_y the_iv the_subj]; + RMAOV1(x,0.05) %one-way RM ANOVA + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%%%% + +%%%%%%%%%%%%%%%%%% SUPPLEMENATARY FIGURE 1 A %%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% REPORTED STATS ONLY - PRECISION, Distractor Absent, Distractor Present Abs(Bin) +% STATS ARE ONLY ON Distractor Present (4-level RM ANOVA) : polar deg +% updated 110620 with only y-component +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_errpol{ii}(:,pp,1,:))'; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + else + thise([ii:5],:)= squeeze(all_errpol{ii}(:,pp,1,:)) ; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error, Polar Angle (\circ)'); + end + title(param_str{pp}); + + + the_y = [thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; % do not use no distractor condition here + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;]; + x = [the_y the_iv the_subj]; + RMAOV1(x,0.05) %one-way RM ANOVA + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%%%%%%%%%%%%%%%%%% SUPPLEMENATARY FIGURE 1 B %%%%%%%%%%%%%%%%%%%%%%%%%%%% +% %% REPORTED STATS ONLY RT :Distractor Absent, Distractor Present abs(bins) + +params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +param_str = {'RT'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + for ii = 1:length(all_rt) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_rt{ii}(:,pp,:,:))'; + + else + thise([ii:5],:)= squeeze(all_rt{ii}(:,pp,:,:)); + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('RT'); + end + title(param_str{pp}); + + the_y = [thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + set(gcf,'position',[549 724 499 571]) + +end + +end + +fprintf('behave done') +%c/p to illustrator, scale by %60 diff --git a/spDist_plotEyeData_Figure1_92220_updates.m b/spDist_plotEyeData_Figure1_92220_updates.m index 4d55ada..057317f 100644 --- a/spDist_plotEyeData_Figure1_92220_updates.m +++ b/spDist_plotEyeData_Figure1_92220_updates.m @@ -12,7 +12,7 @@ %sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed -WHICH_EXCL = [13 20 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. +WHICH_EXCL = [13 20 21 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. if ismember(WHICH_EXCL,13) which_excl_str ={'broken fix'}; elseif ismember(WHICH_EXCL,[13 20]) @@ -99,6 +99,8 @@ % first, error for no-distractor trials tmp_err = nan(1,length(params_of_interest),2,length(subj)); % initial, final tmp_mu = nan(1,length(params_of_interest),2,length(subj)); % initial, final +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); for ss = 1:length(subj) thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; @@ -106,18 +108,27 @@ % distractor bin x param x [radial; tangential] x subj tmp_err(1,pp,:,ss) = nanstd( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); tmp_mu(1,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = nanstd([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(1,pp,:,ss) = nanmean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing end end all_err{1} = tmp_err; % 1st cell of all err and all mu = no distractor all_mu{1} = tmp_mu; %note: the first index of all_ is NO DIST +all_mupol{1} = tmp_mupol; +all_errpol{1} = tmp_errpol; -clear tmp_err tmp_mu; +clear tmp_err tmp_mu tmp_errpol tmp_mupol; tmp_err = nan(1,length(params_of_interest),2,length(subj)); tmp_mu = nan(1,length(params_of_interest),2,length(subj)); tmp_cw = nan(1,length(params_of_interest),2,length(subj)); tmp_ccw = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); for ss = 1:length(subj) @@ -134,19 +145,29 @@ % distractor bin x param x [radial; tangential] x subj tmp_err(bb,pp,:,ss) = nanstd( all_data.s_all.(params_of_interest{pp})(thisorigidx,:), [], 1 ); tmp_mu(bb,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisorigidx,:), 1 ); - + + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisorigidx,1), all_data.s_all.(params_of_interest{pp})(thisorigidx,2)); + tmp_errpol(bb,pp,:,ss) = nanstd([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisorigidx,1), all_data.s_all.(params_of_interest{pp})(thisorigidx,2)); + tmp_mupol(bb,pp,:,ss) = nanmean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + end end end all_err{2} = tmp_err; all_mu{2} = tmp_mu; -clear tmp_err tmp_mu; +all_mupol{2} = tmp_mupol; +all_errpol{2} = tmp_errpol; + +clear tmp_err tmp_mu tmp_mupol tmp_errpol; %put other bins in flip_bins =[1 2 3]; tmp_err = nan(length(flip_bins),length(params_of_interest),2,length(subj)); tmp_mu = nan(length(flip_bins),length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); for ss = 1:length(subj) for bb = 1:length(flip_bins) @@ -161,13 +182,22 @@ tmp_err(bb,pp,:,ss) = nanstd( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); tmp_mu(bb,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = nanstd([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = nanmean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + end end end all_err{3} = tmp_err; all_mu{3} = tmp_mu; -clear tmp_err tmp_mu; +all_mupol{3} = tmp_mupol; +all_errpol{3} = tmp_errpol; +clear tmp_err tmp_mu tmp_errpol tmpmupol; % create a new container for _alldist tmp_err = nan(1,length(params_of_interest),2,length(subj)); % initial, final @@ -343,63 +373,63 @@ % ylabel('Eye position (DVA)'); %% Figure 1C : Aligned Saccadic Endpoints - -dist_colors = [0.7100 0.2128 0.4772; 0 0 1;]; % 1= RED = no distractor; 2 =blue = DISTRACTOR - -params_of_interest = {'f_sacc'}; -param_str = {'f sacc'}; - -figure; -to_plot = {'f_sacc'}; % what fields do we want to plot? -dist_bins = [1 2]; %1 = no dist, 2 = dist - - -for pp = 1:length(to_plot) - - for dd =1:length(dist_bins) - - if dist_bins(dd) == 1 - thisidx = all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; - x = all_data.s_all.(to_plot{pp})(thisidx,1); - y = all_data.s_all.(to_plot{pp})(thisidx,2); - y_save = nanmean(y); - - elseif dist_bins(dd) == 2 - - thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; - x = all_data.s_all.(to_plot{pp})(thisidx,1); - y = all_data.s_all.(to_plot{pp})(thisidx,2); - y_save = nanmean(y); - - end - - if dd ==1 - subplot(1,2,1) - title('Distractor Absent') - elseif dd==2 - subplot(1,2,2) - title('Distractor Present') - end - hold on; - scatter(x,y,30,dist_colors(dd,:),'filled','MarkerFaceAlpha',.2) - scatter(mean(x),mean(y),30,'k','filled') - hold on; - plot([3 15], [0 0],'--','linewidth',1,'color',[.1 .1 .1]) - clear tmpy - clear thisidx - ylim([-6 6]) - xlim([3 15]) - xticks([3:1:15]) - yticks([-6:1:6]) - xticklabels([3:15]) - yticklabels([-6:6]) - axis equal - end -end - -set(gcf,'Renderer','painters') -match_ylim(get(gcf,'Children')) -% copy'ed into AI, scaled by 300% +% +% dist_colors = [0.7100 0.2128 0.4772; 0 0 1;]; % 1= RED = no distractor; 2 =blue = DISTRACTOR +% +% params_of_interest = {'f_sacc'}; +% param_str = {'f sacc'}; +% +% figure; +% to_plot = {'f_sacc'}; % what fields do we want to plot? +% dist_bins = [1 2]; %1 = no dist, 2 = dist +% +% +% for pp = 1:length(to_plot) +% +% for dd =1:length(dist_bins) +% +% if dist_bins(dd) == 1 +% thisidx = all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; +% x = all_data.s_all.(to_plot{pp})(thisidx,1); +% y = all_data.s_all.(to_plot{pp})(thisidx,2); +% y_save = nanmean(y); +% +% elseif dist_bins(dd) == 2 +% +% thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; +% x = all_data.s_all.(to_plot{pp})(thisidx,1); +% y = all_data.s_all.(to_plot{pp})(thisidx,2); +% y_save = nanmean(y); +% +% end +% +% if dd ==1 +% subplot(1,2,1) +% title('Distractor Absent') +% elseif dd==2 +% subplot(1,2,2) +% title('Distractor Present') +% end +% hold on; +% scatter(x,y,30,dist_colors(dd,:),'filled','MarkerFaceAlpha',.2) +% scatter(mean(x),mean(y),30,'k','filled') +% hold on; +% plot([3 15], [0 0],'--','linewidth',1,'color',[.1 .1 .1]) +% clear tmpy +% clear thisidx +% ylim([-6 6]) +% xlim([3 15]) +% xticks([3:1:15]) +% yticks([-6:1:6]) +% xticklabels([3:15]) +% yticklabels([-6:6]) +% axis equal +% end +% end +% +% set(gcf,'Renderer','painters') +% match_ylim(get(gcf,'Children')) +% % copy'ed into AI, scaled by 300% %% no dist, near, far % directly compare error for no distractor, near distractor % trials (subplot for each param); averaged over radial/tang... @@ -515,6 +545,70 @@ ylim([0 1.5]) end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); +%% new avg sd in polar angle,deg, all bins + +% directly compare avg sd for no distractor, near distractor +% trials, final sacc only ; averaged over radial/tang... + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1; 0 0 1;]; %red, blue +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + % thise(ii,:) = mean(mean(all_err{ii}(:,pp,:,:),3),1); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_errpol{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + else + thise([ii:5],:)= squeeze(mean(all_errpol{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + end + set(gca,'XTick',2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, \circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + [p, h]= ttest(thise(1,:)',thise(2,:)') + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + +ylim([0 1.5]) + set(gcf,'position',[ 549 724 499 571]) match_ylim(get(gcf,'Children')); %% REPORTED STATS ONLY - PRECISION, Distractor Absent, Abs(Bin) Distractor Present (4-level RM ANOVA) @@ -802,7 +896,7 @@ subplot(1,length(params_of_interest),pp); hold on; % nbins x nsubj - thism_near = squeeze(all_mu{2}(:,pp,2,:))'; %this is the only condition that is information for this analysis. + thism_near = squeeze(all_errpol{2}(:,pp,2,:))'; %this is the only condition that is information for this analysis. plot(1,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); plot(1,mean(thism_near,2),'o','MarkerSize',20,'Color',cond_colors(2,:),'MarkerFaceColor',cond_colors(2,:)); hold on; diff --git a/spDist_plotEyeData_Figure1_additional_analyses.m b/spDist_plotEyeData_Figure1_additional_analyses.m new file mode 100644 index 0000000..d25198e --- /dev/null +++ b/spDist_plotEyeData_Figure1_additional_analyses.m @@ -0,0 +1,830 @@ +% spDist_plotEyeData_Figure1_additional_analyses.m +% in the actual task, cyan = distractor, magenta = no distractor +% dependencies: misc_util, RMAOV1 + +root = spDist_loadRoot; + +%load raw subject data + + +subj = {'AY','CC','EK','KD','MR','SF','XL'}; + +sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed + +WHICH_EXCL = [13 20 21 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. +if ismember(WHICH_EXCL,13) + which_excl_str ={'broken fix'}; +elseif ismember(WHICH_EXCL,[13 20]) + which_excl_str ={'broken fix','no sacc'}; +elseif ismember(WHICH_EXCL, [13 20 21]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short'}; +elseif ismember(WHICH_EXCL, [13 20 22]) + which_excl_str ={'broken fix','no sacc','i sacc err too lg'}; +elseif ismember(WHICH_EXCL, [13 20 21 22]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short','i sacc err too lg'}; +else + error('which exclusion criteria have you chosen?') +end + +% first-digit: +% - 1 - trial-level exclusion (bad drift correction [11], calibration [12], or delay- +% fixation break [13] +% - 2 - primary saccade exclusion (no primary sacc [20]; too small/short [21] bi, large error [22]ei) + +%21 bad initial saccade (duration/amplitude outside range) +% 22 iniital saccade error + + +% concatenate ALL subject data +all_subj = nan(1000*length(subj),1); + +all_data = []; + +startidx = 1; + +for ss = 1:length(subj) + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + + this_data.s_all = this_scored.ii_sess; + this_data.sess_all = sessidx; + + this_subj = ss; + + all_data = cat_struct(all_data,this_data); + all_subj(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = this_subj; + + startidx = startidx+size(this_scored.ii_sess.trialinfo,1); + + clear this_subj this_data; + end +end + + +all_subj = all_subj(1:(startidx-1)); +all_data.subj_all = all_subj; + +% determine which trials to include + +all_data.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data.s_all.excl_trial, 'UniformOutput',false)); + + +%% organize data +distractor_bins = unique(all_data.s_all.trialinfo(all_data.s_all.trialinfo(:,1)~=1,6)); +distractor_spacing = 360/length(distractor_bins); + +%initialize storage cells +all_err = cell(3,1); +all_mu = cell(3,1); +all_rt = cell(3,1); + + +params_of_interest = {'f_sacc'}; + +% first, error for no-distractor trials +tmp_err = nan(1,length(params_of_interest),2,length(subj)); % condition x param x dimen of param (2) x subj +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(1,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(1,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + end +end + +all_err{1} = tmp_err; % 1st cell of all err and all mu = no distractor +all_mu{1} = tmp_mu; %note: the first index of all_ is NO DIST +all_mupol{1} = tmp_mupol; +all_errpol{1} = tmp_errpol; + +clear tmp_err tmp_mu tmp_errpol tmp_mupol; + +tmp_err = nan(1,length(params_of_interest),2,length(subj)); +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_cw = nan(1,length(params_of_interest),2,length(subj)); +tmp_ccw = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + + for bb =1 %placeholder, keep dimens same size as when we collect others + + for pp = 1:length(params_of_interest) + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0 & all_data.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins, into tmpd ONLY + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; %now, collect all jitters. + + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); % use idx with all zero bin from flipped data + + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd thisidx orig_y orig_y_flip + end + end +end + +all_err{2} = tmp_err; +all_mu{2} = tmp_mu; +all_mupol{2} = tmp_mupol; +all_errpol{2} = tmp_errpol; + +clear tmp_err tmp_mu tmp_mupol tmp_errpol; + +%put other bins in +flip_bins = [1 2 3]; +tmp_err = nan(length(flip_bins),length(params_of_interest),2,length(subj)); +tmp_mu = nan(length(flip_bins),length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + for bb = 1:length(flip_bins) + for pp = 1:length(params_of_interest) + + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==(flip_bins(bb)*-1); + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % the y flip is inserted for CW bins. + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)==flip_bins(bb) | all_data.s_all.trialinfo(:,6)==flip_bins(bb)*-1); + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); + + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later (x,y) indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd tmpd thisidx orig_y orig_y_flip + + end + end +end + +all_err{3} = tmp_err; +all_mu{3} = tmp_mu; +all_mupol{3} = tmp_mupol; +all_errpol{3} = tmp_errpol; +clear tmp_err tmp_mu tmp_errpol tmpmupol; + +% create a new container for _alldist - for precision only +tmp_err = nan(1,length(params_of_interest),2,length(subj)); +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); + +for pp = 1:length(params_of_interest) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + + clear dtheta_err drad_err + end +end + +all_err_alldist{1} = tmp_err; +all_errpol_alldist{1} = tmp_errpol; +clear tmp_err tmp_errpol + +% first, RT for no-distractor trials + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +params_of_interest = {'i_sacc_rt'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{1} = tmp_rt; +clear tmp_rt + +% RT for near dist +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{2} = tmp_rt; +bins = [1 2 3]; +tmp_rt = nan(length(bins),length(params_of_interest),1,length(subj)); % # conditions x # params x dimen of param x subj + +for ss = 1:length(subj) + for bb = 1:length(bins) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)== bins(bb) | all_data.s_all.trialinfo(:,6)== bins(bb)*-1); + + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_rt(bb,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + + end + end +end + +all_rt{3} = tmp_rt; + +% RT for _alldist + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); +params_of_interest = {'i_sacc_rt'}; +param_str = {'RT'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % all distractor x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt_alldist{1} =tmp_rt; + + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%% the following are analyses for additional stats reporting and %% +%%%%%%%%%% /or error /bias reported int DVA, not polar deg %%%%%%%%%%%%%%%% +%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Figure 1C : Aligned Saccadic Endpoints no dist, near, far +% +dist_colors = [ 0.7100 0.2128 0.4772; 0 0 1; 0 0 1; 0 0 1; 0 0 1]; + +params_of_interest = {'f_sacc'}; +param_str = {'f saccade'}; + +figure; +to_plot = {'f_sacc'}; % what fields do we want to plot? +dist_bins = [-1 0 1 2 3]; %why is this like this? -1 means NO DISTRACTOR + +alph = [.4 .4 .4 .4 .4]; %translucence + +for pp = 1:length(to_plot) + + for dd =1:length(dist_bins) + + if dist_bins(dd) == -1 + thisidx = all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + x = all_data.s_all.(to_plot{pp})(thisidx,1); + y = all_data.s_all.(to_plot{pp})(thisidx,2); + y_save = nanmean(y); + + elseif dist_bins(dd) == 0 + + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0 & all_data.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; + + thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + %tmpd = all_data.s_all.(to_plot{pp}); + + x = tmpd(thisidx,1); + y = tmpd(thisidx,2); + y_save = nanmean(y); + + clear tmpd orig_y orig_y_flip tmpidx + else + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)~=0; + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % the y flip is inserted for CW bins. + + thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)~=0; + + % distractor bin x param x [radial; tangential] x subj + % tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + %tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); + + x = tmpd(thisidx,1); + y = tmpd(thisidx,2); + y_save = nanmean(y); + + clear tmpd orig_y orig_y_flip tmpidx + end + + if dd ==1 + subplot(1,2,1) + title('No Distractor') + else + subplot(1,2,2) + title('Distractor') + end + hold on; + scatter(x,y,30,dist_colors(dd,:),'filled','MarkerFaceAlpha',.2) + scatter(mean(x),mean(y),30,'k','filled') + hold on; + plot([3 15], [0 0],'--','linewidth',1,'color',[.1 .1 .1]) + clear tmpy + clear thisidx + ylim([-6 6]) + xlim([3 15]) + xticks([3:1:15]) + yticks([-6:1:6]) + xticklabels([3:15]) + yticklabels([-6:6]) + axis equal + end +end + +set(gcf,'Renderer','painters') +match_ylim(get(gcf,'Children')) +% copy'ed into AI, scaled by 300% + + % alternative Figure 1D: No Distractor, Near distractor, Far distractor, polar degrees + +% directly compare avg sd,pol for no distractor, near distractor +% trials, final sacc only ; averaged over radial/tang... + + params_of_interest = {'f_sacc'}; + +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;.3 .6 .1]; %red, blue +cond_str = {'No distractor','Near dist','Far dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(3,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_errpol{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + else + thise(ii,:)= mean(squeeze(mean(all_errpol{ii}(:,pp,:,:),3))); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + %all dist trials are lumped into a single index, then averaged + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:3 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + + clear tmpe + end + + xlim([0 4]); +end + + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, polar \circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:3,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';thise(3,:)']; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);3*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')) +%% Precision: no dist, all distr bins separately : DVA +% +% %directly compare avg sd for no distractor, near distractor +% %trials, final sacc only ; averaged over radial/tang... +% +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1; 0 0 1;]; %red, blue +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_err) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_err{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + else + thise([ii:5],:)= squeeze(mean(all_err{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); +end + + + + set(gca,'XTick',2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd,\circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + + +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + +%% alt Figure 1D: Precision: distractor absent, near distractor, far distractor : DVA +% directly compare error for no distractor, near distractor +% trials (subplot for each param); averaged over radial/tang... + +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;]; % 1 = red, no dist; 2 = blue, dist +cond_str = {'Distractor Absent','Near Dist','Far Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(length(all_err),length(subj)); %collect this error + for ii = 1:length(all_err) + + thise(ii,:) = mean(mean(all_err{ii}(:,pp,:,:),3),1); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:length(all_err) + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + clear tmpe + end + + xlim([0 length(all_err)+1]); + + set(gca,'XTick',1:length(all_err),'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, \circ)'); + end + title(param_str{pp}); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end +clear tmpe +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) +%% alt Figure 1D : Precision, Distractor Absent vs. Distractor Present (all distractor bins collapsed) : DVA + +% directly compare avg sd for no distractor, near distractor +% trials, final sacc only ; averaged over radial/tang... + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;]; %red, blue +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thise(ii,:) = squeeze(mean(all_err{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + elseif ii ==2 + thise(ii,:) = squeeze(mean(all_err_alldist{1}(:,pp,:,:),3)); % this "all_err_alldist" container is used bc all_err separates near vs. far dists. Simplified w this {} where all dist trials are within a single cell + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:2 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 3]); + + set(gca,'XTick',2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, \circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + [p, h]= ttest(thise(1,:)',thise(2,:)') + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + +%ylim([0 1.5]) +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + +%% REPORTED STATS PRECISION, Distractor Absent, Abs(Bin) +% Distractor Present (4-level RM ANOVA) : polar deg +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +%(F(2,4) = 2.081, p = 0.1148 +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + % thise(ii,:) = mean(mean(all_err{ii}(:,pp,:,:),3),1); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_errpol{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + else + thise([ii:5],:)= squeeze(mean(all_errpol{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error (Avg SD, Polar Angle \circ)'); + end + title(param_str{pp}); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + RMAOV1(x,0.05) %one-way RM ANOVA + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%% alt Figure 1F : Bias in DVA +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thism_near = squeeze(all_mu{2}(:,pp,2,:))'; %this is the only condition that is information for this analysis. + plot(1,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); + plot(1,mean(thism_near,2),'o','MarkerSize',15,'Color',cond_colors(2,:),'MarkerFaceColor',cond_colors(2,:)); + hold on; + + tmpe = std(thism_near)/sqrt(length(subj)); + plot([1 1], mean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(2,:)); + + %errorbar(1, mean(thism_near), [std(thism_near)/sqrt(length(subj))],'linewidth',2,'Color',cond_colors(2,:)) + title(param_str{pp}); + + + ylabel('Memory Bias, toward distractor, DVA '); +end +xlabel('Near Distractor'); + +[h_bias_near p_bias_near,CI,STATS] = ttest(thism_near(1,:)') %t-test to determine if bias is different than zero +text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',p_bias_near),'color','k','fontsize',15) %filled + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%% REPORTED STATS %% RT : No distractor, Distractor bins separately + +params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +param_str = {'RT'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + for ii = 1:length(all_rt) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_rt{ii}(:,pp,:,:))'; + + else + thise([ii:5],:)= squeeze(all_rt{ii}(:,pp,:,:)); + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('RT'); + end + title(param_str{pp}); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + set(gcf,'position',[549 724 499 571]) + +end + +%c/p to illustrator, scale by %60 +%% alt Figure 1E : RT : No distractor, Near Distractor, Far Distractor + cond_colors = [0.7100 0.2128 0.4772;0 0 1;.3 .6 .1]; %colors for illustrator + +params_of_interest = {'i_sacc_rt'}; + +param_str = {'RT'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thisnod_rt = squeeze(all_rt{1}(1,pp,1,:))'; + thisnear_dist = squeeze(all_rt{2}(:,pp,1,:))'; + thisfar_dist = mean(squeeze(all_rt{3}(:,pp,1,:))); + thisrt= [thisnod_rt; thisnear_dist; thisfar_dist]; + plot(1:length(flip_bins),thisrt,'-','color',[.2 .2 .2]); + + for ii = 1:size(thisrt,1) + tmpe = std(thisrt(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thisrt(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thisrt(ii,:)),'o','LineWidth',1.5,'color',cond_colors(ii,:),'markerfacecolor',cond_colors(ii,:),'MarkerSize',10); + end + title(param_str{pp}); + xlabel('Distractor Condition'); + + if pp == 1 + ylabel('RT'); + + end + set(gca,'XTick',[1 2 3],'Xticklabels',({'No Distractor', 'Near Distractor','Far Distractor'}), 'TickDir','out','XTickLabelRotation',45) + the_RT = [thisrt(1,:)'; thisrt(2,:)'; thisrt(3,:)']; %use for just dist + the_ivRT =[ones(length(thisrt(1,:)'),1); 2*ones(length(thisrt(2,:)'),1); 3*ones(length(thisrt(3,:)'),1);]; %use for just dist + the_subj =[subj;subj;subj;]; + x = [the_RT the_ivRT the_subj]; + RMAOV1(x,0.05) + [fval, pval] = RMAOV1_gh(x,0.05); + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) +end +xlim([0 size(thisrt,1)+1]); +set(gcf,'position',[ 549 724 499 571]) + +match_ylim(get(gcf,'Children')); \ No newline at end of file diff --git a/spDist_plotEyeData_suppFigure1.m b/spDist_plotEyeData_suppFigure1.m new file mode 100644 index 0000000..2ef69b1 --- /dev/null +++ b/spDist_plotEyeData_suppFigure1.m @@ -0,0 +1,830 @@ +% spDist_plotEyeData_suppFigure1.m +% in the actual task, cyan = distractor, magenta = no distractor +% dependencies: misc_util, RMAOV1 + +root = spDist_loadRoot; + +%load raw subject data + + +subj = {'AY','CC','EK','KD','MR','SF','XL'}; + +sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed + +WHICH_EXCL = [13 20 21 22]; % see geh spDist_eyeDataNotes.txt on how/why these exclu criteria were chosen. +if ismember(WHICH_EXCL,13) + which_excl_str ={'broken fix'}; +elseif ismember(WHICH_EXCL,[13 20]) + which_excl_str ={'broken fix','no sacc'}; +elseif ismember(WHICH_EXCL, [13 20 21]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short'}; +elseif ismember(WHICH_EXCL, [13 20 22]) + which_excl_str ={'broken fix','no sacc','i sacc err too lg'}; +elseif ismember(WHICH_EXCL, [13 20 21 22]) + which_excl_str ={'broken fix','no sacc','i sacc too small/short','i sacc err too lg'}; +else + error('which exclusion criteria have you chosen?') +end + +% first-digit: +% - 1 - trial-level exclusion (bad drift correction [11], calibration [12], or delay- +% fixation break [13] +% - 2 - primary saccade exclusion (no primary sacc [20]; too small/short [21] bi, large error [22]ei) + +%21 bad initial saccade (duration/amplitude outside range) +% 22 iniital saccade error + + +% concatenate ALL subject data +all_subj = nan(1000*length(subj),1); + +all_data = []; + +startidx = 1; + +for ss = 1:length(subj) + for sessidx = 1:length(sess{ss}) + + fn = sprintf('%s/spDist_behav_92220/%s_%s_scored.mat',root,subj{ss},sess{ss}{sessidx}); + fprintf('Loading scored eye data from %s\n',fn); + this_scored = load(fn); + + this_data.s_all = this_scored.ii_sess; + this_data.sess_all = sessidx; + + this_subj = ss; + + all_data = cat_struct(all_data,this_data); + all_subj(startidx:(startidx-1+size(this_scored.ii_sess.trialinfo,1))) = this_subj; + + startidx = startidx+size(this_scored.ii_sess.trialinfo,1); + + clear this_subj this_data; + end +end + + +all_subj = all_subj(1:(startidx-1)); +all_data.subj_all = all_subj; + +% determine which trials to include + +all_data.use_trial = ~cellfun( @any, cellfun( @(a) ismember(a, WHICH_EXCL), all_data.s_all.excl_trial, 'UniformOutput',false)); + + +%% organize data +distractor_bins = unique(all_data.s_all.trialinfo(all_data.s_all.trialinfo(:,1)~=1,6)); +distractor_spacing = 360/length(distractor_bins); + +%initialize storage cells +all_err = cell(3,1); +all_mu = cell(3,1); +all_rt = cell(3,1); + + +params_of_interest = {'f_sacc'}; + +% first, error for no-distractor trials +tmp_err = nan(1,length(params_of_interest),2,length(subj)); % condition x param x dimen of param (2) x subj +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(1,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_mupol(1,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + end +end + +all_err{1} = tmp_err; % 1st cell of all err and all mu = no distractor +all_mu{1} = tmp_mu; %note: the first index of all_ is NO DIST +all_mupol{1} = tmp_mupol; +all_errpol{1} = tmp_errpol; + +clear tmp_err tmp_mu tmp_errpol tmp_mupol; + +tmp_err = nan(1,length(params_of_interest),2,length(subj)); +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_cw = nan(1,length(params_of_interest),2,length(subj)); +tmp_ccw = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + + for bb =1 %placeholder, keep dimens same size as when we collect others + + for pp = 1:length(params_of_interest) + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0 & all_data.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % here is where the actual y flip is inserted for CW bins, into tmpd ONLY + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; %now, collect all jitters. + + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); % use idx with all zero bin from flipped data + + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd thisidx orig_y orig_y_flip + end + end +end + +all_err{2} = tmp_err; +all_mu{2} = tmp_mu; +all_mupol{2} = tmp_mupol; +all_errpol{2} = tmp_errpol; + +clear tmp_err tmp_mu tmp_mupol tmp_errpol; + +%put other bins in +flip_bins = [1 2 3]; +tmp_err = nan(length(flip_bins),length(params_of_interest),2,length(subj)); +tmp_mu = nan(length(flip_bins),length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); +tmp_mupol = nan(1,length(params_of_interest),2,length(subj)); + +for ss = 1:length(subj) + for bb = 1:length(flip_bins) + for pp = 1:length(params_of_interest) + + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==(flip_bins(bb)*-1); + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % the y flip is inserted for CW bins. + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)==flip_bins(bb) | all_data.s_all.trialinfo(:,6)==flip_bins(bb)*-1); + % distractor bin x param x [radial; tangential] x subj + tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); + + % new + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(bb,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + [dtheta_mu, drad_mu] = cart2pol(tmpd(thisidx,1), tmpd(thisidx,2)); + tmp_mupol(bb,pp,:,ss) = mean([drad_mu rad2deg(dtheta_mu)]); %put rad as x FIRST, theta as Y second, in keeping with later (x,y) indexing + + clear dtheta_err drad_err drad_mu dtheta_mu tmpd tmpd thisidx orig_y orig_y_flip + + end + end +end + +all_err{3} = tmp_err; +all_mu{3} = tmp_mu; +all_mupol{3} = tmp_mupol; +all_errpol{3} = tmp_errpol; +clear tmp_err tmp_mu tmp_errpol tmpmupol; + +% create a new container for _alldist - for precision only +tmp_err = nan(1,length(params_of_interest),2,length(subj)); +tmp_mu = nan(1,length(params_of_interest),2,length(subj)); +tmp_errpol = nan(1,length(params_of_interest),2,length(subj)); + +for pp = 1:length(params_of_interest) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + % distractor bin x param x [radial; tangential] x subj + tmp_err(1,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + [dtheta_err, drad_err]= cart2pol(all_data.s_all.(params_of_interest{pp})(thisidx,1), all_data.s_all.(params_of_interest{pp})(thisidx,2)); + tmp_errpol(1,pp,:,ss) = std([drad_err rad2deg(dtheta_err)]); + + clear dtheta_err drad_err + end +end + +all_err_alldist{1} = tmp_err; +all_errpol_alldist{1} = tmp_errpol; +clear tmp_err tmp_errpol + +% first, RT for no-distractor trials + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +params_of_interest = {'i_sacc_rt'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{1} = tmp_rt; +clear tmp_rt + +% RT for near dist +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + + for pp = 1:length(params_of_interest) + % distractor bin x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt{2} = tmp_rt; +bins = [1 2 3]; +tmp_rt = nan(length(bins),length(params_of_interest),1,length(subj)); % # conditions x # params x dimen of param x subj + +for ss = 1:length(subj) + for bb = 1:length(bins) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & (all_data.s_all.trialinfo(:,6)== bins(bb) | all_data.s_all.trialinfo(:,6)== bins(bb)*-1); + + for pp = 1:length(params_of_interest) + % distractor bin x param x [radial; tangential] x subj + tmp_rt(bb,pp,:,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx,:), 1 ); + + end + end +end + +all_rt{3} = tmp_rt; + +% RT for _alldist + +tmp_rt = nan(1,length(params_of_interest),1,length(subj)); +params_of_interest = {'i_sacc_rt'}; +param_str = {'RT'}; + +for ss = 1:length(subj) + + thisidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1; + + for pp = 1:length(params_of_interest) + % all distractor x param x rt x subj + tmp_rt(1,pp,1,ss) = mean( all_data.s_all.(params_of_interest{pp})(thisidx),1); + + end + +end + +all_rt_alldist{1} =tmp_rt; + + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%% the following are analyses for additional stats reporting and %% +%%%%%%%%%% /or error /bias reported int DVA, not polar deg %%%%%%%%%%%%%%%% +%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Figure 1C : Aligned Saccadic Endpoints no dist, near, far +% +dist_colors = [ 0.7100 0.2128 0.4772; 0 0 1; 0 0 1; 0 0 1; 0 0 1]; + +params_of_interest = {'f_sacc'}; +param_str = {'f saccade'}; + +figure; +to_plot = {'f_sacc'}; % what fields do we want to plot? +dist_bins = [-1 0 1 2 3]; %why is this like this? -1 means NO DISTRACTOR + +alph = [.4 .4 .4 .4 .4]; %translucence + +for pp = 1:length(to_plot) + + for dd =1:length(dist_bins) + + if dist_bins(dd) == -1 + thisidx = all_data.s_all.trialinfo(:,1)==1 & all_data.use_trial==1; + x = all_data.s_all.(to_plot{pp})(thisidx,1); + y = all_data.s_all.(to_plot{pp})(thisidx,2); + y_save = nanmean(y); + + elseif dist_bins(dd) == 0 + + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0 & all_data.s_all.trialinfo(:,10) < 0; %negative CW jitter + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; + + thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)==0; + %tmpd = all_data.s_all.(to_plot{pp}); + + x = tmpd(thisidx,1); + y = tmpd(thisidx,2); + y_save = nanmean(y); + + clear tmpd orig_y orig_y_flip tmpidx + else + tmpd = all_data.s_all.(params_of_interest{pp}); + tmpidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)~=0; + orig_y = tmpd(tmpidx,2); + orig_y_flip = orig_y*-1; + tmpd(tmpidx,2) = orig_y_flip; % the y flip is inserted for CW bins. + + thisidx = all_data.s_all.trialinfo(:,1)==2 & all_data.use_trial==1 & all_data.s_all.trialinfo(:,6)~=0; + + % distractor bin x param x [radial; tangential] x subj + % tmp_err(bb,pp,:,ss) = std( all_data.s_all.(params_of_interest{pp})(thisidx,:), [], 1 ); + %tmp_mu(bb,pp,:,ss) = mean( tmpd(thisidx,:), 1 ); + + x = tmpd(thisidx,1); + y = tmpd(thisidx,2); + y_save = nanmean(y); + + clear tmpd orig_y orig_y_flip tmpidx + end + + if dd ==1 + subplot(1,2,1) + title('No Distractor') + else + subplot(1,2,2) + title('Distractor') + end + hold on; + scatter(x,y,30,dist_colors(dd,:),'filled','MarkerFaceAlpha',.2) + scatter(mean(x),mean(y),30,'k','filled') + hold on; + plot([3 15], [0 0],'--','linewidth',1,'color',[.1 .1 .1]) + clear tmpy + clear thisidx + ylim([-6 6]) + xlim([3 15]) + xticks([3:1:15]) + yticks([-6:1:6]) + xticklabels([3:15]) + yticklabels([-6:6]) + axis equal + end +end + +set(gcf,'Renderer','painters') +match_ylim(get(gcf,'Children')) +% copy'ed into AI, scaled by 300% + + % alternative Figure 1D: No Distractor, Near distractor, Far distractor, polar degrees + +% directly compare avg sd,pol for no distractor, near distractor +% trials, final sacc only ; averaged over radial/tang... + + params_of_interest = {'f_sacc'}; + +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;.3 .6 .1]; %red, blue +cond_str = {'No distractor','Near dist','Far dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(3,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_errpol{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + else + thise(ii,:)= mean(squeeze(mean(all_errpol{ii}(:,pp,:,:),3))); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + %all dist trials are lumped into a single index, then averaged + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:3 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + + clear tmpe + end + + xlim([0 4]); +end + + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, polar \circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:3,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';thise(3,:)']; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);3*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')) +%% Precision: no dist, all distr bins separately : DVA +% +% %directly compare avg sd for no distractor, near distractor +% %trials, final sacc only ; averaged over radial/tang... +% +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1; 0 0 1;]; %red, blue +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_err) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_err{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + else + thise([ii:5],:)= squeeze(mean(all_err{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); +end + + + + set(gca,'XTick',2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd,\circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + + +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + +%% alt Figure 1D: Precision: distractor absent, near distractor, far distractor : DVA +% directly compare error for no distractor, near distractor +% trials (subplot for each param); averaged over radial/tang... + +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;]; % 1 = red, no dist; 2 = blue, dist +cond_str = {'Distractor Absent','Near Dist','Far Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(length(all_err),length(subj)); %collect this error + for ii = 1:length(all_err) + + thise(ii,:) = mean(mean(all_err{ii}(:,pp,:,:),3),1); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:length(all_err) + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + clear tmpe + end + + xlim([0 length(all_err)+1]); + + set(gca,'XTick',1:length(all_err),'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, \circ)'); + end + title(param_str{pp}); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end +clear tmpe +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) +%% alt Figure 1D : Precision, Distractor Absent vs. Distractor Present (all distractor bins collapsed) : DVA + +% directly compare avg sd for no distractor, near distractor +% trials, final sacc only ; averaged over radial/tang... + +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;]; %red, blue +cond_str = {'Distractor Absent','Distractor Present'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(2,length(subj)); %collect this error + for ii = 1:2 + if ii ==1 + thise(ii,:) = squeeze(mean(all_err{1}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bin + elseif ii ==2 + thise(ii,:) = squeeze(mean(all_err_alldist{1}(:,pp,:,:),3)); % this "all_err_alldist" container is used bc all_err separates near vs. far dists. Simplified w this {} where all dist trials are within a single cell + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:2 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 3]); + + set(gca,'XTick',2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Precision (avg sd, \circ)'); + end + title(param_str{pp}); + set(gca,'XTick',1:2,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + + the_y = [thise(1,:)';thise(2,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1);]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05); %one-way RM ANOVA + RMAOV1(x,0.05) + + [p, h]= ttest(thise(1,:)',thise(2,:)') + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + +%ylim([0 1.5]) +end +set(gcf,'position',[ 549 724 499 571]) +match_ylim(get(gcf,'Children')); + +%% REPORTED STATS PRECISION, Distractor Absent, Abs(Bin) +% Distractor Present (4-level RM ANOVA) : polar deg +params_of_interest = {'f_sacc'}; %we're using the final saccade +param_str = {'final sacc'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +%(F(2,4) = 2.081, p = 0.1148 +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + + for ii = 1:length(all_errpol) + % thise(ii,:) = mean(mean(all_err{ii}(:,pp,:,:),3),1); % mean over radial/tangential; distractor bin; for n_bins, then mean over these bins + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(mean(all_errpol{ii}(:,pp,:,:),3))'; % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + else + thise([ii:5],:)= squeeze(mean(all_errpol{ii}(:,pp,:,:),3)); % mean over radial/tangential; distractor bin; for n_bins, then squeeze over these bins to make 1x n_subj vect + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('Error (Avg SD, Polar Angle \circ)'); + end + title(param_str{pp}); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + RMAOV1(x,0.05) %one-way RM ANOVA + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + + +end + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%% alt Figure 1F : Bias in DVA +params_of_interest = {'f_sacc'}; +param_str = {'final sacc'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thism_near = squeeze(all_mu{2}(:,pp,2,:))'; %this is the only condition that is information for this analysis. + plot(1,thism_near,'o','MarkerSize',5,'Markerfacecolor',[0.3 0.3 0.3], 'Color',[0.3 0.3 0.3]); + plot(1,mean(thism_near,2),'o','MarkerSize',15,'Color',cond_colors(2,:),'MarkerFaceColor',cond_colors(2,:)); + hold on; + + tmpe = std(thism_near)/sqrt(length(subj)); + plot([1 1], mean(thism_near)+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(2,:)); + + %errorbar(1, mean(thism_near), [std(thism_near)/sqrt(length(subj))],'linewidth',2,'Color',cond_colors(2,:)) + title(param_str{pp}); + + + ylabel('Memory Bias, toward distractor, DVA '); +end +xlabel('Near Distractor'); + +[h_bias_near p_bias_near,CI,STATS] = ttest(thism_near(1,:)') %t-test to determine if bias is different than zero +text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',p_bias_near),'color','k','fontsize',15) %filled + +match_ylim(get(gcf,'Children')); +set(gcf,'position',[ 549 724 499 571]) + + +%% REPORTED STATS %% RT : No distractor, Distractor bins separately + +params_of_interest = {'i_sacc_rt'}; %we're using the final saccade +param_str = {'RT'}; +cond_colors = [0.7100 0.2128 0.4772;0 0 1;0 0 1;0 0 1;0 0 1;]; +cond_str = {'No distractor','Bin 0 Dist','Bin 1 Dist','Bin 2 Dist','Bin 3 Dist'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % distractor cond x subj + thise = nan(5,length(subj)); %collect this error + for ii = 1:length(all_rt) + if ii == 1 || ii ==2 + thise(ii,:) = squeeze(all_rt{ii}(:,pp,:,:))'; + + else + thise([ii:5],:)= squeeze(all_rt{ii}(:,pp,:,:)); + + end + end + + plot(1:size(thise,1),thise,'-','Color',[0.3 0.3 0.3],'LineWidth',.5); + plot(1:size(thise,1),thise,'-','Color',[0.5 0.5 0.5],'MarkerFaceColor','w','MarkerSize',5,'LineWidth',1); + for ii = 1:5 + hold on; + tmpe = std(thise(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thise(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thise(ii,:)),'o','LineWidth',1.5,'Color',cond_colors(ii,:),'MarkerSize',10,'MarkerFaceColor',cond_colors(ii,:)); + end + + xlim([0 6]); + + set(gca,'XTick',1:5,'XTickLabel',cond_str','XTickLabelRotation',45,'TickDir','out'); + xlabel('Condition'); + if pp == 1 + ylabel('RT'); + end + title(param_str{pp}); + + the_y = [thise(1,:)';thise(2,:)'; thise(3,:)'; thise(4,:)'; thise(5,:)';]; + the_iv =[ones(length(thise(1,:)'),1); 2*ones(length(thise(1,:)'),1); 3*ones(length(thise(1,:)'),1); 4*ones(length(thise(1,:)'),1); 5*ones(length(thise(1,:)'),1)]; + subj = [1 2 3 4 5 6 7]'; + the_subj =[subj;subj;subj;subj;subj]; + x = [the_y the_iv the_subj]; + [fval,pval] = RMAOV1_gh(x,0.05) %one-way RM ANOVA + RMAOV1(x,0.05) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) %filled + set(gcf,'position',[549 724 499 571]) + +end + +%c/p to illustrator, scale by %60 +%% alt Figure 1E : RT : No distractor, Near Distractor, Far Distractor + cond_colors = [0.7100 0.2128 0.4772;0 0 1;.3 .6 .1]; %colors for illustrator + +params_of_interest = {'i_sacc_rt'}; + +param_str = {'RT'}; + +figure; + +for pp = 1:length(params_of_interest) + + subplot(1,length(params_of_interest),pp); hold on; + + % nbins x nsubj + thisnod_rt = squeeze(all_rt{1}(1,pp,1,:))'; + thisnear_dist = squeeze(all_rt{2}(:,pp,1,:))'; + thisfar_dist = mean(squeeze(all_rt{3}(:,pp,1,:))); + thisrt= [thisnod_rt; thisnear_dist; thisfar_dist]; + plot(1:length(flip_bins),thisrt,'-','color',[.2 .2 .2]); + + for ii = 1:size(thisrt,1) + tmpe = std(thisrt(ii,:))/sqrt(length(subj)); + plot(ii*[1 1],mean(thisrt(ii,:))+tmpe*[-1 1],'-','LineWidth',1.5,'Color',cond_colors(ii,:)); + plot(ii,mean(thisrt(ii,:)),'o','LineWidth',1.5,'color',cond_colors(ii,:),'markerfacecolor',cond_colors(ii,:),'MarkerSize',10); + end + title(param_str{pp}); + xlabel('Distractor Condition'); + + if pp == 1 + ylabel('RT'); + + end + set(gca,'XTick',[1 2 3],'Xticklabels',({'No Distractor', 'Near Distractor','Far Distractor'}), 'TickDir','out','XTickLabelRotation',45) + the_RT = [thisrt(1,:)'; thisrt(2,:)'; thisrt(3,:)']; %use for just dist + the_ivRT =[ones(length(thisrt(1,:)'),1); 2*ones(length(thisrt(2,:)'),1); 3*ones(length(thisrt(3,:)'),1);]; %use for just dist + the_subj =[subj;subj;subj;]; + x = [the_RT the_ivRT the_subj]; + RMAOV1(x,0.05) + [fval, pval] = RMAOV1_gh(x,0.05); + + text(max(xlim)-(.2*max(xlim)),max(ylim)-(.1*max(ylim)),sprintf('p = %.3f',pval),'color','k','fontsize',15) +end +xlim([0 size(thisrt,1)+1]); +set(gcf,'position',[ 549 724 499 571]) + +match_ylim(get(gcf,'Children')); \ No newline at end of file diff --git a/spDist_plotGAT1.m b/spDist_plotGAT1.m index 8059b26..1cde87d 100644 --- a/spDist_plotGAT1.m +++ b/spDist_plotGAT1.m @@ -11,8 +11,8 @@ %sess= {{'spDistLong1','spDistLong2'},{'spDistLong1','spDistLong2'},{'spDistLong1','spDistLong2'}}; sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %ROIs = {'V1','V2','V3','V3AB','hV4','VO1','VO2','LO1','LO2','TO1','TO2','IPS0','IPS1','IPS2','IPS3','sPCS','iPCS'}; -ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; - +%ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; +ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; func_suffix = 'surf'; nchan = 8; @@ -38,7 +38,7 @@ % just one file to load - fn = sprintf('%sspDist_reconstructions/%s_%s_%s_%s_%ichan%s_GATdist.mat',root,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str); + fn = sprintf('%sspDist_reconstructions/%s_%s_%s_%s_%ichan%s_GATdist_fig5.mat',root,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str); fprintf('loading %s...\n',fn); data = load(fn); @@ -126,7 +126,7 @@ end imagesc(tpts*myTR,tpts*myTR,mean(thisd,3)); colormap magma - cbh = colorbar('h','location','eastoutside') + title(ROIs{vv}); axis tight square set(gca,'XTick',0:4:24,'YTick',0:4:24,'TickDir','out'); @@ -139,13 +139,13 @@ end end -match_clim(get(gcf,'Children')); -set(cbh,'XTick',[-.2:.1:.3]) -%set(gcf,'Position',[32 778 1910 122]); -set(gcf,'position', [ 23 245 2386 453]) - +%set(gcf,'Position',[32 778 1910 122]); +set(gcf,'position', [ 23 245 2386 453]) +match_clim(get(gcf,'Children')); +cbh = colorbar('h','location','eastoutside') +set(cbh,'XTick',[-.26:.1:.38]) %% plot (individual subj as rows) % NOTE: for now, only matched clim within figure... diff --git a/spDist_plotGATrecon_Figure5_BC.m b/spDist_plotGATrecon_Figure5_BC.m index f4b887d..be5d2fd 100644 --- a/spDist_plotGATrecon_Figure5_BC.m +++ b/spDist_plotGATrecon_Figure5_BC.m @@ -1,5 +1,6 @@ -function spDist_plotGATrecon_fig5c(subj,sess,ROIs) -% GAT data loaded here, _GATdist_fig4TPTS, was created with the script spDist_channelRespAmp_GATdist_gh_082520 +function spDist_plotGATrecon_suppFigure5_BC(subj,sess,ROIs) +% GAT data loaded here, _GATdist_fig4TPTS, was created with the script +% spDist_channelRespAmp_GAT_suppFigure6 % and the tpts delay_tpt_range = [3.75 5.25; 8 9.5; 10.5 12]; root = '/share/data/spDist/'; @@ -19,7 +20,8 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) end if nargin < 3 || isempty(ROIs) - ROIs ={'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; %ORIG + + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; end func_suffix = 'surf'; @@ -53,7 +55,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) vox_str = sprintf('_%ivox',which_vox); end - +rng(spDist_randSeed); n_files= [1 2]; % how many data files do we care about? %% load data @@ -132,7 +134,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) else - fn = sprintf('%sspDist_reconstructions/%s_%s_%s_%s_%ichan%s_GATdist_fig4TPTS.mat',root,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str); + fn = sprintf('%sspDist_reconstructions/%s_%s_%s_%s_%ichan%s_GATdist_fig5TPTS.mat',root,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str); fprintf('loading %s...\n',fn); data = load(fn); @@ -209,135 +211,108 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) end end -%% plot only like trn/tst combindations +%% supp Figure 5 A +%plot only like trn/tst combinations trn_epoch =[1 2 3]; tst_epoch =[1 2 3]; gat_align ={'trn/tst:target/target'}; -%cond_colors =cbrewer('qual','Set1',3); cond_colors = [ 0 0 1; 0 0 1; 0 0 1]; - - for pg=1:length(gat_align) % can be length 1 - target aligned recon or length 2, targ aling and dist align. for now, need only target figure ('Name','trnlines') for vv = 1:length(ROIs) - thisd = nan(length(subj),size(all_recons_gat{1},2)); %recon data h=[]; for aa =1:length(trn_epoch) - %for ee =1:length(tst_epoch) - if aa==1 - ee =1; - elseif aa ==2 - ee =2; - elseif aa ==3 - ee=3; - end - - thisd = nan(length(subj),size(all_recons_gat{1},2)); - for ss = 1:length(subj) - - subplot(size(all_recons_gat,1),length(ROIs),vv+(ee-1)*length(ROIs));hold on; - - thisidx = all_subj_gat==ss & all_ROIs_gat==vv & all_conds_gat(:,1)==2; - thisd(ss,:) = mean(all_recons_gat{aa,ee,pg}(thisidx,:)); %aa = TRN idx, rows; ee = TST idx, col; blue = 1, red =2 , yellow =3 - - end - - my_sem = std(thisd,1)/sqrt((length(subj))); - - h(aa) = plot(linspace(-180,180,90),mean(thisd,1) - min(mean(thisd,1)),'-','LineWidth',1,'color',cond_colors(aa,:))% ,'LineWidth',2,'color',cond_colors(aa,:)) - hold on; - %plot(linspace(-180,180,90),(mean(thisd,1) - min(mean(thisd,1)))+1.*my_sem,'-','LineWidth',.1,'color',cond_colors(aa,:),'HandleVisibility','off') - - %plot(linspace(-180,180,90),(mean(thisd,1) - min(mean(thisd,1)))-1.*my_sem,'-','LineWidth',.1,'color',cond_colors(aa,:),'HandleVisibility','off') + if aa==1 % keeping these as two to avoid future confusion, could use aa in place of ee but would prefer to keep ee + ee =1; + elseif aa ==2 + ee =2; + elseif aa ==3 + ee=3; + end + + thisd = nan(length(subj),size(all_recons_gat{1},2)); + for ss = 1:length(subj) - btwn_fill = [(mean(thisd,1) - min(mean(thisd,1)))+1.*my_sem fliplr((mean(thisd,1) - min(mean(thisd,1)))-1.*my_sem)]; - fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_fill,cond_colors(aa,:),'linestyle','none','facealpha',0.3); - - hold on; - line([min(xlim) max(xlim)], [0 0], 'color',[.2 .2 .2],'linewidth',0.1,'linestyle','-') - ylim([-0.05 1.75]) - if ee== 1 && aa==1 - title(ROIs{vv}); - else - end + subplot(size(all_recons_gat,1),length(ROIs),vv+(ee-1)*length(ROIs));hold on; thisidx = all_subj_gat==ss & all_ROIs_gat==vv & all_conds_gat(:,1)==2; thisd(ss,:) = mean(all_recons_gat{aa,ee,pg}(thisidx,:)); %aa = TRN idx, rows; ee = TST idx, col; blue = 1, red =2 , yellow =3 end - % TCS: added sqrt here - my_sem = std(thisd,1)/sqrt(length(subj)); + my_sem = std(thisd,1)/sqrt((length(subj))); + h(aa) = plot(linspace(-180,180,90),mean(thisd,1),'-','LineWidth',1,'color',cond_colors(aa,:)); - h(aa) = plot(linspace(-180,180,90),mean(thisd,1) - min(mean(thisd,1)),'-','LineWidth',1,'color',cond_colors(aa,:))% ,'LineWidth',2,'color',cond_colors(aa,:)) hold on; - %plot(linspace(-180,180,90),(mean(thisd,1) - min(mean(thisd,1)))+1.*my_sem,'-','LineWidth',.1,'color',cond_colors(aa,:),'HandleVisibility','off') + plot(linspace(-180,180,90),mean(thisd,1)+1.*my_sem,'-','LineWidth',.5,'color',cond_colors(aa,:)) + plot(linspace(-180,180,90),mean(thisd,1)-1.*my_sem,'-','LineWidth',.5,'color',cond_colors(aa,:)) - %plot(linspace(-180,180,90),(mean(thisd,1) - min(mean(thisd,1)))-1.*my_sem,'-','LineWidth',.1,'color',cond_colors(aa,:),'HandleVisibility','off') - % TCS: need to fliplr here too + btwn_fill = [mean(thisd,1)+1.*my_sem fliplr((mean(thisd,1)-1.*my_sem))]; - btwn_fill = [(mean(thisd,1) - min(mean(thisd,1)))+1.*my_sem fliplr((mean(thisd,1) - min(mean(thisd,1)))-1.*my_sem)]; fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_fill,cond_colors(aa,:),'linestyle','none','facealpha',0.3); - hold on; - line([min(xlim) max(xlim)], [0 0], 'color',[.2 .2 .2],'linewidth',0.1,'linestyle','-') - ylim([-0.05 1.75]) + + clear thisidx + clear thisd + + if ee== 1 && aa==1 title(ROIs{vv}); else end if ee==1 && aa==1 && vv ==1 - ylabel('Test Epoch 1') - set(gca,'XTick',-180:90:180,'Xticklabel', {'-180','-90','0','90','180'},'Xticklabelrotation',45,'TickDir','out') - set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'0','0.5','1.0','1.5'},'TickDir','out') + ylabel('Test PRE') + set(gca,'XTick',-180:90:180,'Xticklabel',{'','',''},'TickDir','out'); + set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'','','',''},'TickDir','out') + elseif ee==2 && aa==2 && vv ==1 - ylabel('Test Epoch 2') - set(gca,'XTick',-180:90:180,'Xticklabel',{'-180','-90','0','90','180'},'Xticklabelrotation',45,'TickDir','out') + ylabel('Test DIST') set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'','','',''},'TickDir','out') + set(gca,'XTick',-180:90:180,'Xticklabel',{'','',''},'TickDir','out'); elseif ee==3 && aa==3 && vv ==1 - ylabel('Test Epoch 3') - set(gca,'XTick',-180:180:180,'Xticklabel', {'-180','0','180'},'Xticklabelrotation',45,'TickDir','out') - set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'','','',''},'TickDir','out') + ylabel('Test POST') + set(gca,'XTick',-180:90:180,'Xticklabel',{'-180','-90','0','90','180'},'TickDir','out'); + set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'0','0.5','1.0','1.5'},'TickDir','out') + ylabel('LORO Reconstruction') xlabel('Polar angle (\circ)'); else - set(gca,'XTick',-180:180:180,'Xticklabel',{'','',''},'TickDir','out'); + set(gca,'XTick',-180:90:180,'Xticklabel',{'','',''},'TickDir','out'); + set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'','','',''},'TickDir','out') + end - %end - end end +end + - xlim([-180 180]); - clear thisidx - clear thisd + set(gcf,'Position',[-132 503 2651 495]) match_ylim(get(gcf,'Children')); match_xlim(get(gcf,'Children')); - legend(h, {'Train 1','Train 2','Train 3'}) - % sgtitle(gat_align{pg}) - -end + legend(h, {'PRE','DIST','POST'}) + -%% plot matched trn/tst GAT fidelty data, on same plot, plot independently trained fidelity data +%% supp Figure 5 B +%plot matched trn/tst GAT fidelty data, on same plot, plot independently trained fidelity data % plot fidelity plotting TRAIN as dv % which tpts are we plotting throughout? -delay_tpt_range = [3.75 5.25; 8 9.5; 10.5 12]; +delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; %change middle from 809.5 to 7.5-9 on oct 27 geh myTR = 0.75; delay_tpts = cell(size(delay_tpt_range,1),1); @@ -350,7 +325,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) tst_epoch =[1 2 3]; gat_align ={'Target aligned'}; -for n_files =1:2 +for n_files =1:2 % looping over separatee data types if n_files ==1 for pg=1:length(gat_align) @@ -370,19 +345,18 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) subplot(1,length(ROIs),vv);hold on; thisidx = all_subj_gat==ss & all_ROIs_gat==vv & all_conds_gat(:,1)==2; thisd(aa,ee,ss) = mean(all_fidelity_gat{aa,ee,pg}(thisidx,:)); %aa = TRN idx, rows; ee = tst idx, blue = 1, red =2 , yellow =3 + clear thisidx end end end hold on; - % h(n_files) = plot([1 2 3], [mean(thisd(1,1,:),3) mean(thisd(2,2,:),3) mean(thisd(3,3,:),3)],'k-','linewidth',.5) % CHANGING THIS FROM -- black to - black, may be confuding w previous figs!! - h(n_files) = plot([1 2 3], [mean(thisd(1,1,:),3) mean(thisd(2,2,:),3) mean(thisd(3,3,:),3)],'b-','linewidth',.5) % CHANGING THIS FROM -- black to - black, may be confuding w previous figs!! + h(n_files) = plot([1 2 3], [mean(thisd(1,1,:),3) mean(thisd(2,2,:),3) mean(thisd(3,3,:),3)],'b-','linewidth',.5); % CHANGING THIS FROM -- black to - black, may be confusing w previous figs!! for ii=1:3 my_sem = std(thisd(ii,ii,:),[],3)/sqrt((length(subj))); hold on; - %plot([ii ii],[mean(thisd(ii,ii,:),3)+1.*my_sem mean(thisd(ii,ii,:),3)-1.*my_sem],'k-','linewidth',.5) plot([ii ii],[mean(thisd(ii,ii,:),3)+1.*my_sem mean(thisd(ii,ii,:),3)-1.*my_sem],'b-','linewidth',.5) clear my_sem @@ -392,7 +366,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) if vv ==1 title(ROIs{vv}) xlim([0.5 3.4]) - ylabel('WM target Fidelity') + ylabel('WM Target Fidelity') set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','Epoch 1','Epoch 2','Epoch 3',''},'XTickLabelRotation',45,'TickDir','out'); else @@ -417,39 +391,39 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) for ss = 1:length(subj) subplot(1,length(ROIs),vv);hold on; - % subplot(2,9,vv);hold on; thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2; - thisdata(dd,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2),1); + thisdata(dd,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2),1); % ensure this is identical to the tpts used for GAT + clear thisidx end end hold on; - % h(n_files) = plot([1 2 3], [mean(thisdata(1,:),2) mean(thisdata(2,:),2) mean(thisdata(3,:),2)],'-','color', [0.5 0.5 0.5],'linewidth',.5) %collect n_files plot handle for legend use - h(n_files) = plot([1 2 3], [mean(thisdata(1,:),2) mean(thisdata(2,:),2) mean(thisdata(3,:),2)],'-.','color', [0 0 1],'linewidth',.5) %collect n_files plot handle for legend use + h(n_files) = plot([1 2 3], [mean(thisdata(1,:),2) mean(thisdata(2,:),2) mean(thisdata(3,:),2)],'-.','color', [0 0 1],'linewidth',.5); %collect n_files plot handle for legend use for ii=1:3 my_sem = std(thisdata(ii,:),[],2)/sqrt((length(subj))); hold on; - % plot([ii ii],[mean(thisdata(ii,:),2)+1.*my_sem mean(thisdata(ii,:),2)-1.*my_sem],'-','color', [0.5 0.5 0.5],'linewidth',.5) plot([ii ii],[mean(thisdata(ii,:),2)+1.*my_sem mean(thisdata(ii,:),2)-1.*my_sem],'-','color', [0 0 1],'linewidth',.5) clear my_sem end - clear thisidx + xlim([0.5 3.5]) - ylim([-0.05 .6]) + % ylim([-0.05 .6]) if vv ==1 ylabel('WM target Fidelity') - set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','Epoch 1','Epoch 2','Epoch 3',''},'XTickLabelRotation',45,'TickDir','out'); + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','PRE','DIST','POST',''},'XTickLabelRotation',45,'TickDir','out'); else - set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out'); + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'TickDir','out'); end - + + + clear thisdata end @@ -467,9 +441,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) end end -clear thisidx -clear thisd set(gcf,'Renderer','painters') set(gcf,'Position',[-132 503 2651 495]) legend(h, 'LORO model', 'Ind Model') @@ -536,7 +508,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) end -clear thisroiidx + @@ -546,7 +518,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) thisepoch = epoch_var; thisroi= roi_var; thissubj=subj_var; -iter = 20; +iter = 1000; fprintf(sprintf('computing %i 1 & 2-way ANOVAs on _thruTime1',iter)) T_iter_1 =cell(iter,1); @@ -723,8 +695,8 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) end end -ta_anovan1 = table(ROIs',exact_store_1(:,1)); -ta_anovan1.Properties.VariableNames={'ROI','Epoch'} +ta_anovan1 = table(ROIs',exact_store_1(:,1)); % outcome of 1-way shuffle derived p-vals for _thruTime, compare w/ exact_store_rma +ta_anovan1.Properties.VariableNames={'ROI','Epoch'}; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% do for RMAOV1 @@ -761,9 +733,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) ta_rma1 = table(ROIs',exact_store_rma(:,1)); ta_rma1.Properties.VariableNames={'ROI','Epoch'}; -%% plot sigs on the subplots - based on anovan output -sig_colors = lines(3); -y_mod =[.2]; +%% plot sig markers on the subplots - based on anovan output [p_fdr_perm, p_masked_perm] = fdr(exact_store_1,0.05); @@ -780,7 +750,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) if exact_store_1(vv,ee) > p_fdr_perm(ee) && exact_store_1(vv,ee) <= 0.05 text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color',[.5 .5 .5],'fontsize',15) %unfilled grey for IND elseif exact_store_1(vv,ee) <= p_fdr_perm(ee) - text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color','k','fontsize',15) %filled + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color','k','fontsize',15) %filled black for IND else end @@ -854,7 +824,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) clear thisroiidx - +% 1-way within each ROI for vv = 1:length(ROIs) thisroiidx = roi_var ==vv; @@ -1001,7 +971,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) extract_store=[]; %%%%%%%%%%%%%%%%%%%%%%%%% do for anovan -which_effect = [3]; %3 epoch 4 cond 7epoch*cond +which_effect = [3]; exact_store_tmp=[]; figure('name','1-way perm;anovan GAT') for vv =1:length(ROIs) @@ -1032,7 +1002,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) end ta_gat_anovan1 = table(ROIs',exact_store_gat_1(:,1)); -ta_gat_anovan1.Properties.VariableNames={'ROI','Epoch'} +ta_gat_anovan1.Properties.VariableNames= {'ROI','Epoch'} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% do for RMAOV1 which_effect =1; exact_store_tmp=[]; @@ -1067,8 +1037,7 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) ta_gat_rma1 = table(ROIs',exact_store_gat_rma(:,1)); ta_gat_rma1.Properties.VariableNames={'ROI','Epoch'}; -sig_colors = lines(3); -y_mod =[.3]; + [p_fdr_perm_gat, p_masked_perm_gat] = fdr(exact_store_gat_1,0.05); @@ -1076,15 +1045,15 @@ function spDist_plotGATrecon_fig5c(subj,sess,ROIs) sig_mrkr ={'+'}; y_mod = [.15]; for vv = 1:length(ROIs) - for ee =1 + for ee =1 % only one effect, 'epoch' figure(modelcomp); hold on; subplot(1,length(ROIs),vv) if exact_store_gat_1(vv,ee) > p_fdr_perm_gat(ee) && exact_store_gat_1(vv,ee) <= 0.05 - text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color',[.5 .5 .5],'fontsize',15) %unfilled grey for IND + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color',[.5 .5 .5],'fontsize',15) %unfilled grey for GAT elseif exact_store_gat_1(vv,ee) <= p_fdr_perm_gat(ee) - text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color','k','fontsize',15) %filled + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color','k','fontsize',15) %filled black for GAT else end diff --git a/spDist_plotGATrecon_suppFigure5BC.m b/spDist_plotGATrecon_suppFigure5BC.m new file mode 100644 index 0000000..2e8c1cf --- /dev/null +++ b/spDist_plotGATrecon_suppFigure5BC.m @@ -0,0 +1,1073 @@ +function spDist_plotGATrecon_suppFigure5BC(subj,sess,ROIs) +% GAT data loaded here, _GATdist_fig5TPTS, was created with the script +% spDist_channelRespAmp_GAT_suppFigure5 +% and the tpts delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; +root = '/share/data/spDist/'; + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'AY','CC','EK','KD','MR','SF','XL'}; + + +end + +if nargin < 2 || isempty(sess) + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; + + +end + +if nargin < 3 || isempty(ROIs) + %ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; +end + +func_suffix = 'surf'; + +nchan = 8; + +cat_mode = 1; % if 1, look for catSess1Ses...SessN_ files, otherwise, just look for each session in turn + +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +rng(spDist_randSeed); +n_files= [1 2]; % how many data files do we care about? + +%% load data + + +for yy = 1:length(n_files) + startidx = 1; + for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + if cat_mode == 1 + % just one file to load + if yy ==1 + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + if vv == 1 && ss == 1 && yy ==1 + % initialize variables... + nblankt = length(ROIs)*size(data.recons{1},1); + + + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecoruse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + + end + + + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + + + startidx = thisidx(end)+1; + + clear data; + + else + + fn = sprintf('%sspDist_reconstructions/%s_%s_%s_%s_%ichan%s_GATdist_fig5TPTS.mat',root,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str); + %fn = sprintf('%sspDist_reconstructions/%s_%s_%s_%s_%ichan%s_GATdist_fig5.mat',root,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + if vv == 1 && ss == 1 && yy ==2 + + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons_gat = cell(size(data.recons)); + all_fidelity_gat = cell(size(data.recons)); + + + for pp =1:size(data.recons,3) + for aa =1:size(data.recons,1) + for ee = 1:size(data.recons,2) + all_recons_gat{aa,ee,pp} = nan(nblankt,size(data.recons{aa},2)); + all_fidelity_gat{aa,ee,pp} = nan(nblankt,1); + end + end + end + + all_conds_gat = nan(nblankt,size(data.c_all,2)); + all_angs_gat = nan(nblankt,size(data.a_all,2)); + + all_subj_gat = nan(nblankt,1); + all_ROIs_gat = nan(nblankt,1); + all_sess_gat = nan(nblankt,1); + all_fn_gat = nan(nblankt,1); + + angs_gat = data.angs; + tpts_gat = data.delay_tpts; + end + + + + + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + for pp =1:size(data.recons,3) + for aa =1:size(data.recons,1) + for ee = 1:size(data.recons,2) + all_recons_gat{aa,ee,pp}(thisidx,:) = data.recons{aa,ee,pp}; + all_fidelity_gat{aa,ee,pp}(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons{aa,ee,pp},2)); + end + end + end + + + all_conds_gat(thisidx,:) = data.c_all; + all_angs_gat(thisidx,:) = data.a_all; + + + all_subj_gat(thisidx) = ss; + + + all_ROIs_gat(thisidx) = vv; + + all_sess_gat(thisidx) = data.sess_all; + + all_fn_gat(thisidx) = yy; + + startidx = thisidx(end)+1; + + clear data; + + + + end + + end + end + + end +end +%% supp Figure 5B +%plot only like trn/tst combinations + +trn_epoch =[1 2 3]; +tst_epoch =[1 2 3]; +gat_align ={'trn/tst:target/target'}; + +cond_colors = [ 0 0 1; 0 0 1; 0 0 1]; + + +for pg=1:length(gat_align) % can be length 1 - target aligned recon or length 2, targ aling and dist align. for now, need only target + figure ('Name','trnlines') + + for vv = 1:length(ROIs) + + h=[]; + for aa =1:length(trn_epoch) + if aa==1 % keeping these as two to avoid future confusion, could use aa in place of ee but would prefer to keep ee + ee =1; + elseif aa ==2 + ee =2; + elseif aa ==3 + ee=3; + end + + thisd = nan(length(subj),size(all_recons_gat{1},2)); + for ss = 1:length(subj) + + subplot(size(all_recons_gat,1),length(ROIs),vv+(ee-1)*length(ROIs));hold on; + + thisidx = all_subj_gat==ss & all_ROIs_gat==vv & all_conds_gat(:,1)==2; + thisd(ss,:) = mean(all_recons_gat{aa,ee,pg}(thisidx,:)); %aa = TRN idx, rows; ee = TST idx, col; blue = 1, red =2 , yellow =3 + + end + + my_sem = std(thisd,1)/sqrt((length(subj))); + h(aa) = plot(linspace(-180,180,90),mean(thisd,1),'-','LineWidth',1,'color',cond_colors(aa,:)); + + hold on; + plot(linspace(-180,180,90),mean(thisd,1)+1.*my_sem,'-','LineWidth',.5,'color',cond_colors(aa,:)) + plot(linspace(-180,180,90),mean(thisd,1)-1.*my_sem,'-','LineWidth',.5,'color',cond_colors(aa,:)) + + + btwn_fill = [mean(thisd,1)+1.*my_sem fliplr((mean(thisd,1)-1.*my_sem))]; + + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_fill,cond_colors(aa,:),'linestyle','none','facealpha',0.3); + + + clear thisidx + clear thisd + + + if ee== 1 && aa==1 + title(ROIs{vv}); + else + end + + if ee==1 && aa==1 && vv ==1 + ylabel('PRE') + set(gca,'XTick',-180:90:180,'Xticklabel',{'','',''},'TickDir','out'); + set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'','','',''},'TickDir','out') + + elseif ee==2 && aa==2 && vv ==1 + ylabel('DIST') + set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'','','',''},'TickDir','out') + set(gca,'XTick',-180:90:180,'Xticklabel',{'','',''},'TickDir','out'); + elseif ee==3 && aa==3 && vv ==1 + ylabel('POST') + set(gca,'XTick',-180:90:180,'Xticklabel',{'-180','-90','0','90','180'},'TickDir','out'); + set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'0','0.5','1.0','1.5'},'TickDir','out') + ylabel('TRN/TST Matched TPTS, Recon') + xlabel('Polar angle (\circ)'); + else + set(gca,'XTick',-180:90:180,'Xticklabel',{'','',''},'TickDir','out'); + set(gca,'YTick',0:0.5:1.5,'Yticklabel',{'','','',''},'TickDir','out') + + end + + end + + end + +end + + + + + set(gcf,'Position',[-132 503 2651 495]) + match_ylim(get(gcf,'Children')); + match_xlim(get(gcf,'Children')); + legend(h, {'PRE','DIST','POST'}) + + + + + +%% supp Figure 5C +%plot matched trn/tst GAT fidelty data, on same plot, plot independently trained fidelity data +% plot fidelity plotting TRAIN as dv +% which tpts are we plotting throughout? + +delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; %change middle from 809.5 to 7.5-9 on oct 27 geh +myTR = 0.75; + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + + + +plot_indiv = 1; % if 1, plot individual subj lines in line plot, otherwise, don't. +hoffset = 0.15; % +/- this much + + +gat_align ={'Target aligned'}; +for n_files =1:2 % looping over separatee data types + + if n_files ==1 + for pg=1:length(gat_align) + modelcomp = figure('name','modelcomp'); + + h=[]; + + for vv = 1:length(ROIs) + thisd = []; %recon data + for ee =1:length(tst_epoch) + + + for aa =1:length(trn_epoch) + + for ss = 1:length(subj) + + subplot(1,length(ROIs),vv);hold on; + thisidx = all_subj_gat==ss & all_ROIs_gat==vv & all_conds_gat(:,1)==2; + thisd(aa,ee,ss) = mean(all_fidelity_gat{aa,ee,pg}(thisidx,:)); %aa = TRN idx, rows; ee = tst idx, blue = 1, red =2 , yellow =3 + clear thisidx + end + + end + end + hold on; + h(n_files) = plot([1 2 3], [mean(thisd(1,1,:),3) mean(thisd(2,2,:),3) mean(thisd(3,3,:),3)],'b-','linewidth',.5); % CHANGING THIS FROM -- black to - black, may be confusing w previous figs!! + + for ii=1:3 + my_sem = std(thisd(ii,ii,:),[],3)/sqrt((length(subj))); + + hold on; + plot([ii ii],[mean(thisd(ii,ii,:),3)+1.*my_sem mean(thisd(ii,ii,:),3)-1.*my_sem],'b-','linewidth',.5) + + clear my_sem + end + + %geh pausing on this +% if plot_indiv == 1 +% plot([1 2 3]+hoffset,[squeeze(thisd(1,1,:)) squeeze(thisd(2,2,:)) squeeze(thisd(3,3,:))],'-','LineWidth',0.25,'Color',[0.4 0.4 0.4]); +% hold on; +% plot([1 2 3]+hoffset,[squeeze(thisd(1,1,:)) squeeze(thisd(2,2,:)) squeeze(thisd(3,3,:))],'.','markersize',10,'Color','b'); +% +% end +% + match_ylim(get(gcf,'Children')); + + if vv ==1 + title(ROIs{vv}) + xlim([0.5 3.4]) + ylabel('WM Target Fidelity') + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','PRE','DIST','POST',''},'TickDir','out'); + set(gca,'YTick',0:0.2:.6,'Yticklabel',{'0','.2','.4','.6'},'TickDir','out') + else + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out'); + set(gca,'YTick',0:0.2:.6,'Yticklabel',{'','','',''},'TickDir','out') + end + end + end + + + else + + for pg=1:length(gat_align) + + + hh=[]; + + for vv = 1:length(ROIs) + thisdata = []; %recon data + + for dd =1:length(delay_tpts) + + for ss = 1:length(subj) + + subplot(1,length(ROIs),vv);hold on; + + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2; + thisdata(dd,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2),1); % ensure this is identical to the tpts used for GAT + clear thisidx + end + + end + hold on; + h(n_files) = plot([1 2 3], [mean(thisdata(1,:),2) mean(thisdata(2,:),2) mean(thisdata(3,:),2)],'-.','color', [0 0 1],'linewidth',.5); %collect n_files plot handle for legend use + + for ii=1:3 + my_sem = std(thisdata(ii,:),[],2)/sqrt((length(subj))); + + hold on; + plot([ii ii],[mean(thisdata(ii,:),2)+1.*my_sem mean(thisdata(ii,:),2)-1.*my_sem],'-','color', [0 0 1],'linewidth',.5) + clear my_sem + end + + + xlim([0.5 3.5]) + ylim([-0.05 .6]) + if vv ==1 + + ylabel('WM target Fidelity') + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','PRE','DIST','POST',''},'XTickLabelRotation',45,'TickDir','out'); + + else + + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'TickDir','out'); + end + + + clear thisdata + title(ROIs{vv}); + end + + + + end + + end +end + +set(gcf,'Renderer','painters') +set(gcf,'Position',[-132 503 2651 495]) +legend(h, 'LORO model', 'Ind Model') +% sgtitle('Model Comparison')%% do this, over average delay epochs, for each condition +%% 2-way & 1-way true ANOVA w/_thruTime1 data +% get fidelity , over average delay epochs, for each condition, permutation test +%%%% this takes ~24 minutes to run!!!!! + +thisfide_store = []; +the_y_store= []; + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2; + thisfide_store(dd,vv,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2)); %targ aligned + the_y_store = [the_y_store; thisfide_store(dd,vv,ss) dd vv ss]; + end + + end +end + + + +% sort y_store into individual columns for transparency +y = the_y_store(:,1); +epoch_var = the_y_store(:,2); +roi_var =the_y_store(:,3); +subj_var = the_y_store(:,4); + + +P_truth_1= cell(length(ROIs),1); +T_truth_1 = cell(length(ROIs),1); +F_store_truth_1 = nan(length(ROIs),1); + +P_truth_2= cell(1,3); +T_truth_2 = cell(1,3); +F_store_truth_2 = nan(1,3); + + +%perform the true ANOVA + +thisy = y; +thisepoch = epoch_var; +thisroi= roi_var; +thissubj=subj_var; + +[P_truth_2,T_truth_2,~] = anovan(thisy,{thissubj,thisepoch,thisroi},'model','full','random',1,'varnames',{'subj','epoch','roi'},'display','off'); +[F_store_truth_2] = RMAOV2_gh([thisy,thisepoch,thisroi,thissubj],0.05); + +% perform 1-way anova on a per ROI basis, with epoch as factor +for vv = 1:length(ROIs) + + thisroiidx = roi_var ==vv; + thisy = y(thisroiidx); + thisepoch = epoch_var(thisroiidx); + thissubj=subj_var(thisroiidx); + [P_truth_1{vv},T_truth_1{vv},~] = anovan(thisy,{thissubj,thisepoch},'random',1,'varnames',{'subj','epoch'},'display','off'); + [F_store_truth_1(vv,:)] = RMAOV1_gh([thisy,thisepoch,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj thisy + + +end + + + + + +%% 2-way permuation ANOVA w/_thruTime1 data + +thisy = y; +thisepoch = epoch_var; +thisroi= roi_var; +thissubj=subj_var; +iter = 1000; +fprintf(sprintf('computing %i 1 & 2-way ANOVAs on _thruTime1',iter)) + +T_iter_1 =cell(iter,1); +P_iter_1 =cell(iter,1); +F_store_iter_1 =nan(iter,1); + +T_iter_2 =cell(iter,1); +P_iter_2 =cell(iter,1); +F_store_iter_2 =nan(iter,3); + +tic + +for xx=1:iter + y_shuf=y; + for sbj=1:length(subj) + thisidx = thissubj==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val =find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + end + + thisepoch = epoch_var; + thissubj=subj_var; + thisroi =roi_var; + + [P_iter_2{xx},T_iter_2{xx},~] = anovan(y_shuf,{thissubj,thisepoch,thisroi},'model','full','random',1,'varnames',{'subj','epoch','roi'},'display','off'); + [F_store_iter_2(xx,:)] = RMAOV2_gh([y_shuf,thisepoch,thisroi,thissubj],0.05); + + clear thisidx thisy tmpy shuff_idx + + +end +toc + +%plot F distributions +%which F vals do we want? idx is as follows {iter,1}{var_str,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is the Fval col +var_str ={'Source';'subj';'epoch';'roi';'subj*epoch';... + 'subj*roi';'epoch*roi';... + 'subj*epoch*roi';... + 'Error';'Total'} + + +col_idx = 6; % F val col + +%what factor do we care about? concurs w var_str(vs) +vs = [3 4 7]; %3 epoch 4 roi 7epoch*cond +extract_store=[]; + +figure +for which_test =1:length(vs) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; T_iter_2{ii}{vs(which_test),col_idx}]; + end + hold on; + + subplot(1,length(vs),which_test) + histogram(extract_vals) + line([T_truth_2{vs(which_test),col_idx} T_truth_2{vs(which_test),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(var_str{vs(which_test)},'Interpreter','none'); + exact_p = sum(extract_vals >= T_truth_2{vs(which_test),col_idx})/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) + exact_store(:,which_test) = [extract_store; exact_p]; + clear exact_p + if which_test ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + +end + +ta = table(exact_store(:,1),exact_store(:,2),exact_store(:,3)); +ta.Properties.VariableNames={'Epoch','ROI','EpochROI'} +%% follow-up 1-way test within each ROI + +thisfide_store = []; +the_y_store= []; + +T_iter_1 =cell(length(ROIs),iter); +P_iter_1 =cell(length(ROIs),iter); +F_store_iter_1 =nan(length(ROIs),iter); + + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2; + thisfide_store(dd,vv,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2)); %targ aligned + the_y_store = [the_y_store; thisfide_store(dd,vv,ss) dd vv ss]; + end + + + + + end +end + +y = the_y_store(:,1); +epoch_var = the_y_store(:,2); +roi_var =the_y_store(:,3); +subj_var = the_y_store(:,4); + +for xx=1:iter + for vv = 1:length(ROIs) + y_shuf =y; + thisroiidx = roi_var ==vv; + for sbj = 1:length(subj) + thisidx = roi_var ==vv & subj_var==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + end + thisepoch = epoch_var(thisroiidx); + + thissubj=subj_var(thisroiidx); + + [P_iter_1{vv,xx},T_iter_1{vv,xx},~] = anovan(y_shuf(thisroiidx),{thissubj,thisepoch},'random',1,'varnames',{'subj','epoch'},'display','off'); + [F_store_iter_1(vv,xx,:)] = RMAOV1_gh([y_shuf(thisroiidx),thisepoch,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj thisy tmpy shuffidx + + + end +end +toc + + +%plot F distributions +%which F vals do we want? idx is as follows {iter,1}{var_str,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is the Fval col +iv_str ={'Source';'subj';'epoch';'Error';'Total'}; + + +col_idx = 6; % F val col + +%what factor do we care about? concurs w var_str(vs) +vs = [3]; %3 epoch +extract_store=[]; +% here, i want to see the results of the two anova functions, separately +%%%%%%%%%%%%%%%%%%%%%%%%% do for anovan + +which_effect = [3]; %3 epoch +exact_store_tmp=[]; +figure('name','1-way perm;anovan') +for vv =1:length(ROIs) + + for ww =1:length(which_effect) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; T_iter_1{vv,ii}{which_effect(ww),col_idx}]; + end + hold on; + + subplot(1,length(ROIs),vv) + histogram(extract_vals) + line([T_truth_1{vv}{which_effect(ww),col_idx} T_truth_1{vv}{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str{which_effect(ww)},'Interpreter','none'); + exact_p = sum(extract_vals >= T_truth_1{vv}{which_effect(ww),col_idx})/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) + exact_store_1(vv,ww) = [exact_store_tmp; exact_p]; + clear exact_p + + if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + + end +end + +ta_anovan1 = table(ROIs',exact_store_1(:,1)); % outcome of 1-way shuffle derived p-vals for _thruTime, compare w/ exact_store_rma +ta_anovan1.Properties.VariableNames={'ROI','Epoch'}; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% do for RMAOV1 + +which_effect =1; % col of main effect +exact_store_tmp=[]; +figure('name','1-way perm;RMAOV1') + +for vv =1:length(ROIs) + + for ww =1:length(which_effect) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; F_store_iter_1(vv,ii)]; + end + hold on; + + subplot(1,length(ROIs),vv) + histogram(extract_vals) + line([F_store_truth_1(vv,which_effect(ww)) F_store_truth_1(vv,which_effect(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str{which_effect(ww)},'Interpreter','none'); + exact_p = sum(extract_vals >= F_store_truth_1(vv,which_effect(ww)))/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) + exact_store_rma(vv,ww) = [exact_store_tmp; exact_p]; + clear exact_p + + if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + + end +end + +ta_rma1 = table(ROIs',exact_store_rma(:,1)); +ta_rma1.Properties.VariableNames={'ROI','Epoch'}; +%% plot sig markers on the subplots - based on anovan output + + +[p_fdr_perm, p_masked_perm] = fdr(exact_store_1,0.05); + + +sig_mrkr ={'o'}; +y_mod = [.1]; +for vv = 1:length(ROIs) + for ee =1 + figure(modelcomp); hold on; + subplot(1,length(ROIs),vv) + + + if exact_store_1(vv,ee) > p_fdr_perm(ee) && exact_store_1(vv,ee) <= 0.05 + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color',[.5 .5 .5],'fontsize',15) %unfilled grey for IND + elseif exact_store_1(vv,ee) <= p_fdr_perm(ee) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color','k','fontsize',15) %filled black for IND + else + end + + + end + +end + + + +fprintf('1 & 2-way ANOVA permutations on _thru data are complete. ') + + +%% 1& 2-way true ANOVA, roi & roi x epoch, w/_GAT data +% get fidelity , over average delay epochs, for each condition, permutation test + + +thisfide_store = []; +the_y_store= []; +aa = []; + +for vv = 1:length(ROIs) + for ee = 1:3 + + for ss = 1:length(subj) + + thisidx = all_subj_gat==ss & all_ROIs_gat==vv & all_conds_gat(:,1)==2; + + if ee==1 + thisfide_store(vv,ee,ss) = mean(all_fidelity_gat{1,ee,1}(thisidx,:)); + elseif ee==2 + thisfide_store(vv,ee,ss) = mean(all_fidelity_gat{2,ee,1}(thisidx,:)); + elseif ee==3 + thisfide_store(vv,ee,ss) = mean(all_fidelity_gat{3,ee,1}(thisidx,:)); + else + end + + the_y_store = [the_y_store; thisfide_store(vv,ee,ss) vv ee ss]; + end + + + + + end +end + + +% sort y_store into individual columns for transparency +y = the_y_store(:,1); +roi_var = the_y_store(:,2); +trntst_var = the_y_store(:,3); +subj_var = the_y_store(:,4); + +P_truth_gat_1= cell(length(ROIs),1); +T_truth_gat_1= cell(length(ROIs),1); +F_store_truth_gat_1 = nan(length(ROIs),1); + +P_truth_gat_2= cell(1,3); +T_truth_gat_2= cell(1,3); +F_store_truth_gat_2 = nan(1,3); + + +%perform the "real" ANOVA + +thisy = y; +thisepoch = trntst_var; +thisroi= roi_var; +thissubj=subj_var; +[P_truth_gat_2,T_truth_gat_2,~] = anovan(thisy,{thissubj,thisepoch,thisroi},'model','full','random',1,'varnames',{'subj','epoch','roi'},'display','off'); +[F_store_truth_gat_2] = RMAOV2_gh([thisy,thisepoch,thisroi,thissubj],0.05); + +clear thisroiidx + +% 1-way within each ROI +for vv = 1:length(ROIs) + + thisroiidx = roi_var ==vv; + thisy = y(thisroiidx); + thisepoch = trntst_var(thisroiidx); + thissubj=subj_var(thisroiidx); + [P_truth_gat_1{vv},T_truth_gat_1{vv},~] = anovan(thisy,{thissubj,thisepoch},'random',1,'varnames',{'subj','epoch'},'display','off'); + [F_store_truth_gat_1(vv,:)] = RMAOV1_gh([thisy,thisepoch,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj thisy + + +end + + + + +fprintf(sprintf('computing %i 1 & 2-way ANOVAs on _GAT data',iter)) + +T_iter_gat_2 =cell(iter,1); +P_iter_gat_2 =cell(iter,1); +F_store_iter_gat_2 =nan(iter,3); + +T_iter_gat_1 =cell(length(ROIs),iter); +P_iter_gat_1 =cell(length(ROIs),iter); +F_store_iter_gat_1 =nan(length(ROIs),iter); +% two-way anova for each ROI +tic + +thisy = y; +thisepoch = trntst_var; +thisroi= roi_var; +thissubj=subj_var; + + +for xx=1:iter + y_shuf=y; + for sbj=1:length(subj) + thisidx = thissubj==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val =find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + end + + thisepoch = trntst_var; + thissubj=subj_var; + thisroi =roi_var; + + [P_iter_gat_2{xx},T_iter_gat_2{xx},~] = anovan(y_shuf,{thissubj,thisepoch,thisroi},'model','full','random',1,'varnames',{'subj','epoch','roi'},'display','off'); + [F_store_iter_gat_2(xx,:)] = RMAOV2_gh([y_shuf,thisepoch,thisroi,thissubj],0.05); + + + clear thisidx thisy tmpy shuff_idx + + +end +toc + +%plot F distributions +%which F vals do we want? idx is as follows {iter,1}{var_str,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is the Fval col +var_str ={'Source';'subj';'epoch';'roi';'subj*epoch';... + 'subj*roi';'epoch*roi';... + 'subj*epoch*roi';... + 'Error';'Total'} + + +col_idx = 6; % F val col + +%what factor do we care about? concurs w var_str(vs) +vs = [3 4 7]; %3 epoch 4 roi 7epoch*roi +extract_store=[]; + +figure +for which_test =1:length(vs) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; T_iter_gat_2{ii}{vs(which_test),col_idx}]; + end + hold on; + + subplot(1,length(vs),which_test) + histogram(extract_vals) + line([T_truth_gat_2{vs(which_test),col_idx} T_truth_gat_2{vs(which_test),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(var_str{vs(which_test)},'Interpreter','none'); + exact_p = sum(extract_vals >= T_truth_gat_2{vs(which_test),col_idx})/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) + exact_store(:,which_test) = [extract_store; exact_p]; + clear exact_p + if which_test ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + +end + +ta_gat_2 = table(exact_store(:,1),exact_store(:,2),exact_store(:,3)); +ta_gat_2.Properties.VariableNames={'Epoch','ROI','EpochROI'}; + +% 1-way perm w _GAT +y = the_y_store(:,1); +roi_var = the_y_store(:,2); +epoch_var = the_y_store(:,3); +subj_var = the_y_store(:,4); + +for xx=1:iter + for vv = 1:length(ROIs) + y_shuf =y; + thisroiidx = roi_var ==vv; + for sbj = 1:length(subj) + thisidx = roi_var ==vv & subj_var==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + end + thisepoch = epoch_var(thisroiidx); + + thissubj=subj_var(thisroiidx); + + [P_iter_gat_1{vv,xx},T_iter_gat_1{vv,xx},~] = anovan(y_shuf(thisroiidx),{thissubj,thisepoch},'random',1,'varnames',{'subj','epoch'},'display','off'); + [F_store_iter_gat_1(vv,xx,:)] = RMAOV1_gh([y_shuf(thisroiidx),thisepoch,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj thisy tmpy shuffidx + + + end +end +toc + + +%plot F distributions +%which F vals do we want? idx is as follows {iter,1}{var_str,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is the Fval col +iv_str ={'Source';'subj';'epoch';'Error';'Total'}; + + +col_idx = 6; % F val col + +%what factor do we care about? concurs w var_str(vs) +vs = [3]; %3 epoch +extract_store=[]; + +%%%%%%%%%%%%%%%%%%%%%%%%% do for anovan +which_effect = [3]; +exact_store_tmp=[]; +figure('name','1-way perm;anovan GAT') +for vv =1:length(ROIs) + + for ww =1:length(which_effect) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; T_iter_gat_1{vv,ii}{which_effect(ww),col_idx}]; + end + hold on; + + subplot(1,length(ROIs),vv) + histogram(extract_vals) + line([T_truth_gat_1{vv}{which_effect(ww),col_idx} T_truth_gat_1{vv}{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str{which_effect(ww)},'Interpreter','none'); + exact_p = sum(extract_vals >= T_truth_gat_1{vv}{which_effect(ww),col_idx})/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) + exact_store_gat_1(vv,ww) = [exact_store_tmp; exact_p]; + clear exact_p + + if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + + end +end + +ta_gat_anovan1 = table(ROIs',exact_store_gat_1(:,1)); +ta_gat_anovan1.Properties.VariableNames= {'ROI','Epoch'} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% do for RMAOV1 +which_effect =1; +exact_store_tmp=[]; +figure('name','1-way perm;RMAOV1 GAT') +for vv =1:length(ROIs) + + for ww =1:length(which_effect) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; F_store_iter_gat_1(vv,ii)]; + end + hold on; + + subplot(1,length(ROIs),vv) + histogram(extract_vals) + line([F_store_truth_gat_1(vv,which_effect(ww)) F_store_truth_gat_1(vv,which_effect(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str{which_effect(ww)},'Interpreter','none'); + exact_p = sum(extract_vals >= F_store_truth_gat_1(vv,which_effect(ww)))/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) + exact_store_gat_rma(vv,ww) = [exact_store_tmp; exact_p]; + clear exact_p + + if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + + end +end + +ta_gat_rma1 = table(ROIs',exact_store_gat_rma(:,1)); +ta_gat_rma1.Properties.VariableNames={'ROI','Epoch'}; + + + +[p_fdr_perm_gat, p_masked_perm_gat] = fdr(exact_store_gat_1,0.05); + + +sig_mrkr ={'+'}; +y_mod = [.15]; +for vv = 1:length(ROIs) + for ee =1 % only one effect, 'epoch' + figure(modelcomp); hold on; + subplot(1,length(ROIs),vv) + + + if exact_store_gat_1(vv,ee) > p_fdr_perm_gat(ee) && exact_store_gat_1(vv,ee) <= 0.05 + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color',[.5 .5 .5],'fontsize',15) %unfilled grey for GAT + elseif exact_store_gat_1(vv,ee) <= p_fdr_perm_gat(ee) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color','k','fontsize',15) %filled black for GAT + else + end + + + end + +end + + +fprintf('the end') +end + diff --git a/spDist_plotReconstructions_thruTime_Figure3.m b/spDist_plotReconstructions_thruTime_Figure3.m index 9fe8e72..c346d72 100644 --- a/spDist_plotReconstructions_thruTime_Figure3.m +++ b/spDist_plotReconstructions_thruTime_Figure3.m @@ -17,12 +17,11 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) root = spDist_loadRoot; -%root = '/share/data/spDist/'; task_dir = 'spDist'; if nargin < 1 || isempty(subj) - subj = {'CC','KD','AY','MR','XL','EK','SF'}; + subj = {'AY','CC','EK','KD','MR','SF','XL'}; %geh updated subj to alpha end @@ -33,7 +32,7 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) end if nargin < 3 || isempty(ROIs) - ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; %update ROIs 103020 end @@ -82,20 +81,20 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) % for fidelity timecourses -tmpcolors = lines(7); - -ROI_colors = [repmat(tmpcolors(1,:),3,1); % V1, V2, V3 - tmpcolors(4,:); % V3AB - tmpcolors(1,:); % hV4 - repmat(tmpcolors(3,:),1,1); % VO1 - repmat(tmpcolors(1,:),2,1); % LO1/2 - - repmat(tmpcolors(2,:),2,1); % TO1-2 - - repmat(tmpcolors(5,:),2,1); % IPS0-1 - repmat(tmpcolors(6,:),2,1); % IPS2-3 - tmpcolors(7,:); % sPCS - ]; % iPCS (color 1...) +% tmpcolors = lines(7); +% +% ROI_colors = [repmat(tmpcolors(1,:),3,1); % V1, V2, V3 +% tmpcolors(4,:); % V3AB +% tmpcolors(1,:); % hV4 +% repmat(tmpcolors(3,:),1,1); % VO1 +% repmat(tmpcolors(1,:),2,1); % LO1/2 +% +% repmat(tmpcolors(2,:),2,1); % TO1-2 +% +% repmat(tmpcolors(5,:),2,1); % IPS0-1 +% repmat(tmpcolors(6,:),2,1); % IPS2-3 +% tmpcolors(7,:); % sPCS +% ]; % iPCS (color 1...) %% load data @@ -104,7 +103,6 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) for vv = 1:length(ROIs) - if cat_mode == 1 % just one file to load fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); @@ -171,75 +169,7 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) clear data; - else - % NOT SUPPORTED YET!!!! - - for sess_idx = 1:length(sess{ss}) - % build fn - fn = sprintf('%swmChoose_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_cv_thruTime1.mat',root,subj{ss},sess{ss}{sess_idx},ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); - - fprintf('loading %s...\n',fn); - data = load(fn); - - - if vv == 1 && ss == 1 - % initialize variables... - - - nblankt = length(ROIs)*numel(sess)*size(data.recons,1); - - all_recons = nan(nblankt,size(data.recons,2),size(data.recons,3)); - all_conds = nan(nblankt,size(data.c_map,2)); - - all_fidelity = nan(nblankt,size(data.recons,3)); % timecoruse of fidelity - - - all_subj = nan(nblankt,1); - all_ROIs = nan(nblankt,1); - all_sess = nan(nblankt,1); - - angs = data.angs; - tpts = data.delay_tpts; - - all_r2 = nan(length(ROIs),length(tpts),length(subj)); - - end - - % set up our variable used to compute R2 - if sess_idx == 1 - tmp_r2 = nan(length(tpts),length(sess{ss})); % average acorss sessions... - end - - thisidx = startidx:(startidx+size(data.c_map,1)-1); - - - all_recons(thisidx,:,:) = data.recons; - all_fidelity(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons,2)); - - all_conds(thisidx,:) = data.c_map; - - - - all_subj(thisidx) = ss; - - - all_ROIs(thisidx) = vv; - - all_sess(thisidx) = sess_idx; - - tmp_r2(:,sess_idx) = squeeze(mean(mean(data.r2_all,1),2)); - - startidx = thisidx(end)+1; - - clear data; - - end - - %all_r2(vv,:,ss) = mean(tmp_r2,2); - %clear tmp_r2; - - - end + end end @@ -302,7 +232,7 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) set(gcf,'Position',[102 405 1353 174]); %match_clim(get(gcf,'Children')); - +%set(gcf,'Position',[109 372 989 168]); %for concat ROIs recon_ax = [recon_ax; get(gcf,'Children')]; %c_lim = [ -1.1876 1.7960]; @@ -349,7 +279,7 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) set(gcf,'Position',[102 405 1353 174]); %match_clim(get(gcf,'Children')); %c_limdist = [ -1.1702 1.3151]; - +%set(gcf,'Position',[109 372 989 168]); %for concat ROIs recon_ax = [recon_ax;get(gcf,'Children')]; %% plot distractor-locked (for distractor) @@ -393,7 +323,7 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) %c_lim_distlock =[-1.4808 1.4039]; recon_ax = [recon_ax;get(gcf,'Children')]; - +%set(gcf,'Position',[109 372 989 168]); %for concat ROIs %% plot distractor-removed target representation (all positions) cond_str ={'Target, dist removed'}; figure; @@ -432,7 +362,7 @@ function spDist_plotReconstructions_thruTime_Figure3(subj,sess,ROIs) set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]); set(gcf,'Position',[102 405 1353 174]); - +%set(gcf,'Position',[109 372 989 168]); %for concat ROIs %match_clim(get(gcf,'Children')); %sgtitle('Distractor trials; distractor representation removed'); %c_lim_distrem =[-0.8197 1.1589]; diff --git a/spDist_plotReconstructions_thruTime_suppFigure3.m b/spDist_plotReconstructions_thruTime_suppFigure3.m new file mode 100644 index 0000000..e8f66b1 --- /dev/null +++ b/spDist_plotReconstructions_thruTime_suppFigure3.m @@ -0,0 +1,842 @@ +% spDist_pilot_plotReconstructions_thruTime.m +% adapted from MGSMap_plotReconstructions_cv_thruTime1.m +% +% for plotting WM reconstructions during trials with/without spatial +% distractor, plotting distractor-aligned reconstructions, and sorting +% trials based on relative distractor position +% +% for plotting cross-validated WM reconstructions from mapping task, +% computed using MGSMap_channelRespAmp* scripts +% +% TODO: extend to compareReconstruction, which can load multiple sets of +% sessions per subj, and will compare across sessions (and/or across sets +% of tpts, etc... - only one set of comparisons at a time?) +% +% TODO: automate colorlims across figures + +function spDist_plotReconstructions_thruTime_suppFigure3(subj,sess,ROIs) + +root = spDist_loadRoot; + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'AY','CC','EK','KD','MR','SF','XL'}; %geh updated subj to alpha + +end + +if nargin < 2 || isempty(sess) + % each subj gets one cell, with strings for each sess + + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; +end + +if nargin < 3 || isempty(ROIs) + %ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; +end + + +func_suffix = 'surf'; + +cat_mode = 1; % if 1, look for catSess1Ses...SessN_ files, otherwise, just look for each session in turn + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + +plot_tpts = 7:15; % for a plot where we average reconstructions over a fixed time window + +dist_time = 4.5; % onset at 4 s + + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + +delay_tpt_range = [3.75 5.25; 7.5 9; 10.5 12]; %note: this is not used, just updating time windows in case something comes up + + + +% for fidelity timecourses +% tmpcolors = lines(7); +% +% ROI_colors = [repmat(tmpcolors(1,:),3,1); % V1, V2, V3 +% tmpcolors(4,:); % V3AB +% tmpcolors(1,:); % hV4 +% repmat(tmpcolors(3,:),1,1); % VO1 +% repmat(tmpcolors(1,:),2,1); % LO1/2 +% +% repmat(tmpcolors(2,:),2,1); % TO1-2 +% +% repmat(tmpcolors(5,:),2,1); % IPS0-1 +% repmat(tmpcolors(6,:),2,1); % IPS2-3 +% tmpcolors(7,:); % sPCS +% ]; % iPCS (color 1...) + + +%% load data +startidx = 1; +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data.recons{1},1); + all_recons = cell(size(data.recons)); + for aa = 1:length(data.recons) + all_recons{aa} = nan(nblankt,size(data.recons{aa},2),size(data.recons{aa},3)); + end + + all_recons_nodist = nan(nblankt,size(data.recons_nodist,2),size(data.recons_nodist,3)); + + all_conds = nan(nblankt,size(data.c_all,2)); + all_angs = nan(nblankt,size(data.a_all,2)); + + all_fidelity = nan(nblankt,size(data.recons{1},3),length(data.recons)); % timecoruse of fidelity for each alignment condition + all_fidelity_nodist = nan(nblankt,size(data.recons_nodist,3)); + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + + angs = data.angs; + tpts = data.delay_tpts; + + % ugh have to do this in a multi-D array... + %all_r2 = nan(length(ROIs),length(tpts),length(subj)); + + end + + + + thisidx = startidx:(startidx+size(data.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data.recons{aa},2)); + end + + all_recons_nodist(thisidx,:,:) = data.recons_nodist; + all_fidelity_nodist(thisidx,:) = squeeze(mean(cosd(angs) .* data.recons_nodist,2)); + + all_conds(thisidx,:) = data.c_all; + all_angs(thisidx,:) = data.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data.sess_all; + + + startidx = thisidx(end)+1; + + clear data; + + + end + +end + + +%% which tpts are we plotting throughout? +% TCS: lte to lessthan +tpts_to_plot = (tpts*myTR) >= t_range_to_plot(1) & (tpts*myTR) < t_range_to_plot(2); + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + + +%% plot each condition (target-locked) (average over subj) +% length(cu) x n_rois + +% store all axes across figures +recon_ax = []; + + +cu = 1; +cond_str = {'No distractor trials'}; + +figure; +for cc = 1:length(cu) + for vv = 1:length(ROIs) + + subplot(length(cu),length(ROIs),(cc-1)*length(ROIs)+vv);hold on; + + + thisd = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj)); + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisd(:,:,ss) = squeeze(mean(all_recons{1}(thisidx,:,:),1)).'; + end + % TCS: center each row over middle of TR + imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,mean(thisd(tpts_to_plot,:,:),3)); + colormap viridis + if cc == 1 + title(ROIs{vv}); + end + axis ij tight + set(gca,'XTick',-180:90:180); + if vv == 1 + xlabel('Polar angle (\circ)'); + ylabel(sprintf('%s - time (s)',cond_str{cc})); + set(gca,'XTickLabel',{'-180','','0','','180'}); + + else + set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]); + end + xlim([-180 180]); + caxis([-1.4808 1.7960]) + end +end + +set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]); +set(gcf,'Position',[102 405 1353 174]); + +%match_clim(get(gcf,'Children')); +%set(gcf,'Position',[109 372 989 168]); %for concat ROIs +recon_ax = [recon_ax; get(gcf,'Children')]; + +%c_lim = [ -1.1876 1.7960]; +%% plot each condition (target-locked) (average over subj) +% length(cu) x n_rois + +cu = 2; +cond_str = {'Distractor trials'}; + +figure; +for cc = 1:length(cu) + for vv = 1:length(ROIs) + + subplot(length(cu),length(ROIs),(cc-1)*length(ROIs)+vv);hold on; + + + thisd = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj)); + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisd(:,:,ss) = squeeze(mean(all_recons{1}(thisidx,:,:),1)).'; + end + % TCS: center each row over middle of TR + imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,mean(thisd(tpts_to_plot,:,:),3)); + colormap viridis + if cc == 1 + title(ROIs{vv}); + end + axis ij tight + set(gca,'XTick',-180:90:180); + if vv == 1 + xlabel('Polar angle (\circ)'); + ylabel(sprintf('%s - time (s)',cond_str{cc})); + set(gca,'XTickLabel',{'-180','','0','','180'}); + + else + set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]); + end + xlim([-180 180]); + caxis([-1.4808 1.7960]) + end +end + +set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]); +set(gcf,'Position',[102 405 1353 174]); +%match_clim(get(gcf,'Children')); +%c_limdist = [ -1.1702 1.3151]; +%set(gcf,'Position',[109 372 989 168]); %for concat ROIs +recon_ax = [recon_ax;get(gcf,'Children')]; + +%% plot distractor-locked (for distractor) +cond_str ={'Distractor locked'}; + +figure; +for vv = 1:length(ROIs) + + subplot(1,length(ROIs),vv);hold on; + + + thisd = nan(size(all_recons{1},3),size(all_recons{1},2),length(subj)); + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2; + thisd(:,:,ss) = squeeze(mean(all_recons{2}(thisidx,:,:),1)).'; + end + % TCS: as above... + imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,mean(thisd(tpts_to_plot,:,:),3)); + colormap viridis; + + + title(ROIs{vv}); + + axis ij tight + set(gca,'XTick',-180:90:180); + if vv == 1 + xlabel('Polar angle (\circ)'); + ylabel(sprintf('%s - time (s)',cond_str{cc})); + set(gca,'XTickLabel',{'-180','','0','','180'}); + + else + set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]); + end + xlim([-180 180]); + caxis([-1.4808 1.7960]) +end + +set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]); +set(gcf,'Position',[102 405 1353 174]); +%match_clim(get(gcf,'Children')); +%c_lim_distlock =[-1.4808 1.4039]; +recon_ax = [recon_ax;get(gcf,'Children')]; + +%set(gcf,'Position',[109 372 989 168]); %for concat ROIs +%% plot distractor-removed target representation (all positions) +cond_str ={'Target, dist removed'}; +figure; + +for vv = 1:length(ROIs) + + subplot(1,length(ROIs),vv);hold on; + + + thisd = nan(size(all_recons_nodist,3),size(all_recons_nodist,2),length(subj)); + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==2; + thisd(:,:,ss) = squeeze(mean(all_recons_nodist(thisidx,:,:),1)).'; + end + + % TCS: as above + imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,mean(thisd(tpts_to_plot,:,:),3)); + colormap viridis; + + + title(ROIs{vv}); + + axis ij tight + set(gca,'XTick',-180:90:180); + if vv == 1 + xlabel('Polar angle (\circ)'); + ylabel(sprintf('%s - time (s)',cond_str{cc})); + set(gca,'XTickLabel',{'-180','','0','','180'}); + + else + set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]); + end + xlim([-180 180]); + caxis([-1.4808 1.7960]) +end + +set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',[0 4.5 12]); +set(gcf,'Position',[102 405 1353 174]); +%set(gcf,'Position',[109 372 989 168]); %for concat ROIs +%match_clim(get(gcf,'Children')); +%sgtitle('Distractor trials; distractor representation removed'); +%c_lim_distrem =[-0.8197 1.1589]; + +recon_ax = [recon_ax;get(gcf,'Children')]; + +match_clim(recon_ax); + + +%% plot target fidelity on distractor-/+ trials and distractor fidelity +% row 1: target fidelity +% row 2: distractor fidelity +% row 3: target fidelity (after removing distractor) + +% target: without and with distractor; distractor +fidelity_colors = lines(7); fidelity_colors = fidelity_colors(4:6,:); + +t_markers = [0 4.5 12]; % onset of delay, distractor, response +mh1 = nan(length(ROIs),length(t_markers)); +mh2 = nan(length(ROIs),length(t_markers)); +mh3 = nan(length(ROIs),length(t_markers)); + +mu_fidelity = nan(length(ROIs),size(all_fidelity,2),4); % ROIs x tpts x targ w/ and w/out distractor; distractor; with-distractor after removing distractor... + +figure; +% first, plot the target fidelity +for vv = 1:length(ROIs) + + subplot(3,length(ROIs),vv); hold on; + + + + for cc = 1:length(cu) + + thisd = nan(length(subj),size(all_fidelity,2)); + + for ss = 1:length(subj) + + thisidx = all_conds(:,1)==cu(cc) & all_subj==ss & all_ROIs==vv; + thisd(ss,:) = mean(all_fidelity(thisidx,:,1)); + + end + + mu_fidelity(vv,:,cc) = mean(thisd,1); + + thise = std(thisd,[],1)/sqrt(length(subj)); + + % TCS: updated x axis + % plot mean + plot(myTR*tpts + myTR/2,mean(thisd,1),'-','LineWidth',1.5,'Color',fidelity_colors(cc,:)); + + % plot error bars + plot((myTR*tpts.*[1;1]).' + myTR/2,(mean(thisd,1)+[-1;1].*thise).','--','LineWidth',1,'Color',fidelity_colors(cc,:)); + + + yline(0); + % TODO: plot std error across subj + + title(ROIs{vv}); + if vv == 1 + ylabel('Target fidelity'); + else + set(gca,'YTickLabel',[]); + end + + set(gca,'XTick',[0:6:24],'TickDir','out','XTickLabel',[]); + + clear thisd thise; + end + + mh1(vv,:) = plot(t_markers.*[1;1],[0 .1],'-','Color',[0.7 0.7 0.7],'LineWidth',0.75); + + + % ---------- SECOND ROW --------------------- + subplot(3,length(ROIs),vv+length(ROIs)); hold on; + + + + thisd = nan(length(subj),size(all_fidelity,2)); + + for ss = 1:length(subj) + + thisidx = all_conds(:,1)==2 & all_subj==ss & all_ROIs==vv; + thisd(ss,:) = mean(all_fidelity(thisidx,:,2)); + + end + + mu_fidelity(vv,:,1+length(cu)) = mean(thisd,1); + + thise = std(thisd,[],1)/sqrt(length(subj)); + + + + plot(myTR*tpts + myTR/2,mean(thisd,1),'-','LineWidth',1.5,'Color',fidelity_colors(3,:)); + plot((myTR*tpts.*[1;1]).' + myTR/2,(mean(thisd,1)+[-1;1].*thise).','--','LineWidth',1,'Color',fidelity_colors(3,:)); + + yline(0); + + if vv == 1 + ylabel('Distractor fidelity'); + xlabel('Time (s)'); + else + set(gca,'YTickLabel',[]); + end + + set(gca,'XTick',[0:6:24],'TickDir','out'); + + mh2(vv,:) = plot(t_markers.*[1;1],[0 .1],'-','Color',[0.7 0.7 0.7],'LineWidth',0.75); + + + clear thisd; + % ---------- THIRD ROW ------------ + + subplot(3,length(ROIs),vv+2*length(ROIs)); hold on; + + thisd = nan(length(subj),size(all_fidelity,2)); + + for ss = 1:length(subj) + + thisidx = all_conds(:,1)==2 & all_subj==ss & all_ROIs==vv; + thisd(ss,:) = mean(all_fidelity_nodist(thisidx,:)); + + end + + mu_fidelity(vv,:,2+length(cu)) = mean(thisd,1); + + thise = std(thisd,[],1)/sqrt(length(subj)); + + + + plot(myTR*tpts + myTR/2,mean(thisd,1),'-','LineWidth',1.5,'Color',fidelity_colors(2,:)); + plot((myTR*tpts.*[1;1]).' + myTR/2,(mean(thisd,1)+[-1;1].*thise).','--','LineWidth',1,'Color',fidelity_colors(2,:)); + + yline(0); + + if vv == 1 + ylabel('WM fidelity (minus distractor)'); + xlabel('Time (s)'); + else + set(gca,'YTickLabel',[]); + end + + set(gca,'XTick',[0:6:24],'TickDir','out'); + + mh3(vv,:) = plot(t_markers.*[1;1],[0 .1],'-','Color',[0.7 0.7 0.7],'LineWidth',0.75); + + + clear thisd; + + + +end + +%myy = cell2mat(get(get(gcf,'Children'),'YLim')); + +myy = match_ylim(get(gcf,'Children')); +set(mh1,'YData',[min(myy(:,1)) max(myy(:,2))]); +set(mh2,'YData',[min(myy(:,1)) max(myy(:,2))]); +set(mh3,'YData',[min(myy(:,1)) max(myy(:,2))]); + +set(gcf,'Position',[185 745 1843 470]); + + +%% fidelity difference: distractor present vs absent + + +%diff_fidelity = nan(length(ROIs),size(all_fidelity,2),3); % ROIs x tpts x targ w/ and w/out distractor; distractor + +diff_fidelity = mu_fidelity(:,:,2)-mu_fidelity(:,:,1); % dist - no dist + +figure; +% first, plot the target fidelity +for vv = 1:length(ROIs) + + subplot(1,length(ROIs),vv); hold on; + + + + for cc = 1:length(cu) + + thismu = mean(diff_fidelity,1); + %thise = std(diff_fidelity + + % plot mean + plot(myTR*tpts + myTR/2,diff_fidelity(vv,:),'-','LineWidth',1.5,'Color','k'); + + %plot(myTR*tpts,mean(diff_fidelity,1),'-','LineWidth',1.5,'Color','k');); + + % TODO: plot std error across subj + + title(ROIs{vv}); + if vv == 1 + ylabel('Target fidelity (distractor - no distractor)'); + xlabel('Time (s)'); + end + + set(gca,'XTick',[0:6:24],'TickDir','out'); + + clear thisd; + end + + mh1(vv,:) = plot(t_markers.*[1;1],[0 .1],'-','Color',[0.7 0.7 0.7],'LineWidth',0.75); + +end + +%myy = cell2mat(get(get(gcf,'Children'),'YLim')); + +myy = match_ylim(get(gcf,'Children')); +set(mh1,'YData',[min(myy(:,1)) max(myy(:,2))]); +%set(mh2,'YData',[min(myy(:,1)) max(myy(:,2))]); + + + +%% image view of above (ROIs x time) + +title_str = {'WM target: no distractor','WM target: distractor','Distractor','WM target: distractor removed'}; + +figure; +for cc = 1:size(mu_fidelity,3) + subplot(size(mu_fidelity,3),1,cc); hold on; + + imagesc(tpts(tpts_to_plot)*myTR + myTR/2,1:length(ROIs),mu_fidelity(:,tpts_to_plot,cc)); + + axis ij; axis tight; + colormap viridis; + if cc == size(mu_fidelity,3) + xlabel('Time (s)'); + + end + title(title_str{cc}); + ylabel('ROI'); + set(gca,'YTick',1:length(ROIs),'YTickLabel',ROIs,'TickDir','out','Box','off'); + + for tt = 1:length(t_markers) + plot([1 1]*t_markers(tt),[0.5 length(ROIs)+0.5],'--','Color','r','LineWidth',1); + end + +end + +match_clim(get(gcf,'Children')); +sgtitle('Fidelity'); + +%% same, ROI-normalized + +figure; +for cc = 1:size(mu_fidelity,3) + subplot(size(mu_fidelity,3),1,cc); hold on; + + tmp_fidelity = mu_fidelity(:,tpts_to_plot,cc); + tmp_fidelity = tmp_fidelity./max(tmp_fidelity,[],2); + + imagesc(tpts(tpts_to_plot)*myTR + myTR/2,1:length(ROIs),tmp_fidelity); + + axis ij; axis tight; + colormap viridis; + if cc == size(mu_fidelity,3) + xlabel('Time (s)'); + + end + title(title_str{cc}); + ylabel('ROI'); + set(gca,'YTick',1:length(ROIs),'YTickLabel',ROIs,'TickDir','out','Box','off'); + + for tt = 1:length(t_markers) + plot([1 1]*t_markers(tt),[0.5 length(ROIs)+0.5],'--','Color','r','LineWidth',1); + end + +end + +%match_clim(get(gcf,'Children')); + +sgtitle('Fidelity (normalized)'); + +%% plot (individual subj as rows) +% n_subj x n_rois + +all_ax_ss = []; +for cc = 1:length(cu) + figure; + for ss = 1:length(subj) + + + for vv = 1:length(ROIs) + + %subplot(length(cu),length(ROIs),(cc-1)*length(ROIs)+vv);hold on; + subplot(length(subj),length(ROIs),(ss-1)*length(ROIs)+vv);hold on; + + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisd = squeeze(mean(all_recons{1}(thisidx,:,:),1)).'; + + imagesc(angs,tpts(tpts_to_plot)*myTR + myTR/2,thisd(tpts_to_plot,:)); + colormap viridis + if ss == 1 + title(ROIs{vv}); + end + axis ij tight + set(gca,'XTick',-180:90:180); + if vv == 1 + if ss == length(subj) + xlabel('Polar angle (\circ)'); + end + ylabel(sprintf('%s - time (s)',subj{ss})); + set(gca,'XTickLabel',{'-180','','0','','180'}); + + else + set(gca,'YTick',[],'XTickLabel',[],'YTickLabel',[]); + end + xlim([-180 180]); + end + end + all_ax_ss = [all_ax_ss;get(gcf,'Children')]; + + set(get(gcf,'Children'),'TickDir','out','Box','off','TickLength',[0.015 0.015],'YTick',0:5:10); + set(gcf,'Position',[ 220 1058 1760 194]); + + try + %sgtitle(subj{ss}); % only R2018b or later... + sgtitle(cond_str{cc}) + catch + fprintf('UPGRADE YOUR MATLAB (2018b or newer)!\n'); + set(gcf,'NumberTitle','off','Name',subj{ss}); + end +end + +match_clim(all_ax_ss(:)); + + + + + + +%% plot average reconstruction over defined delay-period +% figure; +% for vv = 1:length(ROIs) +% +% this_recons = nan(length(subj),length(angs)); +% +% for ss = 1:length(subj) +% +% thisidx = all_subj == ss & all_ROIs == vv; +% tidx = ismember(tpts,plot_tpts); +% +% this_recons(ss,:) = mean( mean(all_recons(thisidx,:,tidx),3), 1 ); +% +% end +% +% subplot(1,length(ROIs),vv); hold on; +% plot(angs,mean(this_recons,1),'-','LineWidth',2,'Color',ROI_colors(vv,:)); +% +% thiserr = std(this_recons,[],1)/sqrt(length(subj)); +% plot(angs,mean(this_recons,1)+thiserr,'--','LineWidth',0.5,'Color',ROI_colors(vv,:)); +% plot(angs,mean(this_recons,1)-thiserr,'--','LineWidth',0.5,'Color',ROI_colors(vv,:)); +% +% title(ROIs{vv}); +% +% if vv == 1 +% xlabel('Position (\circ)'); +% ylabel('BOLD Z-score'); +% else +% set(gca,'YTickLabel',[]); +% end +% +% set(gca,'XTick',-180:180:180,'Box','off','TickDir','out','FontSize',14); +% +% end +% +% match_ylim(get(gcf,'Children')); + + + +%% FIDELITY: plot mean across subj + +% if proto_ROI is not empty, draw that ROI's timecourse behind the 'true' +% timecourse in all ROIs (except this ROI) + + +% TEMPORARILY: we'll skip over these (TODO) +if 0 +proto_ROI = 4; % V3AB + +proto_color = [0.7 0.7 0.7]; + + +if ~isempty(proto_ROI) + % quick - compute the mean for proto-ROI - same as below + proto_d = nan(length(subj),size(all_fidelity,2)); + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==proto_ROI; + proto_d(ss,:) = mean(all_fidelity(thisidx,:),1); + clear thisidx; + end + proto_fidelity = mean(proto_d,1); +end + +all_m_fidelity = nan(length(ROIs),size(all_fidelity,2)); +all_subj_fidelity = nan(length(ROIs),size(all_fidelity,2),length(subj)); +% 1x n_rois +figure; +for vv = 1:length(ROIs) + + subplot(1,length(ROIs),vv);hold on; + + + thisd = nan(length(subj),size(all_fidelity,2)); + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv; + thisd(ss,:) = mean(all_fidelity(thisidx,:),1); + all_subj_fidelity(vv,:,ss) = thisd(ss,:); + end + + if ~isempty(proto_ROI) + plot(tpts*myTR,proto_fidelity,'-','LineWidth',1.5,'Color',proto_color); + end + + plot(tpts*myTR,mean(thisd,1),'-','LineWidth',2,'Color',ROI_colors(vv,:)); + plot(tpts*myTR,mean(thisd,1)-std(thisd,[],1)/sqrt(length(subj)),'--','LineWidth',0.5,'Color',ROI_colors(vv,:)); + plot(tpts*myTR,mean(thisd,1)+std(thisd,[],1)/sqrt(length(subj)),'--','LineWidth',0.5,'Color',ROI_colors(vv,:)); + + xlim(t_range_to_plot); + + all_m_fidelity(vv,:) = mean(thisd,1); + + + title(ROIs{vv}); + + if vv == 1 + xlabel('Time (s)'); + ylabel('Fidelity (BOLD Z-score)'); + else + set(gca,'YTickLabel',[]); + end + +end + + +set(get(gcf,'Children'),'YLim',[-0.075 0.8],'TickDir','out','TickLength',[1 1]*0.015,'YTick',[-0.2:0.2:0.8]); +set(gcf,'Position',[216 866 1760 117]); + +%% fidelity for each subj for each ROI (just the above, with one row per subj) + +figure; +for ss = 1:length(subj) + for vv = 1:length(ROIs) + subplot(length(subj),length(ROIs),vv+(ss-1)*length(ROIs)); hold on; + if ~isempty(proto_ROI) % plot this subj's proto-ROI timecourse + plot(tpts*myTR,proto_d(ss,:),'-','LineWidth',1.0,'Color',proto_color); + end + plot(tpts*myTR,all_subj_fidelity(vv,:,ss),'-','LineWidth',1.5,'Color',ROI_colors(vv,:)); + xlim(t_range_to_plot); + + if ss == 1 + title(ROIs{vv}); + end + + if vv == 1 + if ss == length(subj) + xlabel('Time (s)'); + end + ylabel(subj{ss}); + else + set(gca,'YTickLabel',[]); + end + + if ss ~= length(subj) + set(gca,'XTickLabel',[]); + end + + end +end + +set(get(gcf,'Children'),'YLim',[-0.075 1.2],'TickDir','out','TickLength',[1 1]*0.015,'YTick',[0:0.5:1],'XTick',0:6:12); +%set(gcf,'Position',[216 866 1760 117]); + + +end + +return \ No newline at end of file diff --git a/spDist_scoreEyeData.m b/spDist_scoreEyeData.m index 3e26d76..e47c2af 100644 --- a/spDist_scoreEyeData.m +++ b/spDist_scoreEyeData.m @@ -18,12 +18,9 @@ function spDist_scoreEyeData(subj,sess,WHICH_EXCL) close all; %root = spDist_loadRoot; -root = '/share/data/spDist/' -%root = sprintf('/d/DATA/data/spDist/') -%ifg_fn = '~/Documents/MATLAB/toolboxes_dev/iEye_ts/examples/p_500hz.ifg'; -%ifg_fn = '/Volumes/home/grace/iEye/examples/p_500hz.ifg'; +root = '/share/data/spDist/'; + ifg_fn = '/share/home/grace/iEye/examples/p_500hz.ifg'; -%ifg_fn = '/d/DATA/home/grace/iEye/examples/p_500hz.ifg'; task_dir = 'spDist'; diff --git a/spDist_visualizeDistandTarg.m b/spDist_visualizeDistandTarg.m index ab78143..96f143f 100644 --- a/spDist_visualizeDistandTarg.m +++ b/spDist_visualizeDistandTarg.m @@ -3,10 +3,10 @@ root = '/share/data/spDist/' -%subj = {'KD','CC','AY','MR','XL','EK','SF'}; -subj = {'CC','AY','MR'}; -%sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist2'},{'spDist1','spDist2'},{'spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed -sess = {{'spDistLong1','spDistLong2'},{'spDistLong1','spDistLong2'},{'spDistLong1','spDistLong2'}} +subj = {'CC','KD','AY','MR','XL','SF','EK'}; +%subj = {'CC','AY','MR'}; +sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist2'},{'spDist1','spDist2'},{'spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; %two sessions removed +%sess = {{'spDistLong1','spDistLong2'},{'spDistLong1','spDistLong2'},{'spDistLong1','spDistLong2'}} %if nargin < 3 %WHICH_EXCL = [13 20 21 22]; % don't exclude trials w/ calibration failures for now... WHICH_EXCL = []; % don't exclude trials w lg error, this is overridden due to geh inspection @@ -145,12 +145,17 @@ tmp_ccwidxstore = {}; tmp_cwidxstore = {}; +tmprel = all_data.s_all.trialinfo(:,3) - all_data.s_all.trialinfo(:,2); +this_rel = mod((tmprel+180), 360)-180; + % same plot for ss = 1:length(subj) - cwidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.s_all.trialinfo(:,6)== which_bin*-1; %negative jitter = cw - ccwidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.s_all.trialinfo(:,6)== which_bin; %positive jitter = ccw - + %cwidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.s_all.trialinfo(:,6)== which_bin*-1; %negative jitter = cw + %ccwidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.s_all.trialinfo(:,6)== which_bin; %positive jitter = ccw + + cwidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.s_all.trialinfo(:,6)== 0 & this_rel< 0 % %negative jitter = cw + ccwidx = all_subj==ss & all_data.s_all.trialinfo(:,1)==2 & all_data.s_all.trialinfo(:,6)== 0 & this_rel > 0 %positive jitter = ccw for pp = 1:length(params_of_interest) tmp_mu(1,pp,:,ss) = nanmean( all_data.s_all.(params_of_interest{pp})(cwidx,:), 1 ); diff --git a/spDist_withinROI_stats_Figure4.m b/spDist_withinROI_stats_Figure4.m index 7ed5787..c61c8c0 100644 --- a/spDist_withinROI_stats_Figure4.m +++ b/spDist_withinROI_stats_Figure4.m @@ -1,7 +1,8 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) - +% stats checked and confirmed 11/10/2020 +% w /updated middle epoch root = spDist_loadRoot;%'/share/data/spDist/'; %updated root task_dir = 'spDist'; @@ -15,10 +16,9 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) end if nargin < 3 || isempty(ROIs) - ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; end -%roi_str = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; func_suffix = 'surf'; plot_hists = 0; % whether to plot histograms of shuffled stat values or not... @@ -54,7 +54,7 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) end -delay_tpt_range = [3.75 5.25; 7.5 9; 10.5 12]; %for stats - up for discussion? +delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; % number of iterations for permutation... iter = 1000; @@ -171,28 +171,25 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) % added sqrt here (TCS) my_sem = std(thisdata,[],1)/sqrt(length(subj)); + % TCS: plot actual values, not min-removed h(cc) = plot(linspace(-180,180,90),mean(thisdata,1),'-','LineWidth',0.5,'color',cond_colors(cc,:)); - % orig: - %h(cc) = plot(linspace(-180,180,90),mean(thisdata,1) - min(mean(thisdata,1)),'-','LineWidth',0.5,'color',cond_colors(cc,:)); + hold on; - %plot(linspace(-180,180,90),(mean(thisdata,1) - min(mean(thisdata,1)))+1.*my_sem,'-','LineWidth',.1,'color',cond_colors(cc,:),'HandleVisibility','off') + + plot(linspace(-180,180,90),mean(thisdata,1)+1.*my_sem,'-','LineWidth',.1,'color',cond_colors(cc,:),'HandleVisibility','off') - %plot(linspace(-180,180,90),(mean(thisdata,1) - min(mean(thisdata,1)))-1.*my_sem,'-','LineWidth',.1,'color',cond_colors(cc,:),'HandleVisibility','off') + plot(linspace(-180,180,90),mean(thisdata,1)-1.*my_sem,'-','LineWidth',.1,'color',cond_colors(cc,:),'HandleVisibility','off') %color in btwn +/- SEM % TCS: plot actual values, not min removed - btwn_fill = [(mean(thisdata,1))+1.*my_sem fliplr((mean(thisdata,1))-1.*fliplr(my_sem))]; % TCS: fliplr also for my_sem? - - % orig: - %btwn_fill = [(mean(thisdata,1) - min(mean(thisdata,1)))+1.*my_sem fliplr((mean(thisdata,1) - min(mean(thisdata,1)))-1.*my_sem)]; + %btwn_fill = [(mean(thisdata,1))+1.*my_sem fliplr((mean(thisdata,1))-1.*fliplr(my_sem))]; % TCS: fliplr also for my_sem? + btwn_fill = [(mean(thisdata,1))+1.*my_sem fliplr((mean(thisdata,1)-1.*(my_sem)))]; % geh test fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_fill,cond_colors(cc,:),'linestyle','none','facealpha',0.3); - - - %line([0 0], [-.1 2.25], 'color',[.2 .2 .2],'linewidth',0.5,'linestyle','-') + line([min(xlim) max(xlim)], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') - clear my_sem; + clear my_sem btwn_fill end % things to do for every axis: @@ -230,7 +227,8 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) end end match_ylim(get(gcf,'Children')); -set(gcf,'position', [ 23 245 2386 453]) +set(gcf,'position', [ 121 287 1574 503]) +%set(gcf,'position', [ 23 245 2386 453]) @@ -357,7 +355,7 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) %% fidelity line plot per ROI & true 2-way anova stat % TCS: replace w/ loading colors from file -dist_colors = spDist_condColors;% [0.7100 0.2128 0.4772; 0 0 1;]; +dist_colors = spDist_condColors; cond_colors = dist_colors; thisd_store =[]; @@ -397,6 +395,10 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) % subj here if plot_indiv == 1 plot(dd+hoffset*[-1;1],squeeze(thisd(dd,:,:)),'-','LineWidth',0.25,'Color',[0.4 0.4 0.4]); + hold on; + plot(dd+hoffset*-1,squeeze(thisd(dd,1,:)),'.','markersize',10,'Color',dist_colors(1,:)); + hold on; + plot(dd+hoffset*1,squeeze(thisd(dd,2,:)),'.','markersize',10,'Color',dist_colors(2,:)); end @@ -405,29 +407,34 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) for cc =1:length(cu) % TCS: matched these to HRFs (dot makes it slightly easier to see % value when overlapping...) - h(cc) = plot([1 2 3],mean(thisd(:,cc,:),3)','o-','color',cond_colors(cc,:),'linewidth',1,'MarkerSize',3,'MarkerFaceColor',cond_colors(cc,:)); + h(cc) = plot([1 2 3],mean(thisd(:,cc,:),3)','o-','color',cond_colors(cc,:),'linewidth',2,'MarkerSize',8,'MarkerFaceColor',cond_colors(cc,:)); for dd =1:length(delay_tpts) - plot([dd dd],[mean(thisd(dd,cc,:),3)+1.*my_sem(dd,cc) mean(thisd(dd,cc,:),3)-1.*my_sem(dd,cc)], '-','LineWidth',1,'color',cond_colors(cc,:)) + plot([dd dd],[mean(thisd(dd,cc,:),3)+1.*my_sem(dd,cc) mean(thisd(dd,cc,:),3)-1.*my_sem(dd,cc)], '-','LineWidth',2,'color',cond_colors(cc,:)) end end clear thisidx clear thisd - + + line([0 4], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') % geh add y =0 baseline + xlim([0.5 3.5]) if vv ==1 title(ROIs{vv}) ylabel('WM target Fidelity') set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','Epoch 1','Epoch 2','Epoch 3',''},'XTickLabelRotation',45,'TickDir','out'); - + set(gca,'Ytick',[0 .4 .8 ],'TickDir','out'); + else set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out'); + set(gca,'Ytick',[0 .4 .8 ],'TickDir','out'); title(ROIs{vv}) end if plot_indiv - ylim([-0.1 0.8]); + %ylim([-0.1 0.8]); + ylim([-0.1 1]); else ylim([0 0.65]) end @@ -435,7 +442,7 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) end - +set(gcf,'position', [ 121 287 1574 503]) y = thisd_store(:,1); epoch_var = thisd_store(:,2); roi_var =thisd_store(:,3); @@ -556,15 +563,12 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) thisepoch = epoch_var(thisroiidx); thiscond =cond_var(thisroiidx); thissubj=subj_var(thisroiidx); - [P_truth{vv},T_truth{vv},~] = anovan(thisy,{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'},'display','off'); + [P_truth{vv},T_truth{vv},~] = anovan(thisy,{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'}) %,'display','off'); [F_store_truth_2(vv,:)] = RMAOV2_gh([thisy,thisepoch,thiscond,thissubj],0.05); clear thisroiidx thisepoch thiscond thissubj thisy - - %[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to - %correct? confirm w/ TCS - + end @@ -572,181 +576,181 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) match_xlim(get(gcf,'Children')); legend(h, {'No distractor', 'Distractor'}) set(gcf,'position', [ 23 245 2386 453]) +%% 3-way ANOVA permutation +% get fidelity , over average delay epochs, for each condition, permutation test +%%%% this takes ~2.7 hrs minutes to run!!!!! (anovan) -% %% 3-way ANOVA permutation -% % get fidelity , over average delay epochs, for each condition, permutation test -% %%%% this takes ~2.7 hrs minutes to run!!!!! (anovan) -% -% cu =[1 2]; -% thisfide_store = []; -% the_y_store= []; -% -% for dd = 1:length(delay_tpts) -% for vv = 1:length(ROIs) -% for cc = 1:length(cu) -% for ss = 1:length(subj) -% thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); -% thisfide_store(dd,vv,cc,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2)); %targ aligned -% the_y_store = [the_y_store; thisfide_store(dd,vv,cc,ss) dd vv cc ss]; -% end -% -% end -% -% -% end -% end -% -% % sort y_store into individual columns for feasibility/ transparency -% y_3 = the_y_store(:,1); -% epoch_var_3 = the_y_store(:,2); -% roi_var_3 =the_y_store(:,3); -% cond_var_3 =the_y_store(:,4); -% subj_var_3 = the_y_store(:,5); -% -% P_truth_3= cell(1,1); -% T_truth_3= cell(1,1); -% F_store_truth_3 =nan(1,7); -% -% %perform the true ANOVA once -% thisy = y_3; -% thisepoch = epoch_var_3; -% thiscond =cond_var_3; -% thissubj=subj_var_3; -% thisroi =roi_var_3; -% [P_truth_3,T_truth_3,~] = anovan(thisy,{thissubj,thisepoch,thiscond,thisroi},'model','full','random',1,'varnames',{'subj','epoch','cond','roi'},'display','off'); -% [F_store_truth_3] = RMAOV33_gh([thisy,thisepoch,thiscond,thisroi,thissubj],0.05); -% -% clear thisroiidx thisepoch thiscond thissubj thisy -% -% %[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to -% %correct? confirm w/ TCS -% -% % now compute n_iter and store output, compare to true F-values for each -% % factor and each interaction -% -% iter = 1000; -% fprintf(sprintf('computing %i 3-way ANOVAs',iter)) -% -% T_iter_3 =cell(iter,1); -% P_iter_3 =cell(iter,1); -% F_store_iter_3 =nan(iter,7); -% -% -% % 3-way anova for each ROI -% tic -% -% for xx=1:iter -% -% y_shuf=y_3; %start with empty each iter -% -% for sbj = 1:length(subj) -% thisidx = subj_var==sbj; -% tmp_y = y(thisidx); -% shuff_idx = randperm(size(tmp_y,1))'; -% thisidx_val = find(thisidx); -% y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); -% clear thisidx shuff_idx thisidx_val tmp_y -% end -% -% thisepoch = epoch_var_3; %maintain og idx for all IVs -% thiscond =cond_var_3; -% thissubj=subj_var_3; -% thisroi =roi_var_3; -% -% [P_iter_3{xx},T_iter_3{xx},~] = anovan(y_shuf,{thissubj,thisepoch,thiscond,thisroi},'model','full','random',1,'varnames',{'subj','epoch','cond','roi'},'display','off'); -% [F_store_iter_3(xx,:)] = RMAOV33_gh([y_shuf,thisepoch,thiscond,thisroi,thissubj],0.05); -% -% clear thisidx thisepoch thiscond thissubj thisy tmpy shuffidx thisroi -% -% -% %[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to -% %correct? -% -% end -% -% toc -% -% %plot F distributions -% %which F vals do we want? idx is as follows {iter,1}{iv_str_3,6} %1 is -% %fixed because we store iters vertically(1 column). 6 is fixed bc this is the Fval col -% iv_str_3 ={'Source';'subj';'epoch';'cond';'roi';'subj*epoch';... -% 'subj*cond';'subj*roi';'epoch*cond'; 'epoch*roi';'cond_roi';... -% 'subj*epoch*cond'; 'subj*epoch*roi'; 'subj*cond*roi';'epoch*cond*roi';'subj*epoch*cond*roi';... -% 'Error';'Total'}; -% -% -% col_idx = 6; % F val col -% -% %what factor do we care about? concurs w iv_str_3 -% which_effect = [3 4 5 9 10 11 15]; %3 epoch 4 cond 5 roi 9 epoch*cond 10 epoch*cond 11 cond*roi 15 epohc*cond*roi -% exact_store_tmp=[]; -% -% exact_store_3=[]; -% figure('name','3way perm; anovan') -% for ww =1:length(which_effect) -% extract_vals=[]; -% -% for ii=1:iter -% extract_vals = [extract_vals; T_iter_3{ii}{which_effect(ww),col_idx}]; -% end -% hold on; -% -% subplot(1,length(which_effect),ww) -% histogram(extract_vals) -% line([T_truth_3{which_effect(ww),col_idx} T_truth_3{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') -% title(iv_str_3{which_effect(ww)},'Interpreter','none'); -% exact_p = sum(extract_vals >= T_truth_3{which_effect(ww),col_idx})/iter; -% text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) -% exact_store_3(ww) = [exact_store_tmp; exact_p]; -% clear exact_p -% -% if ww ==1 -% xlabel('T-stat') -% ylabel('Frequency of T-stat') -% else -% end -% -% end -% -% ta_3 = table(exact_store_3(:,1),exact_store_3(:,2),exact_store_3(:,3),exact_store_3(:,4),exact_store_3(:,5),exact_store_3(:,6),exact_store_3(:,7)); -% ta_3.Properties.VariableNames={'Epoch','Cond','ROI','EpochCond','EpochROI','CondROI','EpochCondROI'}; -% -% % make analagous plot for RMAOV33 to compare perms -% -% %what factor do we care about? concurs w iv_str_3 -% which_effect_rm_3 = [1 2 3 4 5 6 7]; %3 epoch 4 cond 5 roi 9 epoch*cond 10 epoch*cond 11 cond*roi 15 epohc*cond*roi -% rm_str ={'epoch','cond','roi','epochcond','epochroi','condroi','epochcondroi'}; -% exact_store_tmp_rm=[]; -% exact_store_rm3=[]; -% -% figure('name','3way perm; RMOV33') -% for ww =1:length(which_effect_rm_3) -% extract_vals=[]; -% -% for ii=1:iter -% extract_vals = [extract_vals; F_store_iter_3(ii,which_effect_rm_3(ww))]; -% end -% hold on; -% -% subplot(1,length(which_effect_rm_3),ww) -% histogram(extract_vals) -% % -% line([F_store_truth_3(which_effect_rm_3(ww)) F_store_truth_3(which_effect_rm_3(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') -% title(rm_str{which_effect_rm_3(ww)},'Interpreter','none'); -% exact_p = sum(extract_vals >= F_store_truth_3(which_effect_rm_3(ww)))/iter; -% text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) -% exact_store_rm3(ww) = [exact_store_tmp_rm; exact_p]; -% clear exact_p -% -% if ww ==1 -% xlabel('T-stat') -% ylabel('Frequency of T-stat') -% else -% end -% -% end +cu =[1 2]; +thisfide_store = []; +the_y_store= []; + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + for cc = 1:length(cu) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisfide_store(dd,vv,cc,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2)); %targ aligned + the_y_store = [the_y_store; thisfide_store(dd,vv,cc,ss) dd vv cc ss]; + end + + end + + + end +end + +% sort y_store into individual columns for feasibility/ transparency +y_3 = the_y_store(:,1); +epoch_var_3 = the_y_store(:,2); +roi_var_3 =the_y_store(:,3); +cond_var_3 =the_y_store(:,4); +subj_var_3 = the_y_store(:,5); + +P_truth_3= cell(1,1); +T_truth_3= cell(1,1); +F_store_truth_3 =nan(1,7); + +%perform the true ANOVA once +thisy = y_3; +thisepoch = epoch_var_3; +thiscond =cond_var_3; +thissubj=subj_var_3; +thisroi =roi_var_3; +[P_truth_3,T_truth_3,~] = anovan(thisy,{thissubj,thisepoch,thiscond,thisroi},'model','full','random',1,'varnames',{'subj','epoch','cond','roi'}); +[F_store_truth_3] = RMAOV33_gh([thisy,thisepoch,thiscond,thisroi,thissubj],0.05); + +clear thisroiidx thisepoch thiscond thissubj thisy + +%[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to +%correct? confirm w/ TCS + +% now compute n_iter and store output, compare to true F-values for each +% factor and each interaction + +iter = 1000; +fprintf(sprintf('computing %i 3-way ANOVAs',iter)) + +T_iter_3 =cell(iter,1); +P_iter_3 =cell(iter,1); +F_store_iter_3 =nan(iter,7); + + +% 3-way anova for each ROI +tic + +for xx=1:iter + + y_shuf=y_3; %start with empty each iter + + for sbj = 1:length(subj) + thisidx = subj_var==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + clear thisidx shuff_idx thisidx_val tmp_y + end + + thisepoch = epoch_var_3; %maintain og idx for all IVs + thiscond =cond_var_3; + thissubj=subj_var_3; + thisroi =roi_var_3; + + [P_iter_3{xx},T_iter_3{xx},~] = anovan(y_shuf,{thissubj,thisepoch,thiscond,thisroi},'model','full','random',1,'varnames',{'subj','epoch','cond','roi'},'display','off'); + [F_store_iter_3(xx,:)] = RMAOV33_gh([y_shuf,thisepoch,thiscond,thisroi,thissubj],0.05); + + clear thisidx thisepoch thiscond thissubj thisy tmpy shuffidx thisroi + + +%[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to +%correct? + +end + +toc + +%plot F distributions +%which F vals do we want? idx is as follows {iter,1}{iv_str_3,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is the Fval col +iv_str_3 ={'Source';'subj';'epoch';'cond';'roi';'subj*epoch';... + 'subj*cond';'subj*roi';'epoch*cond'; 'epoch*roi';'cond_roi';... + 'subj*epoch*cond'; 'subj*epoch*roi'; 'subj*cond*roi';'epoch*cond*roi';'subj*epoch*cond*roi';... + 'Error';'Total'}; + + +col_idx = 6; % F val col + +%what factor do we care about? concurs w iv_str_3 +which_effect = [3 4 5 9 10 11 15]; %3 epoch 4 cond 5 roi 9 epoch*cond 10 epoch*cond 11 cond*roi 15 epohc*cond*roi +exact_store_tmp=[]; + +exact_store_3=[]; +figure('name','3way perm; anovan') +for ww =1:length(which_effect) + extract_vals=[]; + +for ii=1:iter + extract_vals = [extract_vals; T_iter_3{ii}{which_effect(ww),col_idx}]; +end +hold on; + +subplot(1,length(which_effect),ww) +histogram(extract_vals) +line([T_truth_3{which_effect(ww),col_idx} T_truth_3{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') +title(iv_str_3{which_effect(ww)},'Interpreter','none'); +exact_p = sum(extract_vals >= T_truth_3{which_effect(ww),col_idx})/iter; +text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) +exact_store_3(ww) = [exact_store_tmp; exact_p]; +clear exact_p + +if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') +else +end + +end + +ta_3 = table(exact_store_3(:,1),exact_store_3(:,2),exact_store_3(:,3),exact_store_3(:,4),exact_store_3(:,5),exact_store_3(:,6),exact_store_3(:,7)); +ta_3.Properties.VariableNames={'Epoch','Cond','ROI','EpochCond','EpochROI','CondROI','EpochCondROI'}; + +% make analagous plot for RMAOV33 to compare perms + +%what factor do we care about? concurs w iv_str_3 +which_effect_rm_3 = [1 2 3 4 5 6 7]; %3 epoch 4 cond 5 roi 9 epoch*cond 10 epoch*cond 11 cond*roi 15 epohc*cond*roi +rm_str ={'epoch','cond','roi','epochcond','epochroi','condroi','epochcondroi'}; +exact_store_tmp_rm=[]; +exact_store_rm3=[]; + +figure('name','3way perm; RMOV33') +for ww =1:length(which_effect_rm_3) + extract_vals=[]; + +for ii=1:iter + extract_vals = [extract_vals; F_store_iter_3(ii,which_effect_rm_3(ww))]; +end +hold on; + +subplot(1,length(which_effect_rm_3),ww) +histogram(extract_vals) % -% %%%% TMP COM +line([F_store_truth_3(which_effect_rm_3(ww)) F_store_truth_3(which_effect_rm_3(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') +title(rm_str{which_effect_rm_3(ww)},'Interpreter','none'); +exact_p = sum(extract_vals >= F_store_truth_3(which_effect_rm_3(ww)))/iter; +text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) +exact_store_rm3(ww) = [exact_store_tmp_rm; exact_p]; +clear exact_p + +if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') +else +end + +end + +%%%% TMP COM + %% 2-way ANOVA permutation % get fidelity , over average delay epochs, for each condition, permutation test %%%% this takes ~24 minutes to run!!!!! @@ -807,9 +811,7 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) clear thisroiidx thisepoch thiscond thissubj thisy tmpy shuffidx - - %[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to - %correct? + end end @@ -831,7 +833,6 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) %what factor do we care about? concurs w iv_str(vs) which_effect = [3 4 7]; %3 epoch 4 cond 7epoch*cond exact_store_tmp=[]; - for vv =1:length(ROIs) figure('name','2-way perm;anovan') for ww =1:length(which_effect) @@ -845,7 +846,7 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) histogram(extract_vals) line([T_truth{vv}{which_effect(ww),col_idx} T_truth{vv}{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') title(iv_str{which_effect(ww)},'Interpreter','none'); - exact_p = sum(extract_vals >= T_truth{vv}{which_effect(ww),col_idx})/iter; + exact_p = sum(extract_vals >= T_truth{vv}{which_effect(ww),col_idx})/iter; text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) exact_store(vv,ww) = [exact_store_tmp; exact_p]; clear exact_p @@ -859,46 +860,14 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) end end ta = table(ROIs',exact_store(:,1),exact_store(:,2),exact_store(:,3)); -ta.Properties.VariableNames={'ROIs','Epoch','Cond','EpochCond'}; +ta.Properties.VariableNames={'ROIs','Epoch','Cond','EpochCond'} -% plot for RMAOV2 output -iv_str_rm ={'epoch','cond','epoch*cond'}; -which_effect_rm = [1 2 3]; -exact_store_tmp=[]; -exact_store_rm_2 =nan(length(ROIs),length(which_effect_rm)); -for vv =1:length(ROIs) - figure('name','2-way perm; RMAOV2') - - for ww =1:length(which_effect_rm) - extract_vals=[]; - for ii=1:iter - extract_vals = [extract_vals; F_store_iter_2(vv,ii,which_effect_rm(ww))]; - end - hold on; - - subplot(1,length(which_effect_rm),ww) - histogram(extract_vals) - line([F_store_truth_2(vv,which_effect_rm(ww)) F_store_truth_2(vv,which_effect_rm(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') - title(iv_str_rm{which_effect_rm(ww)},'Interpreter','none'); - exact_p = sum(extract_vals >= F_store_truth_2(vv,which_effect_rm(ww)))/iter; - text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) - exact_store_rm_2(vv,ww) = [exact_store_tmp; exact_p]; - clear exact_p - - if ww ==1 - xlabel('T-stat') - ylabel('Frequency of T-stat') - else - end - - end -end %% plot sigs on the subplots -- anovan sig_colors = lines(3); %correct them pvals -p_fdr_perm= nan(3); +p_fdr_perm= nan(3,1); p_masked_perm= nan(length(ROIs),3); for ee =1:3 %epoch var @@ -907,7 +876,7 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) end -sig_mrkr ={'o','+','x'}; +sig_mrkr ={'o','+','x'}; %epoch, cond, epoch x cond int y_mod = [.1 .15 .2]; for vv = 1:length(ROIs) for ee =1:3 @@ -927,46 +896,9 @@ function spDist_withinROI_stats_Figure4(subj,sess,ROIs) end -% %perform again for rmaov2 -% for vv = 1:length(ROIs) -% for ee =1:3 -% figure(fidlines); hold on; -% subplot(1,length(ROIs),vv) -% if exact_store_rm_2(vv,ee) >0.01 && exact_store_rm_2(vv,ee) <= 0.05 -% text(max(xlim)-(.7*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),'*','color',sig_colors(ee,:)) -% elseif exact_store_rm_2(vv,ee) >0.001 && exact_store_rm_2(vv,ee) <= 0.01 -% text(max(xlim)-(.7*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),'**','color',sig_colors(ee,:)) -% elseif exact_store_rm_2(vv,ee) <= 0.001 -% text(max(xlim)-(.7*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),'***','color',sig_colors(ee,:)) -% -% -% end -% end -% -% end -fprintf('2-way computations are done. ... onto 3-way') -% tmp -% %% plot sigs on the subplots - 3-way ... TODO: i dont think this is necessary / would not make sense on the figure 4 ROI plot -% % sig_colors = lines(3); -% y_mod =[.1 .15 .2]; -% -% for vv = 1:length(ROIs) -% for ee =1:3 -% figure(linep); hold on; -% subplot(1,length(ROIs),vv) -% if exact_store(vv,ee) >0.01 && exact_store(vv,ee) <= 0.05 -% text(max(xlim)-(.7*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),'*','color',sig_colors(ee,:)) -% elseif exact_store(vv,ee) >0.001 && exact_store(vv,ee) <= 0.01 -% text(max(xlim)-(.7*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),'**','color',sig_colors(ee,:)) -% elseif exact_store(vv,ee) <= 0.001 -% text(max(xlim)-(.7*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),'***','color',sig_colors(ee,:)) -% -% -% end -% end -% -% end +fprintf('done') + return diff --git a/spDist_withinROI_stats_Figure4.m~ b/spDist_withinROI_stats_Figure4.m~ new file mode 100644 index 0000000..b09747c --- /dev/null +++ b/spDist_withinROI_stats_Figure4.m~ @@ -0,0 +1,904 @@ + + +function spDist_withinROI_stats_Figure4(subj,sess,ROIs) +% stats checked and confirmed 11/10/2020 +% w /updated middle epoch +root = spDist_loadRoot;%'/share/data/spDist/'; %updated root + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'AY','CC','EK','KD','MR','SF','XL'}; +end + +if nargin < 2 || isempty(sess) + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1V2V3','V3AB','hV4','LO1','IPS0IPS1','IPS2IPS3','sPCS'}; +end + +func_suffix = 'surf'; + +plot_hists = 0; % whether to plot histograms of shuffled stat values or not... + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +%t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + + +delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; + +% number of iterations for permutation... +iter = 1000; + + +% seed random number generator: +rng(spDist_randSeed); + + + +%% load data +startidx = 1; +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data_ru = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data_ru.recons{1},1); + all_recons = cell(size(data_ru.recons)); + for aa = 1:length(data_ru.recons) + all_recons{aa} = nan(nblankt,size(data_ru.recons{aa},2),size(data_ru.recons{aa},3)); + end + + + all_conds = nan(nblankt,size(data_ru.c_all,2)); + all_angs = nan(nblankt,size(data_ru.a_all,2)); + + all_fidelity = nan(nblankt,size(data_ru.recons{1},3),length(data_ru.recons)); % timecoruse of fidelity for each alignment condition + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + all_r = nan(nblankt,1); + + + angs = data_ru.angs; + tpts = data_ru.delay_tpts; + + + end + + + + thisidx = startidx:(startidx+size(data_ru.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data_ru.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data_ru.recons{aa},2)); + end + + + all_conds(thisidx,:) = data_ru.c_all; + all_angs(thisidx,:) = data_ru.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data_ru.sess_all; + + % run and session combined for shuffled t-test within epoch + all_r(thisidx) = data_ru.sess_all*100+data_ru.r_all; + + + startidx = thisidx(end)+1; + + clear data; + + + end + +end + + +%% which tpts are we plotting throughout? + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + +%% do this, over average delay epochs, for each condition +cu = [1 2]; +dist_colors = spDist_condColors;% [0.7100 0.2128 0.4772; 0 0 1;]; %first is RED, second is blue, beware its opposite matlab (lines(2)). this color scheme is in alignment w precue colors in actual exp (mag - mgs, cyan -dist) +cond_colors = dist_colors; + +reconcomp = figure('name','reconcomp'); + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; + + for cc = 1:length(cu) + thisdata = nan(length(subj),length(angs)); + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisdata(ss,:) = mean(mean(all_recons{1}(thisidx,:,delay_tpts{dd}),3),1); + + end + + % added sqrt here (TCS) + my_sem = std(thisdata,[],1)/sqrt(length(subj)); + + % TCS: plot actual values, not min-removed + h(cc) = plot(linspace(-180,180,90),mean(thisdata,1),'-','LineWidth',0.5,'color',cond_colors(cc,:)); + + hold on; + + plot(linspace(-180,180,90),mean(thisdata,1)+1.*my_sem,'-','LineWidth',.1,'color',cond_colors(cc,:),'HandleVisibility','off') + + plot(linspace(-180,180,90),mean(thisdata,1)-1.*my_sem,'-','LineWidth',.1,'color',cond_colors(cc,:),'HandleVisibility','off') + + %color in btwn +/- SEM + % TCS: plot actual values, not min removed + %btwn_fill = [(mean(thisdata,1))+1.*my_sem fliplr((mean(thisdata,1))-1.*fliplr(my_sem))]; % TCS: fliplr also for my_sem? + btwn_fill = [(mean(thisdata,1))+1.*my_sem fliplr((mean(thisdata,1)-1.*(my_sem)))]; % geh test + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_fill,cond_colors(cc,:),'linestyle','none','facealpha',0.3); + + line([min(xlim) max(xlim)], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') + + clear my_sem btwn_fill + end + + % things to do for every axis: + set(gca,'TickDir','out','XTick',-180:90:180,'XTickLabel',[],'TickLength',1.5*get(gca,'TickLength')); + + + % TCS: here, I added specific XTicks (and ensured XLims are + % -180/180) + if vv == 1 && dd== 1 + ylabel(sprintf('Pre-distractor \n %0.01f to %0.01f s',delay_tpt_range(dd,1),delay_tpt_range(dd,2))); + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','','0','','180'}); + + elseif vv == 1 && dd== 2 + ylabel(sprintf('During distractor \n %0.01f to %0.01f s',delay_tpt_range(dd,1),delay_tpt_range(dd,2))); + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','','0','','180'}); + + elseif vv == 1 && dd== 3 + ylabel(sprintf('Post-distractor \n %0.01f to %0.01f s',delay_tpt_range(dd,1),delay_tpt_range(dd,2))); + if dd == length(delay_tpts) + xlabel('Position (\circ)'); + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','','0','','180'}); + + end + end + if dd == 1 + title(ROIs{vv}); + end + + if vv ~= 1 + set(gca,'YTickLabel',[]); + end + + xlim([-180 180]); + hold off; + end +end +match_ylim(get(gcf,'Children')); +set(gcf,'position', [ 121 287 1574 503]) +%set(gcf,'position', [ 23 245 2386 453]) + + + +%% t-test between condition during each epoch against shuffled null +% +% to shuffle: +% - compute n_runs fidelity for each condition for each subj +% - shuffle labels of *these data* 1000 times, then average across +% condition/subj, compute null T distribution; compute p against this +% (two-tailed) (TODO) + + +% figure out how many total runs... (hack...) +nruns = 0; +for ss = 1:length(subj) + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + clear ru; +end + + +% store 'real' T (ROI x epoch) +fidelity_condcompare_realT = nan(length(ROIs),size(delay_tpt_range,1)); + +% store iter shuffled T's (ROI x epoch x iter) +fidelity_condcompare_shufT = nan(length(ROIs),size(delay_tpt_range,1),iter); + +fprintf('Computing null T-dist for condition comparison w/ in epochs\n'); + +for vv = 1:length(ROIs) + + for tt = 1:size(delay_tpt_range,1) + + fprintf('%s, Epoch %i\n',ROIs{vv},tt); + tic; + thisd = nan(length(subj),2); + for ss = 1:length(subj) + for cc = 1:2 + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cc; + thisd(ss,cc) = mean( mean( all_fidelity(thisidx,delay_tpts{tt},1) , 2), 1 ); % mean across tpts (inner), trials (outer) + clear thisidx; + end + end + + % compute real T + [~,~,~,thisstats] = ttest(thisd(:,1),thisd(:,2)); + fidelity_condcompare_realT(vv,tt) = thisstats.tstat; clear thisstats thisd; + + % create a data structure we can shuffle: for each subj/ROI/cond, + % n_runs datapoints + data_ru = nan(nruns,1); + labels_ru = nan(nruns,2); % condition, subj + + tmpidx = 1; % where to put this run.... + + for ss = 1:length(subj) + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + for rr = 1:length(ru) + for cc = 1:2 + thisidx = all_r==ru(rr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==cc; + data_ru( tmpidx) = mean( mean( all_fidelity(thisidx,delay_tpts{tt},1) , 2), 1 ); + labels_ru(tmpidx,:) = [cc ss]; + tmpidx = tmpidx+1; + end + end + end + + + % iter times.. + for ii = 1:iter + + tmpdata = nan(size(data_ru)); + + % within each subj, shuffle condition labels + for ss = 1:length(subj) + % logical indices for this subject, across runs + thisidx = labels_ru(:,2)==ss; + + % list of numerical indices - plug data in here + subjidx = find(thisidx); + + % used to shuffle subjidx + shufidx = randperm(length(subjidx)); + + % tmpdata will have data, shuffled wrt condition label, for + % each subj + tmpdata(subjidx) = data_ru(subjidx(shufidx)); + + clear thisidx subjidx shufidx; + end + + + % generate data structure for T-test (average across + % runs within condition label within each subj) + thisd = nan(length(subj),2); + for ss = 1:length(subj) + for cc = 1:2 + thisidx = labels_ru(:,1)==cc & labels_ru(:,2)==ss; + thisd(ss,cc) = mean( tmpdata(thisidx), 1 ); % mean across *shuffled* data + clear thisidx; + end + end + + % compute shuffled T + [~,~,~,thisstats] = ttest(thisd(:,1),thisd(:,2)); + fidelity_condcompare_shufT(vv,ii) = thisstats.tstat; clear thisstats + + clear thisd tmpdata; + + end + toc; + end + +end + + +% compute p-values (ROIs x epochs) +fidelity_condcompare_pval = 2 * min(mean(fidelity_condcompare_shufT<=fidelity_condcompare_realT,3), mean(fidelity_condcompare_shufT>=fidelity_condcompare_realT,3)); +fidelity_condcompare_fdrthresh = fdr(fidelity_condcompare_pval(:),0.05); + +%% fidelity line plot per ROI & true 2-way anova stat + +% TCS: replace w/ loading colors from file +dist_colors = spDist_condColors; +cond_colors = dist_colors; + +thisd_store =[]; + +% TCS: should add option for single-subj lines here too... + +plot_indiv = 1; % if 1, plot individual subj lines in line plot, otherwise, don't. +hoffset = 0.15; % +/- this much + +fidlines = figure('Name','Fidelity lines'); + +h=[]; + +for vv = 1:length(ROIs) + thisd = []; %recon data + + % TCS: moved from an inner loop to here + subplot(1,length(ROIs),vv);hold on; + + for dd =1:length(delay_tpts) + + + for cc = 1:length(cu) + for ss = 1:length(subj) + + + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisd(dd,cc,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1))); + thisd_store = [thisd_store; mean(mean(all_fidelity(thisidx,delay_tpts{dd},1))) dd vv cc ss]; + + end + % TCS: added sqrt here + my_sem(dd,cc) = std(thisd(dd,cc,:))/sqrt(length(subj)); + end + + % if we want, this is a good place to plot lines connecting indiv + % subj here + if plot_indiv == 1 + plot(dd+hoffset*[-1;1],squeeze(thisd(dd,:,:)),'-','LineWidth',0.25,'Color',[0.4 0.4 0.4]); + hold on; + plot(dd+hoffset*-1,squeeze(thisd(dd,1,:)),'.','markersize',10,'Color',dist_colors(1,:)); + hold on; + plot(dd+hoffset*1,squeeze(thisd(dd,2,:)),'.','markersize',10,'Color',dist_colors(2,:)); + end + + + end + + for cc =1:length(cu) + % TCS: matched these to HRFs (dot makes it slightly easier to see + % value when overlapping...) + h(cc) = plot([1 2 3],mean(thisd(:,cc,:),3)','o-','color',cond_colors(cc,:),'linewidth',2,'MarkerSize',8,'MarkerFaceColor',cond_colors(cc,:)); + + for dd =1:length(delay_tpts) + plot([dd dd],[mean(thisd(dd,cc,:),3)+1.*my_sem(dd,cc) mean(thisd(dd,cc,:),3)-1.*my_sem(dd,cc)], '-','LineWidth',2,'color',cond_colors(cc,:)) + end + end + clear thisidx + clear thisd + + line([0 4], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') % geh add y =0 baseline + + xlim([0.5 3.5]) + if vv ==1 + title(ROIs{vv}) + + ylabel('WM target Fidelity') + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','Epoch 1','Epoch 2','Epoch 3',''},'XTickLabelRotation',45,'TickDir','out'); + set(gca,'Ytick',[0 .4 .8 ],'TickDir','out'); + + else + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out'); + set(gca,'Ytick',[0 .4 .8 ],'TickDir','out'); + title(ROIs{vv}) + end + + if plot_indiv + ylim([-0.1 1]); + + else + ylim([0 0.65]) + end + + + +end +set(gcf,'position', [ 121 287 1574 503]) +y = thisd_store(:,1); +epoch_var = thisd_store(:,2); +roi_var =thisd_store(:,3); +cond_var =thisd_store(:,4); +subj_var = thisd_store(:,5); + +h_roi = nan(length(ROIs),3); +p_roi = nan(length(ROIs),3); +t_stats = cell(length(ROIs),3); +p_fdr =nan(length(ROIs),3); +p_masked =nan(length(ROIs),3); + + +% t-test across epoch per condition +for vv = 1:length(ROIs) + + for ee =1:3 %epoch var + thisidx_nod = roi_var ==vv & epoch_var == ee & cond_var ==1; + thisidx_dist = roi_var ==vv & epoch_var == ee & cond_var ==2; + [h_roi(vv,ee), p_roi(vv,ee),~,t_stats{vv,ee}] = ttest(y(thisidx_nod),y(thisidx_dist)); + clear thisidx_nod thisidx_dist + end + if vv == length(ROIs) && ee ==3 + [p_fdr, p_masked] = fdr(p_roi(:),0.05); % TCS: added (:) to p_roi + corr_pval_ind = p_roi(p_masked); + else + end + +end +clear vv ee +% perm ttest +for zz = 1:iter + + for vv = 1:length(ROIs) + + for ee =1:3 %epoch var + y_shuf= y; + + for sbj = 1:length(subj) + thisidx = roi_var ==vv & subj_var==sbj & epoch_var ==ee; % dont select by condition + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + end + + thisidx_nod = roi_var ==vv & epoch_var == ee & cond_var ==1; + thisidx_dist = roi_var ==vv & epoch_var == ee & cond_var ==2; + [h_roi_iter(vv,ee,zz), p_roi_iter(vv,ee,zz),~,t_stats_iter(vv,ee,zz)] = ttest(y_shuf(thisidx_nod),y(thisidx_dist)); + clear thisidx_nod thisidx_dist y_shuf + end + + if vv == length(ROIs) && ee ==3 + [p_fdr_iter(:,:,zz), p_masked_iter(:,:,zz)] = fdr(p_roi_iter(:,:,zz),0.05); + else + end + + end + clear vv ee +end + +% TCS: why are some struct arrays and others cell arrays? + +%% plot results of shuffling (hist) +if plot_hists == 1 + figure('name','ttest perm') + for vv =1:length(ROIs) + for ee =1:3 + subplot(1,length(ROIs),vv); hold on; + histogram([t_stats_iter(vv,ee,:).tstat]) + line([t_stats{vv,ee}.tstat t_stats{vv,ee}.tstat], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + exact_p = sum([t_stats_iter(vv,ee,:).tstat] >= t_stats{vv,ee}.tstat)/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%0.3f',exact_p),'FontSize',9) + end + end +end + +%% add significance markers to figure +% this is for parametric stats: +% for vv= 1:length(ROIs) +% for ee =1:3 +% figure(reconcomp); hold on; +% subplot(length(delay_tpts),length(ROIs),(ee-1)*length(ROIs)+vv); hold on; +% +% if p_roi(vv,ee) > p_fdr && p_roi(vv,ee) <= 0.05 +% text(max(xlim)-(.3*max(xlim)),max(ylim)-(.3*max(ylim)),'*','color',[.5 .5 .5],'fontsize',30) +% elseif p_roi(vv,ee) <= p_fdr +% text(max(xlim)-(.3*max(xlim)),max(ylim)-(.3*max(ylim)),'*','color','k','fontsize',30) +% +% end +% end +% end + +% for shuffled stats (TCS) +for vv= 1:length(ROIs) + for ee =1:size(delay_tpt_range,1) + + figure(reconcomp); hold on; + subplot(length(delay_tpts),length(ROIs),(ee-1)*length(ROIs)+vv); hold on; + + if fidelity_condcompare_pval(vv,ee) > fidelity_condcompare_fdrthresh && fidelity_condcompare_pval(vv,ee) <= 0.05 + text(max(xlim)-(.3*max(xlim)),max(ylim)-(.3*max(ylim)),'*','color',[.5 .5 .5],'fontsize',20) + elseif fidelity_condcompare_pval(vv,ee) <= fidelity_condcompare_fdrthresh + text(max(xlim)-(.3*max(xlim)),max(ylim)-(.3*max(ylim)),'*','color','k','fontsize',20) + end + end +end + +%% shuffled ANOVAs (geh) +P_truth ={}; +T_truth = {}; +F_store_truth_2=[]; + +for vv = 1:length(ROIs) + + thisroiidx = roi_var ==vv; + thisy = y(thisroiidx); + thisepoch = epoch_var(thisroiidx); + thiscond =cond_var(thisroiidx); + thissubj=subj_var(thisroiidx); + [P_truth{vv},T_truth{vv},~] = anovan(thisy,{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'}) %,'display','off'); + [F_store_truth_2(vv,:)] = RMAOV2_gh([thisy,thisepoch,thiscond,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj thisy + + +end + + + +match_xlim(get(gcf,'Children')); +legend(h, {'No distractor', 'Distractor'}) +set(gcf,'position', [ 23 245 2386 453]) +%% 3-way ANOVA permutation +% get fidelity , over average delay epochs, for each condition, permutation test +%%%% this takes ~2.7 hrs minutes to run!!!!! (anovan) + +cu =[1 2]; +thisfide_store = []; +the_y_store= []; + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + for cc = 1:length(cu) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisfide_store(dd,vv,cc,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2)); %targ aligned + the_y_store = [the_y_store; thisfide_store(dd,vv,cc,ss) dd vv cc ss]; + end + + end + + + end +end + +% sort y_store into individual columns for feasibility/ transparency +y_3 = the_y_store(:,1); +epoch_var_3 = the_y_store(:,2); +roi_var_3 =the_y_store(:,3); +cond_var_3 =the_y_store(:,4); +subj_var_3 = the_y_store(:,5); + +P_truth_3= cell(1,1); +T_truth_3= cell(1,1); +F_store_truth_3 =nan(1,7); + +%perform the true ANOVA once +thisy = y_3; +thisepoch = epoch_var_3; +thiscond =cond_var_3; +thissubj=subj_var_3; +thisroi =roi_var_3; +[P_truth_3,T_truth_3,~] = anovan(thisy,{thissubj,thisepoch,thiscond,thisroi},'model','full','random',1,'varnames',{'subj','epoch','cond','roi'}); +[F_store_truth_3] = RMAOV33_gh([thisy,thisepoch,thiscond,thisroi,thissubj],0.05); + +clear thisroiidx thisepoch thiscond thissubj thisy + +%[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to +%correct? confirm w/ TCS + +% now compute n_iter and store output, compare to true F-values for each +% factor and each interaction + +iter = 1000; +fprintf(sprintf('computing %i 3-way ANOVAs',iter)) + +T_iter_3 =cell(iter,1); +P_iter_3 =cell(iter,1); +F_store_iter_3 =nan(iter,7); + + +% 3-way anova for each ROI +tic + +for xx=1:iter + + y_shuf=y_3; %start with empty each iter + + for sbj = 1:length(subj) + thisidx = subj_var==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + clear thisidx shuff_idx thisidx_val tmp_y + end + + thisepoch = epoch_var_3; %maintain og idx for all IVs + thiscond =cond_var_3; + thissubj=subj_var_3; + thisroi =roi_var_3; + + [P_iter_3{xx},T_iter_3{xx},~] = anovan(y_shuf,{thissubj,thisepoch,thiscond,thisroi},'model','full','random',1,'varnames',{'subj','epoch','cond','roi'},'display','off'); + [F_store_iter_3(xx,:)] = RMAOV33_gh([y_shuf,thisepoch,thiscond,thisroi,thissubj],0.05); + + clear thisidx thisepoch thiscond thissubj thisy tmpy shuffidx thisroi + + +%[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to +%correct? + +end + +toc + +%plot F distributions +%which F vals do we want? idx is as follows {iter,1}{iv_str_3,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is the Fval col +iv_str_3 ={'Source';'subj';'epoch';'cond';'roi';'subj*epoch';... + 'subj*cond';'subj*roi';'epoch*cond'; 'epoch*roi';'cond_roi';... + 'subj*epoch*cond'; 'subj*epoch*roi'; 'subj*cond*roi';'epoch*cond*roi';'subj*epoch*cond*roi';... + 'Error';'Total'}; + + +col_idx = 6; % F val col + +%what factor do we care about? concurs w iv_str_3 +which_effect = [3 4 5 9 10 11 15]; %3 epoch 4 cond 5 roi 9 epoch*cond 10 epoch*cond 11 cond*roi 15 epohc*cond*roi +exact_store_tmp=[]; + +exact_store_3=[]; +figure('name','3way perm; anovan') +for ww =1:length(which_effect) + extract_vals=[]; + +for ii=1:iter + extract_vals = [extract_vals; T_iter_3{ii}{which_effect(ww),col_idx}]; +end +hold on; + +subplot(1,length(which_effect),ww) +histogram(extract_vals) +line([T_truth_3{which_effect(ww),col_idx} T_truth_3{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') +title(iv_str_3{which_effect(ww)},'Interpreter','none'); +exact_p = sum(extract_vals >= T_truth_3{which_effect(ww),col_idx})/iter; +text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) +exact_store_3(ww) = [exact_store_tmp; exact_p]; +clear exact_p + +if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') +else +end + +end + +ta_3 = table(exact_store_3(:,1),exact_store_3(:,2),exact_store_3(:,3),exact_store_3(:,4),exact_store_3(:,5),exact_store_3(:,6),exact_store_3(:,7)); +ta_3.Properties.VariableNames={'Epoch','Cond','ROI','EpochCond','EpochROI','CondROI','EpochCondROI'}; + +% make analagous plot for RMAOV33 to compare perms + +%what factor do we care about? concurs w iv_str_3 +which_effect_rm_3 = [1 2 3 4 5 6 7]; %3 epoch 4 cond 5 roi 9 epoch*cond 10 epoch*cond 11 cond*roi 15 epohc*cond*roi +rm_str ={'epoch','cond','roi','epochcond','epochroi','condroi','epochcondroi'}; +exact_store_tmp_rm=[]; +exact_store_rm3=[]; + +figure('name','3way perm; RMOV33') +for ww =1:length(which_effect_rm_3) + extract_vals=[]; + +for ii=1:iter + extract_vals = [extract_vals; F_store_iter_3(ii,which_effect_rm_3(ww))]; +end +hold on; + +subplot(1,length(which_effect_rm_3),ww) +histogram(extract_vals) +% +line([F_store_truth_3(which_effect_rm_3(ww)) F_store_truth_3(which_effect_rm_3(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') +title(rm_str{which_effect_rm_3(ww)},'Interpreter','none'); +exact_p = sum(extract_vals >= F_store_truth_3(which_effect_rm_3(ww)))/iter; +text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) +exact_store_rm3(ww) = [exact_store_tmp_rm; exact_p]; +clear exact_p + +if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') +else +end + +end + +%%%% TMP COM + +%% 2-way ANOVA permutation +% get fidelity , over average delay epochs, for each condition, permutation test +%%%% this takes ~24 minutes to run!!!!! + +cu =[1 2]; +thisfide_store = []; +the_y_store= []; + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + for cc = 1:length(cu) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisfide_store(dd,vv,cc,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2)); %targ aligned + the_y_store = [the_y_store; thisfide_store(dd,vv,cc,ss) dd vv cc ss]; + end + + end + + + end +end + + +% sort y_store into individual columns for transparency +y = the_y_store(:,1); +epoch_var = the_y_store(:,2); +roi_var =the_y_store(:,3); +cond_var =the_y_store(:,4); +subj_var = the_y_store(:,5); + + +fprintf(sprintf('computing %i 2-way ANOVAs per ROI',iter)) + +T_iter =cell(length(ROIs),iter); +P_iter =cell(length(ROIs),iter); +F_store_iter_2 = nan(length(ROIs),iter,3); +% two-way anova for each ROI +tic + +for xx=1:iter + for vv = 1:length(ROIs) + y_shuf =y; + thisroiidx = roi_var ==vv; + for sbj = 1:length(subj) + thisidx = roi_var ==vv & subj_var==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + end + thisepoch = epoch_var(thisroiidx); + thiscond =cond_var(thisroiidx); + thissubj=subj_var(thisroiidx); + + [P_iter{vv,xx},T_iter{vv,xx},~] = anovan(y_shuf(thisroiidx),{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'},'display','off'); + [F_store_iter_2(vv,xx,:)] = RMAOV2_gh([y_shuf(thisroiidx),thisepoch,thiscond,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj thisy tmpy shuffidx + + + + end +end +toc + +%plot F distributions; first, for anovan outputs +%which F vals do we want? idx is as follows {iter,1}{iv_str,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is +%the Fval col. iv_str is defined from the vertical organization of the +%output +iv_str ={'Source';'subj';'epoch';'cond';'subj*epoch';... + 'subj*cond';'epoch*cond';... + 'subj*epoch*cond';... + 'Error';'Total'}; + + +col_idx = 6; % F-val col + +%what factor do we care about? concurs w iv_str(vs) +which_effect = [3 4 7]; %3 epoch 4 cond 7epoch*cond +exact_store_tmp=[]; +for vv =1:length(ROIs) + figure('name','2-way perm;anovan') + for ww =1:length(which_effect) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; T_iter{vv,ii}{which_effect(ww),col_idx}]; + end + hold on; + + subplot(1,length(which_effect),ww) + histogram(extract_vals) + line([T_truth{vv}{which_effect(ww),col_idx} T_truth{vv}{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str{which_effect(ww)},'Interpreter','none'); + exact_p = sum(extract_vals >= T_truth{vv}{which_effect(ww),col_idx})/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) + exact_store(vv,ww) = [exact_store_tmp; exact_p]; + clear exact_p + + if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + + end +end +ta = table(ROIs',exact_store(:,1),exact_store(:,2),exact_store(:,3)); +ta.Properties.VariableNames={'ROIs','Epoch','Cond','EpochCond'} + + +%% plot sigs on the subplots -- anovan +sig_colors = lines(3); + +%correct them pvals +p_fdr_perm= nan(3,1); +p_masked_perm= nan(length(ROIs),3); + +for ee =1:3 %epoch var + [p_fdr_perm(ee), p_masked_perm(:,ee)] = fdr(exact_store(:,ee),0.05); + + +end + +sig_mrkr ={'o','+','x'}; %epoch, cond, epoch x cond int +y_mod = [.1 .15 .2]; +for vv = 1:length(ROIs) + for ee =1:3 + figure(fidlines); hold on; + subplot(1,length(ROIs),vv) + + + if exact_store(vv,ee) > p_fdr_perm(ee) && exact_store(vv,ee) <= 0.05 + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color',[.5 .5 .5],'fontsize',15) + elseif exact_store(vv,ee) <= p_fdr_perm(ee) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color','k','fontsize',15) + else + end + + + end + +end + + + +fprintf('done') + + +return diff --git a/spDist_withinROI_stats_suppFigure4.m b/spDist_withinROI_stats_suppFigure4.m new file mode 100644 index 0000000..610f0d1 --- /dev/null +++ b/spDist_withinROI_stats_suppFigure4.m @@ -0,0 +1,902 @@ + + +function spDist_withinROI_stats_suppFigure4(subj,sess,ROIs) + +root = spDist_loadRoot;%'/share/data/spDist/'; %updated root + +task_dir = 'spDist'; + +if nargin < 1 || isempty(subj) + subj = {'AY','CC','EK','KD','MR','SF','XL'}; +end + +if nargin < 2 || isempty(sess) + sess = {{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'},{'spDist1','spDist2'}}; +end + +if nargin < 3 || isempty(ROIs) + ROIs = {'V1','V2','V3','V3AB','hV4','LO1','IPS0','IPS1','IPS2','IPS3','sPCS'}; + +end + +func_suffix = 'surf'; + +plot_hists = 0; % whether to plot histograms of shuffled stat values or not... + +nchan = 8; +which_vox = 0.1; % if > 1 , look for WHICH_VOXvox string; otherwise, look for VE<100*WHICH_VOX> + +smooth_by = 1; % if this is 1, use regular files, otherwise, load smooth_by files + +myTR = 0.75; + +%t_range_to_plot = [-inf 12]; % plot b/w these (s) + +trn_tpts = 7:15; % if blank, load files w/ no _trn%ito%i, otherwise, + +% set up file loading strings for below +if smooth_by == 1 + smooth_str = ''; +else + smooth_str = sprintf('_smooth%i',smooth_by); +end + +if isempty(trn_tpts) + trn_str = ''; +else + trn_str = sprintf('_trn%ito%i',trn_tpts(1),trn_tpts(end)); +end + +if which_vox < 1 + vox_str = sprintf('_VE%03.f',100*which_vox); +else + vox_str = sprintf('_%ivox',which_vox); +end + + + +delay_tpt_range = [3.75 5.25; 8.25 9.75; 10.5 12]; + +% number of iterations for permutation... +iter = 1000; + + +% seed random number generator: +rng(spDist_randSeed); + +%% load data +startidx = 1; +for ss = 1:length(subj) + + for vv = 1:length(ROIs) + + + % just one file to load + fn = sprintf('%s/%s_reconstructions/%s_%s_%s_%s_%ichan%s%s%s_recon_thruTime1.mat',root,task_dir,subj{ss},horzcat(sess{ss}{:}),ROIs{vv},func_suffix,nchan,vox_str,smooth_str,trn_str); + + fprintf('loading %s...\n',fn); + data_ru = load(fn); + + + if vv == 1 && ss == 1 + % initialize variables... + + + nblankt = length(ROIs)*size(data_ru.recons{1},1); + all_recons = cell(size(data_ru.recons)); + for aa = 1:length(data_ru.recons) + all_recons{aa} = nan(nblankt,size(data_ru.recons{aa},2),size(data_ru.recons{aa},3)); + end + + + all_conds = nan(nblankt,size(data_ru.c_all,2)); + all_angs = nan(nblankt,size(data_ru.a_all,2)); + + all_fidelity = nan(nblankt,size(data_ru.recons{1},3),length(data_ru.recons)); % timecoruse of fidelity for each alignment condition + + all_subj = nan(nblankt,1); + all_ROIs = nan(nblankt,1); + all_sess = nan(nblankt,1); + + all_r = nan(nblankt,1); + + + angs = data_ru.angs; + tpts = data_ru.delay_tpts; + + + end + + + + thisidx = startidx:(startidx+size(data_ru.c_all,1)-1); + + for aa = 1:length(all_recons) + all_recons{aa}(thisidx,:,:) = data_ru.recons{aa}; + all_fidelity(thisidx,:,aa) = squeeze(mean(cosd(angs) .* data_ru.recons{aa},2)); + end + + + all_conds(thisidx,:) = data_ru.c_all; + all_angs(thisidx,:) = data_ru.a_all; + + + all_subj(thisidx) = ss; + + + all_ROIs(thisidx) = vv; + + all_sess(thisidx) = data_ru.sess_all; + + % run and session combined for shuffled t-test within epoch + all_r(thisidx) = data_ru.sess_all*100+data_ru.r_all; + + + startidx = thisidx(end)+1; + + clear data; + + + end + +end + + +%% which tpts are we plotting throughout? + +delay_tpts = cell(size(delay_tpt_range,1),1); +for dd = 1:size(delay_tpt_range,1) + delay_tpts{dd} = (tpts*myTR) >= delay_tpt_range(dd,1) & (tpts*myTR) < delay_tpt_range(dd,2); +end + +%% do this, over average delay epochs, for each condition +cu = [1 2]; +dist_colors = spDist_condColors;% [0.7100 0.2128 0.4772; 0 0 1;]; %first is RED, second is blue, beware its opposite matlab (lines(2)). this color scheme is in alignment w precue colors in actual exp (mag - mgs, cyan -dist) +cond_colors = dist_colors; + +reconcomp = figure('name','reconcomp'); + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + subplot(length(delay_tpts),length(ROIs),(dd-1)*length(ROIs)+vv); hold on; + + for cc = 1:length(cu) + thisdata = nan(length(subj),length(angs)); + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisdata(ss,:) = mean(mean(all_recons{1}(thisidx,:,delay_tpts{dd}),3),1); + + end + + % added sqrt here (TCS) + my_sem = std(thisdata,[],1)/sqrt(length(subj)); + + % TCS: plot actual values, not min-removed + h(cc) = plot(linspace(-180,180,90),mean(thisdata,1),'-','LineWidth',0.5,'color',cond_colors(cc,:)); + + hold on; + + plot(linspace(-180,180,90),mean(thisdata,1)+1.*my_sem,'-','LineWidth',.1,'color',cond_colors(cc,:),'HandleVisibility','off') + + plot(linspace(-180,180,90),mean(thisdata,1)-1.*my_sem,'-','LineWidth',.1,'color',cond_colors(cc,:),'HandleVisibility','off') + + %color in btwn +/- SEM + % TCS: plot actual values, not min removed + %btwn_fill = [(mean(thisdata,1))+1.*my_sem fliplr((mean(thisdata,1))-1.*fliplr(my_sem))]; % TCS: fliplr also for my_sem? + btwn_fill = [(mean(thisdata,1))+1.*my_sem fliplr((mean(thisdata,1)-1.*(my_sem)))]; % geh test + fill([linspace(-180,180,90) fliplr(linspace(-180,180,90))],btwn_fill,cond_colors(cc,:),'linestyle','none','facealpha',0.3); + + line([min(xlim) max(xlim)], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') + + clear my_sem btwn_fill + end + + % things to do for every axis: + set(gca,'TickDir','out','XTick',-180:90:180,'XTickLabel',[],'TickLength',1.5*get(gca,'TickLength')); + + + % TCS: here, I added specific XTicks (and ensured XLims are + % -180/180) + if vv == 1 && dd== 1 + ylabel(sprintf('Pre-distractor \n %0.01f to %0.01f s',delay_tpt_range(dd,1),delay_tpt_range(dd,2))); + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','','0','','180'}); + + elseif vv == 1 && dd== 2 + ylabel(sprintf('During distractor \n %0.01f to %0.01f s',delay_tpt_range(dd,1),delay_tpt_range(dd,2))); + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','','0','','180'}); + + elseif vv == 1 && dd== 3 + ylabel(sprintf('Post-distractor \n %0.01f to %0.01f s',delay_tpt_range(dd,1),delay_tpt_range(dd,2))); + if dd == length(delay_tpts) + xlabel('Position (\circ)'); + set(gca,'XTick',-180:90:180,'XTickLabel',{'-180','','0','','180'}); + + end + end + if dd == 1 + title(ROIs{vv}); + end + + if vv ~= 1 + set(gca,'YTickLabel',[]); + end + + xlim([-180 180]); + hold off; + end +end +match_ylim(get(gcf,'Children')); +set(gcf,'position', [ 121 287 1574 503]) + +%% t-test between condition during each epoch against shuffled null +% +% to shuffle: +% - compute n_runs fidelity for each condition for each subj +% - shuffle labels of *these data* 1000 times, then average across +% condition/subj, compute null T distribution; compute p against this +% (two-tailed) (TODO) + + +% figure out how many total runs... (hack...) +nruns = 0; +for ss = 1:length(subj) + % get one example set of trials + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + + % figure out how many runs we have for that subj, add to total + nruns = nruns+length(ru); + clear ru; +end + + +% store 'real' T (ROI x epoch) +fidelity_condcompare_realT = nan(length(ROIs),size(delay_tpt_range,1)); + +% store iter shuffled T's (ROI x epoch x iter) +fidelity_condcompare_shufT = nan(length(ROIs),size(delay_tpt_range,1),iter); + +fprintf('Computing null T-dist for condition comparison w/ in epochs\n'); + +for vv = 1:length(ROIs) + + for tt = 1:size(delay_tpt_range,1) + + fprintf('%s, Epoch %i\n',ROIs{vv},tt); + tic; + thisd = nan(length(subj),2); + for ss = 1:length(subj) + for cc = 1:2 + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cc; + thisd(ss,cc) = mean( mean( all_fidelity(thisidx,delay_tpts{tt},1) , 2), 1 ); % mean across tpts (inner), trials (outer) + clear thisidx; + end + end + + % compute real T + [~,~,~,thisstats] = ttest(thisd(:,1),thisd(:,2)); + fidelity_condcompare_realT(vv,tt) = thisstats.tstat; clear thisstats thisd; + + % create a data structure we can shuffle: for each subj/ROI/cond, + % n_runs datapoints + data_ru = nan(nruns,1); + labels_ru = nan(nruns,2); % condition, subj + + tmpidx = 1; % where to put this run.... + + for ss = 1:length(subj) + ru = unique(all_r(all_subj==ss & all_ROIs==vv)); + for rr = 1:length(ru) + for cc = 1:2 + thisidx = all_r==ru(rr) & all_subj==ss & all_ROIs==vv & all_conds(:,1)==cc; + data_ru( tmpidx) = mean( mean( all_fidelity(thisidx,delay_tpts{tt},1) , 2), 1 ); + labels_ru(tmpidx,:) = [cc ss]; + tmpidx = tmpidx+1; + end + end + end + + + % iter times.. + for ii = 1:iter + + tmpdata = nan(size(data_ru)); + + % within each subj, shuffle condition labels + for ss = 1:length(subj) + % logical indices for this subject, across runs + thisidx = labels_ru(:,2)==ss; + + % list of numerical indices - plug data in here + subjidx = find(thisidx); + + % used to shuffle subjidx + shufidx = randperm(length(subjidx)); + + % tmpdata will have data, shuffled wrt condition label, for + % each subj + tmpdata(subjidx) = data_ru(subjidx(shufidx)); + + clear thisidx subjidx shufidx; + end + + + % generate data structure for T-test (average across + % runs within condition label within each subj) + thisd = nan(length(subj),2); + for ss = 1:length(subj) + for cc = 1:2 + thisidx = labels_ru(:,1)==cc & labels_ru(:,2)==ss; + thisd(ss,cc) = mean( tmpdata(thisidx), 1 ); % mean across *shuffled* data + clear thisidx; + end + end + + % compute shuffled T + [~,~,~,thisstats] = ttest(thisd(:,1),thisd(:,2)); + fidelity_condcompare_shufT(vv,ii) = thisstats.tstat; clear thisstats + + clear thisd tmpdata; + + end + toc; + end + +end + + +% compute p-values (ROIs x epochs) +fidelity_condcompare_pval = 2 * min(mean(fidelity_condcompare_shufT<=fidelity_condcompare_realT,3), mean(fidelity_condcompare_shufT>=fidelity_condcompare_realT,3)); +fidelity_condcompare_fdrthresh = fdr(fidelity_condcompare_pval(:),0.05); + +%% fidelity line plot per ROI & true 2-way anova stat + +% TCS: replace w/ loading colors from file +dist_colors = spDist_condColors; +cond_colors = dist_colors; + +thisd_store =[]; + +% TCS: should add option for single-subj lines here too... + +plot_indiv = 1; % if 1, plot individual subj lines in line plot, otherwise, don't. +hoffset = 0.15; % +/- this much + +fidlines = figure('Name','Fidelity lines'); + +h=[]; + +for vv = 1:length(ROIs) + thisd = []; %recon data + + % TCS: moved from an inner loop to here + subplot(1,length(ROIs),vv);hold on; + + for dd =1:length(delay_tpts) + + + for cc = 1:length(cu) + for ss = 1:length(subj) + + + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisd(dd,cc,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1))); + thisd_store = [thisd_store; mean(mean(all_fidelity(thisidx,delay_tpts{dd},1))) dd vv cc ss]; + + end + % TCS: added sqrt here + my_sem(dd,cc) = std(thisd(dd,cc,:))/sqrt(length(subj)); + end + + % if we want, this is a good place to plot lines connecting indiv + % subj here + if plot_indiv == 1 + plot(dd+hoffset*[-1;1],squeeze(thisd(dd,:,:)),'-','LineWidth',0.25,'Color',[0.4 0.4 0.4]); + hold on; + plot(dd+hoffset*-1,squeeze(thisd(dd,1,:)),'.','markersize',10,'Color',dist_colors(1,:)); + hold on; + plot(dd+hoffset*1,squeeze(thisd(dd,2,:)),'.','markersize',10,'Color',dist_colors(2,:)); + end + + + end + + for cc =1:length(cu) + % TCS: matched these to HRFs (dot makes it slightly easier to see + % value when overlapping...) + h(cc) = plot([1 2 3],mean(thisd(:,cc,:),3)','o-','color',cond_colors(cc,:),'linewidth',2,'MarkerSize',8,'MarkerFaceColor',cond_colors(cc,:)); + + for dd =1:length(delay_tpts) + plot([dd dd],[mean(thisd(dd,cc,:),3)+1.*my_sem(dd,cc) mean(thisd(dd,cc,:),3)-1.*my_sem(dd,cc)], '-','LineWidth',2,'color',cond_colors(cc,:)) + end + end + clear thisidx + clear thisd + + line([0 4], [0 0], 'color',[0 0 0],'linewidth',0.5,'linestyle','-') % geh add y =0 baseline + + xlim([0.5 3.5]) + if vv ==1 + title(ROIs{vv}) + + ylabel('WM target Fidelity') + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','Epoch 1','Epoch 2','Epoch 3',''},'XTickLabelRotation',45,'TickDir','out'); + set(gca,'Ytick',[0 .4 .8 ],'TickDir','out'); + + else + set(gca,'Xtick',[0 1 2 3 4],'Xticklabel',{'','','','',''},'XTickLabelRotation',45,'TickDir','out'); + set(gca,'Ytick',[0 .4 .8 ],'TickDir','out'); + title(ROIs{vv}) + end + + if plot_indiv + ylim([-0.1 0.8]); + else + ylim([0 0.65]) + end + + + +end +set(gcf,'position', [ 121 287 1574 503]) +y = thisd_store(:,1); +epoch_var = thisd_store(:,2); +roi_var =thisd_store(:,3); +cond_var =thisd_store(:,4); +subj_var = thisd_store(:,5); + +h_roi = nan(length(ROIs),3); +p_roi = nan(length(ROIs),3); +t_stats = cell(length(ROIs),3); +p_fdr =nan(length(ROIs),3); +p_masked =nan(length(ROIs),3); + + +% t-test across epoch per condition +for vv = 1:length(ROIs) + + for ee =1:3 %epoch var + thisidx_nod = roi_var ==vv & epoch_var == ee & cond_var ==1; + thisidx_dist = roi_var ==vv & epoch_var == ee & cond_var ==2; + [h_roi(vv,ee), p_roi(vv,ee),~,t_stats{vv,ee}] = ttest(y(thisidx_nod),y(thisidx_dist)); + clear thisidx_nod thisidx_dist + end + if vv == length(ROIs) && ee ==3 + [p_fdr, p_masked] = fdr(p_roi(:),0.05); % TCS: added (:) to p_roi + corr_pval_ind = p_roi(p_masked); + else + end + +end +clear vv ee +% perm ttest +for zz = 1:iter + + for vv = 1:length(ROIs) + + for ee =1:3 %epoch var + y_shuf= y; + + for sbj = 1:length(subj) + thisidx = roi_var ==vv & subj_var==sbj & epoch_var ==ee; % dont select by condition + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + end + + thisidx_nod = roi_var ==vv & epoch_var == ee & cond_var ==1; + thisidx_dist = roi_var ==vv & epoch_var == ee & cond_var ==2; + [h_roi_iter(vv,ee,zz), p_roi_iter(vv,ee,zz),~,t_stats_iter(vv,ee,zz)] = ttest(y_shuf(thisidx_nod),y(thisidx_dist)); + clear thisidx_nod thisidx_dist y_shuf + end + + if vv == length(ROIs) && ee ==3 + [p_fdr_iter(:,:,zz), p_masked_iter(:,:,zz)] = fdr(p_roi_iter(:,:,zz),0.05); + else + end + + end + clear vv ee +end + +% TCS: why are some struct arrays and others cell arrays? + +%% plot results of shuffling (hist) +if plot_hists == 1 + figure('name','ttest perm') + for vv =1:length(ROIs) + for ee =1:3 + subplot(1,length(ROIs),vv); hold on; + histogram([t_stats_iter(vv,ee,:).tstat]) + line([t_stats{vv,ee}.tstat t_stats{vv,ee}.tstat], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + exact_p = sum([t_stats_iter(vv,ee,:).tstat] >= t_stats{vv,ee}.tstat)/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%0.3f',exact_p),'FontSize',9) + end + end +end + +%% add significance markers to figure +% this is for parametric stats: +% for vv= 1:length(ROIs) +% for ee =1:3 +% figure(reconcomp); hold on; +% subplot(length(delay_tpts),length(ROIs),(ee-1)*length(ROIs)+vv); hold on; +% +% if p_roi(vv,ee) > p_fdr && p_roi(vv,ee) <= 0.05 +% text(max(xlim)-(.3*max(xlim)),max(ylim)-(.3*max(ylim)),'*','color',[.5 .5 .5],'fontsize',30) +% elseif p_roi(vv,ee) <= p_fdr +% text(max(xlim)-(.3*max(xlim)),max(ylim)-(.3*max(ylim)),'*','color','k','fontsize',30) +% +% end +% end +% end + +% for shuffled stats (TCS) +for vv= 1:length(ROIs) + for ee =1:size(delay_tpt_range,1) + + figure(reconcomp); hold on; + subplot(length(delay_tpts),length(ROIs),(ee-1)*length(ROIs)+vv); hold on; + + if fidelity_condcompare_pval(vv,ee) > fidelity_condcompare_fdrthresh && fidelity_condcompare_pval(vv,ee) <= 0.05 + text(max(xlim)-(.3*max(xlim)),max(ylim)-(.3*max(ylim)),'*','color',[.5 .5 .5],'fontsize',20) + elseif fidelity_condcompare_pval(vv,ee) <= fidelity_condcompare_fdrthresh + text(max(xlim)-(.3*max(xlim)),max(ylim)-(.3*max(ylim)),'*','color','k','fontsize',20) + end + end +end + +%% shuffled ANOVAs (geh) +P_truth ={}; +T_truth = {}; +F_store_truth_2=[]; + +for vv = 1:length(ROIs) + + thisroiidx = roi_var ==vv; + thisy = y(thisroiidx); + thisepoch = epoch_var(thisroiidx); + thiscond =cond_var(thisroiidx); + thissubj=subj_var(thisroiidx); + [P_truth{vv},T_truth{vv},~] = anovan(thisy,{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'}) %,'display','off'); + [F_store_truth_2(vv,:)] = RMAOV2_gh([thisy,thisepoch,thiscond,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj thisy + + +end + + + +match_xlim(get(gcf,'Children')); +legend(h, {'No distractor', 'Distractor'}) +set(gcf,'position', [ 23 245 2386 453]) + + +%% 3-way ANOVA permutation +% get fidelity , over average delay epochs, for each condition, permutation test +%%%% this takes ~2.7 hrs minutes to run!!!!! (anovan) + +cu =[1 2]; +thisfide_store = []; +the_y_store= []; + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + for cc = 1:length(cu) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisfide_store(dd,vv,cc,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2)); %targ aligned + the_y_store = [the_y_store; thisfide_store(dd,vv,cc,ss) dd vv cc ss]; + end + + end + + + end +end + +% sort y_store into individual columns for feasibility/ transparency +y_3 = the_y_store(:,1); +epoch_var_3 = the_y_store(:,2); +roi_var_3 =the_y_store(:,3); +cond_var_3 =the_y_store(:,4); +subj_var_3 = the_y_store(:,5); + +P_truth_3= cell(1,1); +T_truth_3= cell(1,1); +F_store_truth_3 =nan(1,7); + +%perform the true ANOVA once +thisy = y_3; +thisepoch = epoch_var_3; +thiscond =cond_var_3; +thissubj=subj_var_3; +thisroi =roi_var_3; +[P_truth_3,T_truth_3,~] = anovan(thisy,{thissubj,thisepoch,thiscond,thisroi},'model','full','random',1,'varnames',{'subj','epoch','cond','roi'}); +[F_store_truth_3] = RMAOV33_gh([thisy,thisepoch,thiscond,thisroi,thissubj],0.05); + +clear thisroiidx thisepoch thiscond thissubj thisy + +%[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to +%correct? confirm w/ TCS + +% now compute n_iter and store output, compare to true F-values for each +% factor and each interaction + +iter = 1000; +fprintf(sprintf('computing %i 3-way ANOVAs',iter)) + +T_iter_3 =cell(iter,1); +P_iter_3 =cell(iter,1); +F_store_iter_3 =nan(iter,7); + + +% 3-way anova for each ROI +tic + +for xx=1:iter + + y_shuf=y_3; %start with empty each iter + + for sbj = 1:length(subj) + thisidx = subj_var==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + clear thisidx shuff_idx thisidx_val tmp_y + end + + thisepoch = epoch_var_3; %maintain og idx for all IVs + thiscond =cond_var_3; + thissubj=subj_var_3; + thisroi =roi_var_3; + + [P_iter_3{xx},T_iter_3{xx},~] = anovan(y_shuf,{thissubj,thisepoch,thiscond,thisroi},'model','full','random',1,'varnames',{'subj','epoch','cond','roi'},'display','off'); + [F_store_iter_3(xx,:)] = RMAOV33_gh([y_shuf,thisepoch,thiscond,thisroi,thissubj],0.05); + + clear thisidx thisepoch thiscond thissubj thisy tmpy shuffidx thisroi + + +%[p_fdr(tt,:) p_masked(tt,:)] = fdr(P_roi(vv,:),0.05); dont need to +%correct? + +end + +toc + +%plot F distributions +%which F vals do we want? idx is as follows {iter,1}{iv_str_3,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is the Fval col +iv_str_3 ={'Source';'subj';'epoch';'cond';'roi';'subj*epoch';... + 'subj*cond';'subj*roi';'epoch*cond'; 'epoch*roi';'cond_roi';... + 'subj*epoch*cond'; 'subj*epoch*roi'; 'subj*cond*roi';'epoch*cond*roi';'subj*epoch*cond*roi';... + 'Error';'Total'}; + + +col_idx = 6; % F val col + +%what factor do we care about? concurs w iv_str_3 +which_effect = [3 4 5 9 10 11 15]; %3 epoch 4 cond 5 roi 9 epoch*cond 10 epoch*cond 11 cond*roi 15 epohc*cond*roi +exact_store_tmp=[]; + +exact_store_3=[]; +figure('name','3way perm; anovan') +for ww =1:length(which_effect) + extract_vals=[]; + +for ii=1:iter + extract_vals = [extract_vals; T_iter_3{ii}{which_effect(ww),col_idx}]; +end +hold on; + +subplot(1,length(which_effect),ww) +histogram(extract_vals) +line([T_truth_3{which_effect(ww),col_idx} T_truth_3{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') +title(iv_str_3{which_effect(ww)},'Interpreter','none'); +exact_p = sum(extract_vals >= T_truth_3{which_effect(ww),col_idx})/iter; +text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) +exact_store_3(ww) = [exact_store_tmp; exact_p]; +clear exact_p + +if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') +else +end + +end + +ta_3 = table(exact_store_3(:,1),exact_store_3(:,2),exact_store_3(:,3),exact_store_3(:,4),exact_store_3(:,5),exact_store_3(:,6),exact_store_3(:,7)); +ta_3.Properties.VariableNames={'Epoch','Cond','ROI','EpochCond','EpochROI','CondROI','EpochCondROI'}; + +% make analagous plot for RMAOV33 to compare perms + +%what factor do we care about? concurs w iv_str_3 +which_effect_rm_3 = [1 2 3 4 5 6 7]; %3 epoch 4 cond 5 roi 9 epoch*cond 10 epoch*cond 11 cond*roi 15 epohc*cond*roi +rm_str ={'epoch','cond','roi','epochcond','epochroi','condroi','epochcondroi'}; +exact_store_tmp_rm=[]; +exact_store_rm3=[]; + +figure('name','3way perm; RMOV33') +for ww =1:length(which_effect_rm_3) + extract_vals=[]; + +for ii=1:iter + extract_vals = [extract_vals; F_store_iter_3(ii,which_effect_rm_3(ww))]; +end +hold on; + +subplot(1,length(which_effect_rm_3),ww) +histogram(extract_vals) +% +line([F_store_truth_3(which_effect_rm_3(ww)) F_store_truth_3(which_effect_rm_3(ww))], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') +title(rm_str{which_effect_rm_3(ww)},'Interpreter','none'); +exact_p = sum(extract_vals >= F_store_truth_3(which_effect_rm_3(ww)))/iter; +text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('p=%0.4f',exact_p),'FontSize',9) +exact_store_rm3(ww) = [exact_store_tmp_rm; exact_p]; +clear exact_p + +if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') +else +end + +end + +%%%% TMP COM +%% 2-way ANOVA permutation +% get fidelity , over average delay epochs, for each condition, permutation test +%%%% this takes ~24 minutes to run!!!!! + +cu =[1 2]; +thisfide_store = []; +the_y_store= []; + +for dd = 1:length(delay_tpts) + for vv = 1:length(ROIs) + for cc = 1:length(cu) + for ss = 1:length(subj) + thisidx = all_subj==ss & all_ROIs==vv & all_conds(:,1)==cu(cc); + thisfide_store(dd,vv,cc,ss) = mean(mean(all_fidelity(thisidx,delay_tpts{dd},1),2)); %targ aligned + the_y_store = [the_y_store; thisfide_store(dd,vv,cc,ss) dd vv cc ss]; + end + + end + + + end +end + + +% sort y_store into individual columns for transparency +y = the_y_store(:,1); +epoch_var = the_y_store(:,2); +roi_var =the_y_store(:,3); +cond_var =the_y_store(:,4); +subj_var = the_y_store(:,5); + + +fprintf(sprintf('computing %i 2-way ANOVAs per ROI',iter)) + +T_iter =cell(length(ROIs),iter); +P_iter =cell(length(ROIs),iter); +F_store_iter_2 = nan(length(ROIs),iter,3); +% two-way anova for each ROI +tic + +for xx=1:iter + for vv = 1:length(ROIs) + y_shuf =y; + thisroiidx = roi_var ==vv; + for sbj = 1:length(subj) + thisidx = roi_var ==vv & subj_var==sbj; + tmp_y = y(thisidx); + shuff_idx = randperm(size(tmp_y,1))'; + thisidx_val = find(thisidx); + y_shuf(thisidx_val,:) = tmp_y(shuff_idx,:); + end + thisepoch = epoch_var(thisroiidx); + thiscond =cond_var(thisroiidx); + thissubj=subj_var(thisroiidx); + + [P_iter{vv,xx},T_iter{vv,xx},~] = anovan(y_shuf(thisroiidx),{thissubj,thisepoch,thiscond},'model','full','random',1,'varnames',{'subj','epoch','cond'},'display','off'); + [F_store_iter_2(vv,xx,:)] = RMAOV2_gh([y_shuf(thisroiidx),thisepoch,thiscond,thissubj],0.05); + + clear thisroiidx thisepoch thiscond thissubj thisy tmpy shuffidx + + + + end +end +toc + +%plot F distributions; first, for anovan outputs +%which F vals do we want? idx is as follows {iter,1}{iv_str,6} %1 is +%fixed because we store iters vertically(1 column). 6 is fixed bc this is +%the Fval col. iv_str is defined from the vertical organization of the +%output +iv_str ={'Source';'subj';'epoch';'cond';'subj*epoch';... + 'subj*cond';'epoch*cond';... + 'subj*epoch*cond';... + 'Error';'Total'}; + + +col_idx = 6; % F-val col + +%what factor do we care about? concurs w iv_str(vs) +which_effect = [3 4 7]; %3 epoch 4 cond 7epoch*cond +exact_store_tmp=[]; +for vv =1:length(ROIs) + figure('name','2-way perm;anovan') + for ww =1:length(which_effect) + extract_vals=[]; + for ii=1:iter + extract_vals = [extract_vals; T_iter{vv,ii}{which_effect(ww),col_idx}]; + end + hold on; + + subplot(1,length(which_effect),ww) + histogram(extract_vals) + line([T_truth{vv}{which_effect(ww),col_idx} T_truth{vv}{which_effect(ww),col_idx}], [min(ylim) max(ylim)], 'color','r','linewidth',2,'linestyle','--') + title(iv_str{which_effect(ww)},'Interpreter','none'); + exact_p = sum(extract_vals >= T_truth{vv}{which_effect(ww),col_idx})/iter; + text(max(xlim)-(.5*max(xlim)),max(ylim)-(.25*max(ylim)),sprintf('%i',exact_p),'FontSize',9) + exact_store(vv,ww) = [exact_store_tmp; exact_p]; + clear exact_p + + if ww ==1 + xlabel('T-stat') + ylabel('Frequency of T-stat') + else + end + + end +end +ta = table(ROIs',exact_store(:,1),exact_store(:,2),exact_store(:,3)); +ta.Properties.VariableNames={'ROIs','Epoch','Cond','EpochCond'} + + +%% plot sigs on the subplots -- 2-way ANOVAN shuffle output +% note to self in the future : we DO correct with FDR for 2-way output, but +% NOT for 3-way +sig_colors = lines(3); + +%correct them pvals +p_fdr_perm= nan(3,1); +p_masked_perm= nan(length(ROIs),3); + +for ee =1:3 %effect var + [p_fdr_perm(ee), p_masked_perm(:,ee)] = fdr(exact_store(:,ee),0.05); + + +end + +sig_mrkr ={'o','+','x'}; %epoch, cond, epoch x cond int +y_mod = [.1 .15 .2]; +for vv = 1:length(ROIs) + for ee =1:3 + figure(fidlines); hold on; + subplot(1,length(ROIs),vv) + + + if exact_store(vv,ee) > p_fdr_perm(ee) && exact_store(vv,ee) <= 0.05 + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color',[.5 .5 .5],'fontsize',15) + elseif exact_store(vv,ee) <= p_fdr_perm(ee) + text(max(xlim)-(.2*max(xlim)),max(ylim)-(y_mod(ee)*max(ylim)),sprintf('%s',sig_mrkr{ee}),'color','k','fontsize',15) + else + end + + + end + +end + + + +fprintf('done') + + +return