happy <- read.csv("data_input/world-happiness-report-2021.csv")
str(happy)
## 'data.frame': 149 obs. of 20 variables:
## $ Country.name : chr "Finland" "Denmark" "Switzerland" "Iceland" ...
## $ Regional.indicator : chr "Western Europe" "Western Europe" "Western Europe" "Western Europe" ...
## $ Ladder.score : num 7.84 7.62 7.57 7.55 7.46 ...
## $ Standard.error.of.ladder.score : num 0.032 0.035 0.036 0.059 0.027 0.035 0.036 0.037 0.04 0.036 ...
## $ upperwhisker : num 7.9 7.69 7.64 7.67 7.52 ...
## $ lowerwhisker : num 7.78 7.55 7.5 7.44 7.41 ...
## $ Logged.GDP.per.capita : num 10.8 10.9 11.1 10.9 10.9 ...
## $ Social.support : num 0.954 0.954 0.942 0.983 0.942 0.954 0.934 0.908 0.948 0.934 ...
## $ Healthy.life.expectancy : num 72 72.7 74.4 73 72.4 73.3 72.7 72.6 73.4 73.3 ...
## $ Freedom.to.make.life.choices : num 0.949 0.946 0.919 0.955 0.913 0.96 0.945 0.907 0.929 0.908 ...
## $ Generosity : num -0.098 0.03 0.025 0.16 0.175 0.093 0.086 -0.034 0.134 0.042 ...
## $ Perceptions.of.corruption : num 0.186 0.179 0.292 0.673 0.338 0.27 0.237 0.386 0.242 0.481 ...
## $ Ladder.score.in.Dystopia : num 2.43 2.43 2.43 2.43 2.43 2.43 2.43 2.43 2.43 2.43 ...
## $ Explained.by..Log.GDP.per.capita : num 1.45 1.5 1.57 1.48 1.5 ...
## $ Explained.by..Social.support : num 1.11 1.11 1.08 1.17 1.08 ...
## $ Explained.by..Healthy.life.expectancy : num 0.741 0.763 0.816 0.772 0.753 0.782 0.763 0.76 0.785 0.782 ...
## $ Explained.by..Freedom.to.make.life.choices: num 0.691 0.686 0.653 0.698 0.647 0.703 0.685 0.639 0.665 0.64 ...
## $ Explained.by..Generosity : num 0.124 0.208 0.204 0.293 0.302 0.249 0.244 0.166 0.276 0.215 ...
## $ Explained.by..Perceptions.of.corruption : num 0.481 0.485 0.413 0.17 0.384 0.427 0.448 0.353 0.445 0.292 ...
## $ Dystopia...residual : num 3.25 2.87 2.84 2.97 2.8 ...
Mengubah tipe data untuk kolom Regional Indicator dan memeriksa missing value.
happy$Regional.indicator <- as.factor(happy$Regional.indicator)
colSums(is.na(happy))
## Country.name
## 0
## Regional.indicator
## 0
## Ladder.score
## 0
## Standard.error.of.ladder.score
## 0
## upperwhisker
## 0
## lowerwhisker
## 0
## Logged.GDP.per.capita
## 0
## Social.support
## 0
## Healthy.life.expectancy
## 0
## Freedom.to.make.life.choices
## 0
## Generosity
## 0
## Perceptions.of.corruption
## 0
## Ladder.score.in.Dystopia
## 0
## Explained.by..Log.GDP.per.capita
## 0
## Explained.by..Social.support
## 0
## Explained.by..Healthy.life.expectancy
## 0
## Explained.by..Freedom.to.make.life.choices
## 0
## Explained.by..Generosity
## 0
## Explained.by..Perceptions.of.corruption
## 0
## Dystopia...residual
## 0
happy <- happy[,c(1:3, 7:12)]
colnames(happy)[3] <- 'Happiness.score'
head(happy)
## Country.name Regional.indicator Happiness.score Logged.GDP.per.capita
## 1 Finland Western Europe 7.842 10.775
## 2 Denmark Western Europe 7.620 10.933
## 3 Switzerland Western Europe 7.571 11.117
## 4 Iceland Western Europe 7.554 10.878
## 5 Netherlands Western Europe 7.464 10.932
## 6 Norway Western Europe 7.392 11.053
## Social.support Healthy.life.expectancy Freedom.to.make.life.choices
## 1 0.954 72.0 0.949
## 2 0.954 72.7 0.946
## 3 0.942 74.4 0.919
## 4 0.983 73.0 0.955
## 5 0.942 72.4 0.913
## 6 0.954 73.3 0.960
## Generosity Perceptions.of.corruption
## 1 -0.098 0.186
## 2 0.030 0.179
## 3 0.025 0.292
## 4 0.160 0.673
## 5 0.175 0.338
## 6 0.093 0.270
str(happy)
## 'data.frame': 149 obs. of 9 variables:
## $ Country.name : chr "Finland" "Denmark" "Switzerland" "Iceland" ...
## $ Regional.indicator : Factor w/ 10 levels "Central and Eastern Europe",..: 10 10 10 10 10 10 10 10 6 10 ...
## $ Happiness.score : num 7.84 7.62 7.57 7.55 7.46 ...
## $ Logged.GDP.per.capita : num 10.8 10.9 11.1 10.9 10.9 ...
## $ Social.support : num 0.954 0.954 0.942 0.983 0.942 0.954 0.934 0.908 0.948 0.934 ...
## $ Healthy.life.expectancy : num 72 72.7 74.4 73 72.4 73.3 72.7 72.6 73.4 73.3 ...
## $ Freedom.to.make.life.choices: num 0.949 0.946 0.919 0.955 0.913 0.96 0.945 0.907 0.929 0.908 ...
## $ Generosity : num -0.098 0.03 0.025 0.16 0.175 0.093 0.086 -0.034 0.134 0.042 ...
## $ Perceptions.of.corruption : num 0.186 0.179 0.292 0.673 0.338 0.27 0.237 0.386 0.242 0.481 ...
summary(happy)
## Country.name Regional.indicator Happiness.score
## Length:149 Sub-Saharan Africa :36 Min. :2.523
## Class :character Western Europe :21 1st Qu.:4.852
## Mode :character Latin America and Caribbean :20 Median :5.534
## Central and Eastern Europe :17 Mean :5.533
## Middle East and North Africa :17 3rd Qu.:6.255
## Commonwealth of Independent States:12 Max. :7.842
## (Other) :26
## Logged.GDP.per.capita Social.support Healthy.life.expectancy
## Min. : 6.635 Min. :0.4630 Min. :48.48
## 1st Qu.: 8.541 1st Qu.:0.7500 1st Qu.:59.80
## Median : 9.569 Median :0.8320 Median :66.60
## Mean : 9.432 Mean :0.8147 Mean :64.99
## 3rd Qu.:10.421 3rd Qu.:0.9050 3rd Qu.:69.60
## Max. :11.647 Max. :0.9830 Max. :76.95
##
## Freedom.to.make.life.choices Generosity Perceptions.of.corruption
## Min. :0.3820 Min. :-0.28800 Min. :0.0820
## 1st Qu.:0.7180 1st Qu.:-0.12600 1st Qu.:0.6670
## Median :0.8040 Median :-0.03600 Median :0.7810
## Mean :0.7916 Mean :-0.01513 Mean :0.7274
## 3rd Qu.:0.8770 3rd Qu.: 0.07900 3rd Qu.:0.8450
## Max. :0.9700 Max. : 0.54200 Max. :0.9390
##
Summary:
1. Data diperoleh dari World Happiness Report tahun 2021, dimana didalamnya terdapat 149 negara yang dibagi kedalam 10 Regional Indicator.
2. Happiness Score didapat dengan melakukan kalkulasi dari 6 faktor, yaitu: GDP, Social Support, Healthy Life Expectancy, Freedom to Make Life Choices, Generosity, dan Perceptions of Corruption.
3. Rerata Happiness Score untuk seluruh negara adalah 5.533 dari nilai maksimal yaitu 10.
4. Happiness Score tertinggi adalah negara dengan skor 7.842.
5. Happiness Score terendah adalah negara dengan skor 2.523.
boxplot(happy$Happiness.score)
1. Urutan 10 negara dengan Happiness Score tertinggi?
agg_nat <- aggregate(Happiness.score~Country.name,happy, mean)
head(agg_nat[order(agg_nat$Happiness.score, decreasing = TRUE), ],10)
## Country.name Happiness.score
## 41 Finland 7.842
## 34 Denmark 7.620
## 129 Switzerland 7.571
## 55 Iceland 7.554
## 97 Netherlands 7.464
## 104 Norway 7.392
## 128 Sweden 7.363
## 79 Luxembourg 7.324
## 98 New Zealand 7.277
## 7 Austria 7.268
2. Urutan Regional Indicator dengan rerata Happiness Score tertinggi ke terendah?
agg_reg <- aggregate(Happiness.score~Regional.indicator,happy, mean)
agg_reg[order(agg_reg$Happiness.score, decreasing = TRUE), ]
## Regional.indicator Happiness.score
## 6 North America and ANZ 7.128500
## 10 Western Europe 6.914905
## 1 Central and Eastern Europe 5.984765
## 4 Latin America and Caribbean 5.908050
## 3 East Asia 5.810333
## 2 Commonwealth of Independent States 5.467000
## 8 Southeast Asia 5.407556
## 5 Middle East and North Africa 5.219765
## 9 Sub-Saharan Africa 4.494472
## 7 South Asia 4.441857
barplot(xtabs(Happiness.score ~ Regional.indicator, agg_reg))
3. Urutan 10 negara dengan GDP tertinggi?
agg_gdp <- aggregate(Logged.GDP.per.capita~Country.name,happy, sum)
head(agg_gdp[order(agg_gdp$Logged.GDP.per.capita, decreasing = TRUE), ],10)
## Country.name Logged.GDP.per.capita
## 79 Luxembourg 11.647
## 120 Singapore 11.488
## 60 Ireland 11.342
## 129 Switzerland 11.117
## 140 United Arab Emirates 11.085
## 104 Norway 11.053
## 142 United States 11.023
## 53 Hong Kong S.A.R. of China 11.000
## 34 Denmark 10.933
## 97 Netherlands 10.932
4. Urutan 10 negara dengan Social Support tertinggi?
agg_ss <- aggregate(Social.support~Country.name,happy, sum)
head(agg_ss[order(agg_ss$Social.support, decreasing = TRUE), ],10)
## Country.name Social.support
## 55 Iceland 0.983
## 137 Turkmenistan 0.983
## 34 Denmark 0.954
## 41 Finland 0.954
## 104 Norway 0.954
## 67 Kazakhstan 0.952
## 98 New Zealand 0.948
## 122 Slovenia 0.948
## 33 Czech Republic 0.947
## 60 Ireland 0.947
5. Urutan 10 negara dengan Healthy Life Expectancy tertinggi?
agg_hle <- aggregate(Healthy.life.expectancy~Country.name,happy, sum)
head(agg_hle[order(agg_hle$Healthy.life.expectancy, decreasing = TRUE), ],10)
## Country.name Healthy.life.expectancy
## 120 Singapore 76.953
## 53 Hong Kong S.A.R. of China 76.820
## 65 Japan 75.100
## 125 Spain 74.700
## 129 Switzerland 74.400
## 42 France 74.000
## 6 Australia 73.900
## 124 South Korea 73.900
## 32 Cyprus 73.898
## 102 North Cyprus 73.898
6. Urutan 10 negara dengan Freedom to Make Life Choices tertinggi?
agg_free <- aggregate(Freedom.to.make.life.choices~Country.name,happy, sum)
head(agg_free[order(agg_free$Freedom.to.make.life.choices, decreasing = TRUE), ],10)
## Country.name Freedom.to.make.life.choices
## 144 Uzbekistan 0.970
## 104 Norway 0.960
## 21 Cambodia 0.959
## 55 Iceland 0.955
## 41 Finland 0.949
## 122 Slovenia 0.949
## 34 Denmark 0.946
## 128 Sweden 0.945
## 146 Vietnam 0.940
## 71 Kyrgyzstan 0.935
7. Urutan 10 negara dengan Generosity tertinggi?
agg_gen <- aggregate(Generosity~Country.name,happy, sum)
head(agg_gen[order(agg_gen$Generosity, decreasing = TRUE), ],10)
## Country.name Generosity
## 57 Indonesia 0.542
## 94 Myanmar 0.509
## 44 Gambia 0.424
## 51 Haiti 0.422
## 144 Uzbekistan 0.311
## 68 Kenya 0.287
## 133 Thailand 0.287
## 137 Turkmenistan 0.273
## 69 Kosovo 0.257
## 141 United Kingdom 0.233
8. Urutan 10 negara dengan Perception of Corruption terendah?
agg_corr <- aggregate(Perceptions.of.corruption~Country.name,happy, sum)
head(agg_corr[order(agg_corr$Perceptions.of.corruption, decreasing = FALSE), ],10)
## Country.name Perceptions.of.corruption
## 120 Singapore 0.082
## 115 Rwanda 0.167
## 34 Denmark 0.179
## 41 Finland 0.186
## 128 Sweden 0.237
## 98 New Zealand 0.242
## 104 Norway 0.270
## 129 Switzerland 0.292
## 97 Netherlands 0.338
## 60 Ireland 0.363
9. Happiness Score untuk negara ASEAN:
SEA <- happy[happy$Regional.indicator=="Southeast Asia",]
agg_SEA <- aggregate(Happiness.score~Country.name,SEA, sum)
agg_SEA[order(agg_SEA$Happiness.score, decreasing = TRUE), ]
## Country.name Happiness.score
## 7 Singapore 6.377
## 8 Thailand 5.985
## 6 Philippines 5.880
## 9 Vietnam 5.411
## 4 Malaysia 5.384
## 2 Indonesia 5.345
## 3 Laos 5.030
## 1 Cambodia 4.830
## 5 Myanmar 4.426
10. Breakdown Happiness Score dan variabel pendukung untuk Indonesia:
indo <- happy[happy$Country.name=="Indonesia",]
indo
## Country.name Regional.indicator Happiness.score Logged.GDP.per.capita
## 82 Indonesia Southeast Asia 5.345 9.365
## Social.support Healthy.life.expectancy Freedom.to.make.life.choices
## 82 0.811 62.236 0.873
## Generosity Perceptions.of.corruption
## 82 0.542 0.867