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.

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

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.

Value

Output Table 1

Examples

FullTable1( data = psydat, vars = c("Age", "Height", "depressT"), strata = "Sex" )
#> Warning: N=4 missing/NA in grouping variable: Sex
#> $table #> Variable F (N=2364) M (N=2632) Stat p sig es #> 1 Age 120.65 (7.5) 121.05 (7.66) 1.86 .06 0.05 #> 2 Height 57.34 (3.48) 57.27 (3.28) -0.83 .41 -0.02 #> 3 depressT 55.1 (5.27) 55.88 (6.01) 4.87 <.001 *** 0.14 #> #> $caption #> [1] "Note. N=4 excluded for missing group variable. N=5 missing Height. N=4 missing depressT. * p<.05, ** p<.01, *** p<.001" #>
FullTable1( data = psydat, vars = c("Age", "Height", "depressT"), strata = "Sex" )
#> Warning: N=4 missing/NA in grouping variable: Sex
#> $table #> Variable F (N=2364) M (N=2632) Stat p sig es #> 1 Age 120.65 (7.5) 121.05 (7.66) 1.86 .06 0.05 #> 2 Height 57.34 (3.48) 57.27 (3.28) -0.83 .41 -0.02 #> 3 depressT 55.1 (5.27) 55.88 (6.01) 4.87 <.001 *** 0.14 #> #> $caption #> [1] "Note. N=4 excluded for missing group variable. N=5 missing Height. N=4 missing depressT. * p<.05, ** p<.01, *** p<.001" #>
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 )
#> Warning: N=404 missing/NA in grouping variable: Income
#> $table #> Variable [<50K] (N=1331) [>=100K] (N=1957) [>=50K&<100K] (N=1308) #> 1 Age (months) * 120.61 (7.53) 121.23 (7.6) 120.55 (7.56) #> 2 Sex (M) 690 (51.88%) 1034 (52.86%) 700 (53.52%) #> 3 Height (inches) 57.42 (3.49) 57.29 (3.25) 57.23 (3.25) #> 4 Depression T *** 56.4 (6.56) 54.83 (4.9) 55.63 (5.72) #> Stat es #> 1 F=4.17 η2=0.00 #> 2 χ2=0.72 V=0.01 #> 3 F=1.15 η2=0.00 #> 4 F=31.18 η2=0.01 #> #> $caption #> [1] "Note. N=404 excluded for missing group variable. N=2 missing Sex. N=5 missing Height (inches). N=4 missing Depression T. * p<.05, ** p<.01, *** p<.001" #>
tmp <- FullTable1(data = psydat, vars = c("Age", "Height", "depressT"), strata = "Sex")
#> Warning: N=4 missing/NA in grouping variable: Sex
tmp$caption <- "Write your own caption" #print(htmlTable(x$table, useViewer=T, rnames=F,caption=x$caption, pos.caption="bottom"))