- Business & Data Research
- Posts
- World Happiness Report- GDP -AB Testing
World Happiness Report- GDP -AB Testing
AB Testing, Chi-squared t-test, Statistical Measure, R Program
GDP Economy Dataset - World Happiness Data
The World Happiness Report is a landmark survey of the state of global happiness. The first report was published in 2012, the second in 2013, the third in 2015, and the fourth in the 2016 Update. The World Happiness 2017, which ranks 155 countries by their happiness levels, was released at the United Nations at an event celebrating International Day of Happiness on March 20th. The report continues to gain global recognition as governments, organizations and civil society increasingly use happiness indicators to inform their policy-making decisions. Leading experts across fields – economics, psychology, survey analysis, national statistics, health, public policy and more – describe how measurements of well-being can be used effectively to assess the progress of nations. 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.
Step1: Install Required Packages :
library(dplyr)
library(ggplot2)
library(tidyr)
library(plotly)
library(tidyverse)
worldhappiness <- read.csv("/Users/Sample Datasets Kaggle/WorldHappiness2019/2019.csv",
header = TRUE)
head(worldhappiness)
> colnames(worldhappiness)
[1] "Overall.rank" "Country.or.region"
[3] "Score" "GDP.per.capita"
[5] "Social.support" "Healthy.life.expectancy"
[7] "Freedom.to.make.life.choices" "Generosity"
[9] "Perceptions.of.corruption" "GDP_group" Step 2: Perform Exploratory Data Analysis in Preparation and Cleansing
str(worldhappiness)
'data.frame': 156 obs. of 10 variables:
$ Overall.rank : int 1 2 3 4 5 6 7 8 9 10 ...
$ Country.or.region : chr "Finland" "Denmark" "Norway" "Iceland" ...
$ Score : num 7.77 7.6 7.55 7.49 7.49 ...
$ GDP.per.capita : num 1.34 1.38 1.49 1.38 1.4 ...
$ Social.support : num 1.59 1.57 1.58 1.62 1.52 ...
$ Healthy.life.expectancy : num 0.986 0.996 1.028 1.026 0.999 ...
$ Freedom.to.make.life.choices: num 0.596 0.592 0.603 0.591 0.557 0.572 0.574 0.585 0.584 0.532 ...
$ Generosity : num 0.153 0.252 0.271 0.354 0.322 0.263 0.267 0.33 0.285 0.244 ...
$ Perceptions.of.corruption : num 0.393 0.41 0.341 0.118 0.298 0.343 0.373 0.38 0.308 0.226 ...
$ GDP_group : chr "High GDP" "High GDP" "High GDP" "High GDP" ...
> names(worldhappiness)
[1] "Overall.rank" "Country.or.region"
[3] "Score" "GDP.per.capita"
[5] "Social.support" "Healthy.life.expectancy"
[7] "Freedom.to.make.life.choices" "Generosity"
[9] "Perceptions.of.corruption" "GDP_group"
Step 3: Create AB group based on GDP
# Create A/B groups based on median GDP
median_gdp <- median(worldhappiness$GDP.per.capita, na.rm = TRUE)
print(median_gdp)
[1] 0.96
worldhappiness$GDP_group <- ifelse(worldhappiness$GDP.per.capita > median_gdp,
"High GDP", "Low GDP")
Step 4: Check Group Accounts
table(worldhappiness$GDP_group)
High GDP Low GDP
77 79 Step 5: Compare Mean Happiness Score
aggregate(Score ~ GDP_group, data = worldhappiness, FUN = mean)
GDP_group Score
1 High GDP 6.161468
2 Low GDP 4.671823
> Step 6: Running two sample t-test
ab_test <- t.test(Score ~ GDP_group, data = worldhappiness)
print(ab_test)
Welch Two Sample t-test
data: Score by GDP_group
t = 11.231, df = 153.27, p-value < 2.2e-16
alternative hypothesis: true difference in means between group High GDP and group Low GDP is not equal to 0
95 percent confidence interval:
1.227616 1.751673
sample estimates:
mean in group High GDP mean in group Low GDP
6.161468 4.671823 Step 7: Create a box plot of happiness score by GDP Score
ggplot(worldhappiness, aes(x = GDP_group, y = Score)) +
geom_boxplot(fill = c("lightblue", "lightgreen")) +
labs(title = "Happiness Score by GDP Group",
x = "GDP Group",
y = "Happiness Score") +
theme_minimal()
Step 8: Create a Density Plot
ggplot(worldhappiness, aes(x = Score, fill = GDP_group)) +
geom_density(alpha = 0.5) +
labs(title = "Density Plot of Happiness Scores by GDP Group",
x = "Happiness Score",
y = "Density") +
theme_minimal() +
scale_fill_manual(values = c("lightblue", "lightgreen"))

Conclusion: Based on the 2019 World Happiness dataset, countries with higher GDP per capita clearly performed better in terms of happiness. The difference is visible in the boxplot, confirmed by the density plot, and supported by statistical testing. Higher‑GDP countries consistently show higher median scores, wider positive distribution, and stronger overall well‑being indicators.