# List of packages
packages <- c("tidyverse", "modelsummary", "forcats", "RColorBrewer", 
              "fst", "viridis", "knitr", "rmarkdown", "ggridges", "viridis", "questionr", "flextable", "infer", "broom", "effects", "sandwich")

# 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)
## ── 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
## Loading required package: viridisLite
## 
## 
## Attaching package: 'flextable'
## 
## 
## The following object is masked from 'package:purrr':
## 
##     compose
## 
## 
## Loading required package: carData
## 
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
## [[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] "rmarkdown"    "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] "ggridges"     "rmarkdown"    "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"    "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"        
## 
## [[11]]
##  [1] "questionr"    "ggridges"     "rmarkdown"    "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] "flextable"    "questionr"    "ggridges"     "rmarkdown"    "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] "infer"        "flextable"    "questionr"    "ggridges"     "rmarkdown"   
##  [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"        
## 
## [[14]]
##  [1] "broom"        "infer"        "flextable"    "questionr"    "ggridges"    
##  [6] "rmarkdown"    "knitr"        "viridis"      "viridisLite"  "fst"         
## [11] "RColorBrewer" "modelsummary" "lubridate"    "forcats"      "stringr"     
## [16] "dplyr"        "purrr"        "readr"        "tidyr"        "tibble"      
## [21] "ggplot2"      "tidyverse"    "stats"        "graphics"     "grDevices"   
## [26] "utils"        "datasets"     "methods"      "base"        
## 
## [[15]]
##  [1] "effects"      "carData"      "broom"        "infer"        "flextable"   
##  [6] "questionr"    "ggridges"     "rmarkdown"    "knitr"        "viridis"     
## [11] "viridisLite"  "fst"          "RColorBrewer" "modelsummary" "lubridate"   
## [16] "forcats"      "stringr"      "dplyr"        "purrr"        "readr"       
## [21] "tidyr"        "tibble"       "ggplot2"      "tidyverse"    "stats"       
## [26] "graphics"     "grDevices"    "utils"        "datasets"     "methods"     
## [31] "base"        
## 
## [[16]]
##  [1] "sandwich"     "effects"      "carData"      "broom"        "infer"       
##  [6] "flextable"    "questionr"    "ggridges"     "rmarkdown"    "knitr"       
## [11] "viridis"      "viridisLite"  "fst"          "RColorBrewer" "modelsummary"
## [16] "lubridate"    "forcats"      "stringr"      "dplyr"        "purrr"       
## [21] "readr"        "tidyr"        "tibble"       "ggplot2"      "tidyverse"   
## [26] "stats"        "graphics"     "grDevices"    "utils"        "datasets"    
## [31] "methods"      "base"
ess <- read_fst("All-ESS-Data.fst")

Data Cleaning

table(ess$essround)
## 
##     1     2     3     4     5     6     7     8     9    10 
## 42359 47537 43000 56752 52458 54673 40185 44387 49519 59685
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]
}
sweden_data <- ess[ess$cntry == "SE", ]
sweden_data_subset <- sweden_data %>%
  filter(essround %in% c("8")) %>%
  select(mbtru, prtvtbse, blgetmg, imsclbn, crmvct, edulvlb) %>%
    mutate(
      current_union_member = case_when(
        mbtru == 1 ~ "Yes",
        mbtru %in% c(7, 8, 9) ~ NA_character_,
        TRUE ~ "No"
      ), 

      voted_right_of_center = case_when(
        prtvtbse %in% c(2, 5, 3, 10) ~ 1,
        prtvtbse %in% c(1, 4, 6, 7, 8, 9, 11) ~ 0,
        prtvtbse %in% c(66, 77, 88, 99) ~ NA_real_,
        TRUE ~ prtvtbse
      ),
      
      lr_scaled_parties = case_when(
        prtvtbse == 1 ~ "Centre",
        prtvtbse == 6 ~ "Centre-left",
        prtvtbse %in% c(2, 5) ~ "Centre-right",
        prtvtbse %in% c(3, 10) ~ "Right",
        prtvtbse %in% c(4, 7, 8) ~ "Left",
        prtvtbse %in% c(9, 11) ~ NA_character_,
        TRUE ~ NA_character_
      ),

      majority_ethnic_group = case_when(
        blgetmg == 2 ~ "Yes",
        blgetmg %in% c(7, 8, 9) ~ NA_character_,
        TRUE ~ "No"
      ), 

      attitude_towards_immigrants = case_when(
        imsclbn == 1 ~ "Immediately",
        imsclbn == 2 ~ "One Year",
        imsclbn == 3 ~ "One Year of Work and Taxation",
        imsclbn == 4 ~ "Citizen",
        imsclbn == 5 ~ "Never",
        imsclbn %in% c(7, 8, 9) ~ NA_character_,
        TRUE ~ NA_character_
      ),

      victim_of_crime = case_when(
        crmvct == 1 ~ "Yes",
        crmvct %in% c(7, 8, 9) ~ NA_character_,
        TRUE ~ "No"
      ))
sweden_data_subset$edulvlb[sweden_data_subset$edulvlb == 5555] <- NA  # Set 'other' as NA in edulvlb
sweden_data_subset <- sweden_data_subset %>%
  mutate(
      educ_level = case_when(
      edulvlb > 600 ~ "BA",
      TRUE ~ "No BA"
      ))
sweden_data_subset$attitude_towards_immigrants <- factor(
  sweden_data_subset$attitude_towards_immigrants,
  levels = c("Immediately", "One Year", "One Year of Work and Taxation", "Citizen", "Never")
  # Note: 'ordered = TRUE' is removed
)

levels(sweden_data_subset$attitude_towards_immigrants)
## [1] "Immediately"                   "One Year"                     
## [3] "One Year of Work and Taxation" "Citizen"                      
## [5] "Never"
sweden_data_subset <- subset(sweden_data_subset, select = -c(mbtru, prtvtbse, blgetmg, imsclbn, crmvct, edulvlb))
table(sweden_data_subset$current_union_member)
## 
##  No Yes 
## 788 757
table(sweden_data_subset$voted_right_of_center)
## 
##   0   1 
## 716 546
table(sweden_data_subset$lr_scaled_parties)
## 
##       Centre  Centre-left Centre-right         Left        Right 
##           81          419          408          204          138
table(sweden_data_subset$majority_ethnic_group)
## 
##   No  Yes 
##   53 1483
table(sweden_data_subset$attitude_towards_immigrants)
## 
##                   Immediately                      One Year 
##                           266                           274 
## One Year of Work and Taxation                       Citizen 
##                           487                           421 
##                         Never 
##                            14
table(sweden_data_subset$victim_of_crime)
## 
##   No  Yes 
## 1178  366
table(sweden_data_subset$educ_level)
## 
##    BA No BA 
##   412  1139

Data Summary Table

prop.table(table(sweden_data_subset$majority_ethnic_group))
## 
##         No        Yes 
## 0.03450521 0.96549479
prop.table(table(sweden_data_subset$current_union_member))
## 
##        No       Yes 
## 0.5100324 0.4899676
prop.table(table(sweden_data_subset$lr_scaled_parties))
## 
##       Centre  Centre-left Centre-right         Left        Right 
##       0.0648       0.3352       0.3264       0.1632       0.1104
prop.table(table(sweden_data_subset$attitude_towards_immigrants))
## 
##                   Immediately                      One Year 
##                   0.181942544                   0.187414501 
## One Year of Work and Taxation                       Citizen 
##                   0.333105335                   0.287961696 
##                         Never 
##                   0.009575923
prop.table(table(sweden_data_subset$victim_of_crime))
## 
##        No       Yes 
## 0.7629534 0.2370466
prop.table(table(sweden_data_subset$Benefits))
## numeric(0)
datasummary_skim(sweden_data_subset)
Unique (#) Missing (%) Mean SD Min Median Max
voted_right_of_center 3 19 0.4 0.5 0.0 0.0 1.0
prop.table(table(sweden_data_subset$educ_level))
## 
##        BA     No BA 
## 0.2656351 0.7343649

Descriptive Visuals

plot_df<- sweden_data_subset %>%
          group_by(current_union_member, lr_scaled_parties)%>%
          summarise(.groups = "drop", count = n())

#remove NA

plot_df <- drop_na(plot_df)

#make sure the variable you want to color by is factor

plot_df$current_union_member <- as.factor(plot_df$current_union_member)
plot_df$lr_scaled_parties <- as.factor(plot_df$lr_scaled_parties)
ggplot(sweden_data_subset, mapping = aes(x = lr_scaled_parties)) +
     geom_bar() +
     theme_minimal() +
     labs(x = "Party Voted For", y = "Number of observations")

ggplot(plot_df, aes(x = lr_scaled_parties, y= count, fill = current_union_member)) +
     geom_bar(stat="identity", position = "dodge2") +
     labs(x = "Party voted", y = "Count", color = "current_union_member", title = "Comparison of Party Vote Choice by Union Membership", fill = "Union Membership") +
     theme(legend.position = "bottom") 

plot_df$lr_scaled_parties <- factor(plot_df$lr_scaled_parties, levels = c("Left", "Centre-left", "Centre", "Centre-right", "Right"))
ggplot(plot_df, aes(x = lr_scaled_parties, y= count, fill = current_union_member)) +
  geom_bar(stat="identity", position = "dodge2") +
  
  # Customize fill colors and add labels to the legend
  scale_fill_manual(values = c("Yes" = "navy", "No" = "lightblue")) +
  
  # Customize other plot elements
    labs(title = "Comparison of Party Vote Choice by Union Membership",
       x = "Party Vote",
       y = "Count",
       color= "Union Membership",
       fill = "Union Membership") +
  
  theme_minimal() + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))

# Display the plot
print(plot)
## function (x, y, ...) 
## UseMethod("plot")
## <bytecode: 0x115057698>
## <environment: namespace:base>

Model Summary Output

model1 <- glm(voted_right_of_center ~ current_union_member, data = sweden_data_subset, family = binomial)

model2 <- glm(voted_right_of_center ~ current_union_member + majority_ethnic_group + attitude_towards_immigrants + victim_of_crime, data = sweden_data_subset, family = binomial)

model3 <- glm(voted_right_of_center ~ current_union_member + majority_ethnic_group + attitude_towards_immigrants + victim_of_crime + majority_ethnic_group*attitude_towards_immigrants, data = sweden_data_subset, family = binomial)

modelsummary(
  list(model1, model2, model3),
  fmt = 1,
  estimate  = c( "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}"),
  statistic = NULL,
  coef_omit = "Intercept")
## Warning in predict.lm(object, newdata, se.fit, scale = 1, type = if (type == :
## prediction from rank-deficient fit; attr(*, "non-estim") has doubtful cases
 (1)   (2)   (3)
current_union_memberYes −0.7 (0.1)*** −0.6 (0.1)*** −0.6 (0.1)***
majority_ethnic_groupYes 0.1 (0.4) 0.1 (0.7)
attitude_towards_immigrantsOne Year 0.6 (0.2)* −0.3 (1.3)
attitude_towards_immigrantsOne Year of Work and Taxation 1.1 (0.2)*** 0.1 (1.0)
attitude_towards_immigrantsCitizen 1.4 (0.2)*** 15.8 (351.2)
attitude_towards_immigrantsNever 0.5 (0.6) 0.5 (0.6)
victim_of_crimeYes 0.2 (0.1) 0.2 (0.1)
majority_ethnic_groupYes × attitude_towards_immigrantsOne Year 0.8 (1.3)
majority_ethnic_groupYes × attitude_towards_immigrantsOne Year of Work and Taxation 1.0 (1.1)
majority_ethnic_groupYes × attitude_towards_immigrantsCitizen −14.5 (351.2)
Num.Obs. 1260 1189 1189
AIC 1690.9 1548.4 1544.2
BIC 1701.1 1589.1 1600.0
Log.Lik. −843.435 −766.214 −761.076
RMSE 0.49 0.48 0.47
model4 <- glm(voted_right_of_center ~ current_union_member, data = sweden_data_subset, family = binomial)

model5 <- glm(voted_right_of_center ~ current_union_member + attitude_towards_immigrants + victim_of_crime, data = sweden_data_subset, family = binomial)

model6 <- glm(voted_right_of_center ~ current_union_member + attitude_towards_immigrants + victim_of_crime + attitude_towards_immigrants*victim_of_crime, data = sweden_data_subset, family = binomial)

modelsummary(
  list(model4, model5, model6),
  fmt = 1,
  estimate  = c( "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}"),
  statistic = NULL,
  coef_omit = "Intercept")
 (1)   (2)   (3)
current_union_memberYes −0.7 (0.1)*** −0.6 (0.1)*** −0.6 (0.1)***
attitude_towards_immigrantsOne Year 0.5 (0.2)* 0.5 (0.3)*
attitude_towards_immigrantsOne Year of Work and Taxation 1.1 (0.2)*** 1.0 (0.2)***
attitude_towards_immigrantsCitizen 1.4 (0.2)*** 1.3 (0.2)***
attitude_towards_immigrantsNever 0.5 (0.6) 0.8 (0.7)
victim_of_crimeYes 0.2 (0.1) 0.1 (0.4)
attitude_towards_immigrantsOne Year × victim_of_crimeYes 0.1 (0.5)
attitude_towards_immigrantsOne Year of Work and Taxation × victim_of_crimeYes 0.1 (0.5)
attitude_towards_immigrantsCitizen × victim_of_crimeYes 0.2 (0.5)
attitude_towards_immigrantsNever × victim_of_crimeYes −1.0 (1.4)
Num.Obs. 1260 1196 1196
AIC 1690.9 1556.7 1563.6
BIC 1701.1 1592.3 1619.6
Log.Lik. −843.435 −771.353 −770.820
RMSE 0.49 0.48 0.48
# Recode the 'attitude_towards_immigrants' into 'Benefits'
sweden_data_subset$Benefits <- recode(
  sweden_data_subset$attitude_towards_immigrants,
  "Immediately" = "Open",
  "One Year" = "Lived",
  "One Year of Work and Taxation" = "Lived",
  "Citizen" = "Restricted",
  "Never" = "Restricted"
)

# Convert 'Benefits' into a factor with the new levels
sweden_data_subset$Benefits <- factor(
  sweden_data_subset$Benefits,
  levels = c("Open", "Lived", "Restricted")
)
model7 <- glm(voted_right_of_center ~ current_union_member, data = sweden_data_subset, family = binomial)

model8 <- glm(voted_right_of_center ~ current_union_member + majority_ethnic_group, data = sweden_data_subset, family = binomial)

model9 <- glm(voted_right_of_center ~ current_union_member + majority_ethnic_group + victim_of_crime + majority_ethnic_group*victim_of_crime, data = sweden_data_subset, family = binomial)

modelsummary(
  list(model7, model8, model9),
  fmt = 1,
  estimate  = c( "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}"),
  statistic = NULL,
  coef_omit = "Intercept")
 (1)   (2)   (3)
current_union_memberYes −0.7 (0.1)*** −0.7 (0.1)*** −0.7 (0.1)***
majority_ethnic_groupYes 0.4 (0.4) 0.6 (0.4)
victim_of_crimeYes 1.1 (0.9)
majority_ethnic_groupYes × victim_of_crimeYes −1.0 (0.9)
Num.Obs. 1260 1253 1252
AIC 1690.9 1682.0 1681.2
BIC 1701.1 1697.4 1706.8
Log.Lik. −843.435 −837.975 −835.578
RMSE 0.49 0.49 0.49
model10 <- glm(voted_right_of_center ~ current_union_member, data = sweden_data_subset, family = binomial)

model11 <- glm(voted_right_of_center ~ current_union_member + Benefits, data = sweden_data_subset, family = binomial)

model12 <- glm(voted_right_of_center ~ current_union_member + Benefits + educ_level + current_union_member*educ_level, data = sweden_data_subset, family = binomial)

modelsummary(
  list(model10, model11, model12),
  fmt = 1,
  estimate  = c( "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}"),
  statistic = NULL,
  coef_omit = "Intercept")
 (1)   (2)   (3)
current_union_memberYes −0.7 (0.1)*** −0.6 (0.1)*** −1.3 (0.2)***
BenefitsLived 0.9 (0.2)*** 0.9 (0.2)***
BenefitsRestricted 1.3 (0.2)*** 1.4 (0.2)***
educ_levelNo BA −0.8 (0.2)***
current_union_memberYes × educ_levelNo BA 0.8 (0.3)**
Num.Obs. 1260 1197 1197
AIC 1690.9 1568.3 1555.9
BIC 1701.1 1588.6 1586.4
Log.Lik. −843.435 −780.138 −771.946
RMSE 0.49 0.48 0.48
exp(coef(model10))
##             (Intercept) current_union_memberYes 
##               1.0912281               0.4986914
exp(coef(model11))
##             (Intercept) current_union_memberYes           BenefitsLived 
##               0.4508285               0.5373787               2.3403837 
##      BenefitsRestricted 
##               3.6510598
exp(coef(model12))
##                             (Intercept)                 current_union_memberYes 
##                               0.8079436                               0.2831048 
##                           BenefitsLived                      BenefitsRestricted 
##                               2.5406705                               4.0510416 
##                         educ_levelNo BA current_union_memberYes:educ_levelNo BA 
##                               0.4276306                               2.2717551

Model Checks

# set graphical parameters
par(mfrow = c(2,2)) # plot 2 X 2 matrix, by row

# plot diagnostics plots
plot(model10, pch = 19, col = scales::alpha("grey", .8), cex = .5)

# set graphical parameters
par(mfrow = c(2,2)) # plot 2 X 2 matrix, by row

# plot diagnostics plots
plot(model11, pch = 19, col = scales::alpha("grey", .8), cex = .5)

# set graphical parameters
par(mfrow = c(2,2)) # plot 2 X 2 matrix, by row

# plot diagnostics plots
plot(model12, pch = 19, col = scales::alpha("grey", .8), cex = .5)

Modelling Visualizations

 models <- list(
   "Model 1" = glm(voted_right_of_center ~ current_union_member, family = binomial, data = sweden_data_subset),
   "Model 2" = glm(voted_right_of_center ~ Benefits, family = binomial, data = sweden_data_subset),
   "Model 3" = glm(voted_right_of_center ~ educ_level, family = binomial, data = sweden_data_subset),
   "Model 4"= glm(voted_right_of_center ~ current_union_member*educ_level, family = binomial, data = sweden_data_subset))
   
modelplot(models, coef_omit = 'Interc')

# We use the "effect" function to call the interaction term from model 3. We assign the results to "effect_plot"
interaction_plot <- effect("current_union_member*educ_level", model12, na.rm=TRUE)

# We plot here the interaction term

plot(interaction_plot,
     main="Interaction effect Union Membership x Education Level",
     xlab="Current Union Member",
     ylab="Voted Right of Centre")

model13 <- glm(voted_right_of_center ~ current_union_member + victim_of_crime + current_union_member*victim_of_crime, family = binomial, data = sweden_data_subset)
# We use the "effect" function to call the interaction term from model 3. We assign the results to "effect_plot"
interaction_plot <- effect("current_union_member*victim_of_crime", model5, na.rm=TRUE)
## NOTE: current_union_member:victim_of_crime does not appear in the model
# We plot here the interaction term

plot(interaction_plot,
     main="Interaction effect Union Membership x Victim of Crime",
     xlab="Union Membership",
     ylab="Voted Right of Centre")

model14 <- glm(voted_right_of_center ~ current_union_member + Benefits + current_union_member*Benefits, family = binomial, data = sweden_data_subset)
# We use the "effect" function to call the interaction term from model 3. We assign the results to "effect_plot"
interaction_plot <- effect("current_union_member*Benefits", model14, na.rm=TRUE)

# We plot here the interaction term

plot(interaction_plot,
     main="Interaction effect Union Membership x Attitudes Toward Immigrant Benefits",
     xlab="Attitude Toward Immigrant Benefits",
     ylab="Voted Right of Centre")