## Gini Calculation

Solved
Frequent Contributor
Posts: 126

# Gini Calculation

Hi all,

Any ideas on how the gini measure of diversity  is calculated when creating bins through the interactive binning node? cause i see it alters when i either merge or spliit bins

Accepted Solutions
Solution
‎09-24-2013 05:06 PM
SAS Employee
Posts: 68

## Re: Gini Calculation

Hi, thanks to one of my R&D colleagues, he wrote up a quick solution using IML, which should match your results in EM.

proc iml;

event={517,365,349,269};

nonevent={233,281,451,535};

sum1=0;

do i=2 to 4;

sum2=0;

im1=i-1;

do j=1 to im1;

sum2=sum2+nonevent;

end;

sum1=sum1 + event*sum2;

end;

sum3=0;

do i=1 to 4;

sum3 = sum3 + event*nonevent;

end;

gini = 100*(1 - (2*sum1 + sum3)/ (1500*1500)) ;

print sum1 sum2 sum3 gini;

quit;

 524016 965 524340 30.1168

All Replies
SAS Employee
Posts: 68

## Re: Gini Calculation

Hi as you may already know, the Gini statistic tests for differences in bin values with respect to the target (events vs non-events).  As Gini changes in the Interactive Binning node, you get an idea of the validity of your bin cutoffs.

You can find this equation in the EM reference guide in the Interactive Binning node section.

Thanks,

Jonathan

Frequent Contributor
Posts: 126

## Re: Gini Calculation

Ok i think i am almost there, but how would the formula look like in the following example?

 Value Group Cutoff Event count Non event count Total Event rate MISSING 1 0 0 0 0 AGE <25 2 25.5 517 233 750 68.9% 25.5

Solution
‎09-24-2013 05:06 PM
SAS Employee
Posts: 68

## Re: Gini Calculation

Hi, thanks to one of my R&D colleagues, he wrote up a quick solution using IML, which should match your results in EM.

proc iml;

event={517,365,349,269};

nonevent={233,281,451,535};

sum1=0;

do i=2 to 4;

sum2=0;

im1=i-1;

do j=1 to im1;

sum2=sum2+nonevent;

end;

sum1=sum1 + event*sum2;

end;

sum3=0;

do i=1 to 4;

sum3 = sum3 + event*nonevent;

end;

gini = 100*(1 - (2*sum1 + sum3)/ (1500*1500)) ;

print sum1 sum2 sum3 gini;

quit;

 524016 965 524340 30.1168
Frequent Contributor
Posts: 126

## Re: Gini Calculation

Thank you very much for your help

🔒 This topic is solved and locked.