Calculate Gini Coefficient in VB.Net

Code to calculate Gini Coeddicient in Vb.Net - Enjoy Coding

Page 1 of 1

1 Replies - 3134 Views - Last Post: 19 May 2008 - 11:26 PM Rate Topic: ****- 1 Votes

#1 Thapa  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 25
  • Joined: 24-September 07

Calculate Gini Coefficient in VB.Net

Posted 18 May 2008 - 09:17 AM

[size=4]I had to go through big stress while finding solution to calculate Gini Coefficient in Vb.Net now i discover it So everybody enjoy it ....
Private Sub CalcGiniCoefficient()
	   
		Dim i, j, temp As Integer
		Dim Var_Players As Integer
		Dim Var_Diff_Total As Integer
		Dim Var_M As Integer
		Dim VarG_C_M_Diff As Double
		Dim VarG_C_Con As Double
		Dim Var_Score_Sum As Integer
		Dim Var_Gini_Coefficient As Double
		Dim Var_Total_Player As Integer
	   
		Dim arrScore() As Integer
		arrScore = New Integer() {41, 25, 18, 11, 5}
		Var_Players = CInt(arrScore.Length - 1)
		Var_Total_Player = CInt(arrScore.Length)
		'Var_Total_Player()
		'Sorting the Array in ascending order 
		For i = 0 To Var_Players
			For j = i + 1 To Var_Players
				If arrScore(i) < arrScore(j) Then
					temp = arrScore(i)
					arrScore(i) = arrScore(j)
					arrScore(j) = temp
				End If
			Next j
		Next i

		' Calculating Sum of all positive Difference 
		For i = 0 To Var_Players
			For j = i + 1 To Var_Players
				Var_Diff_Total += arrScore(i) - arrScore(j)
			Next
			Var_Score_Sum += arrScore(i) ' Calculating sum of all scores 

		Next
		' Calculating Observation 
		Var_M = CInt(Var_Total_Player * (Var_Total_Player - 1) / 2)

		' Calculating Gini coefficient of mean difference
		VarG_C_M_Diff = Var_Diff_Total / Var_M

		' Calculating Gini's Coefficient of concentration

		VarG_C_Con = Var_Score_Sum / Var_Total_Player

		' Calculating Gini Coefficient 

		Var_Gini_Coefficient = VarG_C_M_Diff / VarG_C_Con ' More Gini Coefficient is near to "1" equality is more 
		Me.txtGiniCoefficient.Text = CStr(Var_Gini_Coefficient)
 End Sub



This post has been edited by Thapa: 18 May 2008 - 10:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Calculate Gini Coefficient in VB.Net

#2 Thapa  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 25
  • Joined: 24-September 07

Re: Calculate Gini Coefficient in VB.Net

Posted 19 May 2008 - 11:26 PM

Change in above code:- My previous code was having some bug coz i missed (VarG_C_Con * 2), i have made following change Var_Gini_Coefficient = VarG_C_M_Diff / (VarG_C_Con * 2) (My previous post was missing (VarG_C_Con * 2) calculation, Now this code is without bug!


View PostThapa, on 18 May, 2008 - 09:17 AM, said:

[size=4]I had to go through big stress while finding solution to calculate Gini Coefficient in Vb.Net now i discover it So everybody enjoy it ....
Private Sub CalcGiniCoefficient()
	   
		Dim i, j, temp As Integer
		Dim Var_Players As Integer
		Dim Var_Diff_Total As Integer
		Dim Var_M As Integer
		Dim VarG_C_M_Diff As Double
		Dim VarG_C_Con As Double
		Dim Var_Score_Sum As Integer
		Dim Var_Gini_Coefficient As Double
		Dim Var_Total_Player As Integer
	   
		Dim arrScore() As Integer
		arrScore = New Integer() {41, 25, 18, 11, 5}
		Var_Players = CInt(arrScore.Length - 1)
		Var_Total_Player = CInt(arrScore.Length)
		'Var_Total_Player()
		'Sorting the Array in ascending order 
		For i = 0 To Var_Players
			For j = i + 1 To Var_Players
				If arrScore(i) < arrScore(j) Then
					temp = arrScore(i)
					arrScore(i) = arrScore(j)
					arrScore(j) = temp
				End If
			Next j
		Next i

		' Calculating Sum of all positive Difference 
		For i = 0 To Var_Players
			For j = i + 1 To Var_Players
				Var_Diff_Total += arrScore(i) - arrScore(j)
			Next
			Var_Score_Sum += arrScore(i) ' Calculating sum of all scores 

		Next
		' Calculating Observation 
		Var_M = CInt(Var_Total_Player * (Var_Total_Player - 1) / 2)

		' Calculating Gini coefficient of mean difference
		VarG_C_M_Diff = Var_Diff_Total / Var_M

		' Calculating Gini's Coefficient of concentration

		VarG_C_Con = Var_Score_Sum / Var_Total_Player

		' Calculating Gini Coefficient 

		Var_Gini_Coefficient =  VarG_C_M_Diff / (VarG_C_Con * 2) ' More Gini Coefficient is near to "1" equality is more 
		Me.txtGiniCoefficient.Text = CStr(Var_Gini_Coefficient)
 End Sub



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1