library(tidyverse)## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(skimr)
library(knitr)
library(ggthemes)## Warning: package 'ggthemes' was built under R version 4.2.2
library(readr)
library(dplyr)
library(lubridate)## Warning: package 'lubridate' was built under R version 4.2.2
## Loading required package: timechange
## Warning: package 'timechange' was built under R version 4.2.2
##
## Attaching package: 'lubridate'
##
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(stringr)Importing and settings things up.
ESS10 <- read_csv("ESS10.csv")## Rows: 18060 Columns: 513
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): name, proddate, cntry, cntbrthd, lnghom1, lnghom2, fbrncntc, mbr...
## dbl (488): essround, edition, idno, pweight, dweight, nwspol, netusoft, net...
## lgl (1): vteubcmb
## dttm (15): inwds, ainws, ainwe, binwe, cinwe, dinwe, finwe, ginwe, hinwe, i...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
country_name <- read_csv("country_name.csv")## Rows: 249 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Name, Code
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# By joining the "country_name"'s data set to the data set of interest (ESS10), our data set will have the names of each country for readability's sake as opposed to just having the two digit country codes.
ESS10full <- full_join(ESS10,
country_name,
by = c("cntry" = "Code"))Data Dictionary
Listing variables, descriptions, and variable types. First creating the data frame containing the data dictionary
# First creating a subsetted data set with only our variables of interest.
ESS10interest <- ESS10full %>%
select(happy, sclmeet, imprich, rlgblg, gndr, edulvlb, yrbrn, inwds, Name)
# Creating data dictionary.
dataDictionary <- tibble(Variable = colnames(ESS10interest),
Description = c("How happy would you say you are (0 = extremely unhappy 10 = extremely happy)? ",
"How often the participant meets with friends (1 = never 7 = everyday)?",
"How important is it to be rich (1 = very important 6 = not at all important)?",
"Do you belong to a particular religion (1 = yes 2 = no)?",
"What is your gender (1 = male 2 = female)?",
"Highest level of education",
"Year of birth",
"Date of taking the assessment",
"Name of country"),
Type = map_chr(ESS10interest, .f = function(x){typeof(x)[1]}),
Class = map_chr(ESS10interest, .f = function(x){class(x)[1]}))Here, displaying the actual dictionary.
# Printing nicely.
flextable::flextable(dataDictionary, cwidth = 2)Variable | Description | Type | Class |
|---|---|---|---|
happy | How happy would you say you are (0 = extremely unhappy 10 = extremely happy)? | double | numeric |
sclmeet | How often the participant meets with friends (1 = never 7 = everyday)? | double | numeric |
imprich | How important is it to be rich (1 = very important 6 = not at all important)? | double | numeric |
rlgblg | Do you belong to a particular religion (1 = yes 2 = no)? | double | numeric |
gndr | What is your gender (1 = male 2 = female)? | double | numeric |
edulvlb | Highest level of education | double | numeric |
yrbrn | Year of birth | double | numeric |
inwds | Date of taking the assessment | double | POSIXct |
Name | Name of country | character | character |
Above is the data dictionary for the variables of interest for this data set. It’s important to note that not all of the variables are quantitative variables despite their classification as numeric. Religious belonging, gender, and highest level of education were all categorical variables that used numerical inputs as representative of certain factors/categories.
Exploring the data set for missingness and general information.
First, I’ve utilized the glimpse funciton to gather some general information.
glimpse(ESS10interest)## Rows: 18,299
## Columns: 9
## $ happy <dbl> 6, 9, 5, 3, 3, 5, 7, 5, 6, 5, 7, 7, 7, 4, 2, 7, 7, 6, 5, 5, 7,…
## $ sclmeet <dbl> 6, 7, 4, 4, 4, 6, 7, 3, 6, 2, 6, 1, 7, 2, 2, 4, 6, 6, 6, 4, 6,…
## $ imprich <dbl> 2, 3, 4, 5, 3, 5, 4, 2, 4, 6, 5, 5, 2, 4, 6, 3, 4, 4, 3, 5, 3,…
## $ rlgblg <dbl> 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1,…
## $ gndr <dbl> 2, 1, 2, 2, 1, 2, 1, 1, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1,…
## $ edulvlb <dbl> 323, 620, 720, 313, 720, 323, 313, 323, 323, 0, 323, 313, 610,…
## $ yrbrn <dbl> 1945, 1978, 1971, 1970, 1951, 1990, 1981, 1973, 1950, 1950, 19…
## $ inwds <dttm> 2021-07-24 12:17:18, 2021-08-28 07:30:52, 2021-07-15 19:59:32…
## $ Name <chr> "Bulgaria", "Bulgaria", "Bulgaria", "Bulgaria", "Bulgaria", "B…
I then use the skim function to look specifically at information such as missingness.
skim(ESS10interest)| Name | ESS10interest |
| Number of rows | 18299 |
| Number of columns | 9 |
| _______________________ | |
| Column type frequency: | |
| character | 1 |
| numeric | 7 |
| POSIXct | 1 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| Name | 0 | 1 | 4 | 44 | 0 | 249 | 0 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| happy | 239 | 0.99 | 7.34 | 4.48 | 0 | 6 | 8 | 9 | 99 | ▇▁▁▁▁ |
| sclmeet | 239 | 0.99 | 5.00 | 6.24 | 1 | 3 | 5 | 6 | 99 | ▇▁▁▁▁ |
| imprich | 239 | 0.99 | 4.07 | 1.46 | 1 | 3 | 4 | 5 | 9 | ▃▇▆▃▁ |
| rlgblg | 239 | 0.99 | 1.49 | 0.78 | 1 | 1 | 1 | 2 | 9 | ▇▁▁▁▁ |
| gndr | 239 | 0.99 | 1.55 | 0.50 | 1 | 1 | 2 | 2 | 2 | ▆▁▁▁▇ |
| edulvlb | 239 | 0.99 | 443.71 | 572.21 | 0 | 313 | 323 | 610 | 9999 | ▇▁▁▁▁ |
| yrbrn | 239 | 0.99 | 2012.11 | 519.12 | 1931 | 1955 | 1970 | 1985 | 9999 | ▇▁▁▁▁ |
Variable type: POSIXct
| skim_variable | n_missing | complete_rate | min | max | median | n_unique |
|---|---|---|---|---|---|---|
| inwds | 239 | 0.99 | 2020-09-18 10:18:44 | 2022-01-13 11:02:25 | 2021-08-18 15:08:21 | 17907 |
Looking at the skim output, there seems to be missingness within all of the variables of interest. Based on a previous skim with little to no missingness, what we observe here is likely due to teh joining of the data set.
Summary Statistics.
Below I’ve produced summary statistics for happiness by countries.
# Here I create summary statistic variables for later use.
happyMeans <- ESS10full %>% group_by(Name) %>%
summarize(happyMu = round(mean(happy, na.rm = T), digits = 2)) %>% filter(!is.nan(happyMu))
happyStandard <- ESS10full %>% group_by(Name) %>%
summarize(happySd = round(sd(happy, na.rm = T), digits = 2)) %>% filter(!is.na(happySd))
happyMedian <- ESS10full %>% group_by(Name) %>%
summarize(happyMed = round(median(happy, na.rm = T), digits = 2)) %>% filter(!is.na(happyMed))
# I combine the summary statistics into tables for later use.
happyPreSummary <- full_join(happyMeans,
happyStandard,
by = c("Name" = "Name"))
happySummary <- full_join(happyPreSummary,
happyMedian,
by = c("Name" = "Name"))
# Here is an organized and neat table for the summary statistics.
happySummary2 <- ESS10full %>%
filter(happy < 11) %>%
group_by(Name) %>%
summarise(Average = mean(happy, na.rm = TRUE),
Median = median(happy, na.rm = TRUE),
Min = min(happy, nan.rm = TRUE),
Max = max(happy, nan.rm = TRUE)) %>%
mutate(across(Average:Max, ~ round(.x, 3))) %>%
arrange(desc(Average)) %>%
rename(Country = Name)
flextable::flextable(happySummary2, cwidth = 1.15)Country | Average | Median | Min | Max |
|---|---|---|---|---|
Finland | 8.156 | 8 | 0 | 10 |
Slovenia | 7.692 | 8 | 0 | 10 |
Croatia | 7.507 | 8 | 0 | 10 |
Estonia | 7.499 | 8 | 0 | 10 |
France | 7.442 | 8 | 0 | 10 |
Lithuania | 7.122 | 8 | 0 | 10 |
Hungary | 7.018 | 7 | 0 | 10 |
Czech Republic | 6.908 | 7 | 0 | 10 |
Slovakia | 6.539 | 7 | 0 | 10 |
Bulgaria | 6.271 | 7 | 0 | 10 |
Similarly, I’ve produced the same summary table for how often people meet with other people within these countries.
# Below the same process is repeated, first creating variables for later use.
meetMeans <- ESS10full %>% group_by(Name) %>%
summarize(meetMu = round(mean(sclmeet, na.rm = T), digits = 2)) %>% filter(!is.nan(meetMu))
meetStandard <- ESS10full %>% group_by(Name) %>%
summarize(meetSd = round(sd(sclmeet, na.rm = T), digits = 2)) %>% filter(!is.na(meetSd))
meetMedian <- ESS10full %>% group_by(Name) %>%
summarize(meetMed = round(median(sclmeet, na.rm = T), digits = 2)) %>% filter(!is.na(meetMed))
# Combining variables into data frames for later use.
meetPreSummary <- full_join(meetMeans,
meetStandard,
by = c("Name" = "Name"))
meetSummary <- full_join(meetPreSummary,
meetMedian,
by = c("Name" = "Name"))
# A neat table display of the summary statistics.
meetSumary2 <- ESS10full %>%
filter(sclmeet < 11) %>%
group_by(Name) %>%
summarise(Average = mean(sclmeet, na.rm = TRUE),
Median = median(sclmeet, na.rm = TRUE),
Min = min(sclmeet, nan.rm = TRUE),
Max = max(sclmeet, nan.rm = TRUE)) %>%
mutate(across(Average:Max, ~ round(.x, 3))) %>%
arrange(desc(Average)) %>%
rename(Country = Name)
flextable::flextable(happySummary2, cwidth = 1.15)Country | Average | Median | Min | Max |
|---|---|---|---|---|
Finland | 8.156 | 8 | 0 | 10 |
Slovenia | 7.692 | 8 | 0 | 10 |
Croatia | 7.507 | 8 | 0 | 10 |
Estonia | 7.499 | 8 | 0 | 10 |
France | 7.442 | 8 | 0 | 10 |
Lithuania | 7.122 | 8 | 0 | 10 |
Hungary | 7.018 | 7 | 0 | 10 |
Czech Republic | 6.908 | 7 | 0 | 10 |
Slovakia | 6.539 | 7 | 0 | 10 |
Bulgaria | 6.271 | 7 | 0 | 10 |
What I’ve done here is I’ve created a cross frequency table between the countries and how many people in each country identify as religious (1), non-religious (2), there was no useful answer (the remaining numbers).
attach(ESS10full)
freqTable <- table(Name, rlgblg)
freqTable## rlgblg
## Name 1 2 7 8 9
## Afghanistan 0 0 0 0 0
## Åland Islands 0 0 0 0 0
## Albania 0 0 0 0 0
## Algeria 0 0 0 0 0
## American Samoa 0 0 0 0 0
## Andorra 0 0 0 0 0
## Angola 0 0 0 0 0
## Anguilla 0 0 0 0 0
## Antarctica 0 0 0 0 0
## Antigua and Barbuda 0 0 0 0 0
## Argentina 0 0 0 0 0
## Armenia 0 0 0 0 0
## Aruba 0 0 0 0 0
## Australia 0 0 0 0 0
## Austria 0 0 0 0 0
## Azerbaijan 0 0 0 0 0
## Bahamas 0 0 0 0 0
## Bahrain 0 0 0 0 0
## Bangladesh 0 0 0 0 0
## Barbados 0 0 0 0 0
## Belarus 0 0 0 0 0
## Belgium 0 0 0 0 0
## Belize 0 0 0 0 0
## Benin 0 0 0 0 0
## Bermuda 0 0 0 0 0
## Bhutan 0 0 0 0 0
## Bolivia, Plurinational State of 0 0 0 0 0
## Bonaire, Sint Eustatius and Saba 0 0 0 0 0
## Bosnia and Herzegovina 0 0 0 0 0
## Botswana 0 0 0 0 0
## Bouvet Island 0 0 0 0 0
## Brazil 0 0 0 0 0
## British Indian Ocean Territory 0 0 0 0 0
## Brunei Darussalam 0 0 0 0 0
## Bulgaria 2261 435 0 22 0
## Burkina Faso 0 0 0 0 0
## Burundi 0 0 0 0 0
## Cambodia 0 0 0 0 0
## Cameroon 0 0 0 0 0
## Canada 0 0 0 0 0
## Cape Verde 0 0 0 0 0
## Cayman Islands 0 0 0 0 0
## Central African Republic 0 0 0 0 0
## Chad 0 0 0 0 0
## Chile 0 0 0 0 0
## China 0 0 0 0 0
## Christmas Island 0 0 0 0 0
## Cocos (Keeling) Islands 0 0 0 0 0
## Colombia 0 0 0 0 0
## Comoros 0 0 0 0 0
## Congo 0 0 0 0 0
## Congo, the Democratic Republic of the 0 0 0 0 0
## Cook Islands 0 0 0 0 0
## Costa Rica 0 0 0 0 0
## Côte d'Ivoire 0 0 0 0 0
## Croatia 1143 442 5 2 0
## Cuba 0 0 0 0 0
## Curaçao 0 0 0 0 0
## Cyprus 0 0 0 0 0
## Czech Republic 440 2009 19 8 0
## Denmark 0 0 0 0 0
## Djibouti 0 0 0 0 0
## Dominica 0 0 0 0 0
## Dominican Republic 0 0 0 0 0
## Ecuador 0 0 0 0 0
## Egypt 0 0 0 0 0
## El Salvador 0 0 0 0 0
## Equatorial Guinea 0 0 0 0 0
## Eritrea 0 0 0 0 0
## Estonia 395 1143 3 1 0
## Ethiopia 0 0 0 0 0
## Falkland Islands (Malvinas) 0 0 0 0 0
## Faroe Islands 0 0 0 0 0
## Fiji 0 0 0 0 0
## Finland 780 795 0 2 0
## France 994 959 17 7 0
## French Guiana 0 0 0 0 0
## French Polynesia 0 0 0 0 0
## French Southern Territories 0 0 0 0 0
## Gabon 0 0 0 0 0
## Gambia 0 0 0 0 0
## Georgia 0 0 0 0 0
## Germany 0 0 0 0 0
## Ghana 0 0 0 0 0
## Gibraltar 0 0 0 0 0
## Greece 0 0 0 0 0
## Greenland 0 0 0 0 0
## Grenada 0 0 0 0 0
## Guadeloupe 0 0 0 0 0
## Guam 0 0 0 0 0
## Guatemala 0 0 0 0 0
## Guernsey 0 0 0 0 0
## Guinea 0 0 0 0 0
## Guinea-Bissau 0 0 0 0 0
## Guyana 0 0 0 0 0
## Haiti 0 0 0 0 0
## Heard Island and McDonald Islands 0 0 0 0 0
## Holy See (Vatican City State) 0 0 0 0 0
## Honduras 0 0 0 0 0
## Hong Kong 0 0 0 0 0
## Hungary 1126 690 14 19 0
## Iceland 0 0 0 0 0
## India 0 0 0 0 0
## Indonesia 0 0 0 0 0
## Iran, Islamic Republic of 0 0 0 0 0
## Iraq 0 0 0 0 0
## Ireland 0 0 0 0 0
## Isle of Man 0 0 0 0 0
## Israel 0 0 0 0 0
## Italy 0 0 0 0 0
## Jamaica 0 0 0 0 0
## Japan 0 0 0 0 0
## Jersey 0 0 0 0 0
## Jordan 0 0 0 0 0
## Kazakhstan 0 0 0 0 0
## Kenya 0 0 0 0 0
## Kiribati 0 0 0 0 0
## Korea, Democratic People's Republic of 0 0 0 0 0
## Korea, Republic of 0 0 0 0 0
## Kuwait 0 0 0 0 0
## Kyrgyzstan 0 0 0 0 0
## Lao People's Democratic Republic 0 0 0 0 0
## Latvia 0 0 0 0 0
## Lebanon 0 0 0 0 0
## Lesotho 0 0 0 0 0
## Liberia 0 0 0 0 0
## Libya 0 0 0 0 0
## Liechtenstein 0 0 0 0 0
## Lithuania 1271 369 8 11 0
## Luxembourg 0 0 0 0 0
## Macao 0 0 0 0 0
## Macedonia, the Former Yugoslav Republic of 0 0 0 0 0
## Madagascar 0 0 0 0 0
## Malawi 0 0 0 0 0
## Malaysia 0 0 0 0 0
## Maldives 0 0 0 0 0
## Mali 0 0 0 0 0
## Malta 0 0 0 0 0
## Marshall Islands 0 0 0 0 0
## Martinique 0 0 0 0 0
## Mauritania 0 0 0 0 0
## Mauritius 0 0 0 0 0
## Mayotte 0 0 0 0 0
## Mexico 0 0 0 0 0
## Micronesia, Federated States of 0 0 0 0 0
## Moldova, Republic of 0 0 0 0 0
## Monaco 0 0 0 0 0
## Mongolia 0 0 0 0 0
## Montenegro 0 0 0 0 0
## Montserrat 0 0 0 0 0
## Morocco 0 0 0 0 0
## Mozambique 0 0 0 0 0
## Myanmar 0 0 0 0 0
## Namibia 0 0 0 0 0
## Nauru 0 0 0 0 0
## Nepal 0 0 0 0 0
## Netherlands 0 0 0 0 0
## New Caledonia 0 0 0 0 0
## New Zealand 0 0 0 0 0
## Nicaragua 0 0 0 0 0
## Niger 0 0 0 0 0
## Nigeria 0 0 0 0 0
## Niue 0 0 0 0 0
## Norfolk Island 0 0 0 0 0
## Northern Mariana Islands 0 0 0 0 0
## Norway 0 0 0 0 0
## Oman 0 0 0 0 0
## Pakistan 0 0 0 0 0
## Palau 0 0 0 0 0
## Palestine, State of 0 0 0 0 0
## Panama 0 0 0 0 0
## Papua New Guinea 0 0 0 0 0
## Paraguay 0 0 0 0 0
## Peru 0 0 0 0 0
## Philippines 0 0 0 0 0
## Pitcairn 0 0 0 0 0
## Poland 0 0 0 0 0
## Portugal 0 0 0 0 0
## Puerto Rico 0 0 0 0 0
## Qatar 0 0 0 0 0
## Réunion 0 0 0 0 0
## Romania 0 0 0 0 0
## Russian Federation 0 0 0 0 0
## Rwanda 0 0 0 0 0
## Saint Barthélemy 0 0 0 0 0
## Saint Helena, Ascension and Tristan da Cunha 0 0 0 0 0
## Saint Kitts and Nevis 0 0 0 0 0
## Saint Lucia 0 0 0 0 0
## Saint Martin (French part) 0 0 0 0 0
## Saint Pierre and Miquelon 0 0 0 0 0
## Saint Vincent and the Grenadines 0 0 0 0 0
## Samoa 0 0 0 0 0
## San Marino 0 0 0 0 0
## Sao Tome and Principe 0 0 0 0 0
## Saudi Arabia 0 0 0 0 0
## Senegal 0 0 0 0 0
## Serbia 0 0 0 0 0
## Seychelles 0 0 0 0 0
## Sierra Leone 0 0 0 0 0
## Singapore 0 0 0 0 0
## Sint Maarten (Dutch part) 0 0 0 0 0
## Slovakia 1057 340 0 0 21
## Slovenia 743 504 3 1 1
## Solomon Islands 0 0 0 0 0
## Somalia 0 0 0 0 0
## South Africa 0 0 0 0 0
## South Georgia and the South Sandwich Islands 0 0 0 0 0
## South Sudan 0 0 0 0 0
## Spain 0 0 0 0 0
## Sri Lanka 0 0 0 0 0
## Sudan 0 0 0 0 0
## Suriname 0 0 0 0 0
## Svalbard and Jan Mayen 0 0 0 0 0
## Swaziland 0 0 0 0 0
## Sweden 0 0 0 0 0
## Switzerland 0 0 0 0 0
## Syrian Arab Republic 0 0 0 0 0
## Taiwan, Province of China 0 0 0 0 0
## Tajikistan 0 0 0 0 0
## Tanzania, United Republic of 0 0 0 0 0
## Thailand 0 0 0 0 0
## Timor-Leste 0 0 0 0 0
## Togo 0 0 0 0 0
## Tokelau 0 0 0 0 0
## Tonga 0 0 0 0 0
## Trinidad and Tobago 0 0 0 0 0
## Tunisia 0 0 0 0 0
## Turkey 0 0 0 0 0
## Turkmenistan 0 0 0 0 0
## Turks and Caicos Islands 0 0 0 0 0
## Tuvalu 0 0 0 0 0
## Uganda 0 0 0 0 0
## Ukraine 0 0 0 0 0
## United Arab Emirates 0 0 0 0 0
## United Kingdom 0 0 0 0 0
## United States 0 0 0 0 0
## United States Minor Outlying Islands 0 0 0 0 0
## Uruguay 0 0 0 0 0
## Uzbekistan 0 0 0 0 0
## Vanuatu 0 0 0 0 0
## Venezuela, Bolivarian Republic of 0 0 0 0 0
## Viet Nam 0 0 0 0 0
## Virgin Islands, British 0 0 0 0 0
## Virgin Islands, U.S. 0 0 0 0 0
## Wallis and Futuna 0 0 0 0 0
## Western Sahara 0 0 0 0 0
## Yemen 0 0 0 0 0
## Zambia 0 0 0 0 0
## Zimbabwe 0 0 0 0 0
Visualizations
To start, based on the means that we created previously for happiness by country and how often people meet by country, I’ll create bar charts to better visualize the data.
# Below we create a bar chart for average happiness by country
happySummary %>%
ggplot(aes(x = fct_reorder(Name, happyMu), y = happyMu)) +
geom_col(fill = "yellow", color = "black") +
labs(x = "Country",
y = "Average happiness on a 10 point scale.",
title = "Average happiness by country.",
caption = "Data source: The 10th round (2020) of the European Social Survey.") +
coord_flip() +
theme_bw()# Below we create a bar chart for average amount that people see other people by country
meetSummary %>%
ggplot(aes(x = fct_reorder(Name, meetMu), y = meetMu)) +
geom_col(fill = "blue", color = "black") +
labs(x = "Country",
y = "Average amount of social behavior on an 8 point scale.",
title = "Average amount of social behavior by country.",
caption = "Data source: The 10th round (2020) of the European Social Survey.") +
coord_flip() +
theme_bw()
The previous visualization has allowed us to see which countries are the
happiest within the context of this survey and comparing these results
to social behavior. Considering It would seem that there are no patterns
of correspondance between the happiest and saddest countries and how
frequently people engage in social behavior.
According to prior research on values, aspirations, and how these aspects relate to well-being, extrinsic values like materialism (a construct which captures prioritization of wealth and material possession), are negatively related to psychological well-being within Western societies within the United States. This pattern is a bit different for places where there has been more economic and political instability like Romania. Considering the diverse sample size from this data set, I think it would be interesting next to explore how desire for wealth influences happiness within the current data set to see if the relationships within the data set are consistent with that of the current literature.
# Creating the scatterplot looking at importance of wealth related to happiness organized by country.
scatter <- ESS10full %>% filter(happy < 50) %>%
ggplot(aes(x = jitter(imprich, 5),
y = jitter(happy, 5),
color = Name)) +
geom_point()+
labs(x = "The importance of wealth",
y = "Subjective Happiness",
title = "How the importance of wealth relates to happiness.",
caption = "Data source: The 10th round (2020) of the European Social Survey.",
color = "") +
geom_smooth(se = FALSE, method = "lm", size = 1.5)
scatter## `geom_smooth()` using formula 'y ~ x'
From what we can see, overall there isn’t much of a relationship at all
between importance of wealth and happiness when looking broadly across
the countries. It’s important to note that within the variable
importance of wealth, the lower the number, the more important it was to
the individual (1 being very important, 6 being not important at all).
With this in mind, it seems as if there is a slight positive
relationship between importance of wealth and subjective happiness for
Bulgaria, Slovakia, and Hungary.
We’ve briefly explored the means, medians, and standard deviations of happiness but perhaps a boxplot format would give us more insight on just how normally distributed the different countries are and perhaps this spread will be the reason for a lacking relationship.
# Creating a boxplot of happiness by each country.
happyBox <- ESS10full %>% filter(happy < 11) %>%
ggplot(aes( x = fct_reorder(Name, happy) , y = happy)) +
geom_boxplot(fill = "yellow") +
labs(x = "Country",
y = "Happiness",
title = "Boxplots of happiness by country",
caption = "Data source: The 10th round (2020) of the European Social Survey.") +
theme_bw() +
coord_flip()
happyBox
As expected, the variability of each of the countries is quite extreme.
Even within the ones which we noticed a relationship between happiness
and importance of wealth, there is enough variability to have some
concern. This is with the exception of Hungary. Hungary actually seems
to be one of the most normally distributed samples out of the whole data
set ignoring the extreme outliers to the left. What these plots
emphasize is that overall happiness seems to be lower on the countries
where our regression line found a positive relationship between
happiness and importance of wealth.
To gain further insight, it might be helpful to see the distributions of the importance of wealth among these countries.
# Creating a boxplot of importance of wealth by country.
richBox <- ESS10full %>% filter(imprich < 7) %>%
ggplot(aes( x = fct_reorder(Name, imprich) , y = imprich)) +
geom_boxplot(fill = "green") +
labs(x = "Country",
y = "Importance of wealth",
title = "Boxplots of importance of wealth by country",
caption = "Data source: The 10th round (2020) of the European Social Survey.") +
theme_bw() +
coord_flip()
richBox
The distribution of the boxplots of the importance of wealth are quite
varied. The lacking normality makes it a bit difficult to trust any
relationships we might find.
When discussing values and well-being, there’s also been found to be a large generational difference between values which might also influence the relationship between well-being and importance of wealth.
# Creating a line chart for age and happiness.
linechart <- ESS10full %>%
filter(yrbrn < 7777) %>%
ggplot() +
stat_summary(geom = "line", fun = mean,
size = 1, aes(x = yrbrn, y = happy,
color = Name)) +
scale_color_colorblind() +
labs(title = "Happiness related to age (year participant was born)",
x = "Year Born",
y = "Happiness",
caption = "Data source: The 10th round (2020) of the European Social Survey.",
color = "Country") +
theme_bw()
linechart## Warning: This manual palette can handle a maximum of 8 values. You have supplied
## 10.
## Warning: Removed 151 row(s) containing missing values (geom_path).
Overall, there sems to get a general upward trend of happiness the later
you’re born (so the younger you are).
# Creating a linechart for age and importance of wealth.
linechart <- ESS10full %>%
filter(yrbrn < 7777) %>%
ggplot() +
stat_summary(geom = "line", fun = mean,
size = 1, aes(x = yrbrn, y = imprich,
color = Name)) +
scale_color_colorblind() +
labs(title = "Importance of wealth related to age (year participant was born)",
x = "Year Born",
y = "Importance of wealth",
caption = "Data source: The 10th round (2020) of the European Social Survey.",
color = "Country") +
theme_bw()
linechart## Warning: This manual palette can handle a maximum of 8 values. You have supplied
## 10.
## Warning: Removed 151 row(s) containing missing values (geom_path).
Interestingly enough even though happiness increases the younger you get, it would seem that the importance of wealth increases the younger you get as well. It seems that the state of both outcomes are changing throughout the generations which might provide a confound in understanding the relationship between the two variables.
Out of curiosity, it may be interesting to see the distribution of education level for our sample.
#Creating a histogram for education level.
ESS10full%>%
filter(edulvlb < 5000) %>%
ggplot(aes(x = edulvlb)) +
geom_bar(width = 95,
color = "black",
fill = "white") +
labs(title = "Frequency of various educational levels",
y = "Frequency",
x = "Level of Education",
caption = "Data source: The 10th round (2020) of the European Social Survey.") +
theme_bw()## Warning: position_stack requires non-overlapping x intervals
It’s important to note that this is a categorical variable with the
various options coded as numeric values. Between 200 and 400 are the
many vocational schooling options. 600 and above are collegiate degrees
(associate’s, bachelor’s, and doctorate respectively). The level and
prestiege of each form of educational increases as the numbers go up.
They’ve specificed tier prestiege of post-secondary education options
and the levels within. It would seem that much of the subjects within
our sample have achieved a certain level of vocational schooling with a
substantial amount achieving some sort of degree. Understanding that
education often times leads to better well-being, it makes sense why the
happiness of many of our countries are so high.
Understanding that often times, religion can play a role in social support and therefore influencing well-being, it might be interesting to see how the data set is distributed in terms of religious participants.
# Making a bar chart for the frequency of whether people are or aren't religious.
ESS10full%>%
filter(rlgblg < 5) %>%
ggplot(aes(x = rlgblg)) +
geom_bar(color = "black", fill = "gold") +
labs(title = "Frequency of religiousity",
y = "Frequency",
x = "Religious Belonging (y/n respectively)",
caption = "Data source: The 10th round (2020) of the European Social Survey.") +
theme_bw()
What we end up seeing is that there are more religious participants than
there are non religious participants by a good margin. Although this
probably doens’t completely explain the generally higher medians and
means of happiness, it may be a part of the explanation.
Utilizing Lubridate
Fortunately, this data set has various date variables specifically regarding when the survey was administered and when it finished. Uising Lubridate functions, I”ll look specifically at the date the survey was started.
# Using Lubridate to create a new variable for date.
ESS10full <- ESS10full %>%
mutate(assessDate = ymd_hms(inwds))Once this variable has been created using lubridate, I’ll explore how the date the survey was taken influences happiness. Perhaps, considering that this was administered during the pandemic, the later it’s taken, the more acquainted people will be and the better their well-being.
# Producing a scatterplot to explore this contention.
ESS10full %>%
filter(happy < 50) %>%
ggplot(aes(x = assessDate, y = jitter(happy, 5),
color = Name)) +
geom_point() +
labs(x = "Date Administered",
y = "Happiness",
title = "Happiness in relation to the date of administering the survey",
caption = "Data source: The 10th round (2020) of the European Social Survey.")+
geom_smooth(se = FALSE, method = "lm", size = 1.5)## `geom_smooth()` using formula 'y ~ x'
## Utilizing StringR Next, I’ll utilize stringR functions to figure out
a way to identify observations from Hungary.
# Creating a variable which identifies whether or not an observation is from Hungary.
ESS10full <- ESS10full %>%
mutate(contains_Hungary = str_detect(Name, pattern = "Hungary"))Now that I have the appropriate variable created, I’ll utilize it to find out how many observations are from Hungary.
countHungary <- ESS10full %>% pull(contains_Hungary) %>% sum()
countHungary## [1] 1849
From this we see that 1849 observations out of the 18,299 observations are from Hungary, meaning 10.1043773% of the observations are from Hungary.
In all honesty, I couldn’t figure out a productive way of pivoting any of the data so I’m going to pivot the country names variable to show that it’s something I understand. I hope that this is enough to earn at least some of the credit on this requirement.
# Here I'm pivoting the country names to a wider format.
namesWide <- country_name %>%
pivot_wider(id_cols = Code,
names_from = Name,
values_from = Name)
namesWide## # A tibble: 249 × 250
## Code Afghan…¹ Åland…² Albania Algeria Ameri…³ Andorra Angola Angui…⁴ Antar…⁵
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 AF Afghani… <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2 AX <NA> Åland … <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 3 AL <NA> <NA> Albania <NA> <NA> <NA> <NA> <NA> <NA>
## 4 DZ <NA> <NA> <NA> Algeria <NA> <NA> <NA> <NA> <NA>
## 5 AS <NA> <NA> <NA> <NA> Americ… <NA> <NA> <NA> <NA>
## 6 AD <NA> <NA> <NA> <NA> <NA> Andorra <NA> <NA> <NA>
## 7 AO <NA> <NA> <NA> <NA> <NA> <NA> Angola <NA> <NA>
## 8 AI <NA> <NA> <NA> <NA> <NA> <NA> <NA> Anguil… <NA>
## 9 AQ <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> Antarc…
## 10 AG <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## # … with 239 more rows, 240 more variables: `Antigua and Barbuda` <chr>,
## # Argentina <chr>, Armenia <chr>, Aruba <chr>, Australia <chr>,
## # Austria <chr>, Azerbaijan <chr>, Bahamas <chr>, Bahrain <chr>,
## # Bangladesh <chr>, Barbados <chr>, Belarus <chr>, Belgium <chr>,
## # Belize <chr>, Benin <chr>, Bermuda <chr>, Bhutan <chr>,
## # `Bolivia, Plurinational State of` <chr>,
## # `Bonaire, Sint Eustatius and Saba` <chr>, `Bosnia and Herzegovina` <chr>, …