Load relevant packages and data for calculations

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.2     v dplyr   1.0.6
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(dplyr)

cleandata <- read_csv("cleandata.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_double(),
##   ParticipantID = col_character(),
##   General_1_MedList = col_character(),
##   General_1_University = col_character()
## )
## i Use `spec()` for the full column specifications.

Calculating data

implicitbiaslevels <- cleandata %>% 
  select(base_IAT_race, base_IAT_gen, pre_IAT_race, pre_IAT_gen)

#now I'm going to calculate the mean and sd of all of these variables:


implicitbiaslevels <- implicitbiaslevels %>% 
  summarise(across(contains("IAT"), list(mean = mean, sd = sd)))
write_csv(implicitbiaslevels, path = "implicitbiaslevels.csv")
## Warning: The `path` argument of `write_csv()` is deprecated as of readr 1.4.0.
## Please use the `file` argument instead.
library(readr)
implicitbiaslevels <- read_csv("~/Coding-R/replication project/implicitbiaslevels.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   base_IAT_race_mean = col_double(),
##   base_IAT_race_sd = col_double(),
##   base_IAT_gen_mean = col_double(),
##   base_IAT_gen_sd = col_double(),
##   pre_IAT_race_mean = col_double(),
##   pre_IAT_race_sd = col_double(),
##   pre_IAT_gen_mean = col_double(),
##   pre_IAT_gen_sd = col_double()
## )
View(implicitbiaslevels)

Load relevant packages

library(knitr)
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(gt)
library(magick)
## Linking to ImageMagick 6.9.12.3
## Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
## Disabled features: fontconfig, x11
library(glue)
## 
## Attaching package: 'glue'
## The following object is masked from 'package:dplyr':
## 
##     collapse

Creating tibble

table2 <- tibble(
  label = c("race", "gender"),
  mean1 = c(0.6186929, 0.4943818),
  mean2 = c(0.2023364, 0.3109984),
  SD1 = c(0.4423884, 0.36228),
  SD2 = c(0.5633004, 0.3748071)
)

print(table2)
## # A tibble: 2 x 5
##   label  mean1 mean2   SD1   SD2
##   <chr>  <dbl> <dbl> <dbl> <dbl>
## 1 race   0.619 0.202 0.442 0.563
## 2 gender 0.494 0.311 0.362 0.375

Formatting and labelling table

table2 %>% 
  gt() %>% 
  tab_header(
    title = "Table 2: Race and Gender Implicit Bias Levels") %>% 
  tab_source_note("Implicit bias values are the average D600 score for each timepoint") %>% 
  fmt_number(columns = vars(mean1, mean2,  SD1, SD2), decimals = 2) %>% 
  tab_spanner(
    label = "Baseline",
    columns = c(mean1, SD1)
  ) %>% 
  tab_spanner(
    label = "Prenap",
    columns = c(mean2, SD2)
  ) %>% 
  

  cols_label(mean1 = "mean", mean2 = "mean", SD1 = "SD", SD2 = "SD", label = " ")
## Warning: `columns = vars(...)` has been deprecated in gt 0.3.0:
## * please use `columns = c(...)` instead

## Warning: `columns = vars(...)` has been deprecated in gt 0.3.0:
## * please use `columns = c(...)` instead
Table 2: Race and Gender Implicit Bias Levels
Baseline Prenap
mean SD mean SD
race 0.62 0.44 0.20 0.56
gender 0.49 0.36 0.31 0.37
Implicit bias values are the average D600 score for each timepoint
print(table2)
## # A tibble: 2 x 5
##   label  mean1 mean2   SD1   SD2
##   <chr>  <dbl> <dbl> <dbl> <dbl>
## 1 race   0.619 0.202 0.442 0.563
## 2 gender 0.494 0.311 0.362 0.375