-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimingCorrelationsBurstTrial.m
More file actions
143 lines (115 loc) · 5.89 KB
/
TimingCorrelationsBurstTrial.m
File metadata and controls
143 lines (115 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
figdir = '/Users/brainmodulationlab/Dropbox (Brain Modulation Lab)/Speech Project/MerData/figures_DBS2000';
alignment = 'Trial';
CorrType = 'Spearman';
for idx=1:length(DATA)
RT = DATA(idx).RT(DATA(idx).trange); % + DATA(idx).SpDur(DATA(idx).trange);
BBthresh = quantile([DATA(idx).(alignment).BBbase(:).S],0.75);
clear CueBurst BurstSpOnset;
for trial=1:length(DATA(idx).trange)
% timeCue = DATA(idx).(alignment).timeCue{trial} + DATA(idx).(alignment).idxEventTimes{trial}(2)*fs;
% timeSpOnset = DATA(idx).(alignment).timeSpOnset{trial} + DATA(idx).(alignment).idxEventTimes{trial}(2)*fs;
% indDD = find(DATA(idx).(alignment).DD{trial});
% ii = min(DATA(idx).(alignment).BB(trial).ii);
% if ~isempty(ii) && DATA(idx).(alignment).BB(trial).S > BBthresh
if DATA(idx).(alignment).BB(trial).S > BBthresh
% CueBurst.T(trial) = timeCue(indDD(ii));
% BurstSpOnset.T(trial) = -timeSpOnset(indDD(ii));
%% Start of burst
CueBurst.T(trial) = DATA(idx).(alignment).BB(trial).t(1);
BurstSpOnset.T(trial) = RT(trial)-DATA(idx).(alignment).BB(trial).t(1);
% %% Max of burst
% CueBurst.T(trial) = DATA(idx).(alignment).BB(trial).tmax;
% BurstSpOnset.T(trial) = RT(trial)-DATA(idx).(alignment).BB(trial).tmax;
% %% End of burst
% CueBurst.T(trial) = DATA(idx).(alignment).BB(trial).t(end);
% BurstSpOnset.T(trial) = RT(trial)-DATA(idx).(alignment).BB(trial).t(end);
else
CueBurst.T(trial) = NaN;
BurstSpOnset.T(trial) = NaN;
RT(trial) = NaN;
end
end
% get rid of trials with no burst detected
RT(isnan(RT)) = [];
BurstSpOnset.T(isnan(BurstSpOnset.T)) = [];
CueBurst.T(isnan(CueBurst.T)) = [];
BurstSpOnset.T =BurstSpOnset.T';
CueBurst.T = CueBurst.T';
%BurstSpOnset.T = RT - CueBurst.T;
if length(RT) > 3
[BurstSpOnset.Pearson.rho,BurstSpOnset.Pearson.pval] = corr(RT, BurstSpOnset.T, 'type', 'Pearson');
[BurstSpOnset.Spearman.rho,BurstSpOnset.Spearman.pval] = corr(RT, BurstSpOnset.T, 'type', 'Spearman');
[BurstSpOnset.b] = regress(BurstSpOnset.T, [ones(size(RT)), RT]);
% fh = figure; plot(RT, BurstSpOnset.T, 'bo')
% hold on; plot(xlim, BurstSpOnset.b(2)*xlim + BurstSpOnset.b(1), 'b')
[CueBurst.Pearson.rho,CueBurst.Pearson.pval] = corr(RT, CueBurst.T, 'type', 'Pearson');
[CueBurst.Spearman.rho,CueBurst.Spearman.pval] = corr(RT, CueBurst.T, 'type', 'Spearman');
[CueBurst.b] = regress(CueBurst.T, [ones(size(RT)), RT]);
% hold on; plot(RT, CueBurst.T, 'ro')
% hold on; plot(xlim, CueBurst.b(2)*xlim + CueBurst.b(1), 'r')
% XLIM=xlim;
% YLIM=ylim;
% hold on; text(XLIM(1)+0.1*XLIM*[-1; 1], YLIM(1)+0.9*YLIM*[-1; 1], ...
% ['RT vs Burst-to-SpeechOnset: rho= ', ...
% num2str(BurstSpOnset.(CorrType).rho, '%4.2f'), ...
% ' pval= ', num2str(BurstSpOnset.(CorrType).pval, '%2.1e'), ...
% sprintf('\n'), ...
% 'RT vs Cue-to-Burst: rho= ', ...
% num2str(CueBurst.(CorrType).rho, '%4.2f'), ...
% ' pval= ', num2str(CueBurst.(CorrType).pval, '%2.1e')]);
%
% figtitle = sprintf('Rec %d %s, %5.3f, %s, Unit x, (%s)', ...
% idx, DATA(idx).SubjectID, DATA(idx).depth, DATA(idx).elec, DATA(idx).grade);
%
% xlabel('Reaction Time (s)');
% ylabel('Interval duration (s)')
% title(figtitle);
%
% saveas(fh,[figdir,'/TimingCorrelationsTrialBaselinedBurst/',figtitle,'.pdf'], 'pdf');
% close(fh);
else
CueBurst.Pearson.rho=0;
CueBurst.Pearson.pval=1;
BurstSpOnset.Pearson.rho = 0;
BurstSpOnset.Pearson.pval = 1;
CueBurst.Spearman.rho=0;
CueBurst.Spearman.pval=1;
BurstSpOnset.Spearman.rho = 0;
BurstSpOnset.Spearman.pval = 1;
end
% DATA(idx).CueBurst = CueBurst;
% DATA(idx).BurstSpOnset = BurstSpOnset;
end
alpha=0.05;
% SortCat = Csorts;
% SortCat = union(Asorts,Bsorts);
SortCat = union(union(Asorts,Bsorts),Csorts);
SortCat = intersect(SortCat, idxSTN);
idxSigCorrSpOnset = find(arrayfun(@(x) ...
x.BurstSpOnset.(CorrType).pval<=alpha&&x.CueBurst.(CorrType).pval>alpha, DATA));
idxSigCorrCue = find(arrayfun(@(x) ...
x.CueBurst.(CorrType).pval<=alpha&&x.BurstSpOnset.(CorrType).pval>alpha, DATA));
idxSigCorrBoth = find(arrayfun(@(x) ...
x.CueBurst.(CorrType).pval<=alpha&&x.BurstSpOnset.(CorrType).pval<=alpha, DATA));
idxSigCorrSpOnset = intersect(idxSigCorrSpOnset, union(idx_excit_Cue, idx_mix_Cue));
idxSigCorrSpOnset = intersect(idxSigCorrSpOnset, SortCat);
idxSigCorrCue = intersect(idxSigCorrCue, union(idx_excit_SpOnset, idx_mix_SpOnset));
idxSigCorrCue = intersect(idxSigCorrCue, SortCat);
idxSigCorrBoth = intersect(idxSigCorrBoth, union(union(idx_excit_Cue, idx_excit_SpOnset), union(idx_mix_Cue, idx_mix_SpOnset)));
idxSigCorrBoth = intersect(idxSigCorrBoth, SortCat);
figure; plot(arrayfun(@(x) double(x.BurstSpOnset.(CorrType).rho), DATA(idxSigCorrSpOnset)), ...
arrayfun(@(x) double(x.CueBurst.(CorrType).rho), DATA(idxSigCorrSpOnset)) ...
, 'bo');
% , 'b.', 'markersize', 32);
hold on; plot(arrayfun(@(x) double(x.BurstSpOnset.(CorrType).rho), DATA(idxSigCorrCue)), ...
arrayfun(@(x) double(x.CueBurst.(CorrType).rho), DATA(idxSigCorrCue)) ...
, 'ro');
% , 'r.', 'markersize', 32);
hold on; plot(arrayfun(@(x) double(x.BurstSpOnset.(CorrType).rho), DATA(idxSigCorrBoth)), ...
arrayfun(@(x) double(x.CueBurst.(CorrType).rho), DATA(idxSigCorrBoth)) ...
, 'ko');
% , 'k.', 'markersize', 32);
hold on; plot([-1 1], [-1 1])
xlabel('Correlation Coefficient (RT vs Burst-to-SpeechOnset)')
ylabel('Correlation Coefficient (RT vs Cue-to-Burst)')
title('Burst correlations');