forked from nacemikus/STE_model
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpal_BIC_Fit_comparison.m
More file actions
79 lines (64 loc) · 1.97 KB
/
pal_BIC_Fit_comparison.m
File metadata and controls
79 lines (64 loc) · 1.97 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
function pal_BIC_Fit_comparison(theModels,fileSpec)
%reads in Fit structs saved in .mat files
%input:
% theModels: should be a vertical cell containing strings for model names
%example:
%{'PH'}
%{'RW'}
%{'PH_pw'}
%although a string array should also work, ["PH","RW","PH_pw"]';
%IMPORTANT: it must be vertical
% fileSpec: input to sprintf for getting .mat file containing the Fit
if ~exist('fileSpec','var')
fileSpec = 'Fitted_%s.mat'; %default setting
end
% Display the resulting cell array
disp(theModels);
Nmodels = length(theModels);
meanBIC = nan(Nmodels,1);
seBIC = nan(Nmodels,1);
for i = 1:Nmodels
%load the fitted struct
Fit = load(sprintf(fileSpec,theModels{i}));
Fit = Fit.Fit;
%
subNum = Fit.bestFit(:,1); %subject number
%
allBICs(i,:) = Fit.BIC; %column will be n_subjects; each row a model
%IMPORTANT: in different row/column to match VBA requirement
meanBIC(i,:) = mean(Fit.BIC);
seBIC(i,:) = std(Fit.BIC)/sqrt(length(Fit.BIC));
end
tBIC = array2table(allBICs');
tBIC.Properties.VariableNames = theModels;
tBIC.subNum = subNum;
%% doing the aggregate
%bms:
lme = -allBICs/2;
[posterior,out] = VBA_groupBMC(lme);
%[~,~,~,pxp,~,~] = bms(lme); %this is Gershman's old code
pxp = out.pxp;
%size(pxp)
%size(theModels)
%T = array2table(pxp, 'VariableNames', theModels);
T = table(theModels,pxp', 'VariableNames', {'model','PXP'});
disp('Full sample:')
disp(T)
T_modelFreq = table(theModels,out.Ef, 'VariableNames', {'model','estimated model frequencies'});
disp(T_modelFreq)
%visual
figure;
bar(meanBIC)
hold on
errorbar(1:length(theModels), meanBIC, seBIC, '.', 'LineWidth', 1)
hold off
legend('mean BIC across ptp','standard error','Location','Southwest')
xticks(1:length(theModels))
set(gca,'TickLabelInterpreter','none')
xticklabels(theModels)
xtickangle(90)
xlabel('Models')
ylabel('Mean BIC')
title('Comparison based on mean BIC across participants')
ylim([min(meanBIC),max(meanBIC)])
end