-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstrategy_plot_2to7.m
59 lines (48 loc) · 2.14 KB
/
strategy_plot_2to7.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
function strategy_plot_2to7
% Code to fit the history-dependent drift diffusion models as described in
% Urai AE, de Gee JW, Tsetsos K, Donner TH (2019) Choice history biases subsequent evidence accumulation. eLife, in press.
%
% MIT License
% Copyright (c) Anne Urai, 2019
global mypath datasets datasetnames
addpath(genpath('~/code/Tools'));
warning off; close all;
markers = {'d', 's', '^', 'v', '>', '<'};
colors = cbrewer('qual', 'Set2', length(datasets));
for d = 1:length(datasets),
filename = dir(sprintf('%s/%s/*.csv', mypath, datasets{d}));
data = readtable(sprintf('%s/%s/%s', mypath, datasets{d}, filename.name));
%assert(1==0)
if ~ismember(data.Properties.VariableNames, 'correct'),
data.correct = (sign(data.stimulus) == data.response);
end
avg_prevcorrect = nan(numel(unique(data.subj_idx)), 7);
avg_preverror = nan(numel(unique(data.subj_idx)), 7);
for lag = 2:7,
repeat = double(data.response == circshift(data.response, lag));
% exclude trials that are not continuous
trialnum = (data.trial == circshift(data.trial, lag)+lag);
repeat(~trialnum) = NaN;
% split into correct and error
repeat_correct = repeat;
repeat_correct(circshift(data.correct, lag) == 0) = NaN;
repeat_error = repeat;
repeat_error(circshift(data.correct, lag) == 1) = NaN;
avg_prevcorrect(:, lag) = splitapply(@nanmean, repeat_correct, findgroups(data.subj_idx));
avg_preverror(:, lag) = splitapply(@nanmean, repeat_error, findgroups(data.subj_idx));
end
close all; subplot(441); hold on;
plot([0.5 0.5], [0.3 0.7], 'color', 'k', 'linewidth', 0.5);
plot([0.3 0.7], [0.5 0.5], 'color', 'k', 'linewidth', 0.5);
scatter(nanmean(avg_prevcorrect, 2), nanmean(avg_preverror, 2), 5, colors(d, :), markers{d});
xlabel({'P(repeat) after correct', 'lag 2-7'});
ylabel({'P(repeat) after error', 'lag 2-7'});
set(gca, 'xtick', 0.3:0.2:0.7, 'ytick', 0.3:0.2:0.7, 'xcolor', 'k', 'ycolor', 'k');
xlim([0.3 0.7]); ylim([0.3 0.7]);
offsetAxes; axis square;
tightfig;
if d < length(datasets), xlabel(''); end
print(gcf, '-dpdf', sprintf('~/Data/serialHDDM/strategyPlot_2to7_%d.pdf', d));
end
end