1010@njit
1111def lorenz_curve (y ):
1212 """
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.
1515
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.
1718
1819 Parameters
1920 ----------
2021 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.
2224
2325 Returns
2426 -------
@@ -60,7 +62,8 @@ def gini_coefficient(y):
6062 Parameters
6163 -----------
6264 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
6467
6568 Returns
6669 -------
@@ -96,15 +99,15 @@ def shorrocks_index(A):
9699 The Shorrocks mobility index calculated as
97100
98101 .. math::
99-
102+
100103 s(A) = \frac{m - \sum_j a_{jj} }{m - 1} \in (0, 1)
101104
102105 An index equal to 0 indicates complete immobility.
103106
104107 References
105108 -----------
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).
108111 https://www.econ.nyu.edu/user/bisina/RevisionAugust.pdf
109112 """
110113
@@ -119,38 +122,32 @@ def shorrocks_index(A):
119122 return (m - diag_sum ) / (m - 1 )
120123
121124
122- def rank_size_plot (data , ax , label = None , c = 1.0 ):
125+ def rank_size (data , c = 1.0 ):
123126 """
124127 Generate rank-size data corresponding to distribution data.
125128
126129 Examples
127130 --------
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)
135133
136134 Parameters
137135 ----------
138-
139136 data : array_like
140137 the set of observations
141138 c : int or float
142139 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
145147 """
146148 w = - np .sort (- data ) # Reverse sort
147149 w = w [:int (len (w ) * c )] # extract top (c * 100)%
148150 rank_data = np .arange (len (w )) + 1
149151 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
156153
0 commit comments