Combine CreateTableOne & print function in tableone package

CreateTableOne2(
  data,
  strata,
  vars,
  factorVars,
  includeNA = F,
  test = T,
  testApprox = chisq.test,
  argsApprox = list(correct = TRUE),
  testExact = fisher.test,
  argsExact = list(workspace = 2 * 10^5),
  testNormal = oneway.test,
  argsNormal = list(var.equal = F),
  testNonNormal = kruskal.test,
  argsNonNormal = list(NULL),
  showAllLevels = T,
  printToggle = F,
  quote = F,
  smd = F,
  Labels = F,
  exact = NULL,
  nonnormal = NULL,
  catDigits = 1,
  contDigits = 2,
  pDigits = 3,
  labeldata = NULL,
  minMax = F,
  showpm = T,
  addOverall = F
)

Arguments

data

A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.

strata

Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.

vars

Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used.

factorVars

Numerically coded variables that should be handled as categorical variables given as a character vector. Do not include factors, unless you need to relevel them by removing empty levels. If omitted, only factors are considered categorical variables. The variables specified here must also be specified in the vars argument.

includeNA

If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables., Default: F

test

If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed, Default: T

testApprox

A function used to perform the large sample approximation based tests. The default is chisq.test. This is not recommended when some of the cell have small counts like fewer than 5, Default: chisq.test

argsApprox

A named list of arguments passed to the function specified in testApprox. The default is list(correct = TRUE), which turns on the continuity correction for chisq.test, Default: list(correct = TRUE)

testExact

A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice., Default: fisher.test

argsExact

A named list of arguments passed to the function specified in testExact. The default is list(workspace = 2 * 10^5), which specifies the memory space allocated for fisher.test, Default: list(workspace = 2 * 10^5)

testNormal

A function used to perform the normal assumption based tests. The default is oneway.test. This is equivalent of the t-test when there are only two groups, Default: oneway.test

argsNormal

A named list of arguments passed to the function specified in testNormal. The default is list(var.equal = TRUE), which makes it the ordinary ANOVA that assumes equal variance across groups., Default: list(var.equal = F)

testNonNormal

A function used to perform the nonparametric tests. The default is kruskal.test (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups, Default: kruskal.test

argsNonNormal

A named list of arguments passed to the function specified in testNonNormal. The default is list(NULL), which is just a placeholder., Default: list(NULL)

showAllLevels

Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information., Default: T

printToggle

Whether to print the output. If FALSE, no output is created, and a matrix is invisibly returned., Default: F

quote

Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily, Default: F

smd

If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated, Default: F

Labels

Use Label, Default: F

exact

A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test)., Default: NULL

nonnormal

A character vector to specify the variables for which the p-values should be those of nonparametric tests. By default all p-values are from normal assumption-based tests (oneway.test)., Default: NULL

catDigits

Number of digits to print for proportions., Default: 1

contDigits

Number of digits to print for continuous variables. Default 2.

pDigits

Number of digits to print for p-values (also used for standardized mean differences), Default: 3

labeldata

labeldata to use, Default: NULL

minMax

Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE.

showpm

Logical, show normal distributed continuous variables as Mean ± SD. Default: T

addOverall

(optional, only used if strata are supplied) Adds an overall column to the table. Smd and p-value calculations are performed using only the stratifed clolumns. Default: F

Value

A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via write.csv.

Details

DETAILS

Examples

library(survival) CreateTableOne2(vars = names(lung), strata = "sex", data = lung)
#> level 1 2 p test sig #> n "" " 138" " 90" "" "" NA #> inst "" " 10.56 ± 7.80" " 11.89 ± 9.00" " 0.254" "" "" #> time "" "283.23 ± 213.05" "338.97 ± 203.47" " 0.049" "" "**" #> status "" " 1.81 ± 0.39" " 1.59 ± 0.49" "<0.001" "" "**" #> age "" " 63.34 ± 9.14" " 61.08 ± 8.85" " 0.064" "" "" #> sex "" " 1.00 ± 0.00" " 2.00 ± 0.00" " NaN" "" NA #> ph.ecog "" " 0.96 ± 0.71" " 0.93 ± 0.73" " 0.759" "" "" #> ph.karno "" " 81.82 ± 12.38" " 82.11 ± 12.32" " 0.864" "" "" #> pat.karno "" " 79.41 ± 14.29" " 80.79 ± 15.17" " 0.497" "" "" #> meal.cal "" "980.54 ± 413.26" "840.70 ± 369.08" " 0.020" "" "**" #> wt.loss "" " 11.22 ± 12.98" " 7.77 ± 13.18" " 0.060" "" ""