Last data update: 2014.03.03

R: Lorenz Curve
LcR Documentation

Lorenz Curve

Description

Lc computes the (empirical) ordinary and generalized Lorenz curve of a vector x. Desc calculates some key figures for a Lorenz curve and produces a quick description.

Usage


Lc(x, ...)

## Default S3 method:
Lc(x, n = rep(1, length(x)), na.rm = FALSE, ...)

## S3 method for class 'formula'
Lc(formula, data, subset, na.action, ...)

## S3 method for class 'Lc'
plot(x, general = FALSE, lwd = 2, type = "l", xlab = "p", ylab = "L(p)",
     main = "Lorenz curve", las = 1, ...)

## S3 method for class 'Lclist'
plot(x, col = 1, lwd = 2, lty = 1, main = "Lorenz curve",
     xlab = "p", ylab = "L(p)", ...)

Arguments

x

a vector containing non-negative elements.

n

a vector of frequencies, must be same length as x.

na.rm

logical. Should missing values be removed? Defaults to FALSE.

general

logical. If TRUE the empirical Lorenz curve will be plotted.

col

color of the curve

lwd

the linewidth of the curve

lty

the linetype of the curve

type

type of the plot, default is line ("l").

xlab, ylab

label of the x-, resp. y-axis.

main

main title of the plot.

las

las of the axis.

p

a numeric vector with percent points, at which the Lorenz curve will be calculated.

formula

a formula of the form lhs ~ rhs where lhs gives the data values and rhs the corresponding groups.

data

an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).

subset

an optional vector specifying a subset of observations to be used.

na.action

a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").

...

further argument to be passed to methods.

Details

Lc(x) computes the empirical ordinary Lorenz curve of x as well as the generalized Lorenz curve (= ordinary Lorenz curve * mean(x)). The result can be interpreted like this: p*100 percent have L(p)*100 percent of x.

If n is changed to anything but the default x is interpreted as a vector of class means and n as a vector of class frequencies: in this case Lc will compute the minimal Lorenz curve (= no inequality within each group).

Value

A list of class "Lc" with the following components:

p

vector of percentages

L

vector with values of the ordinary Lorenz curve

L.general

vector with values of the generalized Lorenz curve

Note

These functions were previously published as Lc() in the ineq package and have been integrated here without logical changes.

Author(s)

Achim Zeileis <Achim.Zeileis@R-project.org>, minor changes Andri Signorell <andri@signorell.net>

References

Arnold, B. C. (1987) Majorization and the Lorenz Order: A Brief Introduction, Springer

Cowell, F. A. (2000) Measurement of Inequality in Atkinson, A. B. / Bourguignon, F. (Eds): Handbook of Income Distribution. Amsterdam.

Cowell, F. A. (1995) Measuring Inequality Harvester Wheatshef: Prentice Hall.

See Also

The original location Lc(),
inequality measures Gini(), Atkinson()

Examples

priceCarpenter <- d.pizza$price[d.pizza$driver=="Carpenter"]
priceMiller <- d.pizza$price[d.pizza$driver=="Miller"]

# compute the Lorenz curves
Lc.p <- Lc(priceCarpenter, na.rm=TRUE)
Lc.u <- Lc(priceMiller, na.rm=TRUE)
plot(Lc.p)
lines(Lc.u, col=2)

# the picture becomes even clearer with generalized Lorenz curves
plot(Lc.p, general=TRUE)
lines(Lc.u, general=TRUE, col=2)

# inequality measures emphasize these results, e.g. Atkinson's measure
Atkinson(priceCarpenter, na.rm=TRUE)
Atkinson(priceMiller, na.rm=TRUE)


# income distribution of the USA in 1968 (in 10 classes)
# x vector of class means, n vector of class frequencies
x <- c(541, 1463, 2445, 3438, 4437, 5401, 6392, 8304, 11904, 22261)
n <- c(482, 825, 722, 690, 661, 760, 745, 2140, 1911, 1024)

# compute minimal Lorenz curve (= no inequality in each group)
Lc.min <- Lc(x, n=n)
plot(Lc.min)


# input of frequency tables with midpoints of classes
fl <- c(2.5,7.5,15,35,75,150)   # midpoints
n  <- c(25,13,10,5,5,2)	        # frequencies

plot(Lc(fl, n),                 # Lorenz-Curve
     panel.first=grid(10, 10),
     main="Lorenzcurve Farmers",
     xlab="Percent farmers (cumulative)",
     ylab="Percent of area (%)"
)

Gini(fl, n)

# find specific function values using appprox
x <- c(1,1,4)
lx <- Lc(x)
plot(lx)

# get interpolated function value at p = 0.55
y0 <- approx(x=lx$p, y=lx$L, xout=0.55)
abline(v=0.55, h=y0$y, lty="dotted")

# and for the inverse question
y0 <- approx(x=lx$L, y=lx$p, xout=0.6)
abline(h=0.6, v=y0$y, col="red")

text(x=0.1, y=0.65, label=expression(L^{-1}*(0.6) == 0.8), col="red")
text(x=0.65, y=0.2, label=expression(L(0.55) == 0.275))

# input of frequency tables with midpoints of classes
fl <- c(2.5,7.5,15,35,75,150)     # midpoints
n  <- c(25,13,10,5,5,2)           # frequencies

# the formula interface for Lc
lst <- Lc(count ~ cut(price, breaks=5), data=d.pizza)

plot(lst, col=1:length(lst), panel.first=grid(), lwd=2)
legend(x="topleft", legend=names(lst), fill=1:length(lst))

# Describe with Desc-function
lx <- Lc(fl, n)
Desc(lx)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DescTools)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DescTools/Lc.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Lc
> ### Title: Lorenz Curve
> ### Aliases: Lc Lc.default Lc.formula plot.Lc plot.Lclist lines.Lc
> ### Keywords: univar
> 
> ### ** Examples
> 
> priceCarpenter <- d.pizza$price[d.pizza$driver=="Carpenter"]
> priceMiller <- d.pizza$price[d.pizza$driver=="Miller"]
> 
> # compute the Lorenz curves
> Lc.p <- Lc(priceCarpenter, na.rm=TRUE)
> Lc.u <- Lc(priceMiller, na.rm=TRUE)
> plot(Lc.p)
> lines(Lc.u, col=2)
> 
> # the picture becomes even clearer with generalized Lorenz curves
> plot(Lc.p, general=TRUE)
> lines(Lc.u, general=TRUE, col=2)
> 
> # inequality measures emphasize these results, e.g. Atkinson's measure
> Atkinson(priceCarpenter, na.rm=TRUE)
[1] 0.05286775
> Atkinson(priceMiller, na.rm=TRUE)
[1] 0.04893621
> 
> 
> # income distribution of the USA in 1968 (in 10 classes)
> # x vector of class means, n vector of class frequencies
> x <- c(541, 1463, 2445, 3438, 4437, 5401, 6392, 8304, 11904, 22261)
> n <- c(482, 825, 722, 690, 661, 760, 745, 2140, 1911, 1024)
> 
> # compute minimal Lorenz curve (= no inequality in each group)
> Lc.min <- Lc(x, n=n)
> plot(Lc.min)
> 
> 
> # input of frequency tables with midpoints of classes
> fl <- c(2.5,7.5,15,35,75,150)   # midpoints
> n  <- c(25,13,10,5,5,2)	        # frequencies
> 
> plot(Lc(fl, n),                 # Lorenz-Curve
+      panel.first=grid(10, 10),
+      main="Lorenzcurve Farmers",
+      xlab="Percent farmers (cumulative)",
+      ylab="Percent of area (%)"
+ )
> 
> Gini(fl, n)
[1] 0.6678112
> 
> # find specific function values using appprox
> x <- c(1,1,4)
> lx <- Lc(x)
> plot(lx)
> 
> # get interpolated function value at p = 0.55
> y0 <- approx(x=lx$p, y=lx$L, xout=0.55)
> abline(v=0.55, h=y0$y, lty="dotted")
> 
> # and for the inverse question
> y0 <- approx(x=lx$L, y=lx$p, xout=0.6)
> abline(h=0.6, v=y0$y, col="red")
> 
> text(x=0.1, y=0.65, label=expression(L^{-1}*(0.6) == 0.8), col="red")
> text(x=0.65, y=0.2, label=expression(L(0.55) == 0.275))
> 
> # input of frequency tables with midpoints of classes
> fl <- c(2.5,7.5,15,35,75,150)     # midpoints
> n  <- c(25,13,10,5,5,2)           # frequencies
> 
> # the formula interface for Lc
> lst <- Lc(count ~ cut(price, breaks=5), data=d.pizza)
> 
> plot(lst, col=1:length(lst), panel.first=grid(), lwd=2)
> legend(x="topleft", legend=names(lst), fill=1:length(lst))
> 
> # Describe with Desc-function
> lx <- Lc(fl, n)
> Desc(lx)

Sorry, don't know how to handle class(es) list (x)!

------------------------------------------------------------------------------ 
lx (list)

$xname
[1] "lx"

$label
NULL

$class
[1] "list"

$classlabel
[1] "list"

$length
[1] 4

$n
[1] 4

$NAs
[1] 0

$main
[1] "lx (list)"

> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>