0001 function [h,p,cr,ca] = TestRemapping(control,repeat,test,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
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 type = 'linear';
0067 show = 'off';
0068 nBootstrap = 150;
0069 alpha = 0.05;
0070
0071
0072 if nargin < 3 | mod(length(varargin),2) ~= 0,
0073 error('Incorrect number of parameters (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).');
0074 end
0075
0076
0077 if ~isdmatrix(control) || ~isdmatrix(repeat) || ~isdmatrix(test),
0078 error('All firing fields should be MxN matrices (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).');
0079 end
0080 if ~(all(size(control)==size(repeat)) && all(size(control)==size(test))),
0081 error('All firing fields should have the same sizes (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).');
0082 end
0083
0084
0085 for i = 1:2:length(varargin),
0086 if ~ischar(varargin{i}),
0087 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).']);
0088 end
0089 switch(lower(varargin{i})),
0090 case 'type',
0091 type = varargin{i+1};
0092 if ~isastring(type,'linear','circular'),
0093 error('Incorrect value for property ''type'' (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).');
0094 end
0095 case 'alpha',
0096 alpha = varargin{i+1};
0097 if ~isdscalar(alpha,'>=0','<=1'),
0098 error('Incorrect value for property ''alpha'' (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).');
0099 end
0100 case 'iterations',
0101 nBootstrap = varargin{i+1};
0102 if ~isiscalar(nBootstrap,'>0'),
0103 error('Incorrect value for property ''iterations'' (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).');
0104 end
0105 case 'show',
0106 show = varargin{i+1};
0107 if ~isastring(show,'on','off'),
0108 error('Incorrect value for property ''show'' (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).');
0109 end
0110 otherwise,
0111 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help TestRemapping">TestRemapping</a>'' for details).']);
0112 end
0113 end
0114 [m,n] = size(control);
0115
0116
0117 [relativeShiftControl,absoluteShiftControl,xcControl] = FieldShift(control,repeat,'type',type);
0118 [relativeShiftTest,absoluteShiftTest,xcTest] = FieldShift(control,test,'type',type);
0119
0120
0121 meanUnsignedRelativeShift = mean(abs(relativeShiftTest));
0122
0123
0124 global RemappingTest_control RemappingTest_shiftControl RemappingTest_type;
0125 RemappingTest_control = control;
0126 RemappingTest_shiftControl = relativeShiftControl;
0127 RemappingTest_type = type;
0128 bRelativeShift = bootstrp(nBootstrap,@RemappingShift,control);
0129 [bPDF,x] = hist(bRelativeShift,100);
0130 bPDF = bPDF / nBootstrap;
0131 bCDF = cumsum(bPDF);
0132
0133
0134 if meanUnsignedRelativeShift < min(x),
0135 p = 0;
0136 elseif meanUnsignedRelativeShift > max(x),
0137 p = 1;
0138 else
0139 p = interp1(x,bCDF,meanUnsignedRelativeShift);
0140 end
0141 h = double(p<alpha);
0142
0143
0144 s = bootstrp(nBootstrap,@mean,absoluteShiftTest);
0145 ca = [prctile(s,100*(alpha/2)) prctile(s,100*(1-(alpha/2)))];
0146 s = bootstrp(nBootstrap,@mean,relativeShiftTest);
0147 cr = [prctile(s,100*(alpha/2)) prctile(s,100*(1-(alpha/2)))];
0148
0149
0150 [y,x] = find(control==repmat(max(control,[],2),1,n));
0151 peakControl = Accumulate(y,x)./Accumulate(y,1)/n;
0152 [y,x] = find(test==repmat(max(test,[],2),1,n));
0153 peakTest = Accumulate(y,x)./Accumulate(y,1)/n;
0154
0155 if strcmp(show,'on'),
0156
0157 figure;
0158
0159 subplot(1,2,1);hold on;
0160 PlotColorCurves(xcControl,[-1 1],0,'w--',absoluteShiftControl,'.k','gamma',2);
0161 title(['Control (N=' int2str(size(xcControl,1)) ')']);
0162
0163 subplot(1,2,2);hold on;
0164 PlotColorCurves(xcTest,[-1 1],0,'w--',absoluteShiftTest,'.k','gamma',2);
0165 title(['Test (N=' int2str(size(xcTest,1)) ')']);
0166
0167 figure;
0168
0169 [absoluteShiftControl,order] = sort(absoluteShiftControl);
0170 xcControl = xcControl(order,:);
0171 subplot(1,2,1);hold on;
0172 PlotColorCurves(xcControl,[-1 1],0,'w--',absoluteShiftControl,'.k','gamma',2);
0173
0174 SideAxes('top',0.1,'gap',0.01);
0175 [hi,xh] = hist(absoluteShiftControl,50);
0176 bar(xh,hi);
0177 PlotHVLines(mean(absoluteShiftControl),'v','r','linewidth',2);
0178 xlim([-1 1]);
0179 set(gca,'xtick',[]);
0180 title(['Control (N=' int2str(size(xcControl,1)) ')']);
0181
0182 [absoluteShiftTest,order] = sort(absoluteShiftTest);
0183 xcTest = xcTest(order,:);
0184 subplot(1,2,2);hold on;
0185 PlotColorCurves(xcTest,[-1 1],0,'w--',absoluteShiftTest,'.k','gamma',2);
0186
0187 SideAxes('top',0.1,'gap',0.01);
0188 [hi,xh] = hist(absoluteShiftTest,50);
0189 bar(xh,hi);
0190 PlotHVLines(mean(absoluteShiftTest),'v','r','linewidth',2);
0191 xlim([-1 1]);
0192 set(gca,'xtick',[]);
0193 title(['Test (N=' int2str(size(xcTest,1)) ')']);
0194
0195 figure;hold on;
0196
0197 [hi,xh] = hist(relativeShiftTest,50);
0198 bar(xh,hi/nBootstrap);
0199 PlotHVLines(cr,'v','k--');
0200 PlotHVLines(mean(s),'v','r','linewidth',2);
0201 xlabel('Relative Shift');
0202 ylabel('Probability');
0203 title(['N = ' num2str(nBootstrap)]);
0204 xLim = xlim;
0205 yLim = ylim;
0206 [~,pval] = ttest(relativeShiftTest);
0207 prop1 = sum(abs(relativeShiftTest)<=1)/length(relativeShiftTest);
0208 prop2 = sum(abs(relativeShiftTest)<=0.5)/length(relativeShiftTest);
0209 m = mean(relativeShiftTest);
0210 s = sem(relativeShiftTest);
0211 l = length(relativeShiftTest);
0212 text(xLim(1)+0.1*abs(xLim(1)),yLim(2)*0.9,{mean2str(m,s,l),[num2str((1-alpha)*100) '% Confidence Interval [' sprintf('%.3f',cr(1)) ',' num2str(cr(2)) ']'],['t-test p = ' sprintf('%.3f',pval)],[sprintf('%.3f',prop1*100) '% |x|<=1'],[sprintf('%.3f',prop2*100) '% |x|<=0.5']});
0213
0214 figure;
0215
0216 subplot(2,2,1);hold on;
0217 nBins = 500;
0218 range = max([relativeShiftControl;relativeShiftTest])*[-1 1];
0219 sc = Bin(relativeShiftControl,range,nBins);
0220 st = Bin(relativeShiftTest,range,nBins);
0221 z = Smooth(Accumulate([sc st],1,[nBins nBins]),10)'/n;
0222 PlotColorMap(z,'x',linspace(range(1),range(2),n),'y',linspace(range(1),range(2),n));
0223 xlabel('Control Shift (proportion of field size)');
0224 ylabel('Test Shift (proportion of field size)');
0225 clim([0 0.3*max(z(:))]);
0226
0227 subplot(2,2,2);hold on;
0228 PlotRepeat(peakControl,peakTest,'xxyy','k.');
0229 xlabel('Control Peak Position');
0230 ylabel('Test Peak Position');
0231 [beta,R2,pSlope] = CircularRegression(peakControl*2*pi,peakTest*2*pi,'slope',1);
0232 title(['slope = ' num2str(beta(1)) ' (p = ' num2str(pSlope) ')']);
0233 PlotSlope(1,1,beta(1),2,'r','LineWidth',2);
0234
0235 subplot(2,2,[3 4]);hold on;
0236 [hi,x] = hist(bRelativeShift,30);
0237 b = bar(x,hi/nBootstrap);
0238 hold on;
0239 PlotHVLines(meanUnsignedRelativeShift,'v','r');
0240 Y = ylim; Y = Y(2);
0241 text(meanUnsignedRelativeShift*1.25,Y*0.85,['p = ' sprintf('%.3f',p)]);
0242 xlim([0 1]);
0243 title(['N = ' num2str(nBootstrap)]);
0244 xlabel('Mean Unsigned Shift (proportion of field size)');
0245 ylabel('Probability');
0246
0247 figure;
0248
0249 subplot(2,2,1);hold on;
0250 pc = Bin(peakControl,[0 1],10);
0251 [m,stdev] = Accumulate(pc,relativeShiftTest);
0252 s = stdev/sqrt(length(m));
0253
0254 errorbar(0.05+(0:0.1:0.9),m,s,s,'k','LineStyle','none');
0255 bar(0.05+(0:0.1:0.9),m);
0256 plot(peakControl,relativeShiftTest,'.r');
0257 xlabel('Peak Position');
0258 ylabel('Shift (proportion of field size)');
0259 pa = anova1(relativeShiftTest,pc,'off');
0260 yLim = ylim;
0261 text(mean(xlim),yLim(2)*0.9,['p = ' num2str(pa)]);
0262 subplot(2,2,3);hold on;
0263 [m,stdev] = Accumulate(pc,abs(relativeShiftTest));
0264 s = stdev/sqrt(length(m));
0265 errorbar(0.05+(0:0.1:0.9),m,s,s,'k','LineStyle','none');
0266 bar(0.05+(0:0.1:0.9),m);
0267 plot(peakControl,relativeShiftTest,'.r');
0268 xlabel('Peak Position');
0269 ylabel('Unsigned Shift (proportion of field size)');
0270 pa = anova1(abs(relativeShiftTest),pc,'off');
0271 yLim = ylim;
0272 text(mean(xlim),yLim(2)*0.9,['p = ' num2str(pa)]);
0273 subplot(2,2,2);hold on;
0274 [m,stdev] = Accumulate(pc,absoluteShiftTest);
0275 s = stdev/sqrt(length(m));
0276 errorbar(0.05+(0:0.1:0.9),m,s,s,'k','LineStyle','none');
0277 bar(0.05+(0:0.1:0.9),m);
0278 plot(peakControl,absoluteShiftTest,'.r');
0279 xlabel('Peak Position');
0280 ylabel('Shift (proportion of field size)');
0281 pa = anova1(absoluteShiftTest,pc,'off');
0282 yLim = ylim;
0283 text(mean(xlim),yLim(2)*0.9,['p = ' num2str(pa)]);
0284 subplot(2,2,4);hold on;
0285 [m,stdev] = Accumulate(pc,abs(absoluteShiftTest));
0286 s = stdev/sqrt(length(m));
0287 errorbar(0.05+(0:0.1:0.9),m,s,s,'k','LineStyle','none');
0288 bar(0.05+(0:0.1:0.9),m);
0289 plot(peakControl,absoluteShiftTest,'.r');
0290 xlabel('Peak Position');
0291 ylabel('Unsigned Shift (proportion of field size)');
0292 pa = anova1(abs(absoluteShiftTest),pc,'off');
0293 yLim = ylim;
0294 text(mean(xlim),yLim(2)*0.9,['p = ' num2str(pa)]);
0295
0296 end
0297
0298
0299
0300 function meanUnsignedRelativeShift = RemappingShift(test)
0301
0302 global RemappingTest_control RemappingTest_shiftControl RemappingTest_type;
0303 control = RemappingTest_control;
0304 relativeShiftControl = RemappingTest_shiftControl;
0305 type = RemappingTest_type;
0306
0307
0308 relativeShiftTest = FieldShift(control,test,'type',type);
0309
0310
0311 meanUnsignedRelativeShift = mean(abs(relativeShiftTest));