You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that the vector field converges to the eigenvector of $A$ with the largest eigenvalue and diverges from the eigenvector of $A$ with the smallest eigenvalue.
1176
1156
1177
1157
In fact, the eigenvectors are also the directions in which the matrix $A$ stretches or shrinks the space.
@@ -1200,12 +1180,7 @@ Use the visualization in the previous exercise to explain the trajectory of the
1200
1180
Here is one solution
1201
1181
1202
1182
```{code-cell} ipython3
1203
-
---
1204
-
mystnb:
1205
-
figure:
1206
-
caption: Vector fields of the three matrices
1207
-
name: vector-field
1208
-
---
1183
+
1209
1184
figure, ax = plt.subplots(1, 3, figsize=(15, 5))
1210
1185
A = np.array([[sqrt(3) + 1, -2],
1211
1186
[1, sqrt(3) - 1]])
@@ -1264,24 +1239,18 @@ for i, example in enumerate(examples):
1264
1239
ax[i].grid()
1265
1240
ax[i].set_aspect('equal', adjustable='box')
1266
1241
1242
+
plt.title("Vector fields of the three matrices")
1267
1243
plt.show()
1268
1244
```
1269
1245
1270
-
+++ {"user_expressions": []}
1271
-
1272
1246
The vector fields explain why we observed the trajectories of the vector $v$ multiplied by $A$ iteratively before.
1273
1247
1274
1248
The pattern demonstrated here is because we have complex eigenvalues and eigenvectors.
1275
1249
1276
1250
We can plot the complex plane for one of the matrices using `Arrow3D` class retrieved from [stackoverflow](https://stackoverflow.com/questions/22867620/putting-arrowheads-on-vectors-in-a-3d-plot).
Copy file name to clipboardExpand all lines: lectures/inequality.md
+20-35Lines changed: 20 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ jupytext:
4
4
extension: .md
5
5
format_name: myst
6
6
format_version: 0.13
7
-
jupytext_version: 1.15.1
7
+
jupytext_version: 1.17.2
8
8
kernelspec:
9
9
display_name: Python 3 (ipykernel)
10
10
language: python
@@ -95,8 +95,6 @@ import wbgapi as wb
95
95
import plotly.express as px
96
96
```
97
97
98
-
99
-
100
98
## The Lorenz curve
101
99
102
100
One popular measure of inequality is the Lorenz curve.
@@ -239,9 +237,6 @@ ax.legend()
239
237
plt.show()
240
238
```
241
239
242
-
243
-
244
-
245
240
### Lorenz curves for US data
246
241
247
242
Next let's look at US data for both income and wealth.
@@ -333,7 +328,6 @@ ax.legend()
333
328
plt.show()
334
329
```
335
330
336
-
337
331
One key finding from this figure is that wealth inequality is more extreme than income inequality.
338
332
339
333
@@ -402,7 +396,7 @@ G = \frac{A}{A+B}
402
396
$$
403
397
404
398
where $A$ is the area between the 45-degree line of
405
-
perfect equality and the Lorenz curve, while $B$ is the area below the Lorenze curve -- see {numref}`lorenz_gini2`.
399
+
perfect equality and the Lorenz curve, while $B$ is the area below the Lorenze curve -- see {numref}`lorenz_gini2`.
406
400
407
401
```{code-cell} ipython3
408
402
---
@@ -427,8 +421,6 @@ ax.legend()
427
421
plt.show()
428
422
```
429
423
430
-
431
-
432
424
```{seealso}
433
425
The World in Data project has a [graphical exploration of the Lorenz curve and the Gini coefficient](https://ourworldindata.org/what-is-the-gini-coefficient)
434
426
```
@@ -442,7 +434,6 @@ The code below computes the Gini coefficient from a sample.
442
434
(code:gini-coefficient)=
443
435
444
436
```{code-cell} ipython3
445
-
446
437
def gini_coefficient(y):
447
438
r"""
448
439
Implements the Gini inequality index
@@ -503,11 +494,13 @@ for σ in σ_vals:
503
494
Let's build a function that returns a figure (so that we can use it later in the lecture).
504
495
505
496
```{code-cell} ipython3
506
-
def plot_inequality_measures(x, y, legend, xlabel, ylabel):
497
+
def plot_inequality_measures(x, y, legend, xlabel, ylabel, title=None):
507
498
fig, ax = plt.subplots()
508
499
ax.plot(x, y, marker='o', label=legend)
509
500
ax.set_xlabel(xlabel)
510
501
ax.set_ylabel(ylabel)
502
+
if title is not None:
503
+
ax.set_title(title)
511
504
ax.legend()
512
505
return fig, ax
513
506
```
@@ -546,7 +539,7 @@ We now know the series ID is `SI.POV.GINI`.
546
539
547
540
(Another way to find the series ID is to use the [World Bank data portal](https://data.worldbank.org) and then use `wbgapi` to fetch the data.)
548
541
549
-
To get a quick overview, let's histogram Gini coefficients across all countries and all years in the World Bank dataset.
542
+
To get a quick overview, let's histogram Gini coefficients across all countries and all years in the World Bank dataset.
550
543
551
544
```{code-cell} ipython3
552
545
---
@@ -572,7 +565,7 @@ plt.show()
572
565
573
566
We can see in {numref}`gini_histogram` that across 50 years of data and all countries the measure varies between 20 and 65.
(This package often returns data with year information contained in the columns. This is not always convenient for simple plotting with pandas so it can be useful to transpose the results before plotting.)
585
578
586
-
587
579
```{code-cell} ipython3
588
580
data = data.T # Obtain years as rows
589
581
data_usa = data['USA'] # pd.Series of US data
@@ -616,8 +608,7 @@ In the previous section we looked at the Gini coefficient for income, focusing o
616
608
617
609
Now let's look at the Gini coefficient for the distribution of wealth.
618
610
619
-
We will use US data from the {ref}`Survey of Consumer Finances<data:survey-consumer-finance>`
620
-
611
+
We will use US data from the {ref}`Survey of Consumer Finances<data:survey-consumer-finance>`
0 commit comments