function that calculates a coefficient for a given Data set

4 次查看(过去 30 天)
Hello everyone, I am trying to write a function that calculates the Gini coefficient. I have two vectors: one is the vector for the perfect equality line and the other is a vector showing different combinations of income and population share. You can se this on the following image
Now I would like to create a function that calculates (the area between the perfect equality line and the lorenz curve) divided by the lower triangel. The more the red line approaches to the black, the coefficient goes close to zero.
Here I have the codes for the upper graph
%for germany in 2010
Germany2010 = [ZeroIncomeGermany(15) LowestIncome20Germany(15) SecondIncome20Germany(15) ThirdIncome20Germany(15) FourthIncome20Germany(15) FifthIncome20Germany(15)]
Germany2010forGini = cumsum(Germany2010)
ShareOfPopulation = [0 20 40 60 80 100]
figure();
PerfectEqualityX = 0:100;
PerfectEqualityLine = PerfectEqualityX;
plot(PerfectEqualityX,PerfectEqualityLine,'k');
hold on
plot(Populationshare,Germany2010forGini,'r')
xlabel('Population Share')
ylabel('Share of Income')
legend('Perfect Equality','Lorenz Curve','Location','NorthWest')
title('Represantation of Lorentz Curve/Perfect Equality Line: Germany, 2010')
grid on
hold off
Now I know that the following formula delivers the right coefficient
%%GiniGermany2010 = (trapz(PerfectEqualityLine)-trapz(Germany2010forGini)*20)/trapz(PerfectEqualityLine)
I tried with
function [] = GiniCoefficient(x)
%x = Matrix for selected country and year
Gini(x) = (trapz(PerfectEqualityLine)-trapz(x)*20)/trapz(PerfectEqualityLine)
end
but it doesn't work, can anyone help?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by