-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathplotPrior.m
229 lines (199 loc) · 6.29 KB
/
plotPrior.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
function plotPrior(res)
% this function creates the plot illustrating the priors on the different
% parameters
%
% this is meant to be a 3 column, 2 rows multipanel plot.
% parameters
lineW = 2;
lineC = [0,105/255,170/255];
markerSize = 30;
data = res.data;
% get correct stimulus range
if numel(res.options.stimulusRange)<=1
res.options.stimulusRange = [min(data(:,1)),max(data(:,1))];
stimRangeSet = false;
else
stimRangeSet = true;
end
range = res.options.stimulusRange(2)-res.options.stimulusRange(1);
% get borders for width
% minimum = minimal difference of two stimulus levels
if length(unique(data(:,1)))>1 && ~stimRangeSet
widthmin = min(diff(sort(unique(data(:,1)))));
else
widthmin = 100*eps(res.options.stimulusRange(2));
end
% maximum = spread of the data
% We use the same prior as we previously used... e.g. we use the factor by
% which they differ for the cumulative normal function
Cfactor = (my_norminv(.95,0,1) - my_norminv(.05,0,1))./( my_norminv(1-res.options.widthalpha,0,1) - my_norminv(res.options.widthalpha,0,1));
widthmax = range;
% calculate mean for priors
theta = zeros(5, 1);
for itheta = 1:5
if ~isnan(res.options.fixedPars(itheta))
theta(itheta) = res.options.fixedPars(itheta);
else
switch itheta
case 1
x = linspace(res.options.stimulusRange(1)-.5*range,res.options.stimulusRange(2)+.5*range,10000);
case 2
x = linspace(min(res.X1D{itheta}),max(res.X1D{2}),10000);
case 3
x = linspace(0,.5,10000);
case 4
x = linspace(0,.5,10000);
case 5
x = linspace(0,1,10000);
end
y = res.options.priors{itheta}(x);
theta(itheta) = sum(x.*y)./sum(y);
end
end
if strcmp(res.options.expType,'equalAsymptote')
theta(4) = theta(3);
end
if strcmp(res.options.expType,'nAFC')
theta(4) = 1./res.options.expN;
end
% get limits for the psychometric function plots
if res.options.logspace
xLimit = exp([res.options.stimulusRange(1)-.5*range,res.options.stimulusRange(2)+.5*range]);
else
xLimit = [res.options.stimulusRange(1)-.5*range,res.options.stimulusRange(2)+.5*range];
end
% The first row shows the prior marginal densities
%% threshold
xthresh = linspace(res.options.stimulusRange(1)-.5*range,res.options.stimulusRange(2)+.5*range,10000);
ythresh = res.options.priors{1}(xthresh);
wthresh = conv(diff(xthresh),.5*[1,1]);
cthresh = cumsum(ythresh.*wthresh);
subplot(2,3,1)
plot(xthresh,ythresh,'LineWidth',lineW,'Color',lineC)
hold on
xlim([min(xthresh),max(xthresh)])
title('Threshold','FontSize',18)
ylabel('Density','FontSize',18)
subplot(2,3,4)
plot(data(:,1),0,'k','LineStyle','none','Marker','.','MarkerSize',markerSize*.75)
hold on
ylabel('Percent Correct','FontSize',18)
xlim(xLimit)
x = linspace(xLimit(1),xLimit(2),10000);
for idot= 1:5
switch idot
case 1
xcurrent = theta(1);
color = 'k';
case 2
xcurrent = min(xthresh);
color = [1,200/255,0];
case 3
xcurrent = xthresh(find(cthresh>=.25,1,'first'));
color = 'r';
case 4
xcurrent = xthresh(find(cthresh>=.75,1,'first'));
color = 'b';
case 5
xcurrent = max(xthresh);
color = 'g';
end
y = 100*(theta(4)+ (1-theta(3)-theta(4)).* res.options.sigmoidHandle(x,xcurrent,theta(2)));
subplot(2,3,4)
plot(x,y,'-','LineWidth',lineW,'Color',color)
if res.options.logspace
set(gca,'XScale','log')
end
subplot(2,3,1)
plot(xcurrent,res.options.priors{1}(xcurrent),'Color',color,'LineStyle','none','Marker','.','MarkerSize',markerSize)
end
%% width
xwidth = linspace(widthmin,3./Cfactor.*widthmax,10000);
ywidth = res.options.priors{2}(xwidth);
wwidth = conv(diff(xwidth),.5*[1,1]);
cwidth = cumsum(ywidth.*wwidth);
subplot(2,3,2)
plot(xwidth,ywidth,'LineWidth',lineW,'Color',lineC)
hold on
xlim([widthmin,3./Cfactor*widthmax])
title('Width','FontSize',18)
subplot(2,3,5)
plot(data(:,1),0,'k','LineStyle','none','Marker','.','MarkerSize',markerSize*.75)
hold on
xlim(xLimit)
xlabel('Stimulus Level','FontSize',18)
x = linspace(xLimit(1),xLimit(2),10000);
for idot= 1:5
switch idot
case 1
xcurrent = theta(2);
color = 'k';
case 2
xcurrent = min(xwidth);
color = [1,200/255,0];
case 3
xcurrent = xwidth(find(cwidth>=.25,1,'first'));
color = 'r';
case 4
xcurrent = xwidth(find(cwidth>=.75,1,'first'));
color = 'b';
case 5
xcurrent = max(xwidth);
color = 'g';
end
y = 100*(theta(4)+ (1-theta(3)-theta(4)).* res.options.sigmoidHandle(x,theta(1),xcurrent));
subplot(2,3,5)
plot(x,y,'-','LineWidth',lineW,'Color',color)
if res.options.logspace
set(gca,'XScale','log')
end
subplot(2,3,2)
plot(xcurrent,res.options.priors{2}(xcurrent),'Color',color,'LineStyle','none','Marker','.','MarkerSize',markerSize)
end
%% lapse
xlapse = linspace(0,.5,10000);
ylapse = res.options.priors{3}(xlapse);
wlapse = conv(diff(xlapse),.5*[1,1]);
clapse = cumsum(ylapse.*wlapse);
subplot(2,3,3)
plot(xlapse,ylapse,'LineWidth',lineW,'Color',lineC)
hold on
xlim([0,.5])
title('\lambda','FontSize',18)
subplot(2,3,6)
plot(data(:,1),0,'k','LineStyle','none','Marker','.','MarkerSize',markerSize*.75)
hold on
xlim(xLimit)
x = linspace(xLimit(1),xLimit(2),10000);
for idot= 1:5
switch idot
case 1
xcurrent = theta(3);
color = 'k';
case 2
xcurrent = 0;
color = [1,200/255,0];
case 3
xcurrent = xlapse(find(clapse>=.25,1,'first'));
color = 'r';
case 4
xcurrent = xlapse(find(clapse>=.75,1,'first'));
color = 'b';
case 5
xcurrent = .5;
color = 'g';
end
y = 100*(theta(4)+ (1-xcurrent-theta(4)).* res.options.sigmoidHandle(x,theta(1),theta(2)));
subplot(2,3,6)
plot(x,y,'-','LineWidth',lineW,'Color',color)
if res.options.logspace
set(gca,'XScale','log')
end
subplot(2,3,3)
plot(xcurrent,res.options.priors{3}(xcurrent),'Color',color,'LineStyle','none','Marker','.','MarkerSize',markerSize)
end
set(gcf, 'Position',[200,300,1000,600])
for i=1:6
subplot(2,3,i)
box off;
end