7 Helpful Functions
7.1 P-value Formatting
<- function(value,
pval_label_apa breaks = c(.05, .01, .001),
symbols = c("*", "**", "***"),
decimals = 3,
leading = FALSE){
= MOTE::apa(value = value,
value_apa decimals = decimals,
leading = leading)
= MOTE::apa(value = breaks[3],
value_apa_min decimals = decimals,
leading = leading)
::case_when(value < breaks[3] ~ glue::glue("p < {value_apa_min} {symbols[3]}"),
dplyr== breaks[3] ~ glue::glue("p = {value_apa_min} {symbols[3]}"),
value <= breaks[2] ~ glue::glue("p = {value_apa} {symbols[2]}"),
value <= breaks[1] ~ glue::glue("p = {value_apa} {symbols[1]}"),
value > breaks[1] ~ glue::glue("p = {value_apa}"))
value }
c(0.23, 0.023, 0.0023, 0.00023) %>% pval_label_apa()
p = .230
p = .023 *
p = .002 **
p < .001 ***
c(0.05, 0.01, 0.001) %>% pval_label_apa()
p = .050 *
p = .010 **
p = .001 ***
7.2 APA Table Formatting
<- function(x, title = " ", ...) {
gt_apa gt(x, ...) %>%
tab_options(
table.border.top.color = "white",
heading.title.font.size = px(16),
column_labels.border.top.width = 3,
column_labels.border.top.color = "black",
column_labels.border.bottom.width = 3,
column_labels.border.bottom.color = "black",
table_body.border.bottom.color = "black",
table.border.bottom.color = "white",
table.width = pct(100),
table.background.color = "white"
%>%
) cols_align(align="center") %>%
tab_style(
style = list(
cell_borders(
sides = c("top", "bottom"),
color = "white",
weight = px(1)
),cell_text(
align="center"
),cell_fill(color = "white", alpha = NULL)
),locations = cells_body(
columns = everything(),
rows = everything()
)%>%
) #title setup
tab_header(
title = html("<i>", title, "</i>")
%>%
) opt_align_table_header(align = "left")
}