In this report, I’ll have a look at whether countries whose governments adopt open policies with respect to data sharing are the same countries that score highly on the world happiness index. Here I hypothesize that the two are positively correlated.The two datasets I’m going to use are: 1.Open Knowledge International’s 2015 Global Open Data Index 2.Sustainable Development Solutions Network’s World Happiness Report from 2016
###About the dataset
The Global Open Data Index is an annual effort to measure the state of open government data around the world. The crowdsourced survey is designed to assess the openness of specific government datasets according to the Open Definition.
The Global Open Data Index is not an official government representation of the open data offering in each country, but an independent assessment from a citizen’s perspective. It is a civil society audit of open data, and it enables government progress on open data by giving them a measurement tool and a baseline for discussion and analysis of the open data ecosystem in their country and internationally from a key user’s perspective.
The Global Open Data Index plays a powerful role in sustaining momentum for open data around the world and in convening civil society networks to use and collaborate around this data. Governments and open data practitioners can review the index results to see how accessible the open data they publish actually appears to their citizens, see where improvements are necessary to make open data truly open and useful, and track their progress year to year.
According to the common open data assessment framework there are four different ways to evaluate data openess — context, data, use and impact. The Global Open Data Index is intentionally narrowly focused on the data aspect, hence, limiting its inquiry only to the datasets publication by national governments. It does not look at the broader societal context, seek to assess use or impact in a systematic way, or evaluate the quality of the data. This narrow focus of data publication enables it to provide a standardized, robust, comparable assessment of the state of the publication of key data by governments around the world.
The World Happiness Report is a landmark survey of the state of global happiness. The World Happiness Report 2016 Update, which ranks 156 countries by their happiness levels, was released in Rome in advance of UN World Happiness Day, March 20th. The reports review the state of happiness in the world today and show how the new science of happiness explains personal and national variations in happiness. They reflect a new worldwide demand for more attention to happiness as a criteria for government policy.
So, the code below reads in the data sources and joins them together by country name. There are probably some country names that don’t exactly match and I tweak the code to .
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readxl)
# Read in data files from `open-data` and `world-happiness` datasets
open_data <- read.csv("countries.csv", stringsAsFactors=F)
happiness <- read.csv("2015.csv", stringsAsFactors=F)
# Rename from "Country Name" to just "Country" so it's easier to join
colnames(open_data)[2] <- "Country"
# Join the two dataset files on "Country"
open_data_happiness <- open_data %>%
left_join(happiness, by = "Country") %>%
mutate(Country = factor(Country)) %>%
# Keep only columns I plan to use
select(Country, Region, X2015.Score, Happiness.Score, Economy..GDP.per.Capita.,
Family, Health..Life.Expectancy., Freedom, Trust..Government.Corruption.,
Generosity, Dystopia.Residual)
# Give the columns nicer names now that our data is in one dataframe
colnames(open_data_happiness) <- c("Country", "Region", "Openness", "Happiness", "GDP", "Family", "Health", "Freedom", "Trust", "Generosity", "DystopiaResidual")
Now that I have the data roughly how I want it, let’s have a quick peek. I really like this package called formattable for presenting information in dataframes. Here Iuse it to look at the characteristics of the top 10 countries with the highest scores for their open data sharing policies:
library(formattable)
open_data_happiness %>%
# Which countries are the most open?
arrange(desc(Openness)) %>%
# Round our numeric variables to two decimal places
mutate_each(funs(round(., 2)), -c(Country, Region, Openness)) %>%
head(10) %>%
formattable(list(
Openness = color_bar("yellow"),
Happiness = color_bar("lightgreen"),
GDP = color_bar("deepskyblue"),
Family = color_bar("deepskyblue"),
Health = color_bar("deepskyblue"),
Freedom = color_bar("deepskyblue"),
Trust = color_bar("deepskyblue"),
Generosity = color_bar("deepskyblue"),
DystopiaResidual = color_bar("deepskyblue")
), align = "l")
## Warning: `funs()` was deprecated in dplyr 0.8.0.
## ℹ Please use a list of either functions or lambdas:
##
## # Simple named list: list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`: tibble::lst(mean, median)
##
## # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## Warning: `mutate_each_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `across()` instead.
## ℹ The deprecated feature was likely used in the dplyr package.
## Please report the issue at <]8;;https://github.com/tidyverse/dplyr/issueshttps://github.com/tidyverse/dplyr/issues]8;;>.
| Country | Region | Openness | Happiness | GDP | Family | Health | Freedom | Trust | Generosity | DystopiaResidual |
|---|---|---|---|---|---|---|---|---|---|---|
| Taiwan | Eastern Asia | 78 | 6.30 | 1.29 | 1.08 | 0.88 | 0.40 | 0.08 | 0.25 | 2.32 |
| United Kingdom | Western Europe | 76 | 6.87 | 1.27 | 1.29 | 0.91 | 0.60 | 0.32 | 0.52 | 1.97 |
| Denmark | Western Europe | 70 | 7.53 | 1.33 | 1.36 | 0.87 | 0.65 | 0.48 | 0.34 | 2.49 |
| Colombia | Latin America and Caribbean | 68 | 6.48 | 0.92 | 1.24 | 0.69 | 0.53 | 0.05 | 0.18 | 2.86 |
| Finland | Western Europe | 67 | 7.41 | 1.29 | 1.32 | 0.89 | 0.64 | 0.41 | 0.23 | 2.62 |
| Australia | Australia and New Zealand | 67 | 7.28 | 1.33 | 1.31 | 0.93 | 0.65 | 0.36 | 0.44 | 2.27 |
| Uruguay | Latin America and Caribbean | 66 | 6.48 | 1.06 | 1.21 | 0.81 | 0.60 | 0.25 | 0.23 | 2.32 |
| United States | North America | 64 | 7.12 | 1.39 | 1.25 | 0.86 | 0.55 | 0.16 | 0.40 | 2.51 |
| Netherlands | Western Europe | 64 | 7.38 | 1.33 | 1.28 | 0.89 | 0.62 | 0.32 | 0.48 | 2.47 |
| Norway | Western Europe | 63 | 7.52 | 1.46 | 1.33 | 0.89 | 0.67 | 0.37 | 0.35 | 2.47 |
## `mutate_each()` is deprecated.
## Use `mutate_all()`, `mutate_at()` or `mutate_if()` instead.
## To map `funs` over a selection of variables, use `mutate_at()`
The top ten most “open” countries aren’t localized to one or two regions but instead span the globe which is interesting. I was interested to see Colombia in fourth position; you can see the country scores lower relative to other top countries on some measures including “Trust” (Government Corruption). I investigated a bit and found this report from the Open Data Barometer which does in fact call out Colombia as a regional leader in its 2016 analysis of open data readiness, implementation, and impact among Latin American countries.
I also suspect that the United States will get kicked down a few notches in coming years. Anyways, onto answering the main question:
Are open countries happy countries?
Now we’re ready to answer our question of whether countries that index highly for data openness are also home to happy people. Let’s find out, The plot below will show the openness score and happiness score for each country as measured in 2015.
library(ggplot2)
library(ggthemes)
library(viridis)
## Loading required package: viridisLite
ggplot(open_data_happiness,
aes(x = Openness,
y = Happiness)) +
geom_point(aes(colour = Region),
size = 2) +
geom_smooth(method="lm") +
labs(x = "Openness Score",
y = "Happiness Score",
title = "Are open data friendly countries happy countries?",
subtitle = "Data openness and happiness by country in 2015") +
scale_color_viridis(discrete = T) +
theme_minimal() +
theme(text = element_text(size=16))
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 31 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 31 rows containing missing values (`geom_point()`).
Overall, it looks like the answer is ‘Yes’. One thing that stands out from this plot is that Western European countries cluster above the linear fit line on “Happiness” while Sub-Saharan African countries are grouped together at the bottom left, falling lowest on the “Happiness” scale.
What other measures are correlated with “Openness”? Finally, what if we want to look at correlations between all of our variables? While we’re exploring these datasets, let’s spend some time creating a quick correlation matrix or “heatmap” for some additional insight.
library(corrplot)
## corrplot 0.92 loaded
# Subset the data to include only the variables we want to look at
open_data_corr <- open_data_happiness %>%
select(Openness, Happiness, GDP, Family, Health,
Freedom, Trust, Generosity, DystopiaResidual) %>%
mutate(Openness = as.numeric(Openness))
od_corr <- cor(open_data_corr, use = "complete", method = "pearson")
corrplot(od_corr)
The one thing I want to highlight in this plot is the positive
correlation between a country’s happiness and its “Dystopia Residual”.
This seems confusing at a glance! From the dataset’s description,I learn
that the “Dystopia Residual” is a country’s difference from “a
hypothetical country that has values equal to the world’s lowest
national averages for each of the six factors”.