Many data analyses start with a display of descriptive statistics of important variables. This function takes a data frame of nominal variables and possible grouping (such as e.g. treatment), weighting, and subset variables and provides a LaTeX table of descriptive statistics separately per group and jointly for all observations, per variable.
tableNominal(vars, weights = NA, subset = NA,
group = NA, miss.cat = NA, print.pval = c("none", "fisher",
"chi2"), pval.bound = 10^-4, fisher.B = 2000, vertical = TRUE,
cap = "", lab = "", col.tit.font = c("bf", "", "sf", "it", "rm"),
font.size = "footnotesize", longtable = TRUE, nams = NA,
cumsum = TRUE, ...)
Outputs the LaTeX table.
A data frame of nominal variables. See nams
for an alternative
way of specifying the variables to be displayed.
Optional vector of weights of each observation.
Optional logical vector, indicates subset of observations to be used.
Optional grouping variable.
Vector specifying the factors in vars
that should have their NA
s transformed to a separate category.
Add \(p\)-values of Fisher's exact or \(\chi^2\) test for a difference of distributions between groups to the table, if there is more than one group. Note that by default, any missing values are removed for computation of \(p\)-values. If missings should be considered a separate level, define the input variables accordingly.
\(p\)-values below pval.bound
are formatted as < pval.bound
.
Number of simulations to compute \(p\)-value for Fisher's exact test. Note that in the function
fisher.test
the option simulate.p.value
is set to
TRUE
, unless fisher.B == Inf
which asks for the exact computation.
If TRUE
, add vertical lines to the table, separating labels and groups, if applicable.
The caption of the resulting LaTeX table.
The label of the resulting LaTeX table.
Choose the font for the column titles here (default: boldface).
Font size for the generated table in LaTeX.
If TRUE
, function makes use of package longtable
in LaTex to generate tables that
span more than one page. If FALSE
, generates a table in tabular
environment.
A vector of strings, containing the names corresponding to the variables in vars
, if vars
is not a data frame but a list of variables. These are then the names that appear in the LaTeX table.
This option is only kept for backward compatibility.
If TRUE
, the cumulative sums of the percentages
are included for every level of the grouping variable.
Arguments pass through to print.xtable
.
Kaspar Rufibach (maintainer), kaspar.rufibach@gmail.com,
http://www.kasparrufibach.ch
If either one of the arguments group
, weights
, or subset
is different from NA
and if vars
is a list, then it is assumed that all variables
in vars
are of equal length.
Rufibach, K. (2009)
reporttools: R-Functions to Generate LaTeX Tables of Descriptive Statistics.
Journal of Statistical Software, Code Snippets, 31(1).
tools:::Rd_expr_doi("https://doi.org/10.18637/jss.v031.c01").