tableone: Tableone summarizes a selection of the data set as would be...

Description Usage Arguments Details Value Author(s) Examples

Description

Summarize variables by a categorical variable within a given data.frame. Overall and by results are presented along with simiple hypothesis tests.

Usage

1
2
3
4
5
6
7
8
9
tableone(vars, by = NULL, data = NULL, complete = TRUE, margin = 2,
  overall = TRUE, stat.con.1 = mean, stat.con.2 = sd,
  tests = c("chisq.test", "t.test"), fisher = TRUE,
  digits = getOption("qwraps.digits", 3), big.mark = ",")

## S3 method for class 'tableone'
print(tab1, file = "", title = "",
  ctable = getOption("qwraps.tableone.ctable", TRUE), cgroup, n.cgroup,
  rgroup, n.rgroup, rowname, col.just, ...)

Arguments

vars

characer vector of the names of the variables in data to summarize.

by

character name of the variable in data to sumamrize vars by

data

the data.frame

complete

logical reported for the complete data records only? If TRUE, the dataset will be subseted via na.omit(data[, c(vars, by)]), if FALSE, then all avaiable data records will be used.

margin

default to report column percentages for categorical variables, can be set to 1 for row percentages or 1:2 for overall percentages.

overall

logical if TRUE include a column with the summary statistics for the whole sample in addition to the summary of the vars by

stat.con.1

function to summarize continuous variables with, default is the mean

stat.con.2

second function to sumamry continuous variables with, adefault is sd

tests

a vector of length two with the statistical tests to report for 1) categorical variables and 2) continuous variables. If set to NULL, then the tests and associated p-values are omitted from the output. Defaults are for the chisq.test and the t.test. If the value is set to NULL the tests will be omitted from the output. Only chisq.test and fisher.test are allowed for categorical variables at this time. Regardless of the test function specified, the function should return a list value named p.value. The second test can be either a t.test or a aov. more tests will be allowed in later versions.

fisher

logicial if TRUE and tests[1] == "chisq.test" then if any(chisq.test()$expected) < 5 the test is redone using a fisher.exact. This option is ignored if tests[1] == "fisher.test".

big.mark

Default is a comma to separate, i.e., 1000 would be reported as 1,000.

digits

number of digits to round stat.con.1 and stat.con.2

pdigits

number of digits to report p-values to.

show.equal.sign

Details

EXPLAIN THE DETAILS MORE, FACTORS AND NUMERS ARE IMPORANT, WILL TRANSFORM CHARACTERS TO FACTORS

Value

a list with the elements intended to be used with Hmisc::latex

tab

a string of formated numbers. Non-numbers are empty strings. If the p-value is less than 10^(-pdigits) the return will be '< 10^(-pdigits)

cgrp

a character vector for the column groups, the levels of by

ncgrp

a numeric vector for n.cgroup

rgrp

a character vector for the row groups

rcgrp

a numeric vector for n.cgroup

rwnms

a character vector of row names

Author(s)

Peter DeWitt

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
data(diamonds, package = "ggplot2")

## simple examples for the just getting the matrix for table one
## this could be used in xtable, Hmisc::latex, and likely other functions
tableone("cut", "color", diamonds[1:50, ])$tab
tableone("price", "color", diamonds[1:50, ],
         tests = c("chisq.test", #' "aov"))$tab
tableone(c("cut", "price"), "color", diamonds[1:50, ],
         tests = c("chisq.test", "aov"))$tab

## A LaTeX table via Hmisc::latex

tab1 <- tableone(c("cut", "price"), "color", diamonds[1:50, ],
                 tests = c("chisq.test", "aov"))
Hmisc::latex(tab1$tab,
             file     = "",
             title    = "Example from qwraps",
             ctable   = TRUE,
             cgroup   = tab1$cgrp,
             n.cgroup = tab1$ncgrp,
             colhead  = NULL,
             rgroup   = tab1$rgrp,
             n.rgroup = tab1$nrgrp,
             rowname  = tab1$rwnm,
             caption  = "Example Table 1 from the qwraps with Hmisc.",
             label    = "tab:tableone",
             col.just = rep("r", ncol(tab1$tab)))

## A better and easier way to get the table into a LaTeX file
print(tab1)

dewittpe/qwraps documentation built on May 15, 2019, 5:07 a.m.