The Happy Planet Index (HPI) is an index of human well-being and environmental impact that was introduced by NEF, a UK-based economic think tank promoting social, economic and environmental justice. The index is weighted to give progressively higher scores to nations with lower ecological footprints. I downloaded the 2016 dataset from HPI website. My goal is to find correlations between several variables, then use clustering technic to seprarate these 140 countries into different clusters, according to happiness, wealth, life expectancy and carbon emissions.

The head of the data

```
## country region hpi_index life_expectancy
## 1 Afghanistan Middle East and North Africa 20.22535 59.668
## 2 Albania Post-communist 36.76687 77.347
## 3 Algeria Middle East and North Africa 33.30054 74.313
## 4 Argentina Americas 35.19024 75.927
## 5 Armenia Post-communist 25.66642 74.446
## 6 Australia Asia Pacific 21.22897 82.052
## happy_years footprint gdp inequality_outcomes wellbeing
## 1 12.39602 0.79 690.8426 0.42655744 3.8
## 2 34.41474 2.21 4247.4854 0.16513372 5.5
## 3 30.46946 2.12 5583.6162 0.24486175 5.6
## 4 40.16667 3.14 14357.4116 0.16423830 6.5
## 5 24.01876 2.23 3565.5176 0.21664810 4.3
## 6 53.06950 9.31 67646.1039 0.08067825 7.2
## adj_life_expectancy adj_wellbeing population
## 1 38.34882 3.390494 29726803
## 2 69.67116 5.097650 2900489
## 3 60.47454 5.196449 37439427
## 4 68.34958 6.034707 42095224
## 5 66.92168 3.747140 2978339
## 6 78.56002 6.913335 22728254
```

The structure of the data

```
## 'data.frame': 140 obs. of 12 variables:
## $ country : chr "Afghanistan" "Albania" "Algeria" "Argentina" ...
## $ region : chr "Middle East and North Africa" "Post-communist" "Middle East and North Africa" "Americas" ...
## $ hpi_index : num 20.2 36.8 33.3 35.2 25.7 ...
## $ life_expectancy : num 59.7 77.3 74.3 75.9 74.4 ...
## $ happy_years : num 12.4 34.4 30.5 40.2 24 ...
## $ footprint : num 0.79 2.21 2.12 3.14 2.23 9.31 6.06 0.72 5.09 7.44 ...
## $ gdp : num 691 4247 5584 14357 3566 ...
## $ inequality_outcomes: num 0.427 0.165 0.245 0.164 0.217 ...
## $ wellbeing : num 3.8 5.5 5.6 6.5 4.3 7.2 7.4 4.7 5.7 6.9 ...
## $ adj_life_expectancy: num 38.3 69.7 60.5 68.3 66.9 ...
## $ adj_wellbeing : num 3.39 5.1 5.2 6.03 3.75 ...
## $ population : num 29726803 2900489 37439427 42095224 2978339 ...
```

The summary of the data

```
## hpi_index life_expectancy happy_years footprint
## Min. :12.78 Min. :48.91 Min. : 8.97 Min. : 0.610
## 1st Qu.:21.21 1st Qu.:65.04 1st Qu.:18.69 1st Qu.: 1.425
## Median :26.29 Median :73.50 Median :29.40 Median : 2.680
## Mean :26.41 Mean :70.93 Mean :30.25 Mean : 3.258
## 3rd Qu.:31.54 3rd Qu.:77.02 3rd Qu.:39.71 3rd Qu.: 4.482
## Max. :44.71 Max. :83.57 Max. :59.32 Max. :15.820
## gdp inequality_outcomes wellbeing
## Min. : 244.2 Min. :0.04322 Min. :2.867
## 1st Qu.: 1628.1 1st Qu.:0.13353 1st Qu.:4.575
## Median : 5691.1 Median :0.21174 Median :5.250
## Mean : 13911.1 Mean :0.23291 Mean :5.408
## 3rd Qu.: 15159.1 3rd Qu.:0.32932 3rd Qu.:6.225
## Max. :105447.1 Max. :0.50734 Max. :7.800
## adj_life_expectancy adj_wellbeing population
## Min. :27.32 Min. :2.421 Min. :2.475e+05
## 1st Qu.:48.21 1st Qu.:4.047 1st Qu.:4.248e+06
## Median :63.41 Median :4.816 Median :1.065e+07
## Mean :60.34 Mean :4.973 Mean :4.801e+07
## 3rd Qu.:72.57 3rd Qu.:5.704 3rd Qu.:3.343e+07
## Max. :81.26 Max. :7.625 Max. :1.351e+09
```

After log transformation, the relationship between GDP per capita and life expectancy is relatively strong. These two variables are concordant. The Pearson correlation between this two variable is reasonably high, at approximately 0.62.

```
##
## Pearson's product-moment correlation
##
## data: hpi$gdp and hpi$life_expectancy
## t = 9.3042, df = 138, p-value = 2.766e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.5072215 0.7133067
## sample estimates:
## cor
## 0.6208781
```

Many countries in Europe and Americas end up with middle-to-low HPI index because of their big carbon footprints, despite long life expectancy.

GDP can’t buy happiness. The correlation between GDP and Happy Planet Index score is indeed very low, at about 0.11.

```
##
## Pearson's product-moment correlation
##
## data: hpi$gdp and hpi$hpi_index
## t = 1.3507, df = 138, p-value = 0.179
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.05267424 0.27492060
## sample estimates:
## cor
## 0.1142272
```

An important step of meaningful clustering consists of transforming the variables such that they have mean zero and standard deviation one.

```
## hpi_index life_expectancy happy_years footprint
## Min. :-1.86308 Min. :-2.5153 Min. :-1.60493 Min. :-1.1493
## 1st Qu.:-0.71120 1st Qu.:-0.6729 1st Qu.:-0.87191 1st Qu.:-0.7955
## Median :-0.01653 Median : 0.2939 Median :-0.06378 Median :-0.2507
## Mean : 0.00000 Mean : 0.0000 Mean : 0.00000 Mean : 0.0000
## 3rd Qu.: 0.70106 3rd Qu.: 0.6968 3rd Qu.: 0.71388 3rd Qu.: 0.5317
## Max. : 2.50110 Max. : 1.4449 Max. : 2.19247 Max. : 5.4532
## gdp inequality_outcomes wellbeing
## Min. :-0.6921 Min. :-1.5692 Min. :-2.2128
## 1st Qu.:-0.6220 1st Qu.:-0.8222 1st Qu.:-0.7252
## Median :-0.4163 Median :-0.1751 Median :-0.1374
## Mean : 0.0000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.: 0.0632 3rd Qu.: 0.7976 3rd Qu.: 0.7116
## Max. : 4.6356 Max. : 2.2702 Max. : 2.0831
## adj_life_expectancy adj_wellbeing population
## Min. :-2.2192 Min. :-2.1491 Min. :-0.2990
## 1st Qu.:-0.8152 1st Qu.:-0.7795 1st Qu.:-0.2740
## Median : 0.2060 Median :-0.1317 Median :-0.2339
## Mean : 0.0000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.: 0.8221 3rd Qu.: 0.6162 3rd Qu.:-0.0913
## Max. : 1.4059 Max. : 2.2339 Max. : 8.1562
```

A simple correlation heatmap

PCA is a procedure for identifying a smaller number of uncorrelated variables, called “principal components”, from a large set of data. The goal of principal components analysis is to explain the maximum amount of variance with the minimum number of principal components.

```
## **Results for the Principal Component Analysis (PCA)**
## The analysis was performed on 140 individuals, described by 10 variables
## *The results are available in the following objects:
##
## name description
## 1 "$eig" "eigenvalues"
## 2 "$var" "results for the variables"
## 3 "$var$coord" "coord. for the variables"
## 4 "$var$cor" "correlations variables - dimensions"
## 5 "$var$cos2" "cos2 for the variables"
## 6 "$var$contrib" "contributions of the variables"
## 7 "$ind" "results for the individuals"
## 8 "$ind$coord" "coord. for the individuals"
## 9 "$ind$cos2" "cos2 for the individuals"
## 10 "$ind$contrib" "contributions of the individuals"
## 11 "$call" "summary statistics"
## 12 "$call$centre" "mean of the variables"
## 13 "$call$ecart.type" "standard error of the variables"
## 14 "$call$row.w" "weights for the individuals"
## 15 "$call$col.w" "weights for the variables"
```

```
## eigenvalue percentage of variance cumulative percentage of variance
## comp 1 6.66741533 66.6741533 66.67415
## comp 2 1.31161290 13.1161290 79.79028
## comp 3 0.97036077 9.7036077 89.49389
## comp 4 0.70128270 7.0128270 96.50672
## comp 5 0.24150648 2.4150648 98.92178
## comp 6 0.05229306 0.5229306 99.44471
```

Interpreting:

The proportion of variation retained by the principal components was extracted above.

eigenvalues is the amount of variation retained by each PC. The first PC corresponds to the maximum amount of variation in the data set. In this case, the first two principal components are worthy of consideration because A commonly used criterion for the number of factors to rotate is the eigenvalues-greater-than-one rule proposed by Kaiser (1960).

The scree plot shows us which components explain most of the variability in the data. In this case, almost 80% of the variances contained in the data are retained by the first two principal components.

```
## Dim.1 Dim.2 Dim.3 Dim.4
## hpi_index 3.571216 50.96354921 5.368971166 2.1864830
## life_expectancy 12.275001 2.29815687 0.002516184 18.4965447
## happy_years 14.793710 0.01288175 0.027105103 0.7180341
## footprint 9.021277 24.71161977 2.982449522 0.4891428
## gdp 9.688265 11.57381062 1.003632002 2.3980025
## inequality_outcomes 13.363651 0.30494623 0.010038818 9.7957329
## Dim.5
## hpi_index 5.28431372
## life_expectancy 0.31797242
## happy_years 0.03254368
## footprint 7.62967135
## gdp 72.49799232
## inequality_outcomes 2.97699333
```

Variables that are correlated with PC1 and PC2 are the most important in explaining the variability in the data set.

The contribution of variables was extracted above: The larger the value of the contribution, the more the variable contributes to the component.

This highlights the most important variables in explaining the variations retained by the principal components.

When using clustering algorithms, k must be specified by the analyst. I use the following method to help finding the best k.

```
## *** : The Hubert index is a graphical method of determining the number of clusters.
## In the plot of Hubert index, we seek a significant knee that corresponds to a
## significant increase of the value of the measure i.e the significant peak in Hubert
## index second differences plot.
##
```

```
## *** : The D index is a graphical method of determining the number of clusters.
## In the plot of D index, we seek a significant knee (the significant peak in Dindex
## second differences plot) that corresponds to a significant increase of the value of
## the measure.
##
## *******************************************************************
## * Among all indices:
## * 4 proposed 2 as the best number of clusters
## * 7 proposed 3 as the best number of clusters
## * 1 proposed 5 as the best number of clusters
## * 5 proposed 6 as the best number of clusters
## * 3 proposed 10 as the best number of clusters
## * 3 proposed 15 as the best number of clusters
##
## ***** Conclusion *****
##
## * According to the majority rule, the best number of clusters is 3
##
##
## *******************************************************************
```

I will apply K=3 in the following steps.

```
## cluster size ave.sil.width
## 1 1 43 0.46
## 2 2 66 0.32
## 3 3 31 0.37
```

Number of countries assigned in each cluster.

`## [1] "Liberia" "Romania" "Ireland"`

This prints out one typical country represents each cluster.