0001 function [counts,indices] = RadialMaze(data,baitedArms,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 global showANOVAs;
0049 global measures plots;
0050 global nTrials nDays nArms nConfigurations nRats nGroups;
0051 global nVisitsDayOne;
0052 global p0 pInf;
0053 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0054 global alpha;
0055
0056 alpha = 0.05;
0057
0058
0059 RAT = 1;
0060 DAY = 2;
0061 TRIAL = 3;
0062 CONF = 4;
0063 GROUP = 5;
0064
0065
0066 ARM = 6;
0067
0068
0069 REF = 6;
0070 WORK = 7;
0071 REWARDS = 8;
0072 VISITS = 9;
0073 PERF = 10;
0074 PENALTY = 11;
0075 ADJUSTED = 12;
0076
0077
0078 nDays = max(data(:,DAY));
0079 nTrials = 3;
0080 nArms = 8;
0081 nGroups = max(data(:,GROUP));
0082 nConfigurations = max(data(:,CONF));
0083 nRats = length(unique(data(:,RAT)));
0084
0085
0086 nVisitsDayOne = round(Accumulate(data(:,DAY),1)/nRats/nTrials);
0087 nVisitsDayOne = nVisitsDayOne(1);
0088
0089
0090 allMeasures = {'ref','work','rewards','visits','perf','penalty','adjusted'};
0091 allPlots = {'groups','individuals'};
0092 defaultMeasures = {'perf'};
0093 defaultPlots = {'groups','individuals'};
0094 listMeasures = false;
0095 listPlots = false;
0096 measures = {};
0097 plots = {};
0098 showANOVAs = true;
0099
0100 if nargin < 2,
0101 error('Incorrect number of parameters (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).');
0102 end
0103
0104 if mod(length(varargin),2) ~= 0,
0105 error('Incorrect number of parameters (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).');
0106 end
0107
0108
0109 for i = 1:2:length(varargin),
0110 if ~ischar(varargin{i}),
0111 error(['Parameter ' num2str(i+firstIndex) ' is not a property (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).']);
0112 end
0113 switch(lower(varargin{i})),
0114 case 'measures',
0115 p = lower(varargin{i+1});
0116 if ~isa(p,'cell'),
0117 error('Value associated with property ''measures'' is not a cell array of strings (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).');
0118 end
0119 for j = 1:length(p),
0120 if ~isastring(p{j},allMeasures{:}),
0121 error('Incorrect value for property ''measures'' (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).');
0122 end
0123 end
0124 measures = {measures{:},p{:}};
0125 listMeasures = true;
0126 case 'plots',
0127 f = lower(varargin{i+1});
0128 if ~isa(f,'cell'),
0129 error('Value associated with property ''plots'' is not a cell array of strings (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).');
0130 end
0131 for j = 1:length(f),
0132 if ~isastring(f{j},allPlots{:}),
0133 error('Incorrect value for property ''plots'' (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).');
0134 end
0135 end
0136 plots = {plots{:},f{:}};
0137 listPlots = true;
0138 case 'anova',
0139 doIt = lower(varargin{i+1});
0140 if ~isastring(doIt,'on','off'),
0141 error('Incorrect value for property ''anova'' (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).');
0142 end
0143 showANOVAs = strcmp(doIt,'on');
0144 otherwise,
0145 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help RadialMaze">RadialMaze</a>'' for details).']);
0146 end
0147 end
0148
0149 if ~listMeasures, measures = defaultMeasures; end
0150 if ~listPlots, plots = defaultPlots; end
0151
0152
0153 counts = Counts(data,baitedArms);
0154 indices = ComputeIndices(counts);
0155
0156
0157 p0 = 0.481869891541284;
0158 pInf = 0.306735773403144;
0159
0160 h = ComputeANOVAs(indices);
0161
0162 if any(ismember('individuals',plots)),
0163 PlotIndividualStats(counts);
0164 end
0165 if any(ismember('groups',plots)),
0166 PlotGroupStats(indices,h);
0167 end
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 function counts = Counts(data,baitedArms)
0182
0183 global nTrials nDays nArms nConfigurations nGroups;
0184 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0185
0186 nRats = max(data(:,RAT));
0187
0188
0189
0190
0191
0192
0193 line = 1;
0194 for rat = 1:nRats,
0195
0196
0197 group = data(data(:,RAT)==rat,GROUP);
0198 group = group(1);
0199
0200 for configuration = 1:nConfigurations,
0201
0202
0203 b = baitedArms(rat,configuration,:);
0204 baitedArm1 = b(1);
0205 baitedArm2 = b(2);
0206 baitedArm3 = b(3);
0207 unbaitedArms = setdiff(1:8,[baitedArm1 baitedArm2 baitedArm3]);
0208 unbaitedArm1 = unbaitedArms(1);
0209 unbaitedArm2 = unbaitedArms(2);
0210 unbaitedArm3 = unbaitedArms(3);
0211 unbaitedArm4 = unbaitedArms(4);
0212 unbaitedArm5 = unbaitedArms(5);
0213
0214 for day = 1:nDays,
0215 for trial = 1:nTrials,
0216
0217
0218 block = data(data(:,RAT)==rat&data(:,CONF)==configuration&data(:,DAY)==day&data(:,TRIAL)==trial,:);
0219
0220
0221 nVisits = size(block,1);
0222
0223
0224 if nVisits == 0,
0225 continue;
0226 end
0227
0228
0229 counts(line,1:REF-1) = [rat,day,trial,configuration,group];
0230
0231
0232 counts(line,REF:ADJUSTED) = zeros(1,7);
0233 counts(line,VISITS) = nVisits;
0234
0235
0236 visitedBaitedArm1 = false;
0237 visitedBaitedArm2 = false;
0238 visitedBaitedArm3 = false;
0239 visitedUnbaitedArm1 = false;
0240 visitedUnbaitedArm2 = false;
0241 visitedUnbaitedArm3 = false;
0242 visitedUnbaitedArm4 = false;
0243 visitedUnbaitedArm5 = false;
0244
0245 for visit = 1:nVisits,
0246
0247
0248 currentArm = block(visit,ARM);
0249 switch currentArm,
0250 case baitedArm1,
0251 if visitedBaitedArm1,
0252
0253 counts(line,WORK) = counts(line,WORK)+1;
0254 else
0255 visitedBaitedArm1 = true;
0256 counts(line,REWARDS) = counts(line,REWARDS)+1;
0257 end
0258 case baitedArm2,
0259 if visitedBaitedArm2,
0260 counts(line,WORK) = counts(line,WORK)+1;
0261 else
0262 visitedBaitedArm2 = true;
0263 counts(line,REWARDS) = counts(line,REWARDS)+1;
0264 end
0265 case baitedArm3,
0266 if visitedBaitedArm3,
0267 counts(line,WORK) = counts(line,WORK)+1;
0268 else
0269 visitedBaitedArm3 = true;
0270 counts(line,REWARDS) = counts(line,REWARDS)+1;
0271 end
0272 case unbaitedArm1,
0273 if visitedUnbaitedArm1,
0274 counts(line,WORK) = counts(line,WORK)+1;
0275 else
0276 visitedUnbaitedArm1 = true;
0277 counts(line,REF) = counts(line,REF)+1;
0278 end
0279 case unbaitedArm2,
0280 if visitedUnbaitedArm2,
0281 counts(line,WORK) = counts(line,WORK)+1;
0282 else
0283 visitedUnbaitedArm2 = true;
0284 counts(line,REF) = counts(line,REF)+1;
0285 end
0286 case unbaitedArm3,
0287 if visitedUnbaitedArm3,
0288 counts(line,WORK) = counts(line,WORK)+1;
0289 else
0290 visitedUnbaitedArm3 = true;
0291 counts(line,REF) = counts(line,REF)+1;
0292 end
0293 case unbaitedArm4,
0294 if visitedUnbaitedArm4,
0295 counts(line,WORK) = counts(line,WORK)+1;
0296 else
0297 visitedUnbaitedArm4 = true;
0298 counts(line,REF) = counts(line,REF)+1;
0299 end
0300 case unbaitedArm5,
0301 if visitedUnbaitedArm5,
0302 counts(line,WORK) = counts(line,WORK)+1;
0303 else
0304 visitedUnbaitedArm5 = true;
0305 counts(line,REF) = counts(line,REF)+1;
0306 end
0307 end
0308 end
0309 counts(line,PERF) = counts(line,REWARDS)/counts(line,VISITS);
0310
0311 counts(line,ADJUSTED) = counts(line,REF)+(3-counts(line,REWARDS));
0312
0313 if counts(line,REWARDS)~= 3,
0314 counts(line,PENALTY) = 5;
0315 else
0316 counts(line,PENALTY) = counts(line,REF);
0317 end
0318 line = line + 1;
0319 end
0320 end
0321 end
0322 end
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335 function indices = ComputeIndices(counts)
0336
0337 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0338
0339 indices = counts;
0340 indices(:,[REF WORK REWARDS VISITS PENALTY ADJUSTED]) = ComputeCountIndex(counts(:,[REF WORK REWARDS VISITS PENALTY ADJUSTED]));
0341 indices(:,PERF) = ComputeProportionIndex(counts(:,PERF));
0342
0343 function index = ComputeCountIndex(count)
0344
0345 index = sqrt(count+1);
0346
0347 function index = ComputeProportionIndex(proportion)
0348
0349 index = asin(sqrt(proportion))/(pi/2);
0350
0351
0352
0353
0354
0355
0356
0357
0358 function PlotIndividualStats(counts)
0359
0360 global nTrials nDays nConfigurations measures plots testRats controlRats;
0361 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0362
0363 if any(ismember('ref',measures)),
0364 DoPlotIndividualStats(counts,REF,'# ref mem errors',[0 5]);
0365 end
0366 if any(ismember('work',measures)),
0367 DoPlotIndividualStats(counts,WORK,'# work mem errors',[0 5]);
0368 end
0369 if any(ismember('visits',measures)),
0370 DoPlotIndividualStats(counts,VISITS,'# visits',[0 10]);
0371 end
0372 if any(ismember('rewards',measures)),
0373 DoPlotIndividualStats(counts,REWARDS,'# rewards',[0 3]);
0374 end
0375 if any(ismember('perf',measures)),
0376 DoPlotIndividualStats(counts,PERF,'performance',[0 1]);
0377 end
0378 if any(ismember('penalty',measures)),
0379 DoPlotIndividualStats(counts,PENALTY,'# penalty errors',[0 5]);
0380 end
0381 if any(ismember('adjusted',measures)),
0382 DoPlotIndividualStats(counts,ADJUSTED,'# adjusted errors',[0 5]);
0383 end
0384
0385
0386 function DoPlotIndividualStats(counts,measure,measureStr,yLim)
0387
0388 global nRats nConfigurations nDays;
0389 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0390
0391 p0 = 0.481869891541284;
0392 pInf = 0.306735773403144;
0393
0394 colors = 'rbkgcmy';
0395 for configuration = 1:nConfigurations,
0396 figure;
0397 for rat = 1:nRats,
0398 SquareSubplot(nRats,rat);
0399 d = counts(counts(:,RAT)==rat&counts(:,CONF)==configuration,[DAY measure GROUP]);
0400 if isempty(d), continue; end
0401 y = Accumulate(d(:,1),d(:,2));
0402 n = Accumulate(d(:,1),1);
0403 plot(y./n,colors(d(1,3)));
0404 xlabel(['Rat #' int2str(rat) ' - Configuration #' int2str(configuration)]);
0405 ylabel(measureStr);
0406 xlim([0 nDays+1]);set(gca,'xtick',1:nDays);ylim(yLim);
0407 PlotIntervals([pInf,p0],'rectangles','h');
0408 end
0409 end
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419 function PlotGroupStats(indices,h)
0420
0421 global measures;
0422 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0423
0424
0425 if any(ismember('ref',measures)),
0426 DoPlotGroupStats(indices,REF,'index ref mem errors',[0 5],h);
0427 end
0428 if any(ismember('work',measures)),
0429 DoPlotGroupStats(indices,WORK,'index work mem errors',[0.5 2],h);
0430 end
0431 if any(ismember('rewards',measures)),
0432 DoPlotGroupStats(indices,REWARDS,'index rewards errors',[0.3 1],h);
0433 end
0434 if any(ismember('visits',measures)),
0435 DoPlotGroupStats(indices,VISITS,'index visits errors',[0.3 1],h);
0436 end
0437 if any(ismember('perf',measures)),
0438 DoPlotGroupStats(indices,PERF,'index performance errors',[0.3 1],h);
0439 end
0440 if any(ismember('penalty',measures)),
0441 DoPlotGroupStats(indices,PENALTY,'index penalty errors',[0.3 1],h);
0442 end
0443 if any(ismember('adjusted',measures)),
0444 DoPlotGroupStats(indices,ADJUSTED,'index adjusted errors',[0.3 1],h);
0445 end
0446
0447
0448 function DoPlotGroupStats(indices,measure,measureStr,yLim,h)
0449
0450 global nTrials nDays nConfigurations nRats nGroups;
0451 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0452 global p0 pInf;
0453
0454 colors = 'rbkgcmy';
0455 for configuration = 1:nConfigurations,
0456 figure;hold on;
0457 for group = 1:nGroups,
0458 d = indices(indices(:,GROUP)==group&indices(:,CONF)==configuration,[DAY measure]);
0459 if isempty(d), continue; end
0460 [m,s] = Accumulate(d(:,1),d(:,2));
0461 n = Accumulate(d(:,1),1);
0462 sem = s./sqrt(n);
0463 p = errorbar(m,sem,colors(group));
0464 set(p,'marker','.','markersize',24);
0465 xlabel(['Configuration #' int2str(configuration)]);
0466 ylabel(['index ' measureStr]);
0467 xlim([0 nDays+1]);set(gca,'xtick',1:nDays);ylim(yLim);
0468
0469 if ~isempty(h),
0470 x = find(h(:,1+group*2,measure));
0471 plot(x,(m(x)-sem(x))-.025,'k+','markersize',10);
0472 if group == 1 & configuration == 1,
0473 x = find(h(:,1,measure));
0474 plot(x,(m(x)+sem(x))+.025,'k*','markersize',10);
0475 end
0476 end
0477 end
0478 if measure == PERF,
0479 PlotIntervals([pInf,p0],'rectangles','h');
0480 end
0481 end
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491 function h = ComputeANOVAs(indices)
0492
0493 global measures;
0494 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0495
0496 if any(ismember('ref',measures)),
0497 h(:,:,REF) = DoComputeANOVAs(indices,REF,'ref mem errors');
0498 end
0499 if any(ismember('work',measures)),
0500 h(:,:,WORK) = DoComputeANOVAs(indices,WORK,'work mem errors');
0501 end
0502 if any(ismember('visits',measures)),
0503 h(:,:,VISITS) = DoComputeANOVAs(indices,VISITS,'visits');
0504 end
0505 if any(ismember('rewards',measures)),
0506 h(:,:,REWARDS) = DoComputeANOVAs(indices,REWARDS,'rewards');
0507 end
0508 if any(ismember('perf',measures)),
0509 h(:,:,PERF) = DoComputeANOVAs(indices,PERF,'performance');
0510 end
0511 if any(ismember('penalty',measures)),
0512 h(:,:,PENALTY) = DoComputeANOVAs(indices,PENALTY,'penalty errors');
0513 end
0514 if any(ismember('adjusted',measures)),
0515 h(:,:,ADJUSTED) = DoComputeANOVAs(indices,ADJUSTED,'adjusted errors');
0516 end
0517
0518
0519 function h = DoComputeANOVAs(indices,measure,measureStr)
0520
0521 global showANOVAs;
0522 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0523
0524 [p,t,stats,terms,h] = ComputeTwoWayANOVA(indices,measure);
0525 if showANOVAs,
0526 f = statdisptable(t,['ANOVA for ' measureStr],'Analysis of Variance');
0527 set(f,'numbertitle','off');
0528 end
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544 function [p,t,stats,terms,h] = ComputeTwoWayANOVA(indices,measure)
0545
0546 global RAT DAY TRIAL CONF GROUP ARM REF WORK REWARDS VISITS PERF PENALTY ADJUSTED;
0547 global p0 pInf;
0548 global nDays nGroups alpha;
0549
0550 i = indices(:,CONF) == 1;
0551 [p,t,stats,terms] = anovan(indices(i,measure),{indices(i,GROUP) indices(i,DAY)},'model','full','varnames',{'group','day'},'display','off');
0552
0553 h = zeros(nDays,2+2*nGroups);
0554 switch measure,
0555 case { REF, WORK, VISITS, PENALTY, ADJUSTED },
0556 tail = 'right';
0557 case { PERF, REWARDS },
0558 tail = 'left';
0559 end
0560
0561
0562 if all(p<0.05),
0563 for day = 1:nDays,
0564 d1 = indices(i&indices(:,DAY)==day&indices(:,GROUP)==1,measure);
0565 d2 = indices(i&indices(:,DAY)==day&indices(:,GROUP)==2,measure);
0566 if ~isempty(d1) && ~isempty(d2),
0567
0568
0569 [h(day,1),h(day,2)] = ttest2(d1,d2,alpha,tail);
0570 end
0571 for group = 1:nGroups,
0572 d0 = indices(i&indices(:,DAY)==day&indices(:,GROUP)==group,measure);
0573 if ~isempty(d0),
0574 [h(day,1+2*group),h(day,2+2*group)] = ttest(d0,p0,alpha,'right');
0575 end
0576 end
0577 end
0578 end
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592 function ComputeRepeatedMeasuresANOVA(data1,data2)
0593
0594 global nTrials nDays;
0595
0596 group1 = ones(size(data1));
0597 n = size(data1,2);
0598 days1 = repmat((1:nDays)',1,n);
0599 trials1 = repmat((1:nTrials),nDays,n/3);
0600 rats1 = repmat(ceil((1:n)/3),nDays,1);
0601
0602 group2 = 2*ones(size(data2));
0603 n = size(data2,2);
0604 days2 = repmat((1:nDays)',1,n);
0605 trials2 = repmat((1:nTrials),nDays,n/3);
0606 rats2 = repmat(ceil((1:n)/3),nDays,1);
0607
0608 data = [data1(:);data2(:)];
0609 groups = [group1(:);group2(:)];
0610 days = [days1(:);days2(:)];
0611 trials = [trials1(:);trials2(:)];
0612 rats = [rats1(:);rats2(:)];
0613
0614 nans = isnan(data(:,1));
0615 data(nans,:) = [];
0616 groups(nans,:) = [];
0617 days(nans,:) = [];
0618 trials(nans,:) = [];
0619 rats(nans,:) = [];
0620
0621 d = [data groups rats days];
0622
0623 RMAOV1MS(d);
0624
0625
0626
0627
0628
0629 function EstimatePerformanceChanceLevels
0630
0631 global p0 pInf;
0632
0633 p0 = mean(bootstrp(10000,@SimulateOneTrial,0));
0634 pInf = mean(bootstrp(10000,@SimulateOneTrial,Inf));
0635
0636
0637
0638
0639
0640
0641 function index = SimulateOneTrial(nWME)
0642
0643 global nVisitsDayOne;
0644
0645 if isinf(nWME),
0646
0647 n = nVisitsDayOne;
0648 r = floor(Clip(rand(n,1),0,1-eps)*8)+1;
0649
0650 found = any(r==1) + any(r==2) + any(r==3);
0651 else
0652
0653 r = randperm(8);
0654 n1 = find(r==1|r==2|r==3);n1 = n1(1);
0655
0656 r = randperm(8-n1);
0657 n2 = find(r==1|r==2);n2 = n2(1);
0658
0659 r = randperm(8-n1-n2);
0660 n3 = find(r==1);
0661 found = 3;
0662 n = n1+n2+n3+nWME;
0663 end
0664
0665 index = ComputeProportionIndex(found/n);