forked from anne-urai/2019_Urai_choice-history-ddm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
barplots_modelcomparison.m
98 lines (80 loc) · 2.87 KB
/
barplots_modelcomparison.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
function barplots_modelcomparison()
% 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
% anne.urai@gmail.com
addpath(genpath('~/code/Tools'));
warning off; close all;
global datasets datasetnames mypath
modelIC = {'aic'};
for s = 1:length(modelIC),
% ============================================ %
% DIC COMPARISON BETWEEN DC, Z AND BOTH
% ============================================ %
% 1. STIMCODING, only prevresps
mdls = {'z_prevresp', 'dc_prevresp', ...
'dc_z_prevresp', 'nohist'};
for d = 1:length(datasets),
close all;
subplot(4, 5, 1);
getPlotModelIC(mdls, modelIC{s}, d);
title(datasetnames{d});
set(gca, 'xtick', 1:3, 'xticklabel', {'z', 'v_{bias}', 'both'});
ylabel({'\DeltaAIC from model'; 'without history'}, 'interpreter', 'tex');
drawnow; tightfig;
print(gcf, '-dpdf', sprintf('~/Data/serialHDDM/modelcomparison_%s_d%d.pdf', modelIC{s}, d));
disp(d);
end
end
close all;
end
% ============================================ %
% DIC COMPARISON BETWEEN DC, Z AND BOTH
% ============================================ %
function getPlotModelIC(mdls, s, d)
global datasets mypath colors
axis square; hold on;
mdldic = nan(1, length(mdls));
for m = 1:length(mdls),
try
modelcomp = readtable(sprintf('%s/%s/stimcoding_%s/model_comparison.csv', ...
mypath, datasets{d}, mdls{m}));
mdldic(m) = modelcomp.(s);
catch
fprintf('%s/%s/stimcoding_%s/model_comparison.csv NOT FOUND\n', ...
mypath, datasets{d}, mdls{m})
end
end
% everything relative to the full model
mdldic = bsxfun(@minus, mdldic, mdldic(end));
mdldic = mdldic(1:end-1);
[~, bestMdl] = min(mdldic);
for i = 1:length(mdldic),
if i == bestMdl,
b = bar(i, mdldic(i), 'facecolor', colors(i, :), 'barwidth', 0.6, 'BaseValue', 0, ...
'edgecolor', 'k');
else
b = bar(i, mdldic(i), 'facecolor', colors(i, :), 'barwidth', 0.6, 'BaseValue', 0, ...
'edgecolor', 'none');
end
end
axis square; axis tight;
xlim([0.5 length(mdldic)+0.5]);
offsetAxes; box off;
% set(gca, 'color', 'none');
set(gca, 'xcolor', 'k', 'ycolor', 'k');
%# Add a text string above/below each bin
for i = 1:length(mdldic),
if mdldic(i) < 0,
text(i, mdldic(i) + 0.12*range(get(gca, 'ylim')), ...
num2str(round(mdldic(i))), ...
'VerticalAlignment', 'top', 'FontSize', 4, 'horizontalalignment', 'center', 'color', [1 1 1]);
elseif mdldic(i) > 0,
text(i, mdldic(i) + 0.12*range(get(gca, 'ylim')), ...
num2str(round(mdldic(i))), ...
'VerticalAlignment', 'top', 'FontSize', 4, 'horizontalalignment', 'center', 'color', [1 1 1]);
end
end
end