function out=legTrackerD2DBS(data) %legTrackerD2DBS resamples data recorded from day-to-day experiments to %determine the distribution of distances between flies under a null %hypothesis that intra-fly distance measures are no different than %inter-fly distance measures. Output is resampled mean intra-fly distances. %Usage: %out=legTrackerD2DBS(data) %data = n x k array. n is number of flies, k is number of metrics. E.g. k=2 %in analysis of the intra- and inter-fly distance in the first and second %principle components of Figs 3c and 3e. % vector of fly identities (length n). Used for its length. Values are used % to sort shuffled arrays. flies=[1;1;1;2;2;3;3;4;4;5;5;6;6;6;7;7;8;8]; % number of resampling replicates n=50000; %allocate output in memory out=zeros(n,1); %for resampling replicates for i=1:n % randomly re-order fly identity newFlies=flies(randperm(length(flies))); newData=[data newFlies]; % sort data for new resampled identities newData=sortrows(newData,size(data,2)+1); % pairwise dist between all flies dist=squareform(pdist(newData)); % get intra-fly distances d=[dist(2,1) dist(3,1) dist(3,2) dist(5,4) dist(7,6) dist(9,8) dist(11,9) dist(13,12) dist(14,12) dist(14,13) dist(15,16) dist(17,18)]; d=mean(d); out(i)=d; end %optional metrics to display to command window buffer: % dist=squareform(pdist(data(:,1:2))); % intraCluster=mean([dist(2,1) dist(3,1) dist(3,2) dist(5,4) dist(7,6) dist(9,8) dist(11,9) dist(13,12) dist(14,12) dist(14,13) dist(15,16) dist(17,18)]) % meanOut=mean(out) % stdOut=std(out)