pubh (version 1.1.16)

cross_tab: Cross-tabulation.

Description

cross_tab is a wrapper to functions from package moonBook to construct tables of descriptive statistics stratified by levels of a categorical outcome.

Usage

cross_tab(
  object = NULL,
  formula = NULL,
  data = NULL,
  label = NULL,
  show.total = TRUE,
  p_val = FALSE,
  ...
)

Arguments

object

When chaining, this holds an object produced in the earlier portions of the chain. Most users can safely ignore this argument. See details and examples.

formula

A formula with shape: y ~ x, where y is a categorical outcome and x is the explanatory variable or a set of explanatory variables (see Details and Examples).

data

A data frame where the variables in the formula can be found.

label

A character, label to be used for the outcome (for non-labelled data).

show.total

Logical, show column with totals?

p_val

Logical, show p-values?

...

Additional arguments passed to mytable_sub.

Value

A huxtable with descriptive statistics stratified by levels of the outcome.

Details

Function cross_tab is a relatively simple wrapper to function mytable of package moonBook. Its main purpose is to construct contingency tables but it can also be used to report a table with descriptives for all variables as long as they are still stratified by the outcome. Please see examples to see how to list explanatory variables. For categorical explanatory variables, the function reports column percentages. If data is labelled with sjlabelled, the label of the outcome (dependent) variable is used to name the outcome; this name can be changed with argument label.

See Also

mytable

Examples

Run this code
# NOT RUN {
data(Oncho)

## A two by two contingency table:
Oncho %>%
  cross_tab(mf ~ area)

## Reporting prevalence:
Oncho %>%
  cross_tab(area ~ mf)

## Contingency table for both sex and area of residence:
Oncho %>%
  cross_tab(mf ~ sex + area, p_val = TRUE)

## Descriptive statistics for all variables in the \code{Oncho} data set except \code{id}.
require(dplyr)
Oncho %>%
  select(- id) %>%
  cross_tab(mf ~ .)
# }

Run the code above in your browser using DataLab