% Distributional Consistency Algorithm
% 'Survey' is a (nxm) matrix required for input. This survey matrix should be formatted
% so that Columns represent each site while rows represent survey year (or other suitable time step).
% Total population size in each year will be calculated as the sum of each row.
[y,SITES]=size(Survey); % y = years
Popn=sum(Survey,2); %total population size in each year
%------------------------------------------------------------------------
%The following calulates observed consistency
SortedSites=sort(Survey);
DSortSites=flipdim(SortedSites,1); %this is sorted descending order so row number is the level of k
for col = 1:SITES;
for row = 1:(y-1);
ObservedLevels(row,col)=DSortSites(row,col)-DSortSites(row+1,col);
end
ObservedLevels(y,col)=DSortSites(y,col);
end
ObsK= sum(ObservedLevels,2);
%This is the observed consistency vector, with row number corresponding to each level k
%note that ObsK vector also includes k at level 1, which is not 'consistency' and therefore not used in
%future calculations
%The following calculates correction factor for observed instances in higher levels of k
for k=2:y; %loop through each level of k
for p=0:(y-k);
s=k+p;
R=nchoosek(s,k);
TEMPK(p+1)=R*(ObsK(k+p));
end
ObsK_Corr(k)=sum(TEMPK);
clear TEMPK;
end
%-------------------------------------------------------------------------
%The following calculates maximum possible distributional consistency
for k = 2:y; %loop through each level of k
yCk(k) = nchoosek(y,k);
List = nchoosek(Popn,k);
MinVect=min(List,[],2); %minimum population size for each i comparison
M(k) = sum(MinVect); %this is the maximum possible number of consistent site use events for comparison level k
end
%--------------------------------------------------------------------------
%The following calculates ratio of observed to expected consistency at each
%level k, and takes the average to calculate Distributional Consistency for
%the region.
for k = 2:y;
DC_K(k)=(ObsK_Corr(k))/(M(k));
end
DC_K(1)=[]; %DC_K is Consistency for each level k
DC=mean(DC_K) %DC - Distributional Consistency
%clear variables
clear DSortSites, clear List, clear M, clear MinVect, clear ObsK, clear ObsK_Corr, clear ObservedLevels, clear Popn
clear R, clear SITES, clear SortedSites, clear col, clear k, clear p, clear row, clear s, clear y, clear yCk
%--------------------------------------------------------------------------
% this algorithm calculates 'Distributional Consistency' and has been submitted
% as an electronic appendix to accompany the manuscript
% "How consistent are distribution patterns? Using survey data to make inferences about individual
% movements and habitat quality" by Joel Heath, Bill Montevecchi and Dan Esler
% for inquiries or assistance please contact joel_heath@sfu.ca
%--------------------------------------------------------------------------