Libraries

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ 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
library(here)
here() starts at /Users/ethanmilne/Documents/GitHub/ApproachingSignificance
library(ggtext)
library(marginaleffects)
library(margins)
library(gtsummary)
library(webshot2)
library(gt)
library(ggpubr)

Load Data

LW_Raw <- read_csv(here(getwd(), "Data", "lw_qualtrics_clean.csv"))
Rows: 401 Columns: 19
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (19): PID, LWA_13_1, LWA_13_2, LWA_13_3, LWA_13_4, LWA_13_5, LWA_13_6, L...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
RW_Raw <- read_csv(here(getwd(), "Data", "rw_qualtrics_clean.csv"))
Rows: 401 Columns: 28
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (28): PID, RWA_1, RWA_2, RWA_3, RWA_4, RWA_5, RWA_6, RWA_7, RWA_8, RWA_9...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Cleaning

Left-wing

LW_Clean <- LW_Raw |>
  mutate(across(
    starts_with(c("LWA", "intentharmblame")),
    ~ case_when(
      . == "Strongly disagree" ~ 1,
      . == "Disagree" ~ 2,
      . == "Somewhat disagree" ~ 3,
      . == "Neither agree nor disagree" ~ 4,
      . == "Somewhat agree" ~ 5,
      . == "Agree" ~ 6,
      . == "Strongly agree" ~ 7
    )
  )) |>
  mutate(
    DV = case_when(
      DV == "Definitely not" ~ 1,
      DV == "Probably not" ~ 2,
      DV == "Maybe not" ~ 3,
      DV == "Might or might not" ~ 4,
      DV == "Maybe yes" ~ 5,
      DV == "Probably yes" ~ 6,
      DV == "Definitely yes" ~ 7
    )
  ) |>
  mutate(
    AHA = (LWA_13_1 + LWA_13_2 + LWA_13_3 + LWA_13_4)/4,
    AC = (LWA_13_5 + LWA_13_6 + LWA_13_7 + LWA_13_8)/4,
    TDC = (LWA_13_9 + LWA_13_10 + LWA_13_11 + LWA_13_12 + LWA_13_13)/5,
    LWA = (AHA + AC + TDC)/3
  ) |>
  mutate(
    politics = "Left"
  ) |>
  rename(
    authoritarianism = LWA
  ) |>
  select(
    c(PID, politics, authoritarianism, Stories_DO, DV)
  ) |>
  mutate(
    Congruence = ifelse(Stories_DO == "Left_Wing_Issue", 1, 0)
  )

RWA

RW_Clean <- RW_Raw |>
  mutate(across(
    starts_with(c("RWA", "intentharmblame")),
    ~ case_when(
      . == "Strongly disagree" ~ 1,
      . == "Disagree" ~ 2,
      . == "Somewhat disagree" ~ 3,
      . == "Neither agree nor disagree" ~ 4,
      . == "Somewhat agree" ~ 5,
      . == "Agree" ~ 6,
      . == "Strongly agree" ~ 7
    )
  )) |>
  mutate(
    DV = case_when(
      DV == "Definitely not" ~ 1,
      DV == "Probably not" ~ 2,
      DV == "Maybe not" ~ 3,
      DV == "Might or might not" ~ 4,
      DV == "Maybe yes" ~ 5,
      DV == "Probably yes" ~ 6,
      DV == "Definitely yes" ~ 7
    )
  ) |>
  mutate(
    RWA_4 = 8 - RWA_4,
    RWA_6 = 8 - RWA_6,
    RWA_8 = 8 - RWA_8,
    RWA_9 = 8 - RWA_9,
    RWA_11 = 8 - RWA_11,
    RWA_13 = 8 - RWA_13,
    RWA_15 = 8 - RWA_15,
    RWA_18 = 8 - RWA_18,
    RWA_20 = 8 - RWA_20,
    RWA_21 = 8 - RWA_21,
    RWA = (RWA_1 + RWA_2 + RWA_3 + RWA_4 + RWA_5 + RWA_6 + RWA_7 + RWA_8 +
             RWA_9 + RWA_10 + RWA_11 + RWA_12 + RWA_13 + RWA_14 + RWA_15 + RWA_16 +
             RWA_17 + RWA_18 + RWA_19 + RWA_20 + RWA_21 + RWA_22)/22
  ) |>
  mutate(
    politics = "Right"
  ) |>
  rename(
    authoritarianism = RWA
  ) |>
  select(
    c(PID, politics, authoritarianism, Stories_DO, DV)
  ) |>
  mutate(
    Congruence = ifelse(Stories_DO == "Right_Wing_Issue", 1, 0)
  ) 

Analysis

Regression Models

RW_np <- lm(DV ~ authoritarianism, data = RW_Clean)
RW_wp <- lm(DV ~ authoritarianism*Congruence, data = RW_Clean)
LW_np <- lm(DV ~ authoritarianism, data = LW_Clean)
LW_wp <- lm(DV ~ authoritarianism*Congruence, data = LW_Clean)

Anovas

RW_anova <- anova(RW_np, RW_wp) 
LW_anova <- anova (LW_np, LW_wp)

Marginal Effects Comparisons

LW_marginal_comparison <- comparisons(
    LW_wp,
    newdata = datagrid(Congruence = 1:0),
    variables = "authoritarianism",
    hypothesis = "pairwise")

RW_marginal_comparison <- comparisons(
    RW_wp,
    newdata = datagrid(Congruence = 1:0),
    variables = "authoritarianism",
    hypothesis = "pairwise")

Tables

LW_np_tab <- gtsummary::tbl_regression(LW_np) |>
  gtsummary::add_glance_table(include = c("adj.r.squared", nobs)) |>
  modify_column_hide(columns = ci)

LW_wp_tab <- gtsummary::tbl_regression(LW_wp) |>
  gtsummary::add_glance_table(include = c("adj.r.squared", nobs)) |>
  modify_column_hide(columns = ci)

RW_np_tab <- gtsummary::tbl_regression(RW_np) |>
  gtsummary::add_glance_table(include = c("adj.r.squared", nobs)) |>
  modify_column_hide(columns = ci)

RW_wp_tab <- gtsummary::tbl_regression(RW_wp) |>
  gtsummary::add_glance_table(include = c("adj.r.squared", nobs)) |>
  modify_column_hide(columns = ci)

study3_table <- tbl_merge(list(LW_np_tab, LW_wp_tab, RW_np_tab, RW_wp_tab),
tab_spanner = c("**Unpooled** ", "**Pooled** ",
"**Unpooled**", "**Pooled**")) |>
  modify_table_body(~.x |> arrange(row_type == "glance_statistic")) |>
  modify_footnote(everything() ~ NA, abbreviation = TRUE) |>
  as_gt() |> 
  text_case_match(
    "authoritarianism" ~ "Authoritarianism",
    "authoritarianism * Congruence" ~ "Authoritarianism * Congruence"
  ) |>
    tab_spanner(
    label = md("**Liberals**"),
    spanners = c("**Unpooled** ", "**Pooled** "
    )
  ) |>
    tab_spanner(
    label = md("**Conservatives**"),
    spanners = c("**Unpooled**", "**Pooled**"
    )
  ) |>
    tab_options(table.font.names = "Times New Roman")

study3_table

Liberals

Conservatives

Characteristic

Unpooled

Pooled

Unpooled

Pooled

Beta

p-value

Beta

p-value

Beta

p-value

Beta

p-value

Authoritarianism -0.02 0.8 -0.21 0.11 0.45 <0.001 0.02 0.8
Congruence

-0.40 0.6

-1.4 0.070
Authoritarianism * Congruence

0.47 0.013

0.80 <0.001
Adjusted R² -0.002
0.124
0.044
0.304
No. Obs. 401
401
401
401
gtsave(study3_table, file = here(getwd(), "Outputs", "study3_table.png"))

Graphs

Additional Data Cleaning

LW_pooled <- summary(margins(LW_np)) |>
  mutate(sample = "Left Wing Authoritarianism",
         method = "Pooled")

LW_congruent <- summary(margins(LW_wp,
                                variables = "authoritarianism",
                                at = list(Congruence = 1))) |>
  select(-Congruence) |>
  mutate(sample = "Left Wing Authoritarianism",
         method = "Congruent")

LW_incongruent <- summary(margins(LW_wp,
                                  variables = "authoritarianism",
                                  at = list(Congruence = 0))) |>
  select(-Congruence) |>
  mutate(sample = "Left Wing Authoritarianism",
         method = "Incongruent")

RW_pooled <- summary(margins(RW_np)) |>
  mutate(sample = "Right Wing Authoritarianism",
         method = "Pooled")

RW_congruent <- summary(margins(RW_wp,
                                variables = "authoritarianism",
                                at = list(Congruence = 1))) |>
  select(-Congruence) |>
  mutate(sample = "Right Wing Authoritarianism",
         method = "Congruent")

RW_incongruent <- summary(margins(RW_wp,
                                  variables = "authoritarianism",
                                  at = list(Congruence = 0))) |>
  select(-Congruence) |>
  mutate(sample = "Right Wing Authoritarianism",
         method = "Incongruent")

marginal_means <- rbind(LW_pooled, LW_congruent) |>
  rbind(LW_incongruent) |>
  rbind(RW_pooled) |>
  rbind(RW_congruent) |>
  rbind(RW_incongruent)

Marginal Effects Graph

marginal_means |>
  mutate(
    method = fct_relevel(method, "Pooled", "Incongruent", "Congruent")
  ) |>
ggplot(aes(x = method, y = AME, col = sample)) +
  geom_pointrange(aes(ymin = lower, ymax = upper)) +
  facet_wrap(~sample) +
  ggpubr::theme_pubr() +
  geom_hline(yintercept = 0, linetype = "dashed") +
  scale_colour_manual(values=c("black", "black")) +
  theme(axis.text.x = ggtext::element_markdown(),
        legend.position="none") +
  labs(
    y = "Average Marginal Effect",
    x = "Stimuli Political Valence"
  ) 

ggsave(filename = here(getwd(), "Outputs", "study3_graph.png"), height=5, width=8, dpi=300)