Setting Up
# List of packages
packages <- c("tidyverse", "modelsummary", "forcats", "RColorBrewer",
"fst", "viridis", "knitr", "kableExtra", "rmarkdown", "ggridges", "viridis", "questionr", "flextable")
# Install packages if they aren't installed already
new_packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new_packages)) install.packages(new_packages)
# Load the packages
lapply(packages, library, character.only = TRUE)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Warning: package 'modelsummary' was built under R version 4.2.3
## Warning in !is.null(rmarkdown::metadata$output) && rmarkdown::metadata$output
## %in% : 'length(x) = 3 > 1' in coercion to 'logical(1)'
## Warning: package 'fst' was built under R version 4.2.3
## Warning: package 'viridis' was built under R version 4.2.3
## Loading required package: viridisLite
## Warning: package 'viridisLite' was built under R version 4.2.3
## Warning: package 'knitr' was built under R version 4.2.3
## Warning: package 'kableExtra' was built under R version 4.2.3
##
## Attaching package: 'kableExtra'
##
## The following object is masked from 'package:dplyr':
##
## group_rows
## Warning: package 'rmarkdown' was built under R version 4.2.3
## Warning: package 'ggridges' was built under R version 4.2.3
## Warning: package 'questionr' was built under R version 4.2.3
## Warning: package 'flextable' was built under R version 4.2.3
##
## Attaching package: 'flextable'
##
## The following objects are masked from 'package:kableExtra':
##
## as_image, footnote
##
## The following object is masked from 'package:purrr':
##
## compose
## [[1]]
## [1] "lubridate" "forcats" "stringr" "dplyr" "purrr" "readr"
## [7] "tidyr" "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [13] "grDevices" "utils" "datasets" "methods" "base"
##
## [[2]]
## [1] "modelsummary" "lubridate" "forcats" "stringr" "dplyr"
## [6] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [11] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [16] "datasets" "methods" "base"
##
## [[3]]
## [1] "modelsummary" "lubridate" "forcats" "stringr" "dplyr"
## [6] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [11] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [16] "datasets" "methods" "base"
##
## [[4]]
## [1] "RColorBrewer" "modelsummary" "lubridate" "forcats" "stringr"
## [6] "dplyr" "purrr" "readr" "tidyr" "tibble"
## [11] "ggplot2" "tidyverse" "stats" "graphics" "grDevices"
## [16] "utils" "datasets" "methods" "base"
##
## [[5]]
## [1] "fst" "RColorBrewer" "modelsummary" "lubridate" "forcats"
## [6] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [11] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [16] "grDevices" "utils" "datasets" "methods" "base"
##
## [[6]]
## [1] "viridis" "viridisLite" "fst" "RColorBrewer" "modelsummary"
## [6] "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [11] "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [16] "stats" "graphics" "grDevices" "utils" "datasets"
## [21] "methods" "base"
##
## [[7]]
## [1] "knitr" "viridis" "viridisLite" "fst" "RColorBrewer"
## [6] "modelsummary" "lubridate" "forcats" "stringr" "dplyr"
## [11] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [16] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [21] "datasets" "methods" "base"
##
## [[8]]
## [1] "kableExtra" "knitr" "viridis" "viridisLite" "fst"
## [6] "RColorBrewer" "modelsummary" "lubridate" "forcats" "stringr"
## [11] "dplyr" "purrr" "readr" "tidyr" "tibble"
## [16] "ggplot2" "tidyverse" "stats" "graphics" "grDevices"
## [21] "utils" "datasets" "methods" "base"
##
## [[9]]
## [1] "rmarkdown" "kableExtra" "knitr" "viridis" "viridisLite"
## [6] "fst" "RColorBrewer" "modelsummary" "lubridate" "forcats"
## [11] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [16] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [21] "grDevices" "utils" "datasets" "methods" "base"
##
## [[10]]
## [1] "ggridges" "rmarkdown" "kableExtra" "knitr" "viridis"
## [6] "viridisLite" "fst" "RColorBrewer" "modelsummary" "lubridate"
## [11] "forcats" "stringr" "dplyr" "purrr" "readr"
## [16] "tidyr" "tibble" "ggplot2" "tidyverse" "stats"
## [21] "graphics" "grDevices" "utils" "datasets" "methods"
## [26] "base"
##
## [[11]]
## [1] "ggridges" "rmarkdown" "kableExtra" "knitr" "viridis"
## [6] "viridisLite" "fst" "RColorBrewer" "modelsummary" "lubridate"
## [11] "forcats" "stringr" "dplyr" "purrr" "readr"
## [16] "tidyr" "tibble" "ggplot2" "tidyverse" "stats"
## [21] "graphics" "grDevices" "utils" "datasets" "methods"
## [26] "base"
##
## [[12]]
## [1] "questionr" "ggridges" "rmarkdown" "kableExtra" "knitr"
## [6] "viridis" "viridisLite" "fst" "RColorBrewer" "modelsummary"
## [11] "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [16] "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [21] "stats" "graphics" "grDevices" "utils" "datasets"
## [26] "methods" "base"
##
## [[13]]
## [1] "flextable" "questionr" "ggridges" "rmarkdown" "kableExtra"
## [6] "knitr" "viridis" "viridisLite" "fst" "RColorBrewer"
## [11] "modelsummary" "lubridate" "forcats" "stringr" "dplyr"
## [16] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [21] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [26] "datasets" "methods" "base"
ess <- read_fst("All-ESS-Data.fst")
## Warning: package 'fstcore' was built under R version 4.2.3
library(fst)
Creating and Cleaning Israel Dataset
# Creating Israel's dataset
israel_dataset <- ess[ess$cntry == "IL", ]
# Cleaning Israel's dataset
israel_clean <- israel_dataset %>%
select(eduail1, hinctnta, happy, rlgdgr, essround, yrbrn, rlgdnm, imprich, inprdsc) %>%
filter(!yrbrn %in% c(7777, 8888)) %>%
mutate(
happy = ifelse(happy %in% c(77, 88, 99), NA, happy),
rlgdgr = ifelse(rlgdgr %in% c(77, 88, 99), NA, rlgdgr),
eduail1 = ifelse(eduail1 %in% c(4444, 5555, 7777, 8888, 9999), NA, eduail1),
hinctnta = ifelse(hinctnta %in% c(77, 88, 99), NA, hinctnta),
rlgdnm = ifelse(rlgdnm %in% c(77,99), NA, rlgdnm),
imprich = ifelse(imprich %in% c(7, 8, 9), NA, imprich),
inprdsc = ifelse(inprdsc %in% c(77, 88, 99), NA, inprdsc),
) %>%
filter(!is.na(happy) & !is.na(rlgdgr) & !is.na(eduail1) & !is.na(hinctnta) & !is.na(rlgdnm) & !is.na(imprich) & !is.na(inprdsc))
Creating Year Variable
# Create year variable
table(israel_clean$essround)
##
## 6 7
## 1445 1647
israel_clean$year <- NA
replacements <- c(2002, 2004, 2006, 2008, 2010, 2012, 2014, 2016, 2018, 2020)
for(i in 1:10){
israel_clean$year[israel_clean$essround == i] <- replacements[i]
}
Graph of Mean Happiness levels in Israel by Birth Year
#Average Happiness Levels by Birth Year in Israel
happiness_bybirth_IL <- israel_clean %>%
group_by(yrbrn) %>%
summarize(mean_happyIL = mean(happy, na.rm = TRUE))%>%
filter(!is.na(yrbrn))
happiness_bybirth_IL
## # A tibble: 80 × 2
## yrbrn mean_happyIL
## <dbl> <dbl>
## 1 1921 8.5
## 2 1922 7.33
## 3 1923 8
## 4 1924 7.4
## 5 1925 4.33
## 6 1926 5.86
## 7 1927 8
## 8 1928 8
## 9 1929 6.4
## 10 1930 8
## # ℹ 70 more rows
# Visualisation
ggplot(happiness_bybirth_IL, aes(x = yrbrn, y = mean_happyIL)) +
geom_line(color = "skyblue", size = 1, breaks = seq(1910, 2000, by = 5)) + # Line to show the trend
geom_point(color = "orange", size = 2, breaks = seq(1910, 2000, by = 5)) + # Points to highlight each year's value
labs(title = " Mean Happiness Levels by Birth Year" ,
x = "Birth Year",
y = "Mean Happiness (0-10 scale)") +
ylim(0, 10) +
theme_minimal()
## 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.
## Warning in geom_line(color = "skyblue", size = 1, breaks = seq(1910, 2000, :
## Ignoring unknown parameters: `breaks`
## Warning in geom_point(color = "orange", size = 2, breaks = seq(1910, 2000, :
## Ignoring unknown parameters: `breaks`
# Zooming In
ggplot(happiness_bybirth_IL, aes(x = yrbrn, y = mean_happyIL)) +
geom_line(color = "skyblue", size = 1, breaks = seq(1910, 2000, by = 5)) + # Line to show the trend
geom_point(color = "orange", size = 2, breaks = seq(1910, 2000, by = 5)) +
labs(title = " Mean Happiness Levels by Birth Year" ,
x = "Birth Year",
y = "Mean Happiness (0-10 scale)") +
scale_x_continuous() +
ylim(5, 10) +
theme_minimal()
## Warning in geom_line(color = "skyblue", size = 1, breaks = seq(1910, 2000, : Ignoring unknown parameters: `breaks`
## Ignoring unknown parameters: `breaks`
## Warning: Removed 1 rows containing missing values (`geom_point()`).
Comparing to ESS baseline
# Creating mean happiness variable from ESS
happiness_bybirth_all <- ess %>%
select(yrbrn, happy) %>%
filter(!yrbrn %in% c(7777, 8888, 9999)) %>%
mutate(
happy = ifelse(happy %in% c(77, 88, 99), NA, happy)) %>%
filter(!is.na(happy)) %>%
group_by(yrbrn) %>%
summarize(mean_happyALL = mean(happy, na.rm = TRUE))
# Combine data
combined_happiness <- left_join(happiness_bybirth_IL, happiness_bybirth_all, by = "yrbrn")
long_data <- combined_happiness %>%
pivot_longer(
cols = starts_with("mean_happy"),
names_to = "Happiness_level",
values_to = "Mean_Happiness"
)
# Visualisation
ggplot(long_data) +
geom_line(aes(x = yrbrn, y = Mean_Happiness, color = Happiness_level), size = 1 ) +
geom_point(aes(x = yrbrn, y = Mean_Happiness, color = Happiness_level), size = 1.5 ) +
labs(title = "Happiness Level (1910-2000)",
x = "Birth Year",
y = "Mean Happiness Level (0-10 Scale)") +
ylim(5, 10) +
scale_x_continuous() +
scale_color_manual(values = c("mean_happyIL" = "skyblue", "mean_happyALL" = "forestgreen"),
name = "Dataset",
labels = c("All ESS", "Israel")) +
theme_minimal()
## Warning: Removed 1 rows containing missing values (`geom_point()`).
Summary of chosen variables
datasummary_skim(israel_clean)
Unique (#)
Missing (%)
Mean
SD
Min
Median
Max
eduail1
17
0
7.8
4.4
1.0
6.0
17.0
hinctnta
10
0
5.1
2.6
1.0
5.0
10.0
happy
11
0
7.6
1.9
0.0
8.0
10.0
rlgdgr
11
0
5.1
3.3
0.0
5.0
10.0
essround
2
0
6.5
0.5
6.0
7.0
7.0
yrbrn
80
0
1967.0
18.9
1921.0
1970.0
2000.0
rlgdnm
8
0
5.5
5.2
1.0
5.0
66.0
imprich
6
0
3.5
1.5
1.0
4.0
6.0
inprdsc
7
0
2.6
1.6
0.0
3.0
6.0
year
2
0
2013.1
1.0
2012.0
2014.0
2014.0
Statistics for Education Level Against Happiness Levels in
Israel
# Column Percentages
table(israel_clean$happy, israel_clean$eduail1) %>%
cprop()
##
## 1 2 3 4 5 6 7 8 9 10 11 12
## 0 1.0 0.0 0.9 1.4 0.6 1.0 0.0 0.0 0.0 0.6 0.7 0.4
## 1 0.0 0.0 2.8 0.0 0.2 1.0 0.0 0.0 0.0 0.0 1.4 0.0
## 2 1.0 4.0 3.3 1.9 1.2 2.5 0.0 1.1 0.0 0.0 2.1 0.4
## 3 6.2 2.6 1.4 2.2 1.5 2.5 5.6 2.2 3.0 2.5 1.1 0.4
## 4 4.1 5.3 4.2 2.5 2.7 1.0 5.6 1.1 3.0 3.1 1.8 2.4
## 5 11.3 12.8 9.4 7.2 7.3 5.9 5.6 5.6 9.1 4.3 4.6 3.6
## 6 12.4 10.6 10.4 8.9 6.2 10.8 5.6 5.6 15.2 11.1 4.6 10.8
## 7 10.3 16.3 13.2 17.5 17.5 21.1 16.7 14.6 18.2 14.2 15.5 14.8
## 8 21.6 22.0 24.1 24.2 28.1 21.1 27.8 34.8 18.2 26.5 32.5 28.8
## 9 16.5 16.3 13.2 15.3 20.0 13.2 11.1 15.7 18.2 14.8 20.1 26.0
## 10 15.5 10.1 17.0 18.9 14.6 20.1 22.2 19.1 15.2 22.8 15.5 12.4
## Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0
##
## 13 14 15 16 17 All
## 0 0.0 0.0 0.0 0.0 0.0 0.5
## 1 0.0 0.0 0.0 5.0 0.0 0.5
## 2 0.6 3.4 0.5 0.0 0.0 1.6
## 3 0.6 1.7 0.5 0.0 0.0 1.7
## 4 0.6 5.2 1.0 5.0 0.0 2.5
## 5 3.6 3.4 3.1 0.0 0.0 6.3
## 6 7.8 10.3 3.6 0.0 6.5 8.2
## 7 18.0 15.5 20.9 20.0 16.1 16.7
## 8 33.6 32.8 35.7 25.0 51.6 28.1
## 9 21.3 10.3 20.4 30.0 19.4 18.2
## 10 13.8 17.2 14.3 15.0 6.5 15.7
## Total 100.0 100.0 100.0 100.0 100.0 100.0
# Mean Happiness Levels by Education Level
mean_edu_happy <- israel_clean %>%
group_by(eduail1) %>%
summarize(mean_happy_byedu = mean(happy, na.rm = TRUE))
mean_edu_happy
## # A tibble: 17 × 2
## eduail1 mean_happy_byedu
## <dbl> <dbl>
## 1 1 7.16
## 2 2 7.03
## 3 3 7.14
## 4 4 7.52
## 5 5 7.66
## 6 6 7.48
## 7 7 7.61
## 8 8 7.89
## 9 9 7.45
## 10 10 7.81
## 11 11 7.72
## 12 12 7.86
## 13 13 7.95
## 14 14 7.48
## 15 15 8.02
## 16 16 7.85
## 17 17 8.03
# Standard Deviation
std_edu_happy <- israel_clean %>%
group_by(eduail1) %>%
summarize(std_happy_byedu = sd(happy, na.rm = TRUE))
std_edu_happy
## # A tibble: 17 × 2
## eduail1 std_happy_byedu
## <dbl> <dbl>
## 1 1 2.23
## 2 2 2.08
## 3 3 2.39
## 4 4 2.10
## 5 5 1.86
## 6 6 2.15
## 7 7 2.06
## 8 8 1.72
## 9 9 1.86
## 10 10 1.88
## 11 11 1.99
## 12 12 1.59
## 13 13 1.43
## 14 14 1.99
## 15 15 1.37
## 16 16 2.13
## 17 17 0.948
Statistics for Religion Group Against Happiness Levels in
Israel
# Column Percentages
table(israel_clean$happy, israel_clean$rlgdnm) %>%
cprop()
##
## 1 2 3 4 5 6 8 66 All
## 0 0.0 0.0 0.0 0.0 0.5 1.0 0.0 0.0 0.5
## 1 0.0 20.0 0.0 0.0 0.4 0.5 0.0 0.0 0.5
## 2 0.0 0.0 0.0 0.0 1.5 1.7 0.0 4.5 1.6
## 3 0.0 0.0 5.6 0.0 1.6 1.7 0.0 4.5 1.7
## 4 4.4 0.0 0.0 0.0 2.3 3.1 8.3 9.1 2.5
## 5 15.6 0.0 8.3 9.1 5.9 6.6 8.3 9.1 6.3
## 6 6.7 20.0 19.4 0.0 7.2 11.9 16.7 9.1 8.2
## 7 20.0 20.0 11.1 36.4 15.9 19.8 25.0 13.6 16.7
## 8 35.6 20.0 41.7 27.3 27.6 28.8 25.0 31.8 28.1
## 9 15.6 0.0 11.1 27.3 18.4 18.7 0.0 13.6 18.2
## 10 2.2 20.0 2.8 0.0 18.7 5.9 16.7 4.5 15.7
## Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0
# Mean Happiness Levels by Religion Group
mean_rlggrp_happy <- israel_clean %>%
group_by(rlgdnm) %>%
summarize(mean_happy_byrlggrp = mean(happy, na.rm = TRUE))
mean_rlggrp_happy
## # A tibble: 8 × 2
## rlgdnm mean_happy_byrlggrp
## <dbl> <dbl>
## 1 1 7.22
## 2 2 6.4
## 3 3 7.14
## 4 4 7.64
## 5 5 7.75
## 6 6 7.23
## 7 8 7.17
## 8 66 6.77
# Standard Deviation
std_rlggrp_happy <- israel_clean %>%
group_by(rlgdnm) %>%
summarize(std_happy_byrlggrp = sd(happy, na.rm = TRUE))
std_rlggrp_happy
## # A tibble: 8 × 2
## rlgdnm std_happy_byrlggrp
## <dbl> <dbl>
## 1 1 1.51
## 2 2 3.36
## 3 3 1.61
## 4 4 1.21
## 5 5 1.92
## 6 6 1.90
## 7 8 1.80
## 8 66 2.14
Statistics for Religous Feelings Against Happiness Levels in
Israel
# Column Percentages
table(israel_clean$happy, israel_clean$rlgdgr) %>%
cprop()
##
## 0 1 2 3 4 5 6 7 8 9 10 All
## 0 0.5 0.0 0.0 0.0 0.0 0.5 0.7 0.3 1.0 1.6 0.7 0.5
## 1 0.9 0.0 0.0 0.6 0.0 0.5 0.7 0.3 0.5 0.5 0.0 0.5
## 2 2.7 1.4 2.3 2.4 0.0 1.3 1.5 1.1 1.5 1.0 1.0 1.6
## 3 2.0 2.8 2.3 1.2 3.0 2.3 0.7 1.9 1.0 0.0 1.7 1.7
## 4 4.1 2.1 2.3 3.0 3.6 2.0 1.8 2.4 1.0 2.1 2.4 2.5
## 5 6.0 7.0 4.7 4.2 11.4 8.4 6.2 5.4 6.6 6.2 3.1 6.3
## 6 8.2 12.0 9.3 7.3 8.4 10.2 9.9 9.5 7.8 6.2 2.4 8.2
## 7 18.3 20.4 21.7 20.6 20.5 16.9 19.5 15.7 15.2 15.1 7.2 16.7
## 8 24.3 32.4 31.0 34.5 25.3 28.6 33.1 31.1 30.3 26.6 18.8 28.1
## 9 19.7 14.1 17.1 17.0 14.5 14.8 18.8 17.8 17.4 26.0 21.5 18.2
## 10 13.3 7.7 9.3 9.1 13.3 14.3 7.0 14.6 17.8 14.6 41.3 15.7
## Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0
# Mean Happiness Levels by Religious Feelings
mean_rlgious_happy <- israel_clean %>%
group_by(rlgdgr) %>%
summarize(mean_happy_byrlgious = mean(happy, na.rm = TRUE))
mean_rlgious_happy
## # A tibble: 11 × 2
## rlgdgr mean_happy_byrlgious
## <dbl> <dbl>
## 1 0 7.41
## 2 1 7.33
## 3 2 7.47
## 4 3 7.50
## 5 4 7.40
## 6 5 7.46
## 7 6 7.44
## 8 7 7.66
## 9 8 7.74
## 10 9 7.78
## 11 10 8.53
# Standard Deviation
std_rlgious_happy <- israel_clean %>%
group_by(rlgdgr) %>%
summarize(std_happy_byrlgious = sd(happy, na.rm = TRUE))
std_rlgious_happy
## # A tibble: 11 × 2
## rlgdgr std_happy_byrlgious
## <dbl> <dbl>
## 1 0 2.08
## 2 1 1.70
## 3 2 1.75
## 4 3 1.77
## 5 4 1.80
## 6 5 1.93
## 7 6 1.78
## 8 7 1.80
## 9 8 1.92
## 10 9 1.93
## 11 10 1.91
Statistics for Income Decile Against Happiness Levels in Israel
# Column Percentages
table(israel_clean$happy, israel_clean$hinctnta) %>%
cprop()
##
## 1 2 3 4 5 6 7 8 9 10 All
## 0 2.2 0.6 0.4 0.5 0.5 1.0 0.0 0.3 0.0 0.0 0.5
## 1 0.9 1.2 1.1 0.0 0.3 0.0 0.4 0.3 0.0 0.0 0.5
## 2 4.4 2.4 2.2 1.6 1.8 1.0 0.4 0.0 0.5 0.5 1.6
## 3 4.8 1.8 3.1 1.2 2.3 1.3 0.4 0.3 0.5 0.0 1.7
## 4 3.5 3.6 3.8 4.7 2.5 1.0 0.7 1.0 1.1 0.0 2.5
## 5 8.8 10.5 8.1 7.1 6.1 6.7 3.9 2.8 2.2 2.5 6.3
## 6 11.0 11.4 9.4 9.4 6.3 6.7 8.6 6.9 4.4 5.6 8.2
## 7 16.7 13.5 18.1 20.0 18.4 16.8 19.0 14.2 17.5 8.1 16.7
## 8 18.1 26.6 24.8 24.5 27.0 31.4 33.0 33.0 34.4 34.3 28.1
## 9 15.4 13.8 14.3 16.7 16.9 17.1 17.2 24.0 25.7 31.8 18.2
## 10 14.1 14.7 14.5 14.4 17.9 17.1 16.5 17.0 13.7 17.2 15.7
## Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0
# Mean Happiness Levels by Income Decile
mean_inc_happy <- israel_clean %>%
group_by(hinctnta) %>%
summarize(mean_happy_byinc = mean(happy, na.rm = TRUE))
mean_inc_happy
## # A tibble: 10 × 2
## hinctnta mean_happy_byinc
## <dbl> <dbl>
## 1 1 6.90
## 2 2 7.25
## 3 3 7.27
## 4 4 7.47
## 5 5 7.66
## 6 6 7.78
## 7 7 7.93
## 8 8 8.10
## 9 9 8.10
## 10 10 8.36
# Standard Deviation
std_inc_happy <- israel_clean %>%
group_by(hinctnta) %>%
summarize(std_happy_byinc = sd(happy, na.rm = TRUE))
std_inc_happy
## # A tibble: 10 × 2
## hinctnta std_happy_byinc
## <dbl> <dbl>
## 1 1 2.48
## 2 2 2.13
## 3 3 2.12
## 4 4 1.90
## 5 5 1.95
## 6 6 1.81
## 7 7 1.49
## 8 8 1.49
## 9 9 1.36
## 10 10 1.26
Statistics for Importance of Being Rich Against Happiness Levels in
Israel
# Column Percentages
table(israel_clean$happy, israel_clean$imprich) %>%
cprop()
##
## 1 2 3 4 5 6 All
## 0 0.3 0.7 0.2 0.8 0.3 1.5 0.5
## 1 0.0 0.6 0.5 0.3 0.6 0.8 0.5
## 2 2.8 1.9 0.9 1.7 1.3 1.1 1.6
## 3 0.9 1.7 1.6 1.9 1.6 2.6 1.7
## 4 2.8 3.7 3.1 2.3 1.7 0.4 2.5
## 5 8.7 6.9 5.8 6.1 5.8 4.9 6.3
## 6 10.3 9.4 9.8 7.8 6.6 4.9 8.2
## 7 15.0 19.9 20.3 16.4 14.7 10.2 16.7
## 8 22.1 25.3 30.2 30.5 29.8 25.6 28.1
## 9 15.3 18.9 16.5 18.7 20.7 16.9 18.2
## 10 21.8 11.0 11.0 13.6 16.9 31.2 15.7
## Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0
# Mean Happiness Levels by Importance of Being Rich
mean_rich_happy <- israel_clean %>%
group_by(imprich) %>%
summarize(mean_happy_byrich = mean(happy, na.rm = TRUE))
mean_rich_happy
## # A tibble: 6 × 2
## imprich mean_happy_byrich
## <dbl> <dbl>
## 1 1 7.62
## 2 2 7.37
## 3 3 7.51
## 4 4 7.58
## 5 5 7.80
## 6 6 8.06
# Standard Deviation
std_rich_happy <- israel_clean %>%
group_by(imprich) %>%
summarize(std_happy_byrich = sd(happy, na.rm = TRUE))
std_rich_happy
## # A tibble: 6 × 2
## imprich std_happy_byrich
## <dbl> <dbl>
## 1 1 2.03
## 2 2 1.97
## 3 3 1.75
## 4 4 1.92
## 5 5 1.84
## 6 6 2.15
Statistics for Close Friends Against Happiness Levels in Israel
# Column Percentages
table(israel_clean$happy, israel_clean$inprdsc) %>%
cprop()
##
## 0 1 2 3 4 5 6 All
## 0 0.8 0.7 0.7 0.3 0.7 0.0 0.0 0.5
## 1 1.5 0.3 0.5 0.2 0.5 0.0 0.6 0.5
## 2 5.0 2.1 0.8 0.8 1.6 0.8 0.0 1.6
## 3 4.2 2.7 1.3 1.6 0.5 0.0 1.1 1.7
## 4 6.9 2.5 3.1 1.9 1.3 0.8 1.1 2.5
## 5 13.1 7.8 6.7 3.8 4.4 4.1 6.1 6.3
## 6 10.8 10.4 7.4 7.7 6.0 9.1 7.8 8.2
## 7 16.9 15.5 19.5 15.1 16.3 16.5 18.9 16.7
## 8 19.6 24.5 29.5 31.4 33.1 23.1 23.9 28.1
## 9 8.1 14.2 17.7 21.5 21.5 24.0 23.3 18.2
## 10 13.1 19.3 12.8 15.9 14.2 21.5 17.2 15.7
## Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0
# Mean Happiness Levels by Number of Close Friends
mean_friend_happy <- israel_clean %>%
group_by(inprdsc) %>%
summarize(mean_happy_byfriend = mean(happy, na.rm = TRUE))
mean_friend_happy
## # A tibble: 7 × 2
## inprdsc mean_happy_byfriend
## <dbl> <dbl>
## 1 0 6.61
## 2 1 7.49
## 3 2 7.56
## 4 3 7.88
## 5 4 7.82
## 6 5 8.12
## 7 6 7.91
# Standard Deviation
std_friend_happy <- israel_clean %>%
group_by(inprdsc) %>%
summarize(std_happy_byfriend = sd(happy, na.rm = TRUE))
std_friend_happy
## # A tibble: 7 × 2
## inprdsc std_happy_byfriend
## <dbl> <dbl>
## 1 0 2.38
## 2 1 2.09
## 3 2 1.84
## 4 3 1.70
## 5 4 1.77
## 6 5 1.56
## 7 6 1.65
Visualisation for Happiness Levels By Education Level
ggplot(mean_edu_happy, aes(x = eduail1, y = mean_happy_byedu)) +
geom_line(color = "skyblue", size = 1) + # Line to show the trend
geom_point(color = "orange", size = 3) + # Points to highlight each year's value
labs(title = "Happiness Levels (2014-2020)" ,
x = "Education Level",
y = "Mean Happiness (0-10 scale)") +
ylim(6,9) +
theme_minimal()
mean_edu_happy %>%
ggplot(aes(x = eduail1, y = mean_happy_byedu)) +
geom_smooth(method = "loess", se = FALSE, color = "grey50") +
geom_point(aes(color = mean_happy_byedu), size = 2.5) +
scale_color_gradient(low = "darkblue", high = "lightblue") +
labs(title = "Average Happiness Levels by Education Level",
x = "Education Level", y = "Average Happiness Level (0-10)") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'