Created
December 17, 2010 23:48
-
-
Save Protonk/745924 to your computer and use it in GitHub Desktop.
Theil index code from the lorenz.R gist. Works on those numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Computes a very basic Theil index | |
| i<-1 | |
| theil<-matrix(0,4,3) | |
| for (i in i:4) { | |
| theil[i,1]<-0.25*(gini[i,1]/0.25)*log(gini[i,1]/0.25) | |
| theil[i,2]<-0.25*(gini[i,2]/0.25)*log(gini[i,2]/0.25) | |
| theil[i,3]<-0.25*(gini[i,3]/0.25)*log(gini[i,3]/0.25) | |
| } | |
| theil<-rbind(theil,apply(theil,2,sum)) | |
| colnames(theil)<-c("Region A","Region B","Region C"); | |
| rownames(theil)<-c("Bottom 25%","Lower Middle 25%","Upper Middle 25%","Top 25%","Theil Index") | |
| #Computes the two components of a between region Theil index, with regional income shares of 0.4,0.25 and 0.35. | |
| within.theil<-0.4*theil[5,1]+0.25*theil[5,2]+0.35*theil[5,3] | |
| between.theil<-0.4*log(0.4*3)+0.25*log(0.25*3)+0.35*log(0.35*3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment