-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathanalyzeCrowdingSurvey.m
executable file
·430 lines (416 loc) · 17.3 KB
/
analyzeCrowdingSurvey.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
%% Analyze the data collected by runCrowdingSurvey. April 2019
experiment='CrowdingSurvey'; % And CrowdingSurvey2.
printFilenames=false;
makePlotLinear=false;
myPath=fileparts(mfilename('fullpath')); % Takes 0.1 s.
addpath(fullfile(myPath,'lib')); % Folder in same directory as this M file.
dataFolder=fullfile(fileparts(mfilename('fullpath')),'data');
% dataFolder='/Users/denispelli/Dropbox/MATLAB/CriticalSpacing/data/';
cd(dataFolder);
close all
%% READ ALL DATA OF EXPERIMENT FILES INTO A LIST OF THRESHOLDS "oo".
vars={'experiment' 'condition' 'conditionName' 'dataFilename' ...
'experimenter' 'observer' 'localHostName' ...
'trialsDesired' 'responseCount' ...
'thresholdParameter' ...
'eccentricityXYDeg' 'targetDeg' 'spacingDeg' 'flankingDirection'...
'viewingDistanceCm' 'durationSec' ...
'contrast' 'pixPerCm' 'nearPointXYPix' 'beginningTime' 'block' 'blocksDesired' ...
'task' 'readWordPerMin' 'readFilename' ...
'readNumberOfResponses' 'readNumberCorrect' 'targetFont'...
'simulateObserver' 'simulatedLogThreshold' ...
};
oo=ReadExperimentData(experiment,vars);
fprintf('%4.0f conditions in experiment %s\n',length(oo),experiment);
%% CLEAN
ok=logical([]);
for oi=1:length(oo)
switch oo(oi).task
case 'identify'
switch oo(oi).thresholdParameter
case 'size'
oo(oi).spacingDeg=nan;
oo(oi).flankingDirection='none';
case 'spacing'
oo(oi).targetDeg=nan;
end
case 'read'
end
oo(oi).xDeg=oo(oi).eccentricityXYDeg(1);
oo(oi).experiment=experiment;
% USE ONLY 2019 DATA
timeVector=datevec(oo(oi).beginningTime);
ok(oi)= timeVector(1)>2018;
end
oo=oo(ok);
%% SELECT CONDITION(S)
if isempty(oo)
error('No conditions selected.');
end
% Report the relevant fields of each file.
t=struct2table(oo,'AsArray',true);
t=sortrows(t,{'task' 'observer' 'thresholdParameter' 'xDeg' });
% t(:,{'dataFilename' 'targetDeg' 'trialsDesired' 'eccentricityXYDeg' 'observer' 'beginningTime'})
% return
if printFilenames
fprintf('Ready to analyze %d thresholds:\n',length(oo));
switch experiment
case {'CrowdingSurvey' 'CrowdingSurvey2'}
disp(t(:,{'experiment' 'observer' 'localHostName' 'experimenter'...
'task' 'readWordPerMin' 'thresholdParameter' 'eccentricityXYDeg' ...
'flankingDirection' 'spacingDeg' 'targetDeg' ...
'dataFilename'...
'trialsDesired' 'responseCount' ...
'readFilename' ...
'readNumberOfResponses' 'readNumberCorrect' 'targetFont'}));
end
end
t=sortrows(t,{'task' 'experimenter' 'thresholdParameter' 'observer' 'xDeg'});
fprintf('<strong>Writing data to ''%sData.xls''.\n</strong>',oo(1).experiment);
writetable(t,fullfile(dataFolder,'crowdingSurveyData.xls'));
% return
%% SUMMARIZE WHAT WE HAVE FOR EACH OBSERVER
observers=unique({oo.observer});
s=[];
for i=1:length(observers)
s(i).observer=observers{i};
tt=t(ismember(t.observer,{observers{i}}),:);
s(i).conditions=height(tt);
s(i).experimenter=unique(table2cell(tt(:,'experimenter')));
s(i).experimenter=s(i).experimenter{1};
s(i).experiment=unique(table2cell(tt(:,'experiment')));
s(i).localHostName=unique(table2cell(tt(:,'localHostName')));
s(i).numberOfComputers=length(s(i).localHostName);
s(i).task=unique(table2cell(tt(:,'task')));
s(i).task=s(i).task{1};
params={'size' 'spacing'};
for j=1:length(params)
ttt=tt(ismember(tt.thresholdParameter,{params{j}}),:);
ecc=table2array(ttt(:,'xDeg'))';
s(i).([params{j} 'EccXDeg'])=sprintf('%g ',ecc);
if height(ttt)>0
s(i).localHostName=table2array(ttt(1,'localHostName'));
else
s(i).localHostName='';
end
end
s(i).beginningTime=min(table2array(tt(:,'beginningTime')));
s(i).date=datestr(datevec(s(i).beginningTime));
readWordPerMin=table2array(tt(:,'readWordPerMin'));
readWordPerMin=[readWordPerMin{:}];
s(i).readWordPerMinMean=mean(readWordPerMin,'omitnan');
s(i).readWordPerMinSD=std(readWordPerMin,'omitnan');
end
sTable=struct2table(s);
sTable=sortrows(sTable,{'experimenter' 'observer'});
sTable.beginningTime=[];
fprintf('\n<strong>%.0f rows. One row per observer, sorted by experimenter:</strong>\n',height(sTable));
disp(sTable(:,{'date' 'conditions' 'observer' 'localHostName' ...
'experimenter' 'experiment' 'task'...
'spacingEccXDeg' 'sizeEccXDeg' 'readWordPerMinMean' 'readWordPerMinSD'}));
%% Compute each observer's mean and SD of deviation from log normal.
% Struct s with fields: observer, meanReLogNormal, sdReLogNorm.
% Assume we are given a huge oo struct, and each row has one threshold, and
% each row can be any observer.
s=[]; % s(i) is an array struct, indexed across observers.
observers=unique({oo.observer});
for i=1:length(observers)
s(i).observer=observers{i};
ok=ismember({oo.observer},observers{i}); % list of conditions for this observer.
oo1=oo(ok); % All conditions for one observer.
s(i).conditions=length(oo1);
for oi=1:length(oo1) % Iterate over all conditions for this observer.
s(i).eccentricityXYDeg(1:2,oi)=oo1(oi).eccentricityXYDeg;
s(i).beginningTime=oo1(1).beginningTime;
s(i).localHostName=oo1(1).localHostName;
s(i).experimenter=oo1(1).experimenter;
s(i).experiment=oo1(1).experiment;
s(i).date=datestr(datevec(s(i).beginningTime));
switch oo1(oi).thresholdParameter
case 'size'
s(i).sizeDeg(oi)=oo1(oi).targetDeg;
s(i).spacingDeg(oi)=nan;
s(i).sizeReNominal(oi)=oo1(oi).targetDeg/NominalAcuityDeg(oo1(oi).eccentricityXYDeg);
s(i).spacingReNominal(oi)=nan;
case 'spacing'
s(i).sizeDeg(oi)=nan;
s(i).spacingDeg(oi)=oo1(oi).spacingDeg;
s(i).sizeReNominal(oi)=nan;
s(i).spacingReNominal(oi)=...
oo1(oi).spacingDeg/NominalCrowdingDistanceDeg(oo1(oi).eccentricityXYDeg);
end
% s(i).readWordPerMin=oo1(oi).readWordPerMin;
end
ok=isfinite(s(i).eccentricityXYDeg(1,:));
s(i).meanLogSizeReNominal=mean(log10(s(i).sizeReNominal(ok)),'omitnan');
s(i).SDLogSizeReNominal=std(log10(s(i).sizeReNominal(ok)),'omitnan');
ok=s(i).eccentricityXYDeg(1,:)~=0;
s(i).meanLogPeripheralSpacingReNominal=mean(log10(s(i).spacingReNominal(ok)),'omitnan');
s(i).SDLogPeripheralSpacingReNominal=std(log10(s(i).spacingReNominal(ok)),'omitnan');
sortX=-10;
ii=find(s(i).eccentricityXYDeg(1,:)==sortX);
if isempty(ii)
s(i).sort=nan;
else
ii=ii(1);
s(i).sort=s(i).meanLogPeripheralSpacingReNominal;
end
end
t=struct2table(s);
t=sortrows(t,'sort');
s=table2struct(t);
if 1
fprintf('\n<strong>%.0f observers, sorted by MeanLogPeripheralSpacing.\n</strong>',...
height(t));
disp(t);
tableTitle='List of observers, sorted by peripheral crowding';
tableFile=fullfile(fileparts(mfilename('fullpath')),'data',[tableTitle '.csv']);
writetable(t(:,{'observer' 'conditions' 'date' 'beginningTime' 'localHostName' ...
'experimenter' 'experiment' 'meanLogPeripheralSpacingReNominal' ...
'SDLogPeripheralSpacingReNominal'}),tableFile);
end
if 1
fprintf('\n<strong>%.0f observers, sorted by name.\n</strong>',...
height(t));
t.observerLower=lower(t.observer);
t=sortrows(t,{'observerLower'});
disp(t(:,{'observer' 'conditions' 'localHostName' 'date' 'experimenter'}));
tableTitle='List of observers, alphabetical';
tableFile=fullfile(fileparts(mfilename('fullpath')),'data',[tableTitle '.csv']);
writetable(t(:,{'observer' 'conditions' 'localHostName' 'date' 'beginningTime' ...
'experimenter' }),tableFile);
end
return
figure
count=0;
for i=1:length(s)
s(i).quantile=i/length(s);
s(i).color=[1 0 0]*s(i).quantile+[0 1 0]*(1-s(i).quantile);
if s(i).SDLogPeripheralSpacingReNominal>0.26
% continue
end
if s(i).meanLogPeripheralSpacingReNominal>-1 && s(i).meanLogPeripheralSpacingReNominal<0.2
% Plot only the extremes of crowding distance.
% continue
end
% Spacing
ok=ismember({oo.observer},s(i).observer); % list of conditions for this observer.
ok=ok & ismember({oo.thresholdParameter},'spacing');
oo1=oo(ok); % All conditions for this observer and measure.
clear x y y2
for oi=1:length(oo1)
% x(oi)=abs(oo1(oi).eccentricityXYDeg(1));
x(oi)=oo1(oi).eccentricityXYDeg(1);
y(oi)=oo1(oi).spacingDeg / NominalCrowdingDistanceDeg(oo1(oi).eccentricityXYDeg);
y2(oi)=oo1(oi).targetDeg / NominalAcuityDeg(oo1(oi).eccentricityXYDeg);
end
[~,ii]=sort(x);
x=x(ii);
y=y(ii);
y2=y2(ii);
subplot(2,1,1)
semilogy(x,y,'-o','Color',s(i).color);
hold on
ylabel('Crowding dist re nominal');
xlabel('X eccentrity (deg)');
title('Crowding vs eccentricity');
text(-9.8,.015,'Nominal crowding distance = 0.3*(ecc+0.15)');
coloringMessage=sprintf('Color indicates quantile of crowding distance at (%d,0) deg.',...
sortX);
text(-9.8,60,coloringMessage);
ax=gca;
ax.FontSize=12;
count=count+1;
% Acuity
ok=ismember({oo.observer},s(i).observer); % list of conditions for this observer.
ok=ok & ismember({oo.thresholdParameter},'size');
oo1=oo(ok); % All conditions for this observer and measure.
if ~isempty(oo1)
clear x y
for oi=1:length(oo1)
% x(oi)=abs(oo1(oi).eccentricityXYDeg(1));
x(oi)=oo1(oi).eccentricityXYDeg(1);
y(oi)=oo1(oi).targetDeg / NominalAcuityDeg(oo1(oi).eccentricityXYDeg);
end
[~,ii]=sort(x);
x=x(ii);
y=y(ii);
subplot(2,1,2)
semilogy(x,y,'-o','Color',s(i).color);
hold on
xlim([-10 10]);
ylim([.001 10]);
ylabel('Acuity re nominal');
xlabel('X eccentrity (deg)');
title('Acuity vs eccentricity');
text(-9.8,.015/10,'Nominal acuity = 0.029*(ecc+2.72)');
text(-9.8,6,coloringMessage);
ax=gca;
ax.FontSize=12;
end
end
subplot(2,1,1)
text(8.5,.015,sprintf('N = %d',count));
subplot(2,1,2)
text(8.5,.015/10,sprintf('N = %d',count));
% SAVE PLOT TO DISK
figureTitle='Crowding & acuity vs eccentricity';
% graphFile=fullfile(fileparts(mfilename('fullpath')),'data',[figureTitle '.eps']);
% saveas(gcf,graphFile,'epsc')
fprintf('<strong>Writing ''%s.pdf'' to disk.</strong>\n',figureTitle);
graphFile=fullfile(fileparts(mfilename('fullpath')),'data',[figureTitle '.pdf']);
saveas(gcf,graphFile,'pdf')
return
%% COMPUTE MEAN FOR EACH OBSERVER FOR EACH MEASURE
% Replace repeated measures by their mean.
% The new table has the mean of each observer, at each location and
% flankingDirection.
% t=sortrows(t,{'eccentricityXYDeg','thresholdParameter','observer'});
tmean=table();
t(:,'n')={1}; % Number of thresholds represented by each row.
i=1; % row index
while ~isempty(t)
if i>1
tmean(i,:)=tmean(1,:); % Add a row.
end
tmean(i,t.Properties.VariableNames)=t(1,:);
tmean(:,{'spacingDeg' 'targetDeg'})=[];
match=ismember(t{:,'observer'},t{1,'observer'}) ...
& ismember(t.eccentricityXYDeg(:,1),t(1,:).eccentricityXYDeg(:,1)) ...
& ismember(t.flankingDirection,t(1,:).flankingDirection);
tmean(i,'n')={sum(match)};
if sum(match)==0
error('No match.');
end
tmean(i,'logSpacingDegMean')={mean(log10(t{match,'spacingDeg'}))};
tmean(i,'logSpacingDegSD')={std(log10(t{match,'spacingDeg'}))};
tmean(i,'logSpacingDegN')={length(log10(t{match,'spacingDeg'}))};
tmean(i,'logAcuityDegMean')={mean(log10(t{match,'targetDeg'}))};
tmean(i,'logAcuityDegSD')={std(log10(t{match,'targetDeg'}))};
tmean(i,'logAcuityDegN')={length(log10(t{match,'targetDeg'}))};
t(match,:)=[];
i=i+1;
end
t=tmean;
clear height
fprintf('Repeated measures have been replaced by their means. %d thresholds over %d conditions.\n',sum(t.n),height(t));
disp(t(:,{'thresholdParameter','observer','n','eccentricityXYDeg', ...
'flankingDirection'}));
if false % SKIP HISTOGRAMS
%% PLOT HISTOGRAMS (ACROSS OBSERVERS) OF SEVERAL KINDS OF THRESHOLD. AT ±10, ±5, ±2.5, 0 DEG.
figure;
graphWidth=25;
graphHeight=50;
set(0,'units','centimeters');
screenSize=get(groot,'Screensize');
set(gcf,'units','centimeters','position',...
[screenSize(3)-graphWidth,0,graphWidth,graphHeight])
plusMinus=char(177);
for type=1:3
switch type
case 1
ok=streq(t.thresholdParameter,'size');
x=t(ok,:).logAcuityDegMean;
name='Acuity (deg)';
m=mean(x);
sd=std(x);
se=mean(t(ok,:).logAcuityDegSD./sqrt(t(ok,:).logAcuityDegN))/sqrt(length(x));
name=sprintf('%s, mean %.1f%c%.1f, Retest SE %.2f',name,m,plusMinus,sd,se);
case 2
ok=streq(t.thresholdParameter,'spacing') & ...
(streq(t.flankingDirection,'radial') | streq(t.flankingDirection,'horizontal'));
x=t{ok,'logSpacingDegMean'};
name='log Radial or Horizontal crowding distance (deg)';
m=mean(x);
sd=std(x);
se=mean(t(ok,:).logSpacingDegSD./sqrt(t(ok,:).logSpacingDegN))/sqrt(length(x));
name=sprintf('%s, mean %.1f%c%.1f, Retest SE %.2f',name,m,plusMinus,sd,se);
case 3
ok=streq(t.thresholdParameter,'spacing') & streq(t.flankingDirection,'tangential');
x=t{ok,'logSpacingDegMean'};
name='log Tangential crowding distance (deg)';
m=mean(x);
sd=std(x);
okPositive=ok & t.logSpacingDegSD>0;
se=mean(t(okPositive,:).logSpacingDegSD./sqrt(t(okPositive,:).logSpacingDegN))/sqrt(length(x));
name=sprintf('%s, mean %.1f%c%.1f, Retest SE %.2f',name,m,plusMinus,sd,se);
% case 4
% ok=streq(t.thresholdParameter,'spacing') & streq(t.flankingDirection,'radial');
% x=t{ok,'logSpacingDegMean'};
% ok=streq(t.thresholdParameter,'spacing') & streq(t.flankingDirection,'tangential');
% y=t{ok,'logSpacingDegMean'};
% x=x-y;
% name='log Radial:Tangential ratio';
% m=mean(x);
% sd=std(x);
% name=sprintf('%s, mean %.1f%c%.1f',name,m,plusMinus,sd);
% case 5
% ok=streq(t.thresholdParameter,'spacing') & streq(t.flankingDirection,'tangential');
% x=t{ok,'logSpacingDegMean'};
% ok=streq(t.thresholdParameter,'size');
% y=t(ok,:).logAcuityDegMean;
% x=x-y;
% name='log Tangential crowding:Acuity ratio';
% m=mean(x);
% sd=std(x);
% name=sprintf('%s, mean %.1f%c%.1f',name,m,plusMinus,sd);
end
if sum(ok)==0
continue
end
i=find(ok);
parameter=name;
subplot(3,1,type)
histogram(x,'BinWidth',0.1);
ylabel('Count');
xlabel(parameter);
title(sprintf('Histogram of %d hemispheres at (%c%.0f,%.0f) deg',length(x),plusMinus,abs(t{i(1),'eccentricityXYDeg'})));
ax=gca;
ax.FontSize=12;
yticks(unique(round(ax.YTick)));
if ax.YLim(2)>4
ax.YMinorTick='on';
end
end
if true
% Align x axes of radial and tangential histograms.
subplot(3,1,2)
ax=gca;
radialXLim=ax.XLim;
subplot(3,1,3)
ax=gca;
tangentialXLim=ax.XLim;
ax.XLim(1)=min([radialXLim(1) tangentialXLim(1)]);
ax.XLim(2)=max([radialXLim(2) tangentialXLim(2)]);
subplot(3,1,2)
ax=gca;
ax.XLim(1)=min([radialXLim(1) tangentialXLim(1)]);
ax.XLim(2)=max([radialXLim(2) tangentialXLim(2)]);
end
return
%% SAVE PLOT TO DISK
figureTitle='Histograms';
graphFile=fullfile(fileparts(mfilename('fullpath')),'data',[figureTitle '.eps']);
saveas(gcf,graphFile,'epsc')
graphFile=fullfile(fileparts(mfilename('fullpath')),'data',[figureTitle '.fig']);
saveas(gcf,graphFile)
fprintf('Figure saved as ''/data/%s.eps'' and ''/data/%s.fig''\n',figureTitle,figureTitle);
%% SAVE TO DISK AS CSV AND FIG FILES
printConditions=true;
saveSpreadsheet=true;
vars={'thresholdParameter' 'observer' 'eccentricityXYDeg' 'flankingDirection' ...
'experiment' 'experimenter' 'trialsDesired' 'contrast' ...
'targetDeg' 'spacingDeg' 'durationSec' ...
'viewingDistanceCm' 'dataFilename'};
t=struct2table(oo,'AsArray',true);
t=sortrows(t,{'thresholdParameter' 'observer' 'eccentricityXYDeg' });
dataFilename=[experiment '.csv'];
if saveSpreadsheet
spreadsheet=fullfile(fileparts(mfilename('fullpath')),'data',dataFilename);
writetable(t,spreadsheet);
fprintf('Spreadsheet saved as: /data/%s\n',dataFilename);
end
if printConditions
disp(t(:,vars));
end
end