Attempting to recreate Table 3:
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.4 ✓ purrr 0.3.4
## ✓ tibble 3.1.2 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr)
library(gt)
library(glue)
##
## Attaching package: 'glue'
## The following object is masked from 'package:dplyr':
##
## collapse
library(haven)
replicationdata <- read.sav("Humiston & Wamsley 2019 data.sav")
## Error in read.sav("Humiston & Wamsley 2019 data.sav"): could not find function "read.sav"
cleandata <- replicationdata %>%
filter(exclude == "no")
## Error in filter(., exclude == "no"): object 'replicationdata' not found
cued <- cleandata %>% #for cued condition only
select(baseIATcued, preIATcued, postIATcued, weekIATcued)
## Error in select(., baseIATcued, preIATcued, postIATcued, weekIATcued): object 'cleandata' not found
#Selecting these variables from the "cleandata" dataset to create new data "cued"
#now I'm going to calculate the mean and sd of all of these variables:
cued <- cued %>%
summarise(across(contains("IAT"), list(mean = mean, sd = sd))) #captures and calculates the means and SDs of each variable that contains "IAT" within its variable name. Lists the calculated means and sds for each variable under the label "mean" and "sd".
## Error in summarise(., across(contains("IAT"), list(mean = mean, sd = sd))): object 'cued' not found
#now the data "cued" has the means and SDs for each of the variables previously selected, instead of having to separately code for each mean and SD needed and then having to create a new dataframe.
print(cued)
## Error in print(cued): object 'cued' not found
I wanted to see if I could calculate cued and uncued conditions together:
cued_uncued <- cleandata %>% #for cued and uncued conditios
select(baseIATcued, preIATcued, postIATcued, weekIATcued,
baseIATuncued, preIATuncued, postIATuncued, weekIATuncued)
## Error in select(., baseIATcued, preIATcued, postIATcued, weekIATcued, : object 'cleandata' not found
#Selecting these variables from the "cleandata" dataset to create new data "cued_uncued"
#now I'm going to calculate the mean and sd of all of these variables:
cued_uncued <- cued_uncued %>%
summarise(across(contains("IAT"), list(mean = mean, sd = sd))) #captures and calculates the means and SDs of each variable that contains "IAT" within its variable name. Lists the calculated means and sds for each variable under the label "mean" and "sd".
## Error in summarise(., across(contains("IAT"), list(mean = mean, sd = sd))): object 'cued_uncued' not found
#now the data "cued" has the means and SDs for each of the variables previously selected, instead of having to separately code for each mean and SD needed and then having to create a new dataframe.
print(cued_uncued)
## Error in print(cued_uncued): object 'cued_uncued' not found
Create new dataframe with calculated values from "cued_uncued"
table3 <- tibble(
label = c("Baseline", "Prenap", "Postnap", "1-week delay"),
mean1 = c(0.518, 0.211, 0.307, 0.4),
mean2 = c(0.595, 0.302, 0.249, 0.399),
SD1 = c(0.363, 0.514, 0.445, 0.387),
SD2 = c(0.447, 0.442, 0.478, 0.467)
)
print(table3)
## # A tibble: 4 x 5
## label mean1 mean2 SD1 SD2
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Baseline 0.518 0.595 0.363 0.447
## 2 Prenap 0.211 0.302 0.514 0.442
## 3 Postnap 0.307 0.249 0.445 0.478
## 4 1-week delay 0.4 0.399 0.387 0.467
table3 %>%
gt() %>%
tab_header(
title = "Table 3. Implicit bias levels by condition") %>%
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 = "Cued", #Spanner column label
columns = c(mean1, SD1)
) %>%
tab_spanner(
label = "Uncued", #Spanner column label
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 3. Implicit bias levels by condition | ||||
|---|---|---|---|---|
| Cued | Uncued | |||
| Mean | SD | Mean | SD | |
| Baseline | 0.52 | 0.36 | 0.59 | 0.45 |
| Prenap | 0.21 | 0.51 | 0.30 | 0.44 |
| Postnap | 0.31 | 0.45 | 0.25 | 0.48 |
| 1-week delay | 0.40 | 0.39 | 0.40 | 0.47 |
| Implicit bias values are the average D600 score for each timepoint | ||||