Data Cleaning:

france_data <- ess %>%
  filter(cntry == "FR")

france_data <- france_data %>%
    mutate(year = case_when(
    essround == 1 ~ 2002,
    essround == 2 ~ 2004,
    essround == 3 ~ 2006,
    essround == 4 ~ 2008,
    essround == 5 ~ 2010,
    essround == 6 ~ 2012,
    essround == 7 ~ 2014,
    essround == 8 ~ 2016,
    essround == 9 ~ 2018,
    essround == 10 ~ 2020,
    TRUE ~ NA_real_
  ))


france_data <- ess %>%
  filter(cntry == "FR") %>%
  mutate(
    pplfair = ifelse(pplfair %in% c(77, 88, 99), NA_real_, pplfair),
    stfdem = ifelse(stfdem %in% c(77, 88, 99), NA_real_, stfdem)) %>%
  filter(!is.na(pplfair) & !is.na(stfdem))

france_data <- france_data %>%
  mutate(
    edulvla = case_when(
      essround < 5 & edulvla == 55 ~ NA_character_,
      TRUE ~ as.character(edulvla)
    ),
    edulvlb = case_when(
      essround >= 5 & edulvlb == 5555 ~ NA_character_,
      TRUE ~ as.character(edulvlb)
    ),
    educ_level = case_when(
      essround < 5 & edulvla == 5 ~ "No BA",  # Assign "No BA"
      essround >= 5 & edulvlb > 600 ~ "No BA",  # Assign "No BA"
      TRUE ~ "BA"  # Assign "BA"
    )
  )

france_data <- france_data %>%
  mutate(
    edulvla = case_when(
      essround < 5 & edulvla == 55 ~ NA_character_,
      TRUE ~ as.character(edulvla)
    ),
    edulvlb = case_when(
      essround >= 5 & edulvlb == 5555 ~ NA_character_,
      TRUE ~ as.character(edulvlb)
    ),
    educ_level = case_when(
      essround < 5 & edulvla == 5 ~ "No BA",
      essround >= 5 & edulvlb > 600 ~ "No BA",
      TRUE ~ "BA"
    ),
    ba_indicator = case_when(
      educ_level == "BA" ~ 1,
      educ_level == "No BA" ~ 2,
      TRUE ~ NA_integer_
    )
  )

unique(france_data$ba_indicator)
## [1] 1 2
unique(france_data$educ_level)
## [1] "BA"    "No BA"
unique(france_data$pplfair)
##  [1]  5  9 10  7  6  4  8  3  2  0  1
unique(france_data$stfdem)
##  [1]  7  3  0  5  8  2  4  6 10  9  1

Data Summary Table

france_data <- france_data %>%
  mutate('Trust in People' = pplfair)

france_data <- france_data %>%
  mutate('Satisfaction with Democracy' = stfdem)
france_data <- france_data %>%
  mutate('BA [1] or No BA [2]' = ba_indicator)

datasummary_skim(france_data %>% 
                   select('Trust in People', 'Satisfaction with Democracy', 'BA [1] or No BA [2]'),
                 title = "Figure 1: Descriptive Statistics of Variables")
Figure 1: Descriptive Statistics of Variables
Unique (#) Missing (%) Mean SD Min Median Max
Trust in People 11 0 5.8 2.1 0.0 6.0 10.0
Satisfaction with Democracy 11 0 4.6 2.4 0.0 5.0 10.0
BA [1] or No BA [2] 2 0 1.2 0.4 1.0 1.0 2.0
unique(france_data$'Education Level')
## NULL

Hypothesis Testing

t_test_result <- t.test(stfdem ~ educ_level, data = france_data)

# I chose this test statistic as my response variable is a numeric variable and my explanatory variable is categorical.

print(t_test_result)
## 
##  Welch Two Sample t-test
## 
## data:  stfdem by educ_level
## t = -18.169, df = 7029.2, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group BA and group No BA is not equal to 0
## 95 percent confidence interval:
##  -0.8305445 -0.6687805
## sample estimates:
##    mean in group BA mean in group No BA 
##            4.443495            5.193158
# This score of -18.169 indicates a significant level of difference between satisfaction with democracy between those who do and do not have a BA. This is evidence against the null hypothesis.

t_test_num <- -18.169

null_distribution <- france_data %>%
  specify(explanatory = educ_level,
          response = stfdem) %>%
  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 "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 = t_test_num, direction = "two-sided")
## Warning: Please be cautious in reporting a p-value of 0. This result is an
## approximation based on the number of `reps` chosen in the `generate()` step.
## See `?get_p_value()` for more information.
null_distribution %>%
  visualize() +
  shade_p_value(obs_stat = t_test_num, direction = "two-sided")

conf_int <- null_distribution %>%
  get_confidence_interval(level = 0.95, type = "percentile")


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

# After all of the testing, we have enough evidence to reject the null hypothesis given the visualization and the scores received. This means there must be a correlation between education and satisfaction with democracy.

Regression Modelling

model1 <- lm(stfdem ~ educ_level, data = france_data)

coefficients <- coef(model1)
print(coefficients)
##     (Intercept) educ_levelNo BA 
##       4.4434950       0.7496625
# If a person has a BA, their predicted satisfaction with democracy is to be 4.44 or slightly dissatisfied. Having no BA is associated with a 0.75 drop in the predicted value compared to having a BA, coming to 3.69.

models <- list(
   "Model 1" = lm(stfdem ~ educ_level, data = france_data, weights = weight),
   "Model 2" = lm(stfdem ~ educ_level + pplfair, data = france_data, weights = weight))
   
modelplot(models, coef_omit = 'Interc')

modelsummary(
  models,
  fmt = 1,
  estimate = c("{estimate} ({std.error}){stars}",
               "{estimate} ({std.error}){stars}"),
  statistic = NULL,
  title = 'Table 2. Regression models predicting satisfaction with democracy (0 to 100)'
)
Table 2. Regression models predicting satisfaction with democracy (0 to 100)
Model 1  Model 2
(Intercept) 4.0 (0.1)*** 2.1 (0.2)***
educ_levelNo BA 1.1 (0.1)*** 0.8 (0.1)***
pplfair 0.3 (0.0)***
Num.Obs. 1891 1891
R2 0.027 0.103
R2 Adj. 0.026 0.102
AIC 9204.2 9051.2
BIC 9220.8 9073.4
Log.Lik. −4599.100 −4521.622
RMSE 2.44 2.38

Interaction Effect

model3 <- lm(stfdem ~ educ_level * pplfair, data = france_data, weights = weight)
interaction_plot <- effect("educ_level:pplfair", model3)

plot(interaction_plot,
     main="Interaction Effect",
     xlab="Satisfaction With Democracy",
     ylab="Trust in People")

# The interaction Effect model provides visual evidence that there is an interaction between the variables. The unparalleled lines provide this evidence, particularly so with those who do not have a BA.