-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbehaviouralAcuityAnal.m
More file actions
155 lines (128 loc) · 4.87 KB
/
behaviouralAcuityAnal.m
File metadata and controls
155 lines (128 loc) · 4.87 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
144
145
146
147
148
149
150
151
152
153
154
155
%==========================================================================
%===========================================================response values
YESBLANK = 1; YESTARGET = 2; UNSURE = 4; BREAKINIT = -100; BREAKBLANK = -10;
BREAKTARGET = -1; BREAKEXCL = -5; UNDEFINED = 0;
% parametric standard error?
parametric = NaN;
%do we include the break exclude trials?
useExclusion = false;
% do we treat max contrast as only useful for lapse rate, 'nAPLE' (no) or
% 'jAPLE' (yes)
lapseFits = 'nAPLE';
% ---- which psychometric function to use?
PF = @PAL_Gumbel;
% ---- load data
file = uigetfile;
if file == 0; return; end
load(file);
fprintf('\n\DATA: %s\n',file);
% ---- extract values from data
contrasts = task.nVar(1).values;
trials = ana.task([ana.task.showGrating]==true);
trialscorrect = trials([trials.response]==YESTARGET);
trialswrong = trials([trials.response]==BREAKTARGET);
trialswrongall = trials([trials.response]==BREAKTARGET | [trials.response]==BREAKEXCL);
ti=sprintf('Trials: %i - Corr: %i - BREAK: %i - BREAKALL: %i - EXCL: %i',...
length(trials),length(trialscorrect),length(trialswrong),length(trialswrongall),...
useExclusion);
disp(ti);
if useExclusion
trialswrong = trialswrongall;
end
contrastTotal = [];
contrastCorrect = [];
for i = 1 : length(contrasts)
tr = trialscorrect([trialscorrect.contrast] == contrasts(i));
contrastCorrect(i) = length(tr);
tr = trialswrong([trialswrong.contrast] == contrasts(i));
contrastWrong(i) = length(tr);
contrastTotal(i) = contrastWrong(i) + contrastCorrect(i);
end
contrasts(contrasts==0) = 1e-6;
total = contrastTotal;
correct = contrastCorrect;
% ================= Here are our model parameters =========================
% ---- threshold
search.alpha = logspace(min(contrasts), max(contrasts), 100);
% ---- slope
search.beta = logspace(0, 2, 100);
% ---- guess rate
search.gamma = 0;
%searchGrid.gamma = linspace(0,0.5,10);
% ---- lapse bias
%search.lambda = 0;
search.lambda = linspace(0,0.2,10);
% ---- which parameters to search
freeParameters = [1 1 0 1];
% ============================ Here we run the model ======================
[params,b,c,d] = PAL_PFML_Fit(contrasts,correct,total,search,freeParameters,PF,...
'lapseLimits',[0 0.2],'guessLimits',[0 0.5],'lapseFits',lapseFits);
if c ~= 1
warndlg('DID NOT CONVERGE!!!!!');
end
if params(2) == Inf
warning('Had to change the INF slope parameter!!')
params(2) = max(search.beta);
end
xrange = linspace(0, max(contrasts), 1000);
fit = PF(params,xrange);
% ========================= And plot our result ===========================
fname = functions(PF);
fname = fname.function;
r = groot; ss = r.ScreenSize;
f = figure('Position',[ss(3)/4+randi(50) ss(4)/2 ss(3)/2 ss(4)/2]);
tiledlayout(f,'flow');
nexttile; hold on
plot(contrasts,(correct./total),'k.','Color',[0.3 0.3 0.3],'MarkerSize',30);
plot(xrange,fit,'Color',[0.8 0.5 0],'LineWidth', 2);
title([fname ' PARAMS: ' num2str(params,'%.4f ') ' LL: ' num2str(b,'%.3f')],'Interpreter','none');
subtitle([file ' ' ti],'Interpreter','none');
xlim([-(max(contrasts)/100) max(contrasts)+(max(contrasts)/100)]);
ylim([-0.05 1.05]);
xlabel('Stimulus Contrast');
ylabel('Proportion correct [0 - 1]');
grid on; grid minor; box on; hold off
drawnow;
% =======================Get errors and goodness of fit? =================
if islogical(parametric)
warning off
t = text(0.01, 0.1, 'Calculating GOF, please wait...','FontSize',16);drawnow
B=400;
if parametric == 1
[SD, paramsSim, LLSim, converged] = PAL_PFML_BootstrapParametric(...
contrasts, total, params, freeParameters, B, PF, ...
'searchGrid', search);
else
[SD, paramsSim, LLSim, converged] = PAL_PFML_BootstrapNonParametric(...
contrasts, correct, total, [], freeParameters, B, PF,...
'searchGrid',search);
end
message = sprintf('Threshold SE: %6.4f',SD(1));
message = [message sprintf(' | slope SE: %6.4f',SD(2))];
message = [message sprintf(' | lapse SE: %6.4f',SD(4))];
%Number of simulations to perform to determine Goodness-of-Fit
B=500;
disp('Determining Goodness-of-fit.....');
[Dev, pDev] = PAL_PFML_GoodnessOfFit(contrasts, correct, total, ...
params, freeParameters, B, PF, 'searchGrid', search);
%Put summary of results on screen
message = [message sprintf(' | deviance: %6.4f',Dev)];
message = [message sprintf(' | p: %6.4f',pDev)];
delete(t);
text(0.01, 0.1, message,'FontSize',14);
warning on
%Create simple plot
% ProportionCorrectObserved = correct./total;
% StimLevelsFineGrain = linspace(min(contrasts), max(contrasts), 500);
% ProportionCorrectModel = PF(params,StimLevelsFineGrain);
%
% nexttile;
% hold on;
% plot(StimLevelsFineGrain,ProportionCorrectModel,'-','color',[0.8 0.5 0],'linewidth',2);
% plot(contrasts,ProportionCorrectObserved,'k.','markersize',30);
% axis([min(StimLevels) max(StimLevels) -0.05 1.05]);
% xlabel('Stimulus Contrast');
% ylabel('Proportion correct [0 - 1]');
% title(message)
% grid on; grid minor; box on; hold off
end