function G=gini(DATA)
% Calculate Gini-Simpson's diversity
% format G=gini(DATA)
% Also called gene heterogeneity or gene heterozygosity
% input: a sample x species or sample by character matrix.
% output: G, a column vector with Gini-Simpson diversities
% formulas  G=1-sum((ni/N)^2)
% where N is the sample total and ni is the abundance of
% the i'th species.
%    Hurlbert SM (1971)  The non-concept of species diversity:  a
%           critique and alternative parameters.  Ecology 52:  577-586.
%    Magurran AE (1988) Ecological diversity and its measurement.
%            Princeton Unversity Press.
% written 4/5/94 by E. Gallagher, Environmental Sciences Program 
% UMASS/Boston, Eugene.Gallagher@umb.edu
% last revised: 1/15/2011
% See Simpson.m for the unbiased formula
[r,c]=size(DATA);
N=sum(DATA')';
G=1-sum(((DATA./repmat(N,1,c)).^2)')';
