cida_table1: Create a table one

View source: R/cida_table1.R

cida_table1R Documentation

Create a table one

Description

This is a function created to provide characteristics of a study group with an option to stratify by some variable (usually an exposure).

Usage

cida_table1(
  data,
  includeVars,
  stratifyBy,
  group_labels,
  group_label_span,
  caption = NULL,
  footnote = NULL,
  include_total = TRUE,
  exclude_mean = FALSE,
  exclude_missing = FALSE,
  compute_pval = FALSE,
  nonParametricVars = NULL,
  exportWord = FALSE,
  useSciNotation = FALSE
)

Arguments

data

A data frame with data

includeVars

A vector of variable names you wish to include in the table.

stratifyBy

The group by which you wish to stratify your table

group_labels

Higher level labels for you stratified groups

group_label_span

The span of columns for each group in 'group_labels'

caption

Optional; Adds a caption to the table

footnote

Optional; Adds a footnote to the table

include_total

Bool; Default TRUE. Includes a column of the summation of all the stratified groups.

exclude_mean

Bool; Default FALSE. Excludes the mean for numerical variables.

exclude_missing

Bool; Default FALSE. Excludes percentages of missing data and only returns counts

compute_pval

Bool; Default FALSE. Computes p-values for 'includeVars' and add a p-value column in the table.

nonParametricVars

Vector; of the variable names you would like non-parametric testing to be conducted on for p-values returned

exportWord

Bool; whether to export the table in a nice format into word

useSciNotation

Bool; Use scientific notation for large/small continuous variables

Value

an html table with N and percentages for categorical variables, mean , SD, Median, and Range for numeric variables. Returns p-values if specified.

Examples

# Synthetic data
df = data.frame(
    `Age` = c(10,12,14,18,20,19,28,33, rep(NA, 4)),
    `Sex` = c(rep("Female", 4), rep("Male", 4), rep(NA, 4)),
    `Smoking Status` = c(rep('Former', 2), rep('Current', 2), rep('Never', 4), rep(NA, 4)),
    `IL-8` = rnorm(12, 35, sd = 7),
    `Group` = c(rep('Control', 4), rep('Heart Disease', 4), rep('Lung Disease', 4)),
     check.names = FALSE
    )
# Table 1 with no p-values
cida_table1(data = df,
            includeVars = c("Age", "Sex", "Smoking Status", "IL-8"),
            stratifyBy = "Group",
            group_labels = c("Group"),
            group_label_span = c(3),
            caption = "TABLE 1",
            footnote = "My table 1",
            include_total = FALSE,
            compute_pval = FALSE,
            nonParametricVars = NULL,
            exportWord = FALSE)

# Table 1 with p-values, no mean, no percent missing
cida_table1(data = df,
            includeVars = c("Age", "Sex", "Smoking Status", "IL-8"),
            stratifyBy = "Group",
            group_labels = c("", "Group", ""),
            group_label_span = c(1, 3, 1),
            caption = "TABLE 1",
            footnote = "My table 1",
            exclude_mean = TRUE,
            exclude_missing = TRUE,
            include_total = TRUE,
            compute_pval = TRUE,
            nonParametricVars = NULL,
            exportWord = FALSE)

# Table 1 styling the output
# You can also rename the variables like this (name in data = new name)
cida_table1(data = df,
            includeVars = c("Age" = "age",
             "Sex" = "sex",
              "Smoking Status" = "smoking",
               "IL-8"= "Interleukin 8"),
            stratifyBy = "Group",
            group_labels = c("", "Group", ""),
            group_label_span = c(1, 3, 1),
            caption = "TABLE 1",
            footnote = "My table 1",
            exclude_mean = TRUE,
            exclude_missing = TRUE,
            include_total = TRUE,
            compute_pval = TRUE,
            nonParametricVars = c("Age", "IL-8"), # Uses original name
            exportWord = FALSE)

# Tables are html so you can customize them using html and css
cida_table1(data = df,
            includeVars = c("Age" = "age",
                            "Sex" =
                            "<span style =
                            'background-color:pink;'>sex</span>", # Highlight pink
                            "Smoking Status" =
                            "<span style='color:purple;
                             font-family:Snell Roundhand;
                             font-size:1.5em;
                             font-weight:900;'>smoking status</span>",
                            "IL-8"=
                            "Interleukin 8&beta;"), # &beta; is html for greek lowercase beta
            stratifyBy = "Group",
            group_labels = c("", "Group", ""),
            group_label_span = c(1, 3, 1),
            caption = "TABLE 1",
            footnote = "My table 1",
            exclude_mean = TRUE,
            exclude_missing = TRUE,
            include_total = TRUE,
            compute_pval = TRUE,
            nonParametricVars = NULL,
            exportWord = FALSE)

# You can add icons if you like

cida_table1(data = df,
            includeVars = c("Age" = "age", "Sex" = "sex",
            "Smoking Status" =
            "<link rel='stylesheet'
href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'>
            <span>Smoking Status </span>
            <i class='fa fa-medkit'></i>", # Medkit icon
            "IL-8"= "Interleukin 8&beta;"),
            stratifyBy = "Group",
            group_labels = c("", "Group", ""),
            group_label_span = c(1, 3, 1),
            caption = "TABLE 1",
            footnote = "My table 1",
            exclude_mean = TRUE,
            exclude_missing = TRUE,
            include_total = TRUE,
            compute_pval = TRUE,
            nonParametricVars = NULL,
            exportWord = FALSE)


CIDA-CSPH/CIDAtools documentation built on Sept. 18, 2023, 10:55 a.m.