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(readxl)
library(tibble)
library(gt)

Load Data

raw_data <- read.csv(here(getwd(), "Data", "clean.csv"))
email_list <- read_excel(here(getwd(), "Data", "final_email_list.xlsx"))

Results storage

study2_results <- list()

study2_results[["raw_data"]] <- raw_data
study2_results[["email_list"]] <- email_list

Clean Data

analysis_data <- raw_data |>
  mutate(across(
    starts_with("Politics"),
    ~ case_when(
      . == "Very conservative" ~ 1,
      . == "Conservative" ~ 2,
      . == "Somewhat conservative" ~ 3,
      . == "Neither liberal nor conservative" ~ 4,
      . == "Somewhat liberal" ~ 5,
      . == "Liberal" ~ 6,
      . == "Very liberal" ~ 7
    )
  )) |>
  mutate(across(
    starts_with("definition_ranking"),
    ~ case_when(
      . == "Definitely not important" ~ 1,
      . == "Somewhat not important" ~ 2,
      . == "Neither important nor unimportant" ~ 3,
      . == "Somewhat important" ~ 4,
      . == "Definitely important" ~ 5
    )
  )) |>
  mutate(across(
    c(starts_with("Stimuli.Selection"), starts_with("Peer.report"),
      starts_with("Self.report")),
    ~ case_when(
      . == "Strongly disagree" ~ 1,
      . == "Disagree" ~ 2,
      . == "Somewhat disagree" ~ 3,
      . == "Neither agree nor disagree" ~ 4,
      . == "Somewhat agree" ~ 5,
      . == "Agree" ~ 6,
      . == "Strongly agree" ~ 7
    )
  )) |>
  mutate(#reverse coding item 1
    Peer.report_1 = 8 - Peer.report_1,
    Self.report_1 = 8 - Self.report_1
  ) |>
  select(
    c(Gender, Age, Position, starts_with("Politics_"), 
      starts_with("definition_ranking"), starts_with("Stimuli.Selection"),
      starts_with("Peer.report"), starts_with("Self.report"))
  )

Demographics

demographic_data <- analysis_data |>
  select(Gender, Age, Position) |>
  pivot_longer(c(Gender, Age, Position)) |>
  group_by(name, value) |>
  summarize(
    n = n()
    ) |>
  mutate(
       n = case_when(
      name == "Age" ~ scales::percent(n / length(na.omit(analysis_data$Age)), 
                                      accuracy = .01),
      name == "Gender" ~ scales::percent(n / length(na.omit(analysis_data$Gender)),
                                         accuracy = .01),
      name == "Position" ~ scales::percent(n / length(na.omit(analysis_data$Position)),
                                           accuracy = .01)
  )
  ) |>
  mutate(
    name = factor(name)
  )
`summarise()` has grouped output by 'name'. You can override using the
`.groups` argument.

Table

study2_demographic_table <- demographic_data |>
  filter(
    name == "Age" | name == "Position"
  ) |>
  gt() |>
  tab_options(
    column_labels.hidden = TRUE,
    row_group.as_column = TRUE
  ) |>
  tab_style(style = cell_text(weight = "bold"),
            locations = cells_row_groups()) |>
  opt_table_font(
    font = "Times New Roman"
  )

gtsave(study2_demographic_table, filename = here(getwd(), "Outputs", "study2_demographic_table.png"))

Politics

politics_data <- analysis_data |>
  select(starts_with("Politics_")) |>
  pivot_longer(starts_with("Politics_")) |>
  mutate(
    name = case_when(
      name == "Politics_1" ~ "Economic",
      name == "Politics_2" ~ "Social",
      name == "Politics_3" ~ "Foreign Policy",
      name == "Politics_4" ~ "Overall"
    ),
    name = factor(name, levels = c("Economic", "Social",
                                   "Foreign Policy", "Overall"))
  ) |>
  group_by(name, value) |>
  summarize(
    count = n()
  ) |>
  na.omit()
`summarise()` has grouped output by 'name'. You can override using the
`.groups` argument.
political_identity <- politics_data |>
  mutate(
    conservative = ifelse(value < 4, count, 0),
    neutral = ifelse(value == 4, count, 0),
    liberal = ifelse(value > 4, count, 0)
  ) |>
  group_by(name) |>
  summarize(
    total = sum(conservative) + sum(neutral) + sum(liberal),
    conservative = scales::percent(sum(conservative)/total, accuracy = .01),
    neutral = scales::percent(sum(neutral)/total, accuracy = .01),
    liberal = scales::percent(sum(liberal)/total, accuracy = .01)
  )

study2_results[["political_identity"]] <- political_identity

Graphing

study2_politics_graph <- ggplot(politics_data, aes(x = value, y = count)) +
  geom_col() +
  facet_wrap(~name, ncol = 2) +
  labs(
    y = "Count",
    x = "Politics",
    caption = 'Note: 1 = "Very conservative"; 7 = "Very liberal"'
  ) +
  scale_x_continuous(limits = c(1,7.5), n.breaks = 7) +
  ggpubr::theme_pubr()

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

T-tests

### Economic
economic_ttest <- t.test(mu = 4, analysis_data$Politics_1)
study2_results[["economic_ttest"]] <- economic_ttest

### Social Policy
social_ttest <- t.test(mu = 4, analysis_data$Politics_2)
study2_results[["social_ttest"]] <- social_ttest

### Foreign Policy
foreign_ttest <- t.test(mu = 4, analysis_data$Politics_3)
study2_results[["foreign_ttest"]] <- foreign_ttest

### Overall
overall_ttest <- t.test(mu = 4, analysis_data$Politics_4)
study2_results[["overall_ttest"]] <- overall_ttest

### Economic vs Foreign Policy
econ_foreign_ttest <- t.test(analysis_data$Politics_3, analysis_data$Politics_2, paired=TRUE)
study2_results[["econ_foreign_ttest"]] <- econ_foreign_ttest

### Economic vs Social
econ_social_ttest <- t.test(analysis_data$Politics_1, analysis_data$Politics_2, paired=TRUE)
study2_results[["econ_social_ttest"]] <- econ_social_ttest

Stimuli selection

T-tests

## Personal support
personalsupport_ttest <- t.test(analysis_data$Stimuli.Selection_1, mu=4)
study2_results[["personalsupport_ttest"]] <- personalsupport_ttest

## Personal connection
personalconnection_ttest <- t.test(analysis_data$Stimuli.Selection_2, mu=4)
study2_results[["personalconnection_ttest"]] <- personalconnection_ttest

## Societal support
societalsupport_ttest <- t.test(analysis_data$Stimuli.Selection_3, mu=4)
study2_results[["societalsupport_ttest"]] <- societalsupport_ttest

## Participant support
participantsupport_ttest <- t.test(analysis_data$Stimuli.Selection_4, mu=4)
study2_results[["participantsupport_ttest"]] <- participantsupport_ttest

## Prior Use
prioruse_ttest <- t.test(analysis_data$Stimuli.Selection_5, mu=4)
study2_results[["prioruse_ttest"]] <- prioruse_ttest

## Variety
variety_ttest <- t.test(analysis_data$Stimuli.Selection_6, mu=4)
study2_results[["variety_ttest"]] <- variety_ttest

Graph

study2_stimuli_graph <- analysis_data |>
  select(
    starts_with("Stimuli.Selection")
  ) |>
  pivot_longer(cols = starts_with("Stimuli.Selection")) |>
  group_by(name) |>
  summarize(
    mean = mean(value, na.rm=TRUE),
    sd = sd(value, na.rm=TRUE),
    n = n() - sum(is.na(value)),
    se = sd/sqrt(n)
  ) |>
  mutate(
    name = case_when(
      name == "Stimuli.Selection_1" ~ "Personal support",
      name == "Stimuli.Selection_2" ~ "Personal connection",
      name == "Stimuli.Selection_3" ~ "Societal support",
      name == "Stimuli.Selection_4" ~ "Likely participant support",
      name == "Stimuli.Selection_5" ~ "Use in prior research",
      name == "Stimuli.Selection_6" ~ "Desire for variety"
    )
  ) |>
  ggplot(aes(x = mean,y=reorder(name,mean,sum))) +
  geom_point(size = 2.5) +
  geom_errorbar(aes(y=name, xmin=mean-1.96*se, xmax=mean+1.96*se), width = 0.2) +
  labs(
    x = "Agreement",
    y = "Stimuli Choice Considerations",
    caption = 'Note: Error bars denote 95% CI'
  ) +
  ggpubr::theme_pubr() +
  geom_vline(xintercept = 4, linetype = "dashed") +
  scale_x_continuous(limits = c(0.5,7.5), n.breaks = 7)

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

Discrimination

Self report

self_writing <- na.omit(analysis_data$Self.report_1)
self_reading <- na.omit(analysis_data$Self.report_2)
self_candidate <- na.omit(analysis_data$Self.report_3)

### Bias endorsement
study2_results[["self_writing_endorsement"]] <- sum(self_writing >= 4)/length(self_writing)
study2_results[["self_reading_endorsement"]] <- sum(self_reading >= 4)/length(self_reading)
study2_results[["self_candidate_endorsement"]] <- sum(self_candidate >= 4)/length(self_candidate)

## T.tests against maximum "pure" value"
t.test(self_writing, mu = 1)

    One Sample t-test

data:  self_writing
t = 16.745, df = 87, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 1
95 percent confidence interval:
 4.034475 4.851889
sample estimates:
mean of x 
 4.443182 
t.test(self_reading, mu = 1)

    One Sample t-test

data:  self_reading
t = 12.545, df = 87, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 1
95 percent confidence interval:
 2.931774 3.659135
sample estimates:
mean of x 
 3.295455 
t.test(self_candidate, mu = 1)

    One Sample t-test

data:  self_candidate
t = 13.246, df = 84, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 1
95 percent confidence interval:
 3.039688 3.760312
sample estimates:
mean of x 
      3.4 
## T.tests against midpoint
self_writing_ttest <- t.test(self_writing, mu = 4)
study2_results[["self_writing_ttest"]] <- self_writing_ttest
self_reading_ttest <- t.test(self_reading, mu = 4)
study2_results[["self_reading_ttest"]] <- self_reading_ttest
self_candidate_ttest <- t.test(self_candidate, mu = 4)
study2_results[["self_candidate_ttest"]] <- self_candidate_ttest

Peer report

peer_writing <- na.omit(analysis_data$Peer.report_1)
peer_reading <- na.omit(analysis_data$Peer.report_2)
peer_candidate <- na.omit(analysis_data$Peer.report_3)

### Bias endorsement
study2_results[["peer_writing_endorsement"]] <- sum(peer_writing >= 4)/length(peer_writing)
study2_results[["peer_reading_endorsement"]] <- sum(peer_reading >= 4)/length(peer_reading)
study2_results[["peer_candidate_endorsement"]] <- sum(peer_candidate >= 4)/length(peer_candidate)

## T.tests against minimum value
t.test(peer_writing, mu = 1)

    One Sample t-test

data:  peer_writing
t = 21.128, df = 88, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 1
95 percent confidence interval:
 4.165695 4.823069
sample estimates:
mean of x 
 4.494382 
t.test(peer_reading, mu = 1)

    One Sample t-test

data:  peer_reading
t = 21.629, df = 88, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 1
95 percent confidence interval:
 4.122296 4.754109
sample estimates:
mean of x 
 4.438202 
t.test(peer_candidate, mu = 1)

    One Sample t-test

data:  peer_candidate
t = 21.646, df = 87, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 1
95 percent confidence interval:
 4.127018 4.759346
sample estimates:
mean of x 
 4.443182 
## T.tests against midpoint
peer_writing_ttest <- t.test(peer_writing, mu = 4)
study2_results[["peer_writing_ttest"]] <- peer_writing_ttest
peer_reading_ttest <- t.test(peer_reading, mu = 4)
study2_results[["peer_reading_ttest"]] <- peer_reading_ttest
peer_candidate_ttest <- t.test(peer_candidate, mu = 4)
study2_results[["peer_candidate_ttest"]] <- peer_candidate_ttest

Self vs Peer

selfpeer_writing_ttest <- t.test(self_writing, peer_writing)
study2_results[["selfpeer_writing_ttest"]] <- selfpeer_writing_ttest

selfpeer_reading_ttest <- t.test(self_reading, peer_reading)
study2_results[["selfpeer_reading_ttest"]] <- selfpeer_reading_ttest

selfpeer_candidate_ttest <- t.test(self_candidate, peer_candidate)
study2_results[["selfpeer_candidate_ttest"]] <- selfpeer_candidate_ttest

Table

study2_discrimination_table <- tibble(
  Item = c(
    "Writing",
    "Review",
    "Hiring decision"
  ),
  `M (SD)` = c(
    paste0(round(mean(self_writing), 2), " (", round(sd(self_writing), 2), ")"),
    paste0(round(mean(self_reading), 2), " (", round(sd(self_reading), 2), ")"),
    paste0(round(mean(self_candidate), 2), " (", round(sd(self_candidate), 2), ")")
  ),
  `Percentage of responses ≥4` = c(
    scales::percent(sum(self_writing >= 4) / length(self_writing)),
    scales::percent(sum(self_reading >= 4) / length(self_reading)),
    scales::percent(sum(self_candidate >= 4) / length(self_candidate))
  ),
  `M (SD) ` = c(
    paste0(round(mean(peer_writing), 2), " (", round(sd(peer_writing), 2), ")"),
    paste0(round(mean(peer_reading), 2), " (", round(sd(peer_reading), 2), ")"),
    paste0(round(mean(peer_candidate), 2), " (", round(sd(peer_candidate), 2), ")")
  ),
  `Percentage of responses ≥4 ` = c(
    scales::percent(sum(peer_writing >= 4) / length(peer_writing)),
    scales::percent(sum(peer_reading >= 4) / length(peer_reading)),
    scales::percent(sum(peer_candidate >= 4) / length(peer_candidate))
  )
) |>
  gt() |>
  tab_spanner(
    label = md("**Self-Ratings**"),
    columns = c(
      2, 3
    )
  ) |>
  tab_spanner(
    label = md("**Peer-Ratings**"),
    columns = c(
      4, 5
    )
  ) |>
  cols_label(`Percentage of responses ≥4 ` = html("Percentage of<br> responses ≥4")) |>
  cols_label(`Percentage of responses ≥4` = html("Percentage of<br> responses ≥4")) |>
  cols_align(
    align = c("center"),
    columns = c(2, 3, 4, 5)
  ) |>
  tab_options(
    table.border.top.style = "hidden",
    table.border.bottom.style = "hidden"
  ) |>
  tab_footnote(
    md('*Note:* All ratings on a 1 ("Strongly disagree")—7 ("Strongly agree")" scale. <br>All means were significantly different from 1 (*ps* < .001).'),
    locations = NULL,
    placement = "left"
  ) |>
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_row_groups()
  ) |>
  opt_table_font(
    font = "Times New Roman"
  )

gtsave(study2_discrimination_table, filename = here(getwd(), "Outputs", "study2_discrimination_table.png"))

Graph

study2_discrimination_graph <- analysis_data |>
  select(
    starts_with("Peer.Report"),
    starts_with("Self.Report")
  ) |>
  pivot_longer(cols = c(starts_with("Peer.Report"),
                        starts_with("Self.Report"))) |>
  mutate(
    name = case_when(
      name == "Peer.report_1" ~ "Writing (Peers)",
      name == "Peer.report_2" ~ "Reviewing (Peers)",
      name == "Peer.report_3" ~ "Hiring (Peers)",
      name == "Self.report_1" ~ "Writing (Self)",
      name == "Self.report_2" ~ "Reviewing (Self)",
      name == "Self.report_3" ~ "Hiring (Self)",
    )
  ) |>
  group_by(name, value) |>
  summarize(
    n = n()
  ) |>
  na.omit() |>
  mutate(
    report_group = ifelse(str_detect(name, "Peers"), "Peers", "Self"),
    name = str_remove(name, fixed("(Peers)")),
    name = str_remove(name, fixed("(Self)"))
  ) |>
  ggplot(aes(x = value, y = n)) +
  geom_col() +
  facet_grid(report_group~name) +
  labs(
    y = "Count",
    x = "Politics",
    caption = 'Note: 1 = "Strongly Disagree"; 7 = "Strongly Agree"'
  ) +
  scale_x_continuous(limits = c(0.5,7.5), n.breaks = 7) +
  ggpubr::theme_pubr()
`summarise()` has grouped output by 'name'. You can override using the
`.groups` argument.
ggsave(filename = here(getwd(), "Outputs", "study2_discrimination_graph.png"),
height = 5, width = 9)

Save Results File

save(study2_results, file = here(getwd(), "Outputs", "study2_results.rdata"))