-
Notifications
You must be signed in to change notification settings - Fork 0
/
getTgtLatencyCorr.m
148 lines (126 loc) · 7.35 KB
/
getTgtLatencyCorr.m
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
144
145
146
147
148
function [latency_neuro, latency_bhv, latcorr, latcorr_cue, f, fneuro] = ...
getTgtLatencyCorr(PSTH_f, t_r, onsets_cat, catEvTimes, tWin_t, param, dd, validEvents )
% [latency_neuro, latency_bhv, r, f, fneuro] = getTgtLatencyCorr(PSTH_f, t_r, onsets_cat, ...
% catEvTimes, tWin_t, Thresh, param, dd)
% computes neural and behavioural latencies with or without cue
corrOption = 'Spearman'; %'Pearson'
%% neural latency
[latency_neuro, ~,~,fneuro] = getTgtNeuroLatency(PSTH_f, t_r, onsets_cat, ...
catEvTimes, tWin_t, param.threshParam, param, dd, validEvents);
%% behavioural latency
option = 1;
latency_bhv = getTgtBhvLatency(onsets_cat, dd, validEvents, option);
wCue = ~isinf(onsets_cat.cueOnset(validEvents));
woCue = isinf(onsets_cat.cueOnset(validEvents));
[choiceOutcome] = getChoiceOutcome(dd);
hesitant = getChoiceOutcome_hesitant(onsets_cat, dd, validEvents);
success = (choiceOutcome(validEvents) == 1) .* ~hesitant;
fail = choiceOutcome(validEvents) >= 2;
theseEvents = validEvents;%(success);%better to use all conditions??
onsetTimes = catEvTimes.tOnset;
onsetTimes = onsetTimes(theseEvents);
tgtDir = getTgtDir(dd.targetloc, param.cardinalDir);
tgtDir = tgtDir(theseEvents);
%% cue-tgt interval
diffCueFOnset = getDiffCueTgtOnset(onsets_cat, catEvTimes);
diffCueFOnset = abs(diffCueFOnset(validEvents));
%% select trials with preferred direction (showTonsetResp)
[prefDir, prefDirTrials] = getPrefDir(PSTH_f, t_r, onsetTimes, tgtDir, param);
tgt_pref = zeros(numel(validEvents),1);
tgt_pref(prefDirTrials) = 1;
%% select trials with most frequent direction
[prevDir, prevDirTrials] = getPrevDir(tgtDir, param);
tgt_prev = zeros(numel(validEvents),1);
tgt_prev(prevDirTrials) = 1;
validLatency = ~isnan(latency_neuro);
%correlation beteween behaviour and neuro using only successful trials
try
[latcorr.r, latcorr.p] = corr(latency_bhv(logical(validLatency.*~isnan(latency_bhv))), ...
latency_neuro(logical(validLatency.*~isnan(latency_bhv))), 'type', corrOption);
catch err
latcorr.r = nan;
latcorr.p = nan;
end
try
[latcorr.r_success, latcorr.p_success] = corr(latency_bhv(logical(success.*validLatency)), ...
latency_neuro(logical(success.*validLatency)), 'type', corrOption);
catch err
latcorr.r_success = nan;
latcorr.p_success = nan;
end
try
[latcorr.r_pref, latcorr.p_pref] = corr(latency_bhv(logical(validLatency.*~isnan(latency_bhv).*tgt_pref)), ...
latency_neuro(logical(validLatency.*~isnan(latency_bhv).*tgt_pref)), 'type', corrOption);
catch err
latcorr.r_pref = nan;
latcorr.p_pref = nan;
end
try
[latcorr.r_success_pref, latcorr.p_success_pref] = corr(latency_bhv(logical(success.*validLatency.*tgt_pref)), ...
latency_neuro(logical(success.*validLatency.*tgt_pref)), 'type', corrOption);
catch err
latcorr.r_success_pref = nan;
latcorr.p_success_pref = nan;
end
try
[latcorr.r_success_prev, latcorr.p_success_prev] = corr(latency_bhv(logical(success.*validLatency.*(tgtDir==0).*(dd.cuedLoc(validEvents)==1))), ...
latency_neuro(logical(success.*validLatency.*(tgtDir==0).*(dd.cuedLoc(validEvents)==1))), 'type', corrOption);
catch err
latcorr.r_success_prev = nan;
latcorr.p_success_prev = nan;
end
%% correlation between bhv latency and cue-tgt interval
try
[latcorr_cue.r_success_prev, latcorr_cue.p_success_prev] = corr(latency_bhv(logical(success.*validLatency.*tgt_prev)), ...
diffCueFOnset(logical(success.*validLatency.*tgt_prev)), 'type', corrOption);
catch err
latcorr_cue.r_success_prev = nan;
latcorr_cue.p_success_prev = nan;
end
if nargout > 3
f = figure('position',[ 420 5 1405 849]);
ax(1) = subplot(2,6,[1:3 7:9]); %bhv v neuro
plot(latency_bhv(logical(wCue.*success)), latency_neuro(logical(wCue.*success)),'ro','DisplayName','success w cue'); hold on;
plot(latency_bhv(logical(woCue.*success)), latency_neuro(logical(woCue.*success)),'bo','DisplayName','succes wo cue'); hold on;
plot(latency_bhv(logical(wCue.*success.*tgt_pref)), latency_neuro(logical(wCue.*success.*tgt_pref)),'o','MarkerFaceColor','r','DisplayName','success w cue prefDir'); hold on;
plot(latency_bhv(logical(woCue.*success.*tgt_pref)), latency_neuro(logical(woCue.*success.*tgt_pref)),'o','MarkerFaceColor','b','DisplayName','succes wo cue prefDir'); hold on;
plot(latency_bhv(logical(wCue.*fail)), latency_neuro(logical(wCue.*fail)),'rx','DisplayName','failure w cue'); hold on;
plot(latency_bhv(logical(woCue.*fail)), latency_neuro(logical(woCue.*fail)),'bx','DisplayName','failure wo cue'); hold on;
xlabel('behavioural latency');
ylabel('neural latency');
legend('location','southoutside');
tname = sprintf(['all dir: %.2f (p=%.2f), \n' ...
'success all dir: %.2f (p=%.2f) \n' ...
'success pref dir: %.2f (p=%.2f)\n' ...
'success prev dir: %.2f (p=%.2f)'], ...
latcorr.r, latcorr.p, ...
latcorr.r_success, latcorr.p_success, ...
latcorr.r_success_pref, latcorr.p_success_pref,...
latcorr.r_success_prev, latcorr.p_success_prev);
title(tname); %title(['r=' num2str(r) ', r(success)=' num2str(r_success)]);
squareplot;
axis padded; set(gca,'TickDir','out');
bhvrange = get(gca,'XLim');
ax(2) = subplot(2,6,4); %cue v bhv
plot(zeros(numel(find(woCue.*success)),1), latency_bhv(logical(woCue.*success)),'bo','DisplayName','success wo cue'); hold on;
plot(zeros(numel(find(woCue.*success.*tgt_pref)),1),latency_bhv(logical(woCue.*success.*tgt_pref)),'b','MarkerFaceColor','r','DisplayName','success wo cue prefDir'); hold on;
plot(zeros(numel(find(woCue.*fail),1)), latency_bhv(logical(woCue.*fail)),'bx','DisplayName','failure wo cue'); hold on;
ylim(bhvrange); ylabel('bhv latency'); grid on;
ax(3) = subplot(2,6,[5 6]); %cue v bhv
plot(diffCueFOnset(logical(wCue.*success)), latency_bhv(logical(wCue.*success)),'ro','DisplayName','success w cue'); hold on;
plot(diffCueFOnset(logical(wCue.*success.*tgt_pref)),latency_bhv(logical(wCue.*success.*tgt_pref)),'o','MarkerFaceColor','r','DisplayName','success w cue prefDir'); hold on;
plot(diffCueFOnset(logical(wCue.*fail)), latency_bhv(logical(wCue.*fail)),'rx','DisplayName','failure w cue'); hold on;
ylim(bhvrange); xlim([.48 .72]);grid on;
xlabel('cue-tgt interval [s]');
ax(4) = subplot(2,6,10); %cue v bhv
plot(zeros(numel(find(woCue.*success)),1), latency_neuro(logical(woCue.*success)),'bo','DisplayName','success wo cue'); hold on;
plot(zeros(numel(find(woCue.*success.*tgt_pref)),1),latency_neuro(logical(woCue.*success.*tgt_pref)),'b','MarkerFaceColor','r','DisplayName','success wo cue prefDir'); hold on;
plot(zeros(numel(find(woCue.*fail),1)), latency_neuro(logical(woCue.*fail)),'bx','DisplayName','failure wo cue'); hold on;
ylim(bhvrange); ylabel('neuro latency');grid on;
ax(5) = subplot(2,6,[11 12]); %cue v bhv
plot(diffCueFOnset(logical(wCue.*success)), latency_neuro(logical(wCue.*success)),'ro','DisplayName','success w cue'); hold on;
plot(diffCueFOnset(logical(wCue.*success.*tgt_pref)), latency_neuro(logical(wCue.*success.*tgt_pref)),'o','MarkerFaceColor','r','DisplayName','success w cue prefDir'); hold on;
plot(diffCueFOnset(logical(wCue.*fail)), latency_neuro(logical(wCue.*fail)),'rx','DisplayName','failure w cue'); hold on;
ylim(bhvrange);xlim([.48 .72]); xlabel('cue-tgt interval [s]'); grid on;
%linkaxes(ax(:),'y');
end