# List of packages
packages <- c("tidyverse", "modelsummary", "forcats", "RColorBrewer", 
              "fst", "viridis", "knitr", "rmarkdown", "ggridges", "viridis", "questionr", "flextable", "infer") # add any you need here

# 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.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
## Loading required package: viridisLite
## 
## 
## Attaching package: 'flextable'
## 
## 
## 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] "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"
setwd("C:/Users/KRonh/OneDrive/Desktop")
ess <- read_fst("All-ESS-Data.fst")
switzerland_data <- ess %>% 
  filter(cntry == "CH")

Satisfaction with life: stflife https://ess.sikt.no/en/datafile/f37d014a-6958-42d4-b03b-17c29e481d3d/256?tab=1&elements=[%225afa13a1-b82b-4d9c-9268-71b4c14424b3/4%22]

Highest level of education acheived: edulvla https://ess.sikt.no/en/datafile/99ba8b91-a921-4a2a-9436-52c536d7ec9d/64?tab=1&elements=[%22f91d542e-4919-4732-a172-43e33610981f/2%22]

How woried about the environemnt: wrclmch https://ess.sikt.no/en/datafile/f37d014a-6958-42d4-b03b-17c29e481d3d/256?tab=1&elements=[%22d4270c20-6480-4652-9a8a-1eec97a9ee6b/4%22]

Coding for our years of interest: 2018-2020

ess$year <- NA
replacements <- c(2018, 2020)
for(i in 1:10){
  ess$year[ess$essround == i] <- replacements[i]
}

table(ess$year) 
## 
##  2018  2020 
## 42359 47537
library(modelsummary)
table(ess$year)
## 
##  2018  2020 
## 42359 47537

Recoding and creating a model summary table

Cleaning and recoding the variables to binary variables in order to code a model summary graph.

switzerland_data <- switzerland_data %>%
  mutate(
    satisfaction = recode(as.character(stflife), 
                 '0' = "dissatisfied", 
                 '1' = "dissatisfied", 
                 '2' = "dissatisfied", 
                 '3' = "dissatisfied", 
                 '4' = "dissatisfied",
                 '5' = "satisfied",
                 '6' = "satisfied",
                 '7' = "satisfied", 
                 '8' = "satisfied", 
                 '9' = "satisfied", 
                 '10'= "satisfied", 
                 '77' = NA_character_, 
                 '88' = NA_character_,
                 '99' = NA_character_),
  
    worried = recode(wrclmch,
                             `1` = "No",
                             `2` = "No", 
                              `3` = "Yes", 
                              `4` = "Yes", 
                              `5` = "Yes", 
                              `6` = NA_character_, 
                             `7` = NA_character_,
                             `8` = NA_character_,
                             `9` = NA_character_), 
    education = recode(eisced, 
                        '1' = "No BA", 
                        '2' = "No BA", 
                        '3' = "No BA", 
                        '4' = "No BA", 
                        '5' = "No BA", 
                        '6' = "BA", 
                        '7' = "BA", 
                        '55' = NA_character_, 
                        '77' = NA_character_, 
                        '88' = NA_character_, 
                        '99' = NA_character_),
  )


table(switzerland_data$worried)
## 
##   No  Yes 
##  568 2441
table(switzerland_data$satisfaction)
## 
## dissatisfied    satisfied 
##          687        16221
table(switzerland_data$education)
## 
##    BA No BA 
##  2826 14041
switzerland_data_summary <- switzerland_data %>%
  mutate(
    stflife = ifelse(stflife %in% c(77, 88, 99), NA, stflife), 
    eisced = ifelse(eisced %in% c(55, 77, 88, 99), NA, eisced), 
    wrclmch = ifelse(wrclmch %in% c(6, 7, 8, 9), NA, wrclmch) 
  ) %>%
   select(stflife, eisced, wrclmch)

datasummary_skim(switzerland_data_summary)
Unique (#) Missing (%) Mean SD Min Median Max
stflife 12 0 8.1 1.7 0.0 8.0 10.0
eisced 8 0 3.8 1.7 1.0 3.0 7.0
wrclmch 6 82 3.2 0.9 1.0 3.0 5.0
switzerland_data %>%
  # Setting values to NA
  mutate(stflife = ifelse(stflife %in% c(77, 88, 99), NA, stflife),
         eisced = ifelse(eisced %in% c(55, 77, 88, 99), NA, eisced), 
         wrclmch = ifelse(wrclmch %in% c(6, 7, 8, 9), NA, wrclmch)) %>%
  select(stflife, eisced, wrclmch) %>%
  gather(variable, value, c(stflife, eisced, wrclmch)) %>%
  ggplot(aes(x = variable, y = value)) +
  geom_boxplot() +
  labs(y = "Y-axis", x = "X-axis", title = "Satisfaction, education, and worried about the environment 2018-2020") +
  theme(legend.position = "none")
## Warning: Removed 13991 rows containing non-finite values (`stat_boxplot()`).

simulating a null hypothesis with confidence intervals

simulating the null

unique(switzerland_data$satisfaction)
## [1] "satisfied"    "dissatisfied" NA
unique(switzerland_data$education)
## [1] "No BA" NA      "BA"
unique(switzerland_data$worried)
## [1] NA    "Yes" "No"
switzerland_data <- switzerland_data %>% filter(!is.na(satisfaction))
switzerland_data <- switzerland_data %>% filter(!is.na(education))
switzerland_data <- switzerland_data %>% filter(!is.na(worried))

unique(switzerland_data$satisfaction)
## [1] "satisfied"    "dissatisfied"
unique(switzerland_data$education)
## [1] "No BA" "BA"
unique(switzerland_data$worried)
## [1] "Yes" "No"
tab_dat <- switzerland_data

mytab <- table(tab_dat$satisfaction, tab_dat$education)

rsums <- rowSums(mytab)

csums <- colSums(mytab)

N <- sum(mytab)

ptab <- tcrossprod(rsums/N, csums/N)
cat("Table of Expected Proportions:\n")
## Table of Expected Proportions:
print(ptab)
##             [,1]      [,2]
## [1,] 0.008929908 0.0294546
## [2,] 0.223713616 0.7379019
ftab <- N * ptab
cat("Table of Expected Frequencies:\n")
## Table of Expected Frequencies:
print(ftab)
##           [,1]       [,2]
## [1,]  26.75401   88.24599
## [2,] 670.24599 2210.75401
alpha <- 0.05 # significance level
c_val <- qchisq(alpha, df = 1, lower.tail = FALSE)
cat("Critical Value:", round(c_val, 3), "\n")
## Critical Value: 3.841
test_stat <- sum((mytab - ftab)^2 / ftab)
cat("Pearson's X^2:", round(test_stat, 4), "\n")
## Pearson's X^2: 8.2396
p_val <- pchisq(test_stat, df = 1, lower.tail = F)
cat("p-value:", round(p_val, 4), "\n")
## p-value: 0.0041
cat("Chi-squared test result:\n")
## Chi-squared test result:
print(chisq.test(mytab, correct = F))
## 
##  Pearson's Chi-squared test
## 
## data:  mytab
## X-squared = 8.2396, df = 1, p-value = 0.004099
test_stat <- switzerland_data %>%
  specify(explanatory = education,
          response = stflife) %>% 
  hypothesize(null = "independence") %>%
  calculate(stat = "t") 
## Warning: The statistic is based on a difference or ratio; by default, for
## difference-based statistics, the explanatory variable is subtracted in the
## order "BA" - "No BA", or divided in the order "BA" / "No BA" for ratio-based
## statistics. To specify this order yourself, supply `order = c("BA", "No BA")`
## to the calculate() function.
print(test_stat$stat)
##        t 
## 1.809364
null_distribution <- switzerland_data %>%
  specify(explanatory = education,
          response = stflife) %>%
  hypothesize(null = "independence") %>%
  generate(reps = 1000, type = "permute") %>% # only line we are adding, use reps = 1000 as standard
  calculate(stat = "t")
## Warning: The statistic is based on a difference or ratio; by default, for
## difference-based statistics, the explanatory variable is subtracted in the
## order "BA" - "No BA", or divided in the order "BA" / "No BA" for ratio-based
## statistics. To specify this order yourself, supply `order = c("BA", "No BA")`
## to the calculate() function.
p_val <- null_distribution %>% 
  get_pvalue(obs_stat = test_stat, direction = "two-sided")

p_val
## # A tibble: 1 × 1
##   p_value
##     <dbl>
## 1   0.072
null_distribution %>%
  visualize() +
  shade_p_value(obs_stat = test_stat, direction = "two-sided")

null_distribution
## Response: stflife (numeric)
## Explanatory: education (factor)
## Null Hypothesis: independence
## # A tibble: 1,000 × 2
##    replicate   stat
##        <int>  <dbl>
##  1         1  1.03 
##  2         2  1.14 
##  3         3 -1.03 
##  4         4 -0.602
##  5         5 -0.276
##  6         6  1.66 
##  7         7  0.748
##  8         8 -1.09 
##  9         9  0.247
## 10        10  0.635
## # ℹ 990 more rows
conf_int <- null_distribution %>%
  get_confidence_interval(level = 0.95, type = "percentile")


null_distribution %>%
  visualize() +
  shade_p_value(obs_stat = test_stat, direction = "two-sided") +
  shade_confidence_interval(endpoints = conf_int)

null_distribution
## Response: stflife (numeric)
## Explanatory: education (factor)
## Null Hypothesis: independence
## # A tibble: 1,000 × 2
##    replicate   stat
##        <int>  <dbl>
##  1         1  1.03 
##  2         2  1.14 
##  3         3 -1.03 
##  4         4 -0.602
##  5         5 -0.276
##  6         6  1.66 
##  7         7  0.748
##  8         8 -1.09 
##  9         9  0.247
## 10        10  0.635
## # ℹ 990 more rows

Satisfaction with life based on how worried about the environment

tab_dat <- switzerland_data

mytab2 <- table(tab_dat$satisfaction, tab_dat$worried)

rsums2 <- rowSums(mytab2)

csums2 <- colSums(mytab2)

N2 <- sum(mytab2)

ptab2 <- tcrossprod(rsums2/N, csums2/N)
cat("Table of Expected Proportions:\n")
## Table of Expected Proportions:
print(ptab2)
##             [,1]       [,2]
## [1,] 0.007238735 0.03114578
## [2,] 0.181346045 0.78026944
ftab2 <- N * ptab2
cat("Table of Expected Frequencies:\n")
## Table of Expected Frequencies:
print(ftab2)
##           [,1]       [,2]
## [1,]  21.68725   93.31275
## [2,] 543.31275 2337.68725
alpha <- 0.05 # significance level
c_val2 <- qchisq(alpha, df = 1, lower.tail = FALSE)
cat("Critical Value:", round(c_val, 3), "\n")
## Critical Value: 3.841
test_stat2 <- sum((mytab2 - ftab2)^2 / ftab2)
cat("Pearson's X^2:", round(test_stat2, 4), "\n")
## Pearson's X^2: 2.355
p_val2 <- pchisq(test_stat2, df = 1, lower.tail = F)
cat("p-value:", round(p_val2, 4), "\n")
## p-value: 0.1249
cat("Chi-squared test result:\n")
## Chi-squared test result:
print(chisq.test(mytab2, correct = F))
## 
##  Pearson's Chi-squared test
## 
## data:  mytab2
## X-squared = 2.355, df = 1, p-value = 0.1249
test_stat2 <- switzerland_data %>%
  specify(explanatory = worried, 
          response = stflife) %>% 
  hypothesize(null = "independence") %>%
  calculate(stat = "t") 
## Warning: The statistic is based on a difference or ratio; by default, for
## difference-based statistics, the explanatory variable is subtracted in the
## order "No" - "Yes", or divided in the order "No" / "Yes" for ratio-based
## statistics. To specify this order yourself, supply `order = c("No", "Yes")` to
## the calculate() function.
print(test_stat2$stat)
##          t 
## -0.7052172
null_distribution2 <- switzerland_data %>%
  specify(explanatory = worried,
          response = stflife) %>%
  hypothesize(null = "independence") %>%
  generate(reps = 1000, type = "permute") %>% 
  calculate(stat = "t")
## Warning: The statistic is based on a difference or ratio; by default, for
## difference-based statistics, the explanatory variable is subtracted in the
## order "No" - "Yes", or divided in the order "No" / "Yes" for ratio-based
## statistics. To specify this order yourself, supply `order = c("No", "Yes")` to
## the calculate() function.
p_val2 <- null_distribution2 %>% 
  get_pvalue(obs_stat = test_stat2, direction = "two-sided") 

p_val2
## # A tibble: 1 × 1
##   p_value
##     <dbl>
## 1   0.486
null_distribution2 %>%
  visualize() +
  shade_p_value(obs_stat = test_stat2, direction = "two-sided")

null_distribution2
## Response: stflife (numeric)
## Explanatory: worried (factor)
## Null Hypothesis: independence
## # A tibble: 1,000 × 2
##    replicate    stat
##        <int>   <dbl>
##  1         1 -0.990 
##  2         2 -0.108 
##  3         3  1.07  
##  4         4 -0.826 
##  5         5 -0.0252
##  6         6 -1.39  
##  7         7 -1.17  
##  8         8 -2.18  
##  9         9 -0.233 
## 10        10  1.19  
## # ℹ 990 more rows
conf_int2 <- null_distribution2 %>%
  get_confidence_interval(level = 0.95, type = "percentile")


null_distribution2 %>%
  visualize() +
  shade_p_value(obs_stat = test_stat2, direction = "two-sided") +
  shade_confidence_interval(endpoints = conf_int) 

null_distribution2
## Response: stflife (numeric)
## Explanatory: worried (factor)
## Null Hypothesis: independence
## # A tibble: 1,000 × 2
##    replicate    stat
##        <int>   <dbl>
##  1         1 -0.990 
##  2         2 -0.108 
##  3         3  1.07  
##  4         4 -0.826 
##  5         5 -0.0252
##  6         6 -1.39  
##  7         7 -1.17  
##  8         8 -2.18  
##  9         9 -0.233 
## 10        10  1.19  
## # ℹ 990 more rows
switzerland_satisfaction <- ess %>%
  select(stflife)

switzerland_satisfaction$y <- switzerland_satisfaction$stflife

table(switzerland_satisfaction$y)
## 
##      0      1      2      3      4      5      6      7      8      9     10 
##   9190   6123  11739  20254  21903  56264  43866  81908 118078  67371  50950 
##     77     88     99 
##    476   1990    443
switzerland_satisfaction$y[switzerland_satisfaction$y %in% 77:99] <- NA

# checking again
table(switzerland_satisfaction$y)
## 
##      0      1      2      3      4      5      6      7      8      9     10 
##   9190   6123  11739  20254  21903  56264  43866  81908 118078  67371  50950
switzerland_education <- ess %>%
  select(eisced)

switzerland_education$y <- switzerland_education$eisced

table(switzerland_education$y)
## 
##     0     1     2     3     4     5     6     7    55    77    88    99 
## 73306 38823 71917 74258 87348 49268 42651 49558  1052   483   497  1394
switzerland_education$y[switzerland_education$y %in% 55:99] <- NA

table(switzerland_education$y)
## 
##     0     1     2     3     4     5     6     7 
## 73306 38823 71917 74258 87348 49268 42651 49558
switzerland_env <- ess %>%
  select(wrclmch)

switzerland_env$y <- switzerland_env$wrclmch

table(switzerland_env$y)
## 
##     1     2     3     4     5     6     7     8     9 
##  4793 16034 44210 28111  7832  1954    63   645   430
switzerland_env$y[switzerland_env$y %in% 6:9] <- NA

table(switzerland_env$y)
## 
##     1     2     3     4     5 
##  4793 16034 44210 28111  7832
switzerland_satisfaction1 <- switzerland_satisfaction %>%
  select(stflife)%>% 
  mutate(satisfaction = stflife) %>%
  mutate(across(c("satisfaction"), ~ 7 - .x ))

switzerland_satisfaction1$satisfaction <- scales::rescale(switzerland_satisfaction1$satisfaction, to=c(0,10), na.rm=T)
ggplot(switzerland_satisfaction1, aes(x = satisfaction)) +
  geom_histogram(bins = 30, fill = "blue", color = "black") +
  theme_minimal() +
  labs(title = "Histogram of Satisfaction Scale",
       x = "Satisfaction Scale",
       y = "Count")

switzerland_data_1 <- switzerland_satisfaction1 %>%
  mutate(
    satisfied = case_when(
      stflife %in% 0:2 ~ "1",
      stflife %in% 3:5 ~ "2",
      stflife %in% 6:8 ~ "3",
      stflife %in% 9:11 ~ "4",
      TRUE ~ as.character(stflife)  
    ),
    # Converting cohort to a factor with labels
    satisfied = factor(stflife,
                 levels = c("1", "2", "3", "4"),
                 labels = c("extremly dissatisfied", "not satisfied", "satisfied", "extremely satisfied"))
  )
model1 <- lm(stflife ~ satisfied, data = switzerland_data_1)
modelsummary(
  list(model1),
  fmt = 1,
  estimate  = c( "{estimate} ({std.error}){stars}"),
  statistic = NULL,
  coef_omit = "Intercept")
 (1)
satisfiednot satisfied 1.0 (0.0)***
satisfiedsatisfied 2.0 (0.0)***
satisfiedextremely satisfied 3.0 (0.0)***
Num.Obs. 60019
R2 1.000
R2 Adj. 1.000
AIC −3200768.9
BIC −3200723.9
Log.Lik. 1600389.448
RMSE 0.00
switzerland_data0 <- switzerland_satisfaction$stflife
switzerland_data0 <- switzerland_education$eisced
switzerland_data0 <- switzerland_env$wrclmch
switzerland_data_2 <- switzerland_education %>%
  mutate(
    edu = case_when(
      eisced %in% 1:2 ~ "1",
      eisced %in% 3:4 ~ "2",
      eisced %in% 5:7 ~ "3",
      TRUE ~ as.character(eisced)  
    ),
    edu = factor(eisced,
                 levels = c("1", "2", "3"),
                 labels = c("low education", "some education", "high education"))
  )

model2 <- lm(eisced ~ edu, data = switzerland_data_2)
switzerland_data_3 <- switzerland_env %>%
  mutate(
    env = case_when(
      wrclmch %in% 1:2 ~ "1",
      wrclmch %in% 3:4 ~ "2",
      wrclmch %in% 5 ~ "3",
      TRUE ~ as.character(wrclmch)
    ),
    env = factor(wrclmch,
                 levels = c("1", "2", "3"),
                 labels = c("low worry", "some worry", "high worry"))
  )

model3 <- lm(wrclmch ~ env, data = switzerland_data_3)
models <- list(
  "Model 1" = lm(stflife ~ satisfied, data = switzerland_data_1), 
  "Model 2" =  lm(eisced ~ edu, data = switzerland_data_2), 
  "Model 3" = lm(wrclmch ~ env, data = switzerland_data_3))

modelplot(models, coef_omit = 'Interc')

modelsummary(models, fmt = 1,
  estimate  = c("{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}"),
  statistic = NULL,
  coef_rename = c("Satisfaction1" = "PSatisfaction"),
  title = 'Table 2. Regression models predicting satisfaction (scale 0 to 100)')
Table 2. Regression models predicting satisfaction (scale 0 to 100)
Model 1  Model 2  Model 3
(Intercept) 1.0 (0.0)*** 1.0 (0.0)*** 1.0 (0.0)***
satisfiednot satisfied 1.0 (0.0)***
satisfiedsatisfied 2.0 (0.0)***
satisfiedextremely satisfied 3.0 (0.0)***
edusome education 1.0 (0.0)***
eduhigh education 2.0 (0.0)***
envsome worry 1.0 (0.0)***
envhigh worry 2.0 (0.0)***
Num.Obs. 60019 184998 65037
R2 1.000 1.000 1.000
R2 Adj. 1.000 1.000 1.000
AIC −3200768.9 −9176860.3 −3319798.9
BIC −3200723.9 −9176819.7 −3319762.6
Log.Lik. 1600389.448 4588434.129 1659903.474
RMSE 0.00 0.00 0.00