tabglm: Create Summary Table for Fitted Generalized Linear Model

Description Usage Arguments Value Examples

View source: R/archived/tabglm-2020-03-18.R View source: R/archived/tabglm-2020-03-21.R View source: R/tabglm.R

Description

Creates a table summarizing a GLM fit using glm.

Usage

1
2
3
4
5
6
7
8
9
tabglm(
  fit,
  columns = NULL,
  xvarlabels = NULL,
  factor.compression = 1,
  sep.char = ", ",
  decimals = 2,
  formatp.list = NULL
)

Arguments

fit

Fitted glm object.

columns

Character vector specifying what columns to include. Choices for each element are "beta", "se", "betaci" for 95% CI for Beta, "beta.se" for Beta (SE), "beta.ci" for Beta (95% CI), "or", "orci" for 95% CI for OR, "or.ci" for OR (95% CI), "hr", "hrci" for 95% CI for HR, "hr.ci" for HR (95% CI), "test" for z/t statistic, and "p". If OR's or HR's are requested, the function will trust that exponentiated betas correspond to these quantities.

xvarlabels

Named list specifying labels to use for certain predictors. For example, if fit includes a predictor named "race" that you want to label "Race/ethnicity" and a predictor named "age_yrs" that you want to label "Age (years)", use xvarlabels = list(race = "Race/ethnicity", age_yrs = "Age (years)".

factor.compression

Integer value from 1 to 5 controlling how much compression is applied to factor predictors (higher value = more compression). If 1, rows are Variable, Level 1 (ref), Level 2, ...; if 2, rows are Variable (ref = Level 1), Level 2, ...; if 3, rows are Level 1 (ref), Level 2, ...; if 4, rows are Level 2 (ref = Level 1), ...; if 5, rows are Level 2, ...

sep.char

Character string with separator to place between lower and upper bound of confidence intervals. Typically "-" or ", ". kable.

decimals

Numeric value specifying number of decimal places for numbers other than p-values.

formatp.list

List of arguments to pass to formatp.

Value

kable.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Linear regression: BMI vs. age, sex, race, and treatment
fit <- glm(BMI ~ Age + Sex + Race + Group, data = tabdata)
tabglm(fit)

# Can also use piping
fit %>% tabglm()

# Logistic regression: 1-year mortality vs. age, sex, race, and treatment
fit <- glm(
  death_1yr ~ Age + Sex + Race + Group,
  data = tabdata,
  family = binomial
)
fit %>% tabglm()

# Same as previous, but with custom labels for Age and Race and factors
# displayed in slightly more compressed format
fit %>%
  tabglm(
    xvarlabels = list(Age = "Age (years)", Race = "Race/ethnicity"),
    factor.compression = 2
  )

# Logistic regression model with some higher-order terms
fit <- glm(
  death_1yr ~ poly(Age, 2, raw = TRUE) + Sex + BMI + Sex * BMI,
  data = tabdata,
  family = "binomial"
)
fit %>% tabglm()

tab documentation built on Aug. 2, 2021, 9:06 a.m.