FullTable1: Create Table1 of group summary with stats for scientific...

View source: R/FullTable1.R

FullTable1R Documentation

Create Table1 of group summary with stats for scientific publication

Description

The FullTable1 function can be used to create a Table1 for scientific publication. This is intended to summarize demographic and other variables (vars) split by a grouping variable (strata) from an input dataset (data). Continuous variables will be summarized as mean (SD) and tested across groups using t-test or ANOVA (for 3+ level strata). Categorical variables will be summarized as N (%) and tested across groups as chi-squared. Effect sizes for group differences will be calculated as Cohen's d, partial eta-squared, Odds Ratio, Cramer's V depending on the test. Requires tidyverse and stats libraries.

Usage

FullTable1(
  data,
  strata = NULL,
  vars = NULL,
  var_names = vars,
  factor_vars = NULL,
  round_n = 2,
  es_col = TRUE,
  p_col = TRUE,
  stars = "col",
  html = FALSE
)

Arguments

data

The input dataset (will be converted to tibble).

strata

The grouping variable of interest (converted to factor), if NULL will make one column table.

vars

A list of variables to summarize, e.g. c("Age","sex","WASI").

var_names

An optional list to rename the variable colnames in the output table, e.g. c("Age (years)","Sex","IQ"). Must match vars in length. If not supplied, vars will be printed as is.

factor_vars

An optional list of variables from vars to use as class factor, e.g. c("sex"). Note that any character, factor, or logical class variables will be summarized as categorical by default.

round_n

The number of decimal places to round output to (default=2).

es_col

Include a column for effect size of group difference? (default=T).

p_col

Include a column for p-value of group difference? (default=TRUE).

stars

Where to include stars indicating significance of group differences. Options: "col"=separate column (default), "name"= append to variable name, "stat"= append to group difference statistic, "none" for no stars.

html

Format as html in viewer or not (default=FALSE, print in console), needs library(htmlTable) installed.

Details

Variables are automatically classified as numeric or categorical. Character, logical, ordered, and binary variables are converted to factors with warnings.

Effect sizes: Cohen's d (t-test), partial n2 (ANOVA), OR (2x2 chi-squared), Cramer's V (larger chi-squared tables).

Stars indicate significance: * p<.05, ** p<.01, *** p<.001

Value

Output Table 1

Examples

## Not run: 
FullTable1(
  data = psydat,
  vars = c("Age", "Height", "depressT"), strata = "Sex"
)
FullTable1(
  data = psydat,
  vars = c("Age", "Height", "depressT"), strata = "Sex"
)
FullTable1(
  data = psydat, vars = c("Age", "Sex", "Height", "depressT"),
  var_names = c("Age (months)", "Sex", "Height (inches)", "Depression T"),
  strata = "Income", stars = "name", p_col = FALSE
)
tmp <- FullTable1(data = psydat,
  vars = c("Age", "Height", "depressT"), strata = "Sex")
  tmp$caption <- "Write your own caption"
  #print(htmlTable(x$table, useViewer=T, rnames=F,caption=x$caption, pos.caption="bottom"))
  
## End(Not run)

scipub documentation built on Jan. 10, 2026, 5:07 p.m.