dot-create_table_one_strata: Make a Table 1 with strata.

.create_table_one_strataR Documentation

Make a Table 1 with strata.

Description

Wrapper function for tableone::CreateTableOne that adds in formatting and other preferences of mine. Per their documentation: The tableone package is an R package that eases the construction of "Table 1", i.e., patient baseline characteristics table commonly found in biomedical research papers. The packages can summarize both continuous and categorical variables mixed within one table. Categorical variables can be summarized as counts and/or percentages. Continuous variables can be summarized in the “normal” way (means and standard deviations) or "nonnormal" way (medians and interquartile ranges).

Usage

.create_table_one_strata(
  data,
  strata,
  vars,
  fct_vars,
  catDigits = 1,
  contDigits = 2,
  pDigits = 3,
  show_smd = FALSE,
  keep_test = FALSE,
  var_labels = TRUE,
  exact = NULL,
  nonnormal = NULL,
  includeNA = FALSE,
  testApprox = chisq.test,
  argsApprox = list(correct = TRUE),
  testExact = fisher.test,
  argsExact = list(workspace = 2 * 10^5),
  testNormal = oneway.test,
  argsNormal = list(var.equal = TRUE),
  testNonNormal = kruskal.test,
  argsNonNormal = list(NULL),
  ...
)

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.

fct_vars

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.

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.

show_smd

Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown.

keep_test

Logical; Whether to keep the column named "test" FALSE by default.

var_labels

Whether to replace variable names with variable labels obtained from labelled::var_label() function.

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).

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).

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.

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.

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.

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.

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.

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.

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.

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.

argsNonNormal

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

...

Optional parameters

Value

A tbl_df

References

https://cran.r-project.org/web/packages/tableone/tableone.pdf


emilelatour/latable documentation built on Sept. 14, 2023, 9:32 a.m.