% LMex020507_4th.m
% Example 2.5.5 Application of Gini-Simpson diversity  p 74 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Written by Eugene.Gallagher@umb.edu, revised 1/15/11
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% Blood type frequencies: A 40%, B 10%, AB 5% and O 45%
DATA=[.4 .1 .05 .45];
[r,c]=size(DATA);
N=sum(DATA')';
P=1-sum(((DATA./repmat(N,1,c)).^2)')';  % This formula works for multiple
%                                         rows of data
G=gini(DATA); % application of the Gini-Simpson index.
fprintf(...
    'Probability that Emma & Josh have different blood types = %5.3f\n',P)
fprintf('Gini-Simpson index of gene heterogeneity = %5.3f\n',G)