Table 4. Sound cue reporting
Attempting to recreate Table 4: 
Load packages
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)
load data
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
Calculate Table 4 data
report_no <- cleandata %>%
select(heard_cue_report) %>%
tally(heard_cue_report == "no")
## Error in select(., heard_cue_report): object 'cleandata' not found
report_maybe <- cleandata %>%
select(heard_cue_report) %>%
tally(heard_cue_report == "maybe, unsure, unclear")
## Error in select(., heard_cue_report): object 'cleandata' not found
glimpse(report_maybe)
## Error in glimpse(report_maybe): object 'report_maybe' not found
glimpse(report_no)
## Error in glimpse(report_no): object 'report_no' not found
report <- cleandata %>%
select(report_no, report_maybe) %>%
sum(c(report_no, report_maybe))
## Error in select(., report_no, report_maybe): object 'cleandata' not found
#Keeps giving error: Error: Must subset columns with a valid subscript vector. x Subscript has the wrong type `data.frame<n:integer>`. ℹ It must be numeric or character.
#I think I need to change this to numeric
#I thought that the variables were integers so tried converting to numeric
#tried converting integer into a numeric value
report_no <- as.numeric(as.integer(report_no))
## Error in eval(expr, envir, enclos): object 'report_no' not found
report_maybe <- as.numeric(as.integer(report_maybe))
## Error in eval(expr, envir, enclos): object 'report_maybe' not found
#check if the above variables are the type
typeof(report_maybe)
## Error in typeof(report_maybe): object 'report_maybe' not found
typeof(report_no)
## Error in typeof(report_no): object 'report_no' not found
#the above are outputting as "double"
#According to google, a "double" output means it's a numeric value
report_maybe <- as.numeric(unlist(report_maybe))
## Error in unlist(report_maybe): object 'report_maybe' not found
report_no <- as.numeric(unlist(report_no))
## Error in unlist(report_no): object 'report_no' not found
typeof(report_maybe)
## Error in typeof(report_maybe): object 'report_maybe' not found
report_total <- cleandata %>%
select(report_no, report_maybe) %>%
sum(report_no, report_maybe)
## Error in select(., report_no, report_maybe): object 'cleandata' not found
#Gives error: Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric-alike variables
report_total <- c(2, 28) #add values of report_maybe and report_no to create report_total
sum(report_total)
## [1] 30
exit_no <- cleandata %>%
select(heard_cue_exit) %>%
tally(heard_cue_exit == "no", exclude = participantID$ub46)
## Error in tally(., heard_cue_exit == "no", exclude = participantID$ub46): unused argument (exclude = participantID$ub46)
exit_maybe <- cleandata %>%
select(heard_cue_exit) %>%
tally(heard_cue_exit == "unsure")
## Error in select(., heard_cue_exit): object 'cleandata' not found
glimpse(exit_no)
## Error in glimpse(exit_no): object 'exit_no' not found
glimpse(exit_maybe) #this gives incorrect value of 29, instead of 28.
## Error in glimpse(exit_maybe): object 'exit_maybe' not found
exit_total <- c(0, 29) #add values of report_maybe and report_no to create report_total
sum(exit_total)
## [1] 29
Create new dataframe without the participant who had incomplete response
soundcuereporting <- cleandata %>%
select(heard_cue_exit, heard_cue_report) %>%
na.omit() #omitted row with incomplete response
## Error in select(., heard_cue_exit, heard_cue_report): object 'cleandata' not found
Recalculate table 4 data with omitted participant
report_no <- soundcuereporting %>%
select(heard_cue_report) %>%
tally(heard_cue_report == "no")
## Error in select(., heard_cue_report): object 'soundcuereporting' not found
report_maybe <- soundcuereporting %>%
select(heard_cue_report) %>%
tally(heard_cue_report == "maybe, unsure, unclear")
## Error in select(., heard_cue_report): object 'soundcuereporting' not found
glimpse(report_maybe)
## Error in glimpse(report_maybe): object 'report_maybe' not found
glimpse(report_no)
## Error in glimpse(report_no): object 'report_no' not found
exit_no <- soundcuereporting %>%
select(heard_cue_exit) %>%
tally(heard_cue_exit == "no")
## Error in select(., heard_cue_exit): object 'soundcuereporting' not found
exit_maybe <- soundcuereporting %>%
select(heard_cue_exit) %>%
tally(heard_cue_exit == "unsure")
## Error in select(., heard_cue_exit): object 'soundcuereporting' not found
glimpse(exit_no)
## Error in glimpse(exit_no): object 'exit_no' not found
glimpse(exit_maybe) #this gives incorrect value of 29, instead of 28.
## Error in glimpse(exit_maybe): object 'exit_maybe' not found
exitno_reportno <- soundcuereporting %>%
filter(heard_cue_exit == "no", heard_cue_report == "no") %>%
summarise(n=n())
## Error in filter(., heard_cue_exit == "no", heard_cue_report == "no"): object 'soundcuereporting' not found
exitno_reportmaybe <- soundcuereporting %>%
filter(heard_cue_exit == "no", heard_cue_report == "maybe, unsure, unclear") %>%
summarise(n=n())
## Error in filter(., heard_cue_exit == "no", heard_cue_report == "maybe, unsure, unclear"): object 'soundcuereporting' not found
exitmaybe_reportno <- soundcuereporting %>%
filter(heard_cue_exit == "unsure", heard_cue_report == "no") %>%
summarise(n=n())
## Error in filter(., heard_cue_exit == "unsure", heard_cue_report == "no"): object 'soundcuereporting' not found
exitmaybe_reportmaybe <- soundcuereporting %>%
filter(heard_cue_exit == "unsure", heard_cue_report == "maybe, unsure, unclear") %>%
summarise(n=n())
## Error in filter(., heard_cue_exit == "unsure", heard_cue_report == "maybe, unsure, unclear"): object 'soundcuereporting' not found
glimpse(exitno_reportno)
## Error in glimpse(exitno_reportno): object 'exitno_reportno' not found
glimpse(exitno_reportmaybe)
## Error in glimpse(exitno_reportmaybe): object 'exitno_reportmaybe' not found
glimpse(exitmaybe_reportno)
## Error in glimpse(exitmaybe_reportno): object 'exitmaybe_reportno' not found
glimpse(exitmaybe_reportmaybe)
## Error in glimpse(exitmaybe_reportmaybe): object 'exitmaybe_reportmaybe' not found
soundcuereporting_total <- soundcuereporting %>%
summarise(n=n())
## Error in summarise(., n = n()): object 'soundcuereporting' not found
Create dataframe using calculated data from above
table4 <- tibble(
label = c("No", "Maybe", "Total"),
no = c(26, 2, 28),
maybe = c(2, 0, 2),
total = c(28, 2, 30)
)
print(table4)
## # A tibble: 3 x 4
## label no maybe total
## <chr> <dbl> <dbl> <dbl>
## 1 No 26 2 28
## 2 Maybe 2 0 2
## 3 Total 28 2 30
Create Table 4
table4 %>%
gt() %>%
tab_header(
title = "Table 4. Sound cue reporting. ") %>%
tab_source_note("Participants’ responses to the postnap verbal inquiry and to the exit questionnaire. A response was not recorded for n = 1 participant; this participant reported that they did not hear the sound cue on the final exit questionnaire.") %>%
fmt_number(columns = vars(no, maybe, total)) %>%
tab_spanner(
label = "Reported Hearing Cue on Verbal Report?", #Spanner column label
columns = c(no, maybe, total)
) %>%
tab_row_group(
label = "Reported Hearing Cue on Exit Questionnaire?",
rows = 3
)
## 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
| label |
Reported Hearing Cue on Verbal Report?
|
| no |
maybe |
total |
| Reported Hearing Cue on Exit Questionnaire? |
| Total |
28.00 |
2.00 |
30.00 |
|
| No |
26.00 |
2.00 |
28.00 |
| Maybe |
2.00 |
0.00 |
2.00 |
| Participants’ responses to the postnap verbal inquiry and to the exit questionnaire. A response was not recorded for n = 1 participant; this participant reported that they did not hear the sound cue on the final exit questionnaire. |
#formatting is very strange, need to change
Create new dataframe using calculated data from above
table4_ <- tibble(
label = c("label", "No", "Maybe", "Total"),
no = c("No", 26, 2, 28),
maybe = c("Maybe", 2, 0, 2),
total = c("Total", 28, 2, 30)
)
print(table4_)
## # A tibble: 4 x 4
## label no maybe total
## <chr> <chr> <chr> <chr>
## 1 label No Maybe Total
## 2 No 26 2 28
## 3 Maybe 2 0 2
## 4 Total 28 2 30
Table 4
table4_ %>%
gt() %>%
tab_header(
title = "Table 4. Sound cue reporting. ") %>%
tab_source_note("Participants’ responses to the postnap verbal inquiry and to the exit questionnaire. A response was not recorded for n = 1 participant; this participant reported that they did not hear the sound cue on the final exit questionnaire.") %>%
fmt_number(columns = vars(no, maybe, total)) %>%
tab_spanner(
label = "Reported Hearing Cue on Verbal Report?", #Spanner column label
columns = c(no, maybe, total)
) %>%
tab_row_group(
label = "Reported Hearing Cue on Exit Questionnaire?",
rows = 3
) %>%
cols_label(no = "No", maybe = "Maybe", total = "Total", label = " ")
## Warning: `columns = vars(...)` has been deprecated in gt 0.3.0:
## * please use `columns = c(...)` instead
## Error: The `fmt_number()` function can only be used on `columns` with numeric data
table4 %>%
gt() %>%
tab_header(
title = "Table 4. Sound cue reporting. ") %>%
tab_source_note("Participants’ responses to the postnap verbal inquiry and to the exit questionnaire. A response was not recorded for n = 1 participant; this participant reported that they did not hear the sound cue on the final exit questionnaire.") %>%
fmt_number(columns = c(no, maybe, total)) %>%
tab_spanner(
label = "Reported Hearing Cue on Verbal Report?", #Spanner column label
columns = c(no, maybe, total)
) %>%
tab_stubhead(
label = "Reported Hearing Cue on Exit Questionnaire?"
) %>%
cols_label(no = "No", maybe = "Maybe", total = "Total", label = " ")
| |
Reported Hearing Cue on Verbal Report?
|
| No |
Maybe |
Total |
| No |
26.00 |
2.00 |
28.00 |
| Maybe |
2.00 |
0.00 |
2.00 |
| Total |
28.00 |
2.00 |
30.00 |
| Participants’ responses to the postnap verbal inquiry and to the exit questionnaire. A response was not recorded for n = 1 participant; this participant reported that they did not hear the sound cue on the final exit questionnaire. |
#Looks similar to original paper, but the tab stubhead label for "Reported Hearing Cue on Exit Questionnaire?" is not appearing.
table4 %>%
gt(rowname_col = "label") %>%
tab_header(
title = "Table 4. Sound cue reporting. ") %>%
tab_source_note("Participants’ responses to the postnap verbal inquiry and to the exit questionnaire. A response was not recorded for n = 1 participant; this participant reported that they did not hear the sound cue on the final exit questionnaire.") %>%
fmt_number(columns = c(no, maybe, total)) %>%
tab_spanner(
label = "Reported Hearing Cue on Verbal Report?", #Spanner column label
columns = c(no, maybe, total)
) %>%
tab_stubhead(label = "Reported Hearing Cue on Exit Questionnaire?"
) %>%
cols_label(no = "No", maybe = "Maybe", total = "Total", label = " ")
| Reported Hearing Cue on Exit Questionnaire? |
Reported Hearing Cue on Verbal Report?
|
| No |
Maybe |
Total |
| No |
26.00 |
2.00 |
28.00 |
| Maybe |
2.00 |
0.00 |
2.00 |
| Total |
28.00 |
2.00 |
30.00 |
| Participants’ responses to the postnap verbal inquiry and to the exit questionnaire. A response was not recorded for n = 1 participant; this participant reported that they did not hear the sound cue on the final exit questionnaire. |