report_cat_vars: Create a summary table for categorical variables and their...

View source: R/cat_desc_table.R

report_cat_varsR Documentation

Create a summary table for categorical variables and their relationship with a continuous outcome variable

Description

This takes a set of categorical variables and a continuous dependent variable and produces a table that shows the distribution of data across the levels of the categorical variables, as well as the mean of the dependent variable for each level and the significance of pairwise comparisons between these means.

Usage

report_cat_vars(
  data,
  dv,
  ...,
  var_names = NULL,
  level_names = NULL,
  p_adjust = p.adjust.methods,
  alpha_level = 0.05,
  filename = NULL,
  notes = list(),
  dv_name = NULL,
  bold_vars = TRUE,
  apa_style = TRUE,
  css_tags = list(),
  na.rm = TRUE,
  exclude_na = FALSE
)

Arguments

data

Dataframe containing the variables specified

dv

The continuous dependent variable to be presented alongside the levels of categorical variables. Set to NULL to just show the distribution of the categorical variables.

...

Categorical variables to be included

var_names

Tibble of old and new variable names, if variables are to be renamed for display. See get_rename_tribbles() for required format

level_names

Tibble of old and new level names, if levels are to be renamed for display. See get_rename_tribbles() for required format

p_adjust

One of p_adjust.methods, defaults to Holm

alpha_level

The level of significance for the pairwise comparisons (after p.adjust). Defaults to .05

filename

If provided, the table will be saved as an HTML file with this name.

notes

List of notes to append to bottom of table.

dv_name

Optional. A different name to use for the dependent variable in the automatic table footnote explaining the M(SD) column. Defaults to dv.

bold_vars

Should rows with variable names be bold. Defaults to TRUE

apa_style

Logical, should APA-style formatting be applied

css_tags

List of css tags to be added, each named with the class that the tag should be added to.

na.rm

Should missing values be dropped in the dv when summary statistics are calculated?

exclude_na

Should cases that are NA on a categorical variable be dropped from that section?

Value

A list including a tibble of descriptive statistics (descr), the gt-table (tab) and the HTML code (html_code) with css_tags added

Examples


report_cat_vars(iris, Sepal.Length, Species)

# You can rename variables and levels reasonably easily
# Use get_rename_tribbles() to get the basis of these tibbles

var_renames <- tibble::tribble(
 ~old,     ~new,     
 "gndr",   "Gender",  
 "cntry",  "Country"
 )

level_renames <- tibble::tribble(
 ~var,     ~level_old, ~level_new, 
 "gndr",   "1",        "male",       
 "gndr",   "2",        "female",       
 "cntry",  "DE",       "Germany",      
 "cntry",  "FR",       "France",      
 "cntry",  "GB",       "UK"
 )
 
report_cat_vars(ess_health, health, gndr, cntry, var_names = var_renames, 
             level_names = level_renames)

LukasWallrich/timesaveR documentation built on Nov. 29, 2024, 4:47 a.m.