FemNAT/code/demographics_table.R

36 lines
873 B
R

library(dplyr)
library(readr)
library(gtsummary)
library(gt)
library(broom)
# generate demographics table
# (markdown, docx, pdf or png)
# ! set path to dataset
bids_dir <- "."
# read participants.tsv
study_participants <- readr::read_tsv(paste0(bids_dir, "participants.tsv"))%>%
dplyr::mutate(
sex = as.factor(sex),
group = as.factor(group)
)
study_participants_table <- study_participants %>%
dplyr::select(group, age, sex, IQ)%>%
gtsummary::tbl_summary(
by = group,
statistic = list(
all_continuous() ~ "{mean}±{sd} [{min}-{max}]",
all_categorical() ~ "{n} ({p}%)"
),
digits = all_continuous() ~ 2,
label = list(
age ~ "Age [yrs]",
sex ~ "Sex",
IQ ~ "Full-scale IQ (FSIQ)"
),
missing = "no"
) %>%
add_stat