-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME.Rmd
More file actions
110 lines (77 loc) · 3.26 KB
/
README.Rmd
File metadata and controls
110 lines (77 loc) · 3.26 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
output: github_document
title: "Summary Tables with 'tab'"
author: "Dane Van Domelen <br> vandomed@gmail.com"
date: "`r Sys.Date()`"
bibliography: vignettes/bibliography.bib
always_allow_html: true
nocite: |
@gee,
@Kmisc,
@knitr1,
@knitr2,
@knitr3,
@survey,
@survey-paper,
@survival-package,
@survival-book
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
message = FALSE
)
# Load packages
library("tab")
library("knitr")
library("gee")
# Set xtable options
options("xtable.caption.placement" = "top",
"xtable.include.rownames" = TRUE,
"xtable.comment" = FALSE)
```
## Installation
You can install and load **tab** from GitHub via the following code:
```{r, eval = FALSE}
devtools::install_github("vandomed/tab")
library("tab")
```
## Functions
The main purpose of **tab** is to create neatly formatted summary tables for papers and presentations. The following functions are included:
* `glm_v` prints a GLM summary table to the RStudio Viewer
* `tabglm` summarizes generalized linear models (GLM's) fit via `glm` or `survey::svyglm`
* `tabgee` summarizes generalized estimating equation models (GEE's) fit via `gee::gee`
* `tabcoxph` summarizes Cox Proportional Hazards models fit via `survival::coxph` or `survey::svycoxph`
* `tabmulti` compares variables across two or more groups, e.g. to create a "Table 1"
* `tabmulti.svy` does the same thing as `tabmulti` but for complex survey data
## Regressions
To summarize a fitted generalized linear model, simply call `glm_v` as you would `glm`. The result will be a formatted summary table printed to the RStudio Viewer. Here's an example for logistic regression:
```{r eval = FALSE}
glm_v(
death_1yr ~ poly(Age, 2, raw = TRUE) + Sex * BMI,
data = tabdata,
family = binomial
)
```

From here, you can "snip" the summary table and save it as a figure (as I did for this README) or copy directly from the Viewer and paste outside of R.
For more flexibility, see `tabglm`. That function lets you control things like what columns to present, how categorical predictors are presented, and so on.
## Summary tables for continuous and categorical variables
You can use `tabmulti` to summarize variables across two or more groups, using a formula interface. Here's an example:
```{r eval = FALSE}
tabmulti(Age + Sex + Race + BMI ~ Group, data = tabdata)
```

## Compatibility with Markdown/Knitr
The functions all return `kable` objects, so they should work perfectly well in R Markdown and knitr documents.
<!-- ## Exporting tables, e.g. to Word -->
<!-- All of the functions in **tab** have an argument called `print.html` which can -->
<!-- be used to export tables to word processors. Setting `print.html = TRUE` will -->
<!-- result in a HTML table being output to your current working directory. You can -->
<!-- open the table (e.g. in Chrome) and copy/paste into your report. -->
<!-- ## Options for printing in R -->
<!-- I used **knitr**'s `kable` function for the examples here, but other approaches -->
<!-- should also work (e.g. **xtable**'s `xtable` or **pandoc**'s `pandoc.table`). -->
## References