10
10
@njit
11
11
def lorenz_curve (y ):
12
12
"""
13
- Calculates the Lorenz Curve, a graphical representation of the distribution of income
14
- or wealth.
13
+ Calculates the Lorenz Curve, a graphical representation of
14
+ the distribution of income or wealth.
15
15
16
- It returns the cumulative share of people (x-axis) and the cumulative share of income earned
16
+ It returns the cumulative share of people (x-axis) and
17
+ the cumulative share of income earned.
17
18
18
19
Parameters
19
20
----------
20
21
y : array_like(float or int, ndim=1)
21
- Array of income/wealth for each individual. Unordered or ordered is fine.
22
+ Array of income/wealth for each individual.
23
+ Unordered or ordered is fine.
22
24
23
25
Returns
24
26
-------
@@ -60,7 +62,8 @@ def gini_coefficient(y):
60
62
Parameters
61
63
-----------
62
64
y : array_like(float)
63
- Array of income/wealth for each individual. Ordered or unordered is fine
65
+ Array of income/wealth for each individual.
66
+ Ordered or unordered is fine
64
67
65
68
Returns
66
69
-------
@@ -96,15 +99,15 @@ def shorrocks_index(A):
96
99
The Shorrocks mobility index calculated as
97
100
98
101
.. math::
99
-
102
+
100
103
s(A) = \frac{m - \sum_j a_{jj} }{m - 1} \in (0, 1)
101
104
102
105
An index equal to 0 indicates complete immobility.
103
106
104
107
References
105
108
-----------
106
- .. [1] Wealth distribution and social mobility in the US: A quantitative approach
107
- (Benhabib, Bisin, Luo, 2017).
109
+ .. [1] Wealth distribution and social mobility in the US:
110
+ A quantitative approach (Benhabib, Bisin, Luo, 2017).
108
111
https://www.econ.nyu.edu/user/bisina/RevisionAugust.pdf
109
112
"""
110
113
@@ -119,38 +122,32 @@ def shorrocks_index(A):
119
122
return (m - diag_sum ) / (m - 1 )
120
123
121
124
122
- def rank_size_plot (data , ax , label = None , c = 1.0 ):
125
+ def rank_size (data , c = 1.0 ):
123
126
"""
124
127
Generate rank-size data corresponding to distribution data.
125
128
126
129
Examples
127
130
--------
128
-
129
- > import numpy as np
130
- > import matplotlib.pyplot as plt
131
- > y = np.exp(np.random.randn(1000)) # simulate data
132
- > fig, ax = plt.subplots()
133
- > rank_size_plot(y, ax)
134
- > plt.show()
131
+ >>> y = np.exp(np.random.randn(1000)) # simulate data
132
+ >>> rank_data, size_data = rank_size(y, c=0.85)
135
133
136
134
Parameters
137
135
----------
138
-
139
136
data : array_like
140
137
the set of observations
141
138
c : int or float
142
139
restrict plot to top (c x 100)% of the distribution
143
- ax : axis object
144
- for plotting on, has method ax.loglog
140
+
141
+ Returns
142
+ -------
143
+ rank_data : array_like(float, ndim=1)
144
+ Location in the population when sorted from smallest to largest
145
+ size_data : array_like(float, ndim=1)
146
+ Size data for top (c x 100)% of the observations
145
147
"""
146
148
w = - np .sort (- data ) # Reverse sort
147
149
w = w [:int (len (w ) * c )] # extract top (c * 100)%
148
150
rank_data = np .arange (len (w )) + 1
149
151
size_data = w
150
- ax .loglog (rank_data , size_data , 'o' , markersize = 3.0 , alpha = 0.5 , label = label )
151
- if label :
152
- ax .legend ()
153
- ax .set_xlabel ("log rank" )
154
- ax .set_ylabel ("log size" )
155
-
152
+ return rank_data , size_data
156
153
0 commit comments