packages <- c("tidyverse", "infer", "fst", "modelsummary", "effects", "survey", "MASS", "kableExtra", "flextable", "equatiomatic", "sjPlot", "tinytex", "officer", "flextable", "ggplot2")
new_packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new_packages)) install.packages(new_packages)
lapply(packages, library, character.only = TRUE)
## ── 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.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ 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 'effects' was built under R version 4.3.2
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.3.2
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
## Warning: package 'survey' was built under R version 4.3.2
## Loading required package: grid
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
##
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
##
## Loading required package: survival
##
## Attaching package: 'survey'
##
## The following object is masked from 'package:graphics':
##
## dotchart
##
##
## Attaching package: 'MASS'
##
## The following object is masked from 'package:dplyr':
##
## select
##
##
## Attaching package: 'kableExtra'
##
## The following object is masked from 'package:dplyr':
##
## group_rows
##
##
## Attaching package: 'flextable'
##
## The following objects are masked from 'package:kableExtra':
##
## as_image, footnote
##
## The following object is masked from 'package:purrr':
##
## compose
## Warning: package 'sjPlot' was built under R version 4.3.2
## [[1]]
## [1] "lubridate" "forcats" "stringr" "dplyr" "purrr" "readr"
## [7] "tidyr" "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [13] "grDevices" "utils" "datasets" "methods" "base"
##
## [[2]]
## [1] "infer" "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [7] "readr" "tidyr" "tibble" "ggplot2" "tidyverse" "stats"
## [13] "graphics" "grDevices" "utils" "datasets" "methods" "base"
##
## [[3]]
## [1] "fst" "infer" "lubridate" "forcats" "stringr" "dplyr"
## [7] "purrr" "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [13] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
## [19] "base"
##
## [[4]]
## [1] "modelsummary" "fst" "infer" "lubridate" "forcats"
## [6] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [11] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [16] "grDevices" "utils" "datasets" "methods" "base"
##
## [[5]]
## [1] "effects" "carData" "modelsummary" "fst" "infer"
## [6] "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [11] "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [16] "stats" "graphics" "grDevices" "utils" "datasets"
## [21] "methods" "base"
##
## [[6]]
## [1] "survey" "survival" "Matrix" "grid" "effects"
## [6] "carData" "modelsummary" "fst" "infer" "lubridate"
## [11] "forcats" "stringr" "dplyr" "purrr" "readr"
## [16] "tidyr" "tibble" "ggplot2" "tidyverse" "stats"
## [21] "graphics" "grDevices" "utils" "datasets" "methods"
## [26] "base"
##
## [[7]]
## [1] "MASS" "survey" "survival" "Matrix" "grid"
## [6] "effects" "carData" "modelsummary" "fst" "infer"
## [11] "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [16] "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [21] "stats" "graphics" "grDevices" "utils" "datasets"
## [26] "methods" "base"
##
## [[8]]
## [1] "kableExtra" "MASS" "survey" "survival" "Matrix"
## [6] "grid" "effects" "carData" "modelsummary" "fst"
## [11] "infer" "lubridate" "forcats" "stringr" "dplyr"
## [16] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [21] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [26] "datasets" "methods" "base"
##
## [[9]]
## [1] "flextable" "kableExtra" "MASS" "survey" "survival"
## [6] "Matrix" "grid" "effects" "carData" "modelsummary"
## [11] "fst" "infer" "lubridate" "forcats" "stringr"
## [16] "dplyr" "purrr" "readr" "tidyr" "tibble"
## [21] "ggplot2" "tidyverse" "stats" "graphics" "grDevices"
## [26] "utils" "datasets" "methods" "base"
##
## [[10]]
## [1] "equatiomatic" "flextable" "kableExtra" "MASS" "survey"
## [6] "survival" "Matrix" "grid" "effects" "carData"
## [11] "modelsummary" "fst" "infer" "lubridate" "forcats"
## [16] "stringr" "dplyr" "purrr" "readr" "tidyr"
## [21] "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [26] "grDevices" "utils" "datasets" "methods" "base"
##
## [[11]]
## [1] "sjPlot" "equatiomatic" "flextable" "kableExtra" "MASS"
## [6] "survey" "survival" "Matrix" "grid" "effects"
## [11] "carData" "modelsummary" "fst" "infer" "lubridate"
## [16] "forcats" "stringr" "dplyr" "purrr" "readr"
## [21] "tidyr" "tibble" "ggplot2" "tidyverse" "stats"
## [26] "graphics" "grDevices" "utils" "datasets" "methods"
## [31] "base"
##
## [[12]]
## [1] "tinytex" "sjPlot" "equatiomatic" "flextable" "kableExtra"
## [6] "MASS" "survey" "survival" "Matrix" "grid"
## [11] "effects" "carData" "modelsummary" "fst" "infer"
## [16] "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [21] "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [26] "stats" "graphics" "grDevices" "utils" "datasets"
## [31] "methods" "base"
##
## [[13]]
## [1] "officer" "tinytex" "sjPlot" "equatiomatic" "flextable"
## [6] "kableExtra" "MASS" "survey" "survival" "Matrix"
## [11] "grid" "effects" "carData" "modelsummary" "fst"
## [16] "infer" "lubridate" "forcats" "stringr" "dplyr"
## [21] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [26] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [31] "datasets" "methods" "base"
##
## [[14]]
## [1] "officer" "tinytex" "sjPlot" "equatiomatic" "flextable"
## [6] "kableExtra" "MASS" "survey" "survival" "Matrix"
## [11] "grid" "effects" "carData" "modelsummary" "fst"
## [16] "infer" "lubridate" "forcats" "stringr" "dplyr"
## [21] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [26] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [31] "datasets" "methods" "base"
##
## [[15]]
## [1] "officer" "tinytex" "sjPlot" "equatiomatic" "flextable"
## [6] "kableExtra" "MASS" "survey" "survival" "Matrix"
## [11] "grid" "effects" "carData" "modelsummary" "fst"
## [16] "infer" "lubridate" "forcats" "stringr" "dplyr"
## [21] "purrr" "readr" "tidyr" "tibble" "ggplot2"
## [26] "tidyverse" "stats" "graphics" "grDevices" "utils"
## [31] "datasets" "methods" "base"
ess <- read_fst("All-ESS-Data.fst")
ess$year <- NA
replacements <- c(2002, 2004, 2006, 2008, 2010, 2012, 2014, 2016, 2018, 2020)
for(i in 1:10){
ess$year[ess$essround == i] <- replacements[i]
}
This is the summary table for table 1 in the context section. The predictors of income and education were turn into binary. For income it is the top 10% of earners versus the bottom 90% of earners to be consistent with the existing literature. For education is it those who have a BA versus those who don’t. ESS data from 2008 onwards was used as prior ESS had categories for income instead of deciles. Part ID was already a binary although it was cleaned into 0 and 1. Therefore all predictors cleaned up were already numeric & did not need to be converted.
poland_data <- ess %>%
filter(cntry == "PL")
working_poland_data <- poland_data
working_poland_data <- poland_data %>%
filter(year > 2007) %>%
mutate(
HighIncome = case_when(
hinctnta %in% 1:9 ~ 0,
hinctnta %in% 10 ~ 1,
hinctnta %in% c(77, 88, 99) ~ NA
),
HaveBA = case_when(
edulvlb %in% 0:520 ~ 0,
edulvlb %in% 610:800 ~ 1,
edulvlb %in% c(5555, 7777, 8888, 9999) ~ NA,
edulvla %in% 0:4 ~ 0,
edulvla %in% 5 ~ 1,
edulvla %in% c(55, 77, 88, 99) ~ NA
),
PartyID = case_when(
clsprty %in% 1 ~ 1,
clsprty %in% 2 ~ 0,
clsprty %in% c(7, 8, 9) ~ NA
)
)
working_poland_data <- working_poland_data %>% filter(!is.na(HighIncome))
working_poland_data <- working_poland_data %>% filter(!is.na(HaveBA))
working_poland_data <- working_poland_data %>% filter(!is.na(PartyID))
wnum_poland_data <- working_poland_data
table1 <- datasummary_skim(wnum_poland_data %>%
dplyr::select(HighIncome, HaveBA, PartyID),
title = "Table 1. Summary Statistics",
output = "flextable")
## Warning: The histogram argument is only supported for (a) output types "default",
## "html", "kableExtra", or "gt"; (b) writing to file paths with extensions
## ".html", ".jpg", or ".png"; and (c) Rmarkdown, knitr or Quarto documents
## compiled to PDF (via kableExtra) or HTML (via kableExtra or gt). Use
## `histogram=FALSE` to silence this warning.
table1
| Unique (#) | Missing (%) | Mean | SD | Min | Median | Max |
|---|---|---|---|---|---|---|---|
HighIncome | 2 | 0 | 0.1 | 0.3 | 0.0 | 0.0 | 1.0 |
HaveBA | 2 | 0 | 0.2 | 0.4 | 0.0 | 0.0 | 1.0 |
PartyID | 2 | 0 | 0.3 | 0.5 | 0.0 | 0.0 | 1.0 |
flextable::save_as_docx(table1, path = "Table1.docx",
width = 7.0, height = 7.0)
set_flextable_defaults(fonts_ignore=TRUE)
These are supplementary tables used to keep track of n while coding and not used in the poster.
table(working_poland_data$HighIncome, working_poland_data$year)
##
## 2008 2010 2012 2014 2016 2018 2020
## 0 1104 1195 1370 1093 1170 827 1379
## 1 179 101 93 92 83 73 170
questionr::freq(working_poland_data$HighIncome)
## n % val%
## 0 8138 91.1 91.1
## 1 791 8.9 8.9
table(poland_data$hinctnta, poland_data$year) %>% questionr::cprop()
##
## 2008 2010 2012 2014 2016 2018 2020 All
## 1 4.3 6.9 7.6 8.4 7.1 5.5 6.8 6.7
## 2 4.9 7.9 8.0 7.0 7.0 4.2 9.0 7.0
## 3 8.5 9.4 8.2 8.1 8.1 7.1 7.3 8.1
## 4 9.2 9.1 9.3 8.8 8.7 7.4 8.2 8.7
## 5 6.7 7.3 11.1 7.3 10.0 7.1 7.4 8.2
## 6 8.5 8.6 8.4 8.0 8.5 9.1 7.3 8.3
## 7 7.6 7.7 8.0 7.4 8.6 6.7 7.3 7.6
## 8 9.2 6.9 6.0 8.2 7.0 5.5 7.8 7.2
## 9 10.4 5.5 7.0 5.6 5.4 3.8 7.1 6.5
## 10 11.1 5.9 4.9 5.7 4.9 5.1 8.3 6.6
## 77 10.4 13.4 12.4 15.6 16.0 27.1 14.5 15.4
## 88 8.8 11.1 9.0 9.7 8.4 11.6 0.0 8.1
## 99 0.4 0.4 0.3 0.1 0.4 0.0 9.1 1.8
## Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0
wnum_poland_data$partyid %>%
questionr::freq()
## [1] n % val%
## <0 rows> (or 0-length row.names)
wnum_poland_data$year %>%
questionr::freq()
## n % val%
## 2008 1283 14.4 14.4
## 2010 1296 14.5 14.5
## 2012 1463 16.4 16.4
## 2014 1185 13.3 13.3
## 2016 1253 14.0 14.0
## 2018 900 10.1 10.1
## 2020 1549 17.3 17.3
This is the log regression models and odds ratio for the predictors of time, education, and income to analyze the hypotheses with, it is for Table 2 under Findings. There is also a calculation for each odds ratio of interest that is Table 2 under Findings. And a visualization of all odds ratios that is Figure 1 under Findings. Please see poster for the actual analyses of the odds ratios.
results <- glm(formula = PartyID ~ Yearfrom2008 * HighIncome * HaveBA, family = binomial(link = "logit"),
data = wnum_poland_data %>%
mutate(Yearfrom2008=year - 2008))
summary(results)
##
## Call:
## glm(formula = PartyID ~ Yearfrom2008 * HighIncome * HaveBA, family = binomial(link = "logit"),
## data = wnum_poland_data %>% mutate(Yearfrom2008 = year -
## 2008))
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.247056 0.049727 -25.078 < 2e-16 ***
## Yearfrom2008 0.083311 0.006712 12.412 < 2e-16 ***
## HighIncome 0.508974 0.187345 2.717 0.00659 **
## HaveBA 0.497935 0.115243 4.321 1.56e-05 ***
## Yearfrom2008:HighIncome -0.070312 0.026764 -2.627 0.00861 **
## Yearfrom2008:HaveBA -0.040061 0.014619 -2.740 0.00614 **
## HighIncome:HaveBA -0.301562 0.268718 -1.122 0.26177
## Yearfrom2008:HighIncome:HaveBA 0.095928 0.036564 2.624 0.00870 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 11468 on 8928 degrees of freedom
## Residual deviance: 11229 on 8921 degrees of freedom
## AIC: 11245
##
## Number of Fisher Scoring iterations: 4
odds_ratio1 <- exp(0.083311)
odds_ratio4 <- exp(-0.070312)
odds_ratio5 <- exp(-0.040061)
odds_ratio7 <- exp(0.095928)
cat("Odds Ratio of Time:", odds_ratio1, "\n")
## Odds Ratio of Time: 1.08688
cat("Odds Ratio of Time and Income:", odds_ratio4, "\n")
## Odds Ratio of Time and Income: 0.932103
cat("Odds Ratio of Time and Education:", odds_ratio5, "\n")
## Odds Ratio of Time and Education: 0.9607308
cat("Odds Ratio of Time, Education, and Income:", odds_ratio7, "\n")
## Odds Ratio of Time, Education, and Income: 1.10068
sjPlot::plot_model(results, type = "std", show.p = TRUE)