-
Notifications
You must be signed in to change notification settings - Fork 1
/
peace0.Rmd
494 lines (338 loc) · 19.7 KB
/
peace0.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
---
title: "探索的データ分析 - EDA"
author: "ID, Last, First"
date: "2024年2月13日"
output:
html_notebook: default
---
## 課題
以下の指標の中から、二つ以上(複数)を選択して、データの概要(description)を記録し、データを WDI で取得し、以下の分析をする。
1. 各年毎のデータの数の棒グラフ
2. 経年変化を表す折れ線グラフ
a. 日本、またはデータがある国
b. 選択したいくつかの国
3. 複数の指標の値を一列に含む縦長の表(Long Table)を作成し
a. 日本、またはデータがある国の、複数の指標を色分けした経年変化のグラフ
b. 選択したいくつかの国についての経年変化のグラフを、国を色分けし、指標は線の種類を変えたグラフ
4. データが十分ある最近の年の値のヒストグラム
5. データが十分ある最近の年の値の10カ国の値の棒グラフ
a. 値が大きい方から
b. 値が小さい方から
6. 二つのデータの散布図- NA は取り除くこと。(log10 スケールを用いる場合は値が正のもののみに限定)
a. (地域を除き)国のみの散布図 (近似(回帰)直線を表示)
b. 最近の年の(地域を除き)国のみの散布図 (近似(回帰)直線を表示)
c. b に対応する相関係数
7. カテゴリー変数(Categorical Variable: region, income, year など)と、数値変数(Numberical Variable)一組についての箱ヒゲ図(Boxplot)
それぞれについて考察(気づいたこと、疑問など)を記す
これは、課題1と課題2の合わせたものです。課題1も課題2も終わった人は、挑戦してください。
**2023.2.17.23:59** までに Moodle の課題2追加提出ボックスに提出してくださればフィードバックを書きます。。
### データ
1. Refugee population by country or territory of asylum:SM.POP.REFG [[Link](https://data.worldbank.org/indicator/SM.POP.REFG)]
2. Refugee population by country or territory of origin:SM.POP.REFG.OR [[Link](https://data.worldbank.org/indicator/SM.POP.REFG.OR)]
3. Net ODA received (% of GNI):DT.ODA.ODAT.GN.ZS [[Link](https://data.worldbank.org/indicator/DT.ODA.ODAT.GN.ZS)]
4. Net official development assistance and official aid received (current US\$):DT.ODA.ALLD.CD [[Link](https://data.worldbank.org/indicator/DT.ODA.ALLD.CD)]
5. Net ODA received (% of central government expense):DT.ODA.ODAT.XP.ZS [[Link](https://data.worldbank.org/indicator/DT.ODA.ODAT.XP.ZS)]
6. Military expenditure (current USD):MS.MIL.XPND.CD [[Link](https://data.worldbank.org/indicator/MS.MIL.XPND.CD)]
7. Military expenditure (% of general government expenditure):MS.MIL.XPND.ZS [[Link](https://data.worldbank.org/indicator/MS.MIL.XPND.ZS)]
8. Arms imports (SIPRI trend indicator values):MS.MIL.MPRT.KD [[Link](https://databank.worldbank.org/metadataglossary/world-development-indicators/series/MS.MIL.MPRT.KD)]
9. Arms exports (SIPRI trend indicator values):MS.MIL.XPRT.KD [[Link](https://databank.worldbank.org/metadataglossary/world-development-indicators/series/MS.MIL.XPRT.KD)]
# 難民人口
## データ
### データ情報
1. 難民受け入れ人口:Refugee population by country or territory of asylum:SM.POP.REFG [[Link](https://data.worldbank.org/indicator/SM.POP.REFG)]
2. 難民となる人口:Refugee population by country or territory of origin:SM.POP.REFG.OR [[Link](https://data.worldbank.org/indicator/SM.POP.REFG.OR)]
- 難民の庇護国とは、庇護請求が提出され、認められた国のことである。出身国とは、一般的に請求者の国籍または市民権のある国を指す。
- **Description:** Refugees are people who are recognized as refugees under the 1951 Convention Relating to the Status of Refugees or its 1967 Protocol, the 1969 Organization of African Unity Convention Governing the Specific Aspects of Refugee Problems in Africa, people recognized as refugees in accordance with the UNHCR statute, people granted refugee-like humanitarian status, and people provided temporary protection. Asylum seekers--people who have applied for asylum or refugee status and who have not yet received a decision or who are registered as asylum seekers--are excluded. Palestinian refugees are people (and their descendants) whose residence was Palestine between June 1946 and May 1948 and who lost their homes and means of livelihood as a result of the 1948 Arab-Israeli conflict. Country of asylum is the country where an asylum claim was filed and granted. Country of origin generally refers to the nationality or country of citizenship of a claimant.
- **概要:** 難民とは、「難民の地位に関する1951年条約」またはその「1967年議定書」、「アフリカにおける難民問題の特定の側面を管理する1969年アフリカ統一機構条約」に基づき難民と認められた人、UNHCRの法令に基づき難民と認められた人、難民に準ずる人道的地位を与えられた人、一時的な保護を与えられた人を指す。庇護申請者--庇護または難民認定を申請し、まだ決定を受けていない人、または庇護申請者として登録されている人--は除外される。パレスチナ難民とは、1946年6月から1948年5月までの間に居住地がパレスチナであり、1948年のアラブ・イスラエル紛争の結果、住居と生計手段を失った人々(およびその子孫)である。庇護国とは、庇護請求が提出され、認められた国のことである。出身国とは、一般的に請求者の国籍または市民権のある国を指す。
### データの取得
#### 準備
*これまでとも同じように二つのパッケージを読み込み(load)ます。*
```{r}
library(tidyverse)
library(WDI)
```
*変数名を指定します。ここでは、`refugee_asylum` と、`refugee_origin` としました。なるべくわかりやすい名前にします。*
*この変数名は、今後使いますから、重要です。一応、例として、わたしが使った、変数名を書いてあります。他の変数名を使っても構いません。`extra = TRUE` とすると、地域名(region)や、収入レベル(income)などが追加されます。*
```{r eval = FALSE}
df_refugee <- WDI(indicator = c(refugee_asylum = "SM.POP.REFG",
refugee_origin = "SM.POP.REFG.OR"),
extra = TRUE)
```
*data ディレクトリに書き込んでおきます。*
```{r eval = FALSE}
write_csv(df_refugee, "data/refugee.csv")
```
*data ディレクトリから読み出します。Run All や、Run All Chunks Above をする時は、上の二つをスキップする設定にしてあります。*
```{r}
df_refugee <- read_csv("data/refugee.csv")
```
### データの確認
*データ名で、中身を表示できます。`head(df_refugee)` とすると、6行表示されます。*
```{r}
df_refugee
```
*変数の情報を得ることができます。*
```{r}
str(df_refugee)
```
### 変形
#### 変数の選択(selecting)
```{r}
df_ref <- df_refugee |>
select(country, iso2c, year, refugee_asylum, refugee_origin, region, income)
df_unemp
```
*データには country のところに、国だけでなく、地域も入っているので、地域のリストを、`iso2c` で `REGION` に入れておきます。*
```{r}
REGION <- c("1A", "1W", "4E", "6F", "6N", "6X", "7E", "8S", "A4", "A5",
"A9", "B1", "B2", "B3", "B4", "B6", "B7", "B8", "C4", "C5", "C6",
"C7", "C8", "C9", "D2", "D3", "D4", "D5", "D6", "D7", "EU", "F1",
"F6", "M1", "M2", "N6", "OE", "R6", "S1", "S2", "S3", "S4", "T2",
"T3", "T4", "T5", "T6", "T7", "V1", "V2", "V3", "V4", "XC", "XD",
"XE", "XF", "XG", "XH", "XI", "XJ", "XL", "XM", "XN", "XO", "XP",
"XQ", "XT", "XU", "XY", "Z4", "Z7", "ZB", "ZF", "ZG", "ZH", "ZI",
"ZJ", "ZQ", "ZT")
```
*地域名にはどのようなものがあるか見ておきます。*
```{r}
df_ref |> filter(iso2c %in% REGION) |> distinct(country, iso2c)
```
*国名も、地域(region)と、所得レベル(income)と共に、表示しておきます。*
```{r}
df_ref |> filter(!(iso2c %in% REGION)) |> distinct(country, iso2c, region, income)
```
### 分析する国のリスト
*自分で分析したい国のリストを作ってください。ここでは、紛争に関係がありそうな国を CONFLICTS にします。*
```{r}
CONFLICTS <- c("Syrian Arab Republic", "Ukraine", "Afghanistan", "South Sudan", "Myanmar", "Congo, Dem. Rep.", "Turkiye", "West Bank and Gaza")
```
## 視覚化
### 1. 各年毎のデータの数の棒グラフ
*まずは、NA の値を削除します。そのあとで、国の情報の数を数えたいので、`!(iso2c %in% REGION)` で、上でおいた、地域の iso2c を選択し、! は否定でしたから、地域ではないものを選択し、その数を棒グラフにしています。*
```{r}
df_ref |> drop_na(refugee_asylum, refugee_origin) |> filter(!(iso2c %in% REGION)) |>
ggplot(aes(year)) + geom_bar()
```
**気づいたこと・疑問**
- 1995年ごろからは、十分データがあるが、その前は少ない。2022年までありそう。
### 2. 経年変化を表す折れ線グラフ
#### a. 日本、またはデータがある国
```{r}
df_ref |> filter(country == "Japan") |> drop_na(refugee_asylum) |>
ggplot(aes(year, refugee_asylum)) + geom_line() +
labs(title = "日本の受け入れ難民数")
```
```{r}
df_ref |> filter(country == "Japan") |> drop_na(refugee_origin) |>
ggplot(aes(year, refugee_origin)) + geom_line() +
labs(title = "日本からの難民数")
```
**気づいたこと・疑問**
- 何を意味しているのだろう。
#### b. 選択したいくつかの国
CONFLICTS は、`country` ですから、下のようにします。
```{r}
df_ref |> filter(country %in% CONFLICTS) |> drop_na(refugee_asylum) |>
ggplot(aes(year, refugee_asylum, col = country)) + geom_line() +
labs(title = "紛争国の難民受け入れ数")
```
**気づいたこと・疑問**
- ミャンマーは登場していない。
```{r}
df_ref |> filter(country %in% CONFLICTS) |> drop_na(refugee_origin) |>
ggplot(aes(year, refugee_origin, col = country)) + geom_line() +
labs(title = "紛争国の難民数")
```
### 3. 縦長の表(Long Table)
*`cols = c(refugee_asylum, refugee_origin)` と、一つの指標にまとめるものをリストすると、`name` に指標名が入り、`value` に、その値が入る。書式は、`pivot_longer(cols = ..., names_to = ..., values_to = ...)` で、初期設定では、`names_to = "name", values_to = "value"` となっているので、指定しないと、下のようになる。Help 参照。*
```{r}
df_ref_long <- df_ref |> pivot_longer(cols = c(refugee_asylum, refugee_origin))
df_ref_long
```
#### a. 日本の複数の指標を色分けした経年変化のグラフ
*`col = name` と指定すると、色で区別して、一つのグラフに描ける*
```{r}
df_ref_long |> filter(country == "Japan") |> drop_na(value) |>
ggplot(aes(year, value, col = name)) + geom_line() +
labs(title = "日本からの難民")
```
**気づいたこと・疑問**
- 急激に増えているのは何なのだろう。
```{r}
df_ref_long |> filter(country == "World") |> drop_na(value) |>
ggplot(aes(year, value, col = name)) + geom_line() +
labs(title = "世界の難民")
```
**気づいたこと・疑問**
- 世界では、難民受け入れと、難民数が一致している。2010年ごろから、増加している。
#### b. 選択したいくつかの国の複数の指標を色分けした経年変化のグラフ
```{r}
df_ref_long |> filter(iso2c %in% ASEAN) |> drop_na(value) |>
ggplot(aes(year, value, col = country, linetype = name)) + geom_line() +
labs(title = "紛争国の難民")
```
**気づいたこと・疑問**
- もうすこし丁寧にみないとわからない。国の数が多い
### 4. ヒストグラム
それぞれのデータが十分ある最近の年の値のヒストグラム(度数分布)
_分け方の数 bins や、幅 binwidth を適切に変更_
#### 一つ目の指標
```{r}
df_pc |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |> drop_na(refugee_asylum) |>
ggplot(aes(refugee_asylum, fill = region)) + geom_histogram(bins = 10, col = "black", linewidth = 0.2) + scale_x_log10()
```
```{r}
df_pc |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |> drop_na(refugee_asylum) |>
ggplot(aes(refugee_asylum, fill = income)) + geom_histogram(bins = 10, col = "black", linewidth = 0.2) + scale_x_log10()
```
#### 二つ目の指標
```{r}
df_pc |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |> drop_na(refugee_origin) |>
ggplot(aes(refugee_asylum, fill = region)) + geom_histogram(bins = 10, col = "black", linewidth = 0.2) + scale_x_log10()
```
```{r}
df_pc |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |> drop_na(refugee_origin) |>
ggplot(aes(refugee_asylum, fill = income)) + geom_histogram(bins = 10, col = "black", linewidth = 0.2) + scale_x_log10()
```
**気づいたこと・疑問点**
- いろいろと考えることがある。
### 5. 棒グラフ
データが十分ある最近の年の値の10カ国の値の棒グラフ
#### a. 一つ目の指標:値が大きい方から
```{r}
df_pc |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |> drop_na(refugee_asylum) |>
arrange(desc(refugee_asylum)) |> slice_head(n = 10) |>
ggplot(aes(fct_rev(fct_inorder(country)), refugee_asylum, fill = region)) + geom_col() + coord_flip() + labs(title = "難民受け入れの多い順")
```
#### b. 一つ目の指標:値が小さい方から
```{r}
df_pc |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |> drop_na(refugee_asylum) |>
arrange(refugee_asylum) |> slice_head(n = 10) |>
ggplot(aes(fct_rev(fct_inorder(country)), refugee_asylum, fill = region)) + geom_col() + coord_flip() + labs(title = "難民受け入れの少ない順")
```
#### a. 二つ目の指標:値が大きい方から
```{r}
df_pc |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |> drop_na(refugee_origin) |>
arrange(desc(refugee_origin)) |> slice_head(n = 10) |>
ggplot(aes(fct_rev(fct_inorder(country)), refugee_origin, fill = region)) + geom_col() + coord_flip() + labs(title = "難民の多い順")
```
#### b. 二つ目の指標:値が小さい方から
```{r}
df_pc |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |> drop_na(refugee_origin) |>
arrange(refugee_origin) |> slice_head(n = 10) |>
ggplot(aes(fct_rev(fct_inorder(country)), refugee_origin, fill = region)) + geom_col() + coord_flip() + labs(title = "難民の少ない順")
```
### 6. 散布図
#### a.(地域を除き)国のみの散布図
_LOG10 スケールを使っています。_
```{r}
df_ref |> filter(!(iso2c %in% REGION)) |> drop_na(refugee_asylum, refugee_origin) |>
ggplot(aes(refugee_asylum, refugee_origin)) + geom_point() + scale_x_log10() + scale_y_log10() +
labs(title = "難民・受け入れ")
```
**気づいたこと・疑問**
- 相関はみられない。
#### 近似(回帰)直線の表示
```{r}
df_ref |> filter(!(iso2c %in% REGION)) |> drop_na(refugee_asylum, refugee_origin) |>
ggplot(aes(refugee_asylum, refugee_origin)) + geom_point() +
geom_smooth(formula = 'y~x', method = "lm", se = FALSE) + scale_x_log10() + scale_y_log10() +
labs(title = "難民・受け入れ(回帰直線付)")
```
**気づいたこと・疑問**
- 直線の傾きから、弱い、正の相関があるのだろう。
#### b. 最近の年の(地域を除き)国のみの散布図
```{r}
df_ref |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |>
drop_na(refugee_asylum, refugee_origin) |>
ggplot(aes(refugee_asylum, refugee_origin)) + geom_point() + scale_x_log10() + scale_y_log10() +
labs(title = "2022年の難民相関")
```
**気づいたこと・疑問**
- いろいろな国があるように見える。
#### 近似(回帰)直線の表示
```{r}
df_ref |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |>
drop_na(refugee_asylum, refugee_origin) |>
ggplot(aes(refugee_asylum, refugee_origin)) + geom_point() +
geom_smooth(formula = 'y~x', method = "lm", se = FALSE) + scale_x_log10() + scale_y_log10() +
labs(title = "難民(回帰直線付)")
```
**気づいたこと・疑問**
- こちらも、弱い相関がありそうだ。
#### c. 相関係数
```{r}
df_ref |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |>
drop_na(refugee_asylum, refugee_origin) |> select(refugee_asylum, refugee_origin) |> cor()
```
相関係数が、0.025 で、ほとんど相関はないと言って良い。
### 7. 箱ヒゲ図(Boxplot)
```{r}
df_ref_long |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |>
drop_na(value) |>
ggplot(aes(name, value)) + geom_boxplot() + scale_y_log10() +
labs(title = "難民:箱ひげ図")
```
**気づいたこと・疑問**
- 受け入れ国が限定されているということだろうか。
```{r}
df_ref_long |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |>
drop_na(value, region) |>
ggplot(aes(region, value, fill = name)) + geom_boxplot() + coord_flip() +scale_y_log10() +
labs(title = "難民・地域別箱ひげ図")
```
**気づいたこと・疑問**
- 地域差がある。これだけでは、あまりわからない。
```{r}
df_ref_long |> filter(!(iso2c %in% REGION)) |> filter(year == 2022) |>
drop_na(value, income) |> filter(income != "Not classified") |>
ggplot(aes(income, value, fill = name)) + geom_boxplot() + coord_flip() + scale_y_log10() +
labs(title = "難民・収入レベル別箱ひげ図")
```
**気づいたこと・疑問**
- 高所得の国では、難民が少ないのは、当然として、ほかは、さまざま。
```{r}
df_ref_long |> filter(!(iso2c %in% REGION)) |> filter(year %in% c(1991, 2001, 2011, 2021)) |>
drop_na(value) |>
ggplot(aes(factor(year), value, fill = name)) + geom_boxplot() + scale_y_log10() +
labs(title = "難民・10年ごとの箱ひげ図")
```
**気づいたこと・疑問**
- この期間では、あまり大きな変化はないように見える。
```{r}
df_ref_long |> filter(country %in% CONFLICTS) |> drop_na(value) |>
ggplot(aes(country, value, fill = name)) + geom_boxplot() + coord_flip() + scale_y_log10() +
labs(title = "紛争国の難民箱ひげ図")
```
**気づいたこと・疑問**
- それぞれの国のデータは、データのある年の中での、値である。
- アフガニスタンは、継続して、難民が多いことがわかる。
### 参考
```{r}
regions <- c("South Asia", "Europe & Central Asia",
"Middle East & North Africa", "East Asia & Pacific", "Sub-Saharan Africa",
"Latin America & Caribbean", "North America")
```
```{r}
df_ref |> filter(country %in% regions) |> drop_na(refugee_asylum) |>
ggplot(aes(year, refugee_asylum, fill = country)) +
geom_area(col = "black", linewidth = 0.1) +
labs(title = "Refugee Population by Region of Asylum")
```
```{r}
df_ref |> filter(country %in% regions) |> drop_na(refugee_origin) |>
ggplot(aes(year, refugee_origin, fill = country)) +
geom_area(col = "black", linewidth = 0.1) +
labs(title = "Refugee Population by Region of Origin")
```
```{r}
df_ref_long |> filter(country %in% regions) |> drop_na(value) |>
ggplot(aes(year, value, fill = country)) +
geom_area(col = "black", linewidth = 0.1) +
facet_wrap(~name) +
labs(title = "Refugee Population by Region of Asylum and Origin", fill = "") +
theme(legend.position = "top")
```
```{r}
df_ref_long |> filter(country %in% regions, year >= 1990) |> filter(is.na(value))
```