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



Re: lorenz curve
Posted:
Nov 30, 2005 8:50 AM


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



