Combine svyCreateTableOne & print function in tableone package

svyCreateTableOneJS(
  vars,
  strata = NULL,
  strata2 = NULL,
  data,
  factorVars = NULL,
  includeNA = F,
  test = T,
  showAllLevels = T,
  printToggle = F,
  quote = F,
  smd = F,
  Labels = F,
  nonnormal = NULL,
  catDigits = 1,
  contDigits = 2,
  pDigits = 3,
  labeldata = NULL,
  psub = T,
  minMax = F,
  showpm = T,
  addOverall = F,
  pairwise = F,
  pairwise.showtest = F
)

Arguments

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.

strata

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

strata2

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

data

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

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

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

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

psub

show sub-group p-values, Default: F

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

pairwise

(optional, only used if strata are supplied) When there are three or more strata, it displays the p-values for pairwise comparisons. Default: F

pairwise.showtest

(optional, only used if strata are supplied) When using pairwise comparison, it displays the test used to calculate p-values for pairwise comparisons. 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(survey) data(nhanes) nhanes$SDMVPSU <- as.factor(nhanes$SDMVPSU) nhanesSvy <- svydesign( ids = ~SDMVPSU, strata = ~SDMVSTRA, weights = ~WTMEC2YR, nest = TRUE, data = nhanes ) svyCreateTableOneJS( vars = c("HI_CHOL", "race", "agecat", "RIAGENDR"), strata = "RIAGENDR", data = nhanesSvy, factorVars = c("HI_CHOL", "race", "RIAGENDR") )
#> $table #> level 1 2 p #> n "" "134944553.9" "141591892.0" "" #> HI_CHOL (%) "0" "112307738.4 ( 89.9) " "114402926.5 ( 87.7) " " 0.010" #> "1" " 12579208.9 ( 10.1) " " 16056036.4 ( 12.3) " "" #> race (%) "1" " 21381884.2 ( 15.8) " " 20251367.4 ( 14.3) " " 0.042" #> "2" " 89315751.4 ( 66.2) " " 92486945.1 ( 65.3) " "" #> "3" " 15045455.5 ( 11.1) " " 17967228.3 ( 12.7) " "" #> "4" " 9201462.9 ( 6.8) " " 10886351.1 ( 7.7) " "" #> agecat (%) "(0,19]" " 29299546.1 ( 21.7) " " 28150760.5 ( 19.9) " " 0.001" #> "(19,39]" " 40497613.1 ( 30.0) " " 40640361.5 ( 28.7) " "" #> "(39,59]" " 41053579.4 ( 30.4) " " 42817044.0 ( 30.2) " "" #> "(59,Inf]" " 24093815.3 ( 17.9) " " 29983725.9 ( 21.2) " "" #> RIAGENDR (%) "1" "134944553.9 (100.0) " " 0.0 ( 0.0) " "<0.001" #> "2" " 0.0 ( 0.0) " "141591892.0 (100.0) " "" #> test sig #> n "" NA #> HI_CHOL (%) "" "**" #> "" NA #> race (%) "" "**" #> "" NA #> "" NA #> "" NA #> agecat (%) "" "**" #> "" NA #> "" NA #> "" NA #> RIAGENDR (%) "" "**" #> "" NA #> #> $caption #> [1] "Stratified by RIAGENDR- weighted data" #>