Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Pardha
Posts:
1
Registered:
5/13/13


Re: lorenz curve
Posted:
May 13, 2013 7:38 AM


Hi Jacob, How did you compute the gini coefficient from the plot/ code?
Thanks Pardha "jacob muller" <jacob@muller.com> wrote in message <ef1c97f.3@webx.raydaftYaTP>... > hello Titus, > > the Lorenz function of matlab is not what i was looking for (but > thanks anyway). > I wanted an script to plot the lorenz curve and to compute the gini > coefficient. Now i think that i managed thanks to the code posted by > NZTideMan (THANKS!!) > the script is looking like this: > > function [cumulative]=lorenz2dist(X,Y,plotting,plotvarx) > > % basic checkings > if length(X)~=length(Y) > error('vectors X and Y must have the same length') > end > > % cumulation for the lorenz curve > ratiodist=X./Y; > % ranking based on the ratio > [ratiosort, indexsort] =sort(ratiodist); > % converting X and Y to percentage > Xperce=X/sum(X)*100; > Yperce=Y/sum(Y)*100; > % sorting the distributions > Xsort=Xperce([indexsort]); > Ysort=Yperce([indexsort]); > % Cumulative sum of sorted elements > Xcumsum=cumsum(Xsort) > Ycumsum=cumsum(Ysort) > cumulative=[0 0; Xcumsum Ycumsum]; > > switch plotting > case 'yes' > if plotvarx==1 > plotvary=2; > else > plotvary=1; > end > figure > plot(cumulative(:,plotvarx), cumulative(:,plotvary),'*') > hold on > plot(0:100,0:100,'k:') > end



