summaryfactorlist: Summarize a set of factors (or continuous variables) by a...

Description Usage Arguments Examples

Description

A function that takes a single dependent variable with a vector of explanatory variable names (continuous or categorical variables) to produce a summary table.

Usage

1
2
3
summary.factorlist(df, dependent, explanatory, cont=c("mean","median"),
	p=FALSE, na.include=FALSE, column=FALSE, total_col=FALSE,
	orderbytotal=FALSE, glm.id=FALSE, na.to.missing = TRUE)

Arguments

df

Dataframe

dependent

Character vector of length 1: name of depdendent variable (2 to 5 factor levels)

explanatory

Character vector of any length: name(s) of explanatory variables

cont

Summary for continuous variables: mean (standard deviation) or median (interquartile range)

p

Logical: Include statistical test (see library(Hmisc))

na.include

Logical: include missing data in summary (NA)

column

Logical: Compute margins by column rather than row

total_col

Logical: include a total column summing across factor levels

orderbytotal

Logical: order final table by total column high to low

glm.id

Logical: not used directly, allows merging via summary.merge

na.to.missing

Logical: convert NA to 'Missing' when na.include=TRUE

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# summary.factorlist() wraps `Hmisc::summary.formula` to summarise any number of variables by a single categorical
# variable. This is usually "Table 1" of a study report.

library(summarizer)
library(tidyverse)

# Load example dataset, modified version of survival::colon
data(colon_s)

# Table 1 - Patient demographics ----
explanatory = c("age", "age.factor", "sex.factor", "obstruct.factor")
dependent = "perfor.factor"
colon_s %>%
  summary.factorlist(dependent, explanatory, p=T)

# summary.factorlist() is also commonly used to summarise any number of variables by an outcome variable (say dead yes/no).

# Table 2 - 5 yr mortality ----
explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor")
dependent = 'mort_5yr'
colon_s %>%
  summary.factorlist(dependent, explanatory)

ewenharrison/summarizer documentation built on May 16, 2019, 9:41 a.m.