Team

Aim

\(A\) - {“Being a student of IT&BA”}

\(B\) - {“Being a future billionaire”}

\(P(A \cap B) = 1\)

As we are BA-students, we decided to dive into the world of billionaires and explore the dependency between billionaires and related to them characteristics.

Preparing data

This dataset provides us with a certain information about the richest people in the world, such as: industry of their occupation, titles in the companies they work, basic characteristics of the countries, where they live, etc. In our research we will focus on such data:

  • Age

  • Countries, where billionaires live

  • GDP of those countries

library(tidytext)
library(readr)
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(ggplot2)
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(plyr)
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
## 
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
library(fitdistrplus)
## Warning: package 'fitdistrplus' was built under R version 4.3.2
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
## Loading required package: survival
## 
## Attaching package: 'survival'
## The following object is masked from 'package:caret':
## 
##     cluster
require(BSDA)
## Loading required package: BSDA
## Warning: package 'BSDA' was built under R version 4.3.2
## 
## Attaching package: 'BSDA'
## The following object is masked from 'package:datasets':
## 
##     Orange
library(BSDA)
require(EnvStats)   
## Loading required package: EnvStats
## Warning: package 'EnvStats' was built under R version 4.3.2
## Registered S3 method overwritten by 'EnvStats':
##   method         from
##   print.estimate lava
## 
## Attaching package: 'EnvStats'
## The following object is masked from 'package:MASS':
## 
##     boxcox
## The following objects are masked from 'package:stats':
## 
##     predict, predict.lm
library(EnvStats)
data <- read.csv("Billionaires Statistics Dataset.csv")
rows_to_remove <- c()

for (i in 1:nrow(data)) {
  if (is.na(data[i, "age"]) || is.na(data[i, "population_country"])) {
    rows_to_remove <- c(rows_to_remove, i)
  }
}

data_clean <- data[-rows_to_remove, ]

First hypothesis

Age data

billionaires_age <- data_clean$age
length(billionaires_age)
## [1] 2427

We selected age data from a general dataset. It will be our sample of 2427 values that we will analyze.

Analysis

summary_statistics <- summary(billionaires_age)

sample_mean <- mean(billionaires_age)
sample_deviation <- sd(billionaires_age)

summary_statistics
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   18.00   56.00   65.00   64.93   74.00  101.00
sample_mean
## [1] 64.92501
sample_deviation
## [1] 13.09821
  • Mean: The average age is approximately 65.14 years.
  • Standard Deviation: The age data has a standard deviation of approximately 13.1 years, indicating the spread of ages around the mean.
  • Minimum Age: The youngest age in the dataset is 18 years.
  • 25th Percentile: 25% of the billionaires are 56 years old or younger.
  • Median: The median age is 65 years, meaning that half of the billionaires are younger than 65 and half are older.
  • 75th Percentile: 75% of the billionaires are 74 years old or younger.
  • Maximum Age: The oldest age in the dataset is 101 years.

c.d.f. vs empirical c.d.f.

x <- seq(min(billionaires_age), max(billionaires_age), length.out = 100)
empirical_cdf <- ecdf(billionaires_age)
theoretical_cdf <- pnorm(x, mean = sample_mean, sd = sample_deviation)

plot(empirical_cdf, main = "Empirical vs Theoretical CDF", xlab = "Age", ylab = "CDF", col = "blue")
lines(x, theoretical_cdf, col = "red")
legend("bottomright", legend = c("Empirical CDF", "Theoretical CDF"), col = c("blue", "red"), lty = 1)

As we may see, empirical cdf of the age data is pretty close to cdf of Normal distribution with \(\mu\) = sample mean and \(\sigma^2\) = sample variance. This led us to idea that the distribution of the data is normal with corresponding parameters.

Let’s continue our analysis!

p.d.f. vs empirical p.d.f.

x <- seq(min(data_clean$age, na.rm = TRUE), max(data_clean$age, na.rm = TRUE), length.out = 100)

hist(data_clean$age, freq = FALSE, col = "pink", main = "Normal Distribution Overlaid on Age Data", xlab = "Age", ylab = "Density")

lines(density(data_clean$age, na.rm = TRUE), col = 'darkred', lwd = 3)

lines(x, dnorm(x, mean = sample_mean, sd = sample_deviation), col = 'blue', lwd = 3)

df <- data.frame(age = billionaires_age)
mean_age <- mean(df$age, na.rm = TRUE) 
sd_age <- sd(df$age, na.rm = TRUE) 
p <- ggplot(df, aes(x = age)) +   geom_density(fill = "pink", alpha = 0.5) +   labs(title = "Density of Billionaires' Ages", x = "Age", y = "Density") +   theme_minimal()
p <- p + stat_function(fun = dnorm, args = list(mean = mean_age, sd = sd_age), geom = "area", fill = "blue", alpha = 0.3)
p + stat_function(fun = dnorm, args = list(mean = mean_age, sd = sd_age), geom = "line", color = "black", size = 1)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Skewness

sk <- skewness(billionaires_age)
sk
## [1] -0.02471791

We got negative skewness. That means that the distribution of age data is left-skewed. Since the skewness is close to zero, it indicates that the data’s distribution is quite symmetrical.

Kurtosis

k <- kurtosis(billionaires_age)
k
## [1] -0.2777582

Kurtosis of standard normal distribution is equal to 0 (if we substract 3). We got kurtosis that is less than 0. That means that distribution of our data has ‘flatter peak’. The data is more evenly distributed across the range, with fewer values around the mean compared to a normal distribution.

Hypothesis Testing

\(H_0\): Distribution of age data is Normal.
\(H_1\): Distribution of age data is not Normal.

For testing distribution of our sample we are going to use Kolmogorov’s Goodness-of-fit test.

Kolmogorov’s Goodness-of-fit test.

\(X_1,…,X_n\) - independent identically distributed random variables from unknown distribution \(F\).

For a given hypothetical distribution \(F_0\) we want to test \[H_0:F=F_0\,\,\,\, vs \,\,\,\,H_1:F≠F_0\]

By LLN, the sample c.d.f. \(\hat F_X(t)\) is close to \(F_0(t)\).

Thus under \(H_0\) the d-statistics: \[ d = sup_{t\in \mathbb{R}}|\hat F_X(t) - F_0(t)|\] should take small values. 

Under \(H_1\), \(d\) assumes larger values. This is the Kolmogorov’s goodness-of-fit test with rejection region 
\[ \mathcal{C}_\alpha := \{ \mathbf{x} \in \mathbb{R}^n \mid d \geq d^{(n)}_{1-\alpha} \} \]

Let’s test our hypothesis!

ks_result <- ks.test(billionaires_age, 'pnorm', mean = sample_mean, sd = sample_deviation)
## Warning in ks.test.default(billionaires_age, "pnorm", mean = sample_mean, :
## ties should not be present for the Kolmogorov-Smirnov test
print(ks_result)
## 
##  Asymptotic one-sample Kolmogorov-Smirnov test
## 
## data:  billionaires_age
## D = 0.043742, p-value = 0.0001852
## alternative hypothesis: two-sided

By using this test, we got p-value = 0,004479. It is even smaller than 0,01. That means that we are going to reject \(H_0\) .

Cullen and Frey graph

We also want to see if our data fits some other distribution. That’s why we are going to use the Cullen and Frey graph.

The Cullen and Frey graph is a graphical tool used to assess the skewness and kurtosis of data for the purpose of identifying a theoretical distribution that may fit the data well. The graph plots the square of skewness against kurtosis and overlays regions that correspond to different types of distributions.

Here’s a brief explanation of how the descdist function, which generates the Cullen and Frey graph, typically works:

The function computes the skewness and kurtosis of the provided dataset. It then plots the square of the skewness on the x-axis and the kurtosis on the y-axis. The graph includes lines or areas that represent the range of values for skewness and kurtosis for different theoretical distributions, such as normal, uniform, exponential, lognormal, etc… A marker indicates the skewness and kurtosis of the actual data on the graph.

descdist(billionaires_age)

## summary statistics
## ------
## min:  18   max:  101 
## median:  65 
## mean:  64.92501 
## estimated sd:  13.09821 
## estimated skewness:  -0.02471791 
## estimated kurtosis:  2.722242

From the Cullen and Frey graph that we got after our analysis, we can make such conclusions:

The observation marker lies in the region that corresponds to the normal distribution, which is indicated by a skewness close to zero and kurtosis close to three. This placement suggests that the data may be normally distributed or close normal distribution. The fact that the observation marker is not exactly on the line for the normal distribution but slightly above suggests that the data might have a slightly lower kurtosis than the normal distribution, implying a more peaked distribution with potentially heavier tails.

Conclusion

So, based on our test and analysis, we may say that our data is close to normal distribution but it isn’t exactly normal one. In fact, it doesn’t fit to any known distribution.

Second hypothesis

Intro

There is a rumor that richer people live in countries with higher GDP. We decided to explore whether this is true or not, so we formulated the following hypotheses:

\(H_0\): There is no dependency between the number of billionaires and GDP per capita of the country where they live.
\(H_1\): There is dependency between the number of billionaires and GDP per capita of the country where they live.

Preparing GDP and other data

gdp_per_capita_df <- data_clean %>%
  mutate(gdp_country = as.numeric(gsub("[^0-9.]", "", gdp_country)), 
         population_country = as.numeric(gsub("[^0-9.]", "", population_country)), 
         GDP_per_Capita = gdp_country / population_country) %>%
  dplyr::select(country, GDP_per_Capita) %>%
  distinct(country, .keep_all = TRUE)

country_counts <- table(data_clean$country)
country_mentions_df <- as.data.frame(country_counts)
names(country_mentions_df) <- c("Country", "Quantity")

combined_df <- left_join(country_mentions_df, gdp_per_capita_df, by = c("Country" = "country"))

combined_df
##                 Country Quantity GDP_per_Capita
## 1               Algeria        1       3948.343
## 2               Andorra        1      40886.391
## 3             Argentina        3      10006.149
## 4               Armenia        1       4622.733
## 5             Australia       43      54049.829
## 6               Austria       11      50277.275
## 7               Bahrain        1      25688.046
## 8               Belgium        3      46116.699
## 9                Brazil       43       8655.265
## 10             Cambodia        1       1643.121
## 11               Canada       40      46940.596
## 12                Chile        6      14896.454
## 13                China      504      14244.678
## 14             Colombia        1       6432.388
## 15               Cyprus        5      20494.878
## 16       Czech Republic        7      23101.778
## 17              Denmark        7      59822.093
## 18                Egypt        4       3020.031
## 19              Finland        7      48685.854
## 20               France       34      40493.929
## 21              Georgia        1       4769.187
## 22              Germany       88      46258.878
## 23               Greece        3      19582.536
## 24              Hungary        3      16475.742
## 25                India      157       1910.836
## 26            Indonesia       25       4142.023
## 27               Israel       26      43641.398
## 28                Italy       55      33189.566
## 29                Japan       37      40259.112
## 30           Kazakhstan        7       9731.145
## 31               Latvia        1      17836.365
## 32              Lebanon        2       7784.317
## 33        Liechtenstein        1     172357.472
## 34           Luxembourg        1     110172.373
## 35             Malaysia       11      11239.782
## 36               Mexico       13       9985.291
## 37               Monaco       17     184396.987
## 38              Morocco        2       3216.567
## 39                Nepal        1       1071.051
## 40          Netherlands       10      52447.831
## 41          New Zealand        2      42745.046
## 42              Nigeria        3       2229.859
## 43               Norway        9      75419.635
## 44                 Oman        1      14617.409
## 45                 Peru        2       6977.696
## 46          Philippines       14       3485.084
## 47               Poland        5      15595.227
## 48             Portugal        1      23145.041
## 49                Qatar        2      64781.733
## 50              Romania        3      12919.530
## 51               Russia       79      11774.156
## 52            Singapore       46      65233.282
## 53             Slovakia        2      19329.097
## 54         South Africa        5       6001.401
## 55          South Korea       29      39238.743
## 56                Spain       24      29613.671
## 57               Sweden       26      51610.066
## 58          Switzerland       75      81993.727
## 59             Tanzania        1       1089.157
## 60             Thailand       25       7808.193
## 61               Turkey       25       9042.493
## 62              Ukraine        6       3464.696
## 63 United Arab Emirates       16      43103.323
## 64       United Kingdom       80      42300.267
## 65        United States      754      65280.682
## 66              Uruguay        1      16190.127
## 67           Uzbekistan        1       1724.841
## 68              Vietnam        6       2715.276

Analysis

combined_df <- combined_df %>%
  arrange(desc(Quantity))

ggplot(combined_df, aes(x = reorder(Country, -Quantity))) +
  geom_bar(aes(y = Quantity), stat = "identity", fill = "#1f77b4") + 
  geom_line(aes(y = GDP_per_Capita / 1000, group = 1), color = "#d62728", size = 1) +

  scale_y_continuous(
    name = "Quantity",
    sec.axis = sec_axis(~ . * 1000, name = "GDP per Capita (in thousands)")
  ) +

  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5, size = 10, color = "grey20"),
        axis.text.y = element_text(size = 10, color = "grey20"),
        axis.title = element_text(size = 12, face = "bold"),
        plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
        legend.position = "bottom",
        panel.background = element_rect(fill = "white"),
        panel.grid.major = element_line(color = "grey80"),
        panel.grid.minor = element_blank(),
        plot.margin = margin(10, 10, 10, 10)) +

  xlab("Country") +
  ggtitle("Quantity and GDP per Capita per Country")

On this plot we can see quantity of billionaires in a certain country in descending order and GDP per capita in this country. We did it in order to visually observe if there is any dependency between them. From this plot we cannot claim that these 2 factors are dependent, but only visual representation of the data is not enough for us to accept or reject our null hypothesis, so we proceed our testing.

Testing using Chi-squared test for independence

The chi-square statistic is a measure of the difference between the observed frequencies and the expected frequencies. It’s calculated using the formula: \[ \chi^2 = \sum_{i,\, j} \frac{(O_{ij} - E_{ij})^2}{E_{ij}}, \] A large value of \(\chi^2\) will suggest a big difference between the observed and expected frequencies, indicating that ‘Quantity’ and ‘GDP per Capita’ may not be independent.

table_data <- table(combined_df$Quantity, combined_df$GDP_per_Capita)
test <- chisq.test(table_data)
## Warning in chisq.test(table_data): Chi-squared approximation may be incorrect
test
## 
##  Pearson's Chi-squared test
## 
## data:  table_data
## X-squared = 2040, df = 2010, p-value = 0.3151

We got p-value = 0.3151. It is pretty large value comparing to standard 0.05 or even 0.1. So according to this test we can not reject \(H_0\).

Constructing linear regression

Also we want to be more precise and test our hypothesis using linear regression.

Let \(X\) be the independent r.v. that represents GDP per capita at each country and \(Y\) be r.v. that represents number of billionaires at each country

x <- combined_df$GDP_per_Capita
y <- combined_df$Quantity

billionaires.lm <- lm(y~x)
plot(x,y,pch = 16,xlim=c(0,200000), col = "blue")
abline(billionaires.lm, col = "red")

summary(billionaires.lm)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -73.45 -30.16 -26.63  -8.02 708.80 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.736e+01  1.773e+01   1.543    0.128
## x           2.732e-04  3.827e-04   0.714    0.478
## 
## Residual standard error: 110.1 on 66 degrees of freedom
## Multiple R-squared:  0.007665,   Adjusted R-squared:  -0.00737 
## F-statistic: 0.5098 on 1 and 66 DF,  p-value: 0.4777

Estimate of slope is quite close to zero. Also p-value of t-test that b = 0 (where b - slope) is pretty large comparing to 0.05 . It means that we are more likely not to reject that b = 0.

We know that if \(r^2\) is close to 1 we reject that b = 0. But we got the opposite output (\(r^2\) is pretty far from 0). That means that we are more likely not to reject.

All in all, based on this, we may say that there is extremely small dependency between \(Y\) and \(X\). So we are more likely not to reject our \(H_0\).

Conclusion

We got pretty similar results from the chi-squared test and linear regression model. Both of them tells us that we are likely not to reject our null hypothesis. So we can claim that there is no dependency between the GDP of the country and the quantity of billionaires in the country.

General conclusion

From our tests we got that the age data probably has its unique distribution. Also we got that probably there is no dependency between number of billionaires and the country where they live. Therefore, we believe we can become billionaires anywhere and hope to earn our first billion as soon as possible:)