%Linear Binning estimator %Estimates the exponent of power-laws using linear binning. This function %allows for a variety of modifications including the presence of a known %minimum value of x (minval_present = 1), the specification of the minimum %number of points required to include a bin in the regression(minpts), %and the ability to drop the last bin from the analysis (droplastbin=1). %The minimum value of x is accomodated by starting the edge of the first %bin at that minimum value, thus avoiding underestimating the frequency in %the first bin. Dropping the last bin can avoid the related problem of %underestimating the frequency in the largest bin if there is a meaningful %maximum value of x. In most analyses minpts is set to 1, but allowing the %specification of this value allows the dropping of singleton bins as %recommended by Pickering et al. 1995 (since bins with fractional densities %will most commonly be realized as zeros or ones and dropping only the %zeros can lead to biased estimates; we follow this approach in the %simulations reported in the paper) and also allows the replication of %analyses where greater values of minpts have been used (e.g., Enquist and %Niklas 2001). See the text of the paper for citation details. 'data' is a %vector of x values function [exponent] = linbin_estimator(data,binwidth,minval_present,minval,droplastbin,minpts) %Bin the data using the provided bin width and starting the first bin edge %either at the default position for a histogram, or at the provided minimum %value, and determine the centers of the bins. if minval_present==1 %Determine the upper edge of the last bin upperedge=minval+binwidth*ceil((max(data)-minval)/binwidth); %Bin the data using the 'histc' function n=histc(data,minval:binwidth:upperedge); %Include any data point equal to the upper edge in the last bin and %remove the bin that original caught these data. n(length(n)-1)=n(length(n)-1)+n(length(n));n(length(n))=[]; %Determine the bin centers centers=[minval+.5*binwidth:binwidth:upperedge-.5*binwidth]'; else %Or simple retrieve n and centers using 'hist' if no minimum is present [n,centers]=hist(data); end %Drop the last bin if instructed if droplastbin==1 centers(length(centers))=[]; n(length(n))=[]; end %Drop bins with less thean the minimum number of points for analysis centers=centers(n>=minpts); n=n(n>=minpts); %Fit an OLS regression to the log transformed data paras=polyfit(log(centers),log(n),1); %Return the slope of the above regression as an estimate of the exponent exponent=paras(:,1);