聯合國「永續發展解決方案」從2012年開始,每年公布「世界快樂報告」排名,了衡量快樂之可持續發展方案,在網路出版的國際調查報告。 影響快樂度最重要的6個因素為:人均GDP、預期健康壽命、社會支援、捐獻佔所得的比重、選擇人生的自由和對政府與企業的貪腐程度。
| 代碼 | 項目 |
|---|---|
| Country | 國家 |
| HapRank | 排名 |
| HapScore | 快樂指數 |
| avgGDP | 人均GDP |
| Socialsup | 社會支援 |
| Health | 預期健康壽命 |
| Freedom | 選擇人生的自由 |
| Generosity | 捐獻佔所得的比重 |
| TrustG | 政府與企業的貪腐程度 |
library(readr)
library(dplyr)
library(ggplot2)
library(plotly)
## import data
happiness <- read_csv("C:/Users/user/Desktop/1023/happiness.csv")
happiness<-happiness%>%
select(Country,Happiness.Rank,Happiness.Score,Economy..GDP.per.Capita.,Family,Health..Life.Expectancy.,Freedom,Generosity,Trust..Government.Corruption.)
colnames(happiness) <- c("Country","HapRank","HapScore","avgGDP","Socialsup",
"Health","Freedom","Generosity","TrustG")
str(happiness)
## Classes 'tbl_df', 'tbl' and 'data.frame': 155 obs. of 9 variables:
## $ Country : chr "Norway" "Denmark" "Iceland" "Switzerland" ...
## $ HapRank : int 1 2 3 4 5 6 7 8 9 10 ...
## $ HapScore : num 7.54 7.52 7.5 7.49 7.47 ...
## $ avgGDP : num 1.62 1.48 1.48 1.56 1.44 ...
## $ Socialsup : num 1.53 1.55 1.61 1.52 1.54 ...
## $ Health : num 0.797 0.793 0.834 0.858 0.809 ...
## $ Freedom : num 0.635 0.626 0.627 0.62 0.618 ...
## $ Generosity: num 0.362 0.355 0.476 0.291 0.245 ...
## $ TrustG : num 0.316 0.401 0.154 0.367 0.383 ...
## - attr(*, "spec")=List of 2
## ..$ cols :List of 12
## .. ..$ Country : list()
## .. .. ..- attr(*, "class")= chr "collector_character" "collector"
## .. ..$ Happiness.Rank : list()
## .. .. ..- attr(*, "class")= chr "collector_integer" "collector"
## .. ..$ Happiness.Score : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Whisker.high : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Whisker.low : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Economy..GDP.per.Capita. : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Family : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Health..Life.Expectancy. : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Freedom : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Generosity : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Trust..Government.Corruption.: list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Dystopia.Residual : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## ..$ default: list()
## .. ..- attr(*, "class")= chr "collector_guess" "collector"
## ..- attr(*, "class")= chr "col_spec"
summary(happiness)
## Country HapRank HapScore avgGDP
## Length:155 Min. : 1.0 Min. :2.693 Min. :0.0000
## Class :character 1st Qu.: 39.5 1st Qu.:4.505 1st Qu.:0.6634
## Mode :character Median : 78.0 Median :5.279 Median :1.0646
## Mean : 78.0 Mean :5.354 Mean :0.9847
## 3rd Qu.:116.5 3rd Qu.:6.101 3rd Qu.:1.3180
## Max. :155.0 Max. :7.537 Max. :1.8708
## Socialsup Health Freedom Generosity
## Min. :0.000 Min. :0.0000 Min. :0.0000 Min. :0.0000
## 1st Qu.:1.043 1st Qu.:0.3699 1st Qu.:0.3037 1st Qu.:0.1541
## Median :1.254 Median :0.6060 Median :0.4375 Median :0.2315
## Mean :1.189 Mean :0.5513 Mean :0.4088 Mean :0.2469
## 3rd Qu.:1.414 3rd Qu.:0.7230 3rd Qu.:0.5166 3rd Qu.:0.3238
## Max. :1.611 Max. :0.9495 Max. :0.6582 Max. :0.8381
## TrustG
## Min. :0.00000
## 1st Qu.:0.05727
## Median :0.08985
## Mean :0.12312
## 3rd Qu.:0.15330
## Max. :0.46431
分數區間5-6的國家數最多,整體趨於常態分配。
hist(happiness$HapScore)
由圖可知,各國間的人均GDP分布最廣,顯示全球財富不均現象。 p.s.因為技術問題,有三條箱型圖的類別名稱沒有顯示,由下而上依序為avgGDP, Socialsup, Health, Freedom, Generosity,TrustG。
happiness%>%
select(avgGDP, Socialsup, Health, Freedom, Generosity,TrustG) %>%
boxplot(horizontal = TRUE)
人均GDP與快樂分數有最高的正相關性,其次是預期健康壽命和社會支援。 另外, 捐獻佔所得的比重和人均GDP之間的相關系數趨於0。
## correlation
happiness %>% select(HapScore, avgGDP, Socialsup,TrustG,Generosity,Freedom,Health) %>% cor() %>% knitr::kable()
| HapScore | avgGDP | Socialsup | TrustG | Generosity | Freedom | Health | |
|---|---|---|---|---|---|---|---|
| HapScore | 1.0000000 | 0.8124688 | 0.7527367 | 0.4290797 | 0.1552558 | 0.5701372 | 0.7819506 |
| avgGDP | 0.8124688 | 1.0000000 | 0.6882963 | 0.3509441 | -0.0190113 | 0.3698734 | 0.8430766 |
| Socialsup | 0.7527367 | 0.6882963 | 1.0000000 | 0.2318414 | 0.0516926 | 0.4249658 | 0.6120801 |
| TrustG | 0.4290797 | 0.3509441 | 0.2318414 | 1.0000000 | 0.2941595 | 0.4991828 | 0.2797520 |
| Generosity | 0.1552558 | -0.0190113 | 0.0516926 | 0.2941595 | 1.0000000 | 0.3160827 | 0.0631915 |
| Freedom | 0.5701372 | 0.3698734 | 0.4249658 | 0.4991828 | 0.3160827 | 1.0000000 | 0.3498268 |
| Health | 0.7819506 | 0.8430766 | 0.6120801 | 0.2797520 | 0.0631915 | 0.3498268 | 1.0000000 |
library(corrplot)
happiness %>% select(HapScore, avgGDP, Socialsup,TrustG,Generosity,Freedom,Health) %>% cor(use="na.or.complete") %>% corrplot()
由下圖可以發現,人均GDP最富裕(超過1.5)的幾個國家,如:卡達、新加坡、科威特,卻不是最快樂的。 普遍來說,最貧窮的幾個國家,也是快樂指數最低的。 但是,資料中第二貧困的國家-Somalia(所馬利亞)的快樂指數卻遠遠高於其他人均GDP相仿國家。
plot_ly(happiness, x = ~avgGDP, y = ~HapScore,
# Hover text:
text = ~paste("Country: ", Country))
單看預期健康壽命的密度圖可以發現兩個高峰,分別在約0.3、0.65兩處,顯示國家的預期健康壽命約分為兩塊。 第二張圖可以看出國家預期壽命較高的群體,快樂指數涵蓋4-7以上;另一部分預期壽命較短的國家快樂指數範圍基本上在5以下。
plot(density(happiness$Health))
plot_ly(happiness, x = ~Health, y = ~HapScore,
# Hover text:
text = ~paste("Country: ", Country))
從下圖表可看出人均GDP和預期健康壽命呈現正相關。 但是國家南非、奈及利亞、安哥拉的預期健康壽命遠低於平均線。
plot_ly(happiness, x = ~avgGDP, y = ~Health,
# Hover text:
text = ~paste("Country: ", Country))
ggplot(happiness, aes(x=avgGDP, y=Health)) +
geom_point(size=1 ,alpha=1)+
stat_smooth()
由下圖來看,捐獻佔所得的比重和人均GDP並沒有呈現明顯的相關性。 資料之中,Myanmar(緬甸)的捐獻佔所得的比重高於其他國家許多,原因值得進一步探討。 另外,捐獻佔所得的比重第二、三、四名家分別為印尼、泰國和馬爾他,這些國家的人均GDP皆屬在中下水準。
plot_ly(happiness, x = ~avgGDP, y = ~Generosity,
# Hover text:
text = ~paste("Country: ", Country),
color = ~HapScore)
1.六個影響快樂指數的變數之中,國家的人均國內生產毛額的最大及最小值差距最大,顯現出國家間的貧富落差。另外在政府與企業的貪腐程度上的離群值也能夠進一步探討。
2.六個影響快樂指數的變數之中,國家的人均GDP和該國的快樂分數有最高的相關,其次是預期健康壽命和社會支援,最不相關的是捐獻佔所得的比重。以上結果顯示出財富和健康對於人們來說,是過得快樂或不快樂的重要因素之一。
3.儘管財富是影響快樂的重要因素,但並非越富有就越快樂。而索馬利亞的案例,也值得深入探討,是什麼原因讓索馬利亞人儘管貧窮卻快樂。
4.從探討結果做進一步推測,預期健康壽命若低於某一水準,可能會導致快樂指數也低於水平、甚至墊底。
5.人均GDP和捐獻佔所得的比重並沒有很強的相關性,但是異常突出的最大值值得探討。