-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kaz-yos
committed
Feb 15, 2014
1 parent
27c34ca
commit 21d32e1
Showing
2 changed files
with
79 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,110 @@ | ||
tableone | ||
=============================================================================== | ||
|
||
An R package to create "Table 1", description of baseline characteristics | ||
**An R package to create "Table 1", description of baseline characteristics** | ||
|
||
This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroups and groupwise comparison. The package was insipired by and based on descriptive statistics functions in Deducer, a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for CUI users. | ||
|
||
For some reasons, there are no good functions to create the "Table 1", i.e., description of baseline characteristics in R although it is essential in every medical research. The package was insipired by descriptive statistics functions in Deducer, Java-based GUI package. This package does not require GUI or Java, and intended for CUI users. | ||
|
||
Examples | ||
------------------------------------------------------------------------------- | ||
|
||
**Continuous variables** | ||
See also the demonstration here: http://rpubs.com/kaz_yos/tableone-demo-e | ||
|
||
You can specifiy which variables you handle as nonnormal variables. The corresponding p-values will be from nonparametric tests. | ||
``` | ||
> print(contTable2, nonnormal = nonNormalVars) | ||
Stratified by status | ||
0 1 2 p | ||
n 232 25 161 | ||
time (mean (sd)) 2333.16 (994.66) 1546.20 (753.07) 1376.93 (1049.23) <0.001 | ||
age (mean (sd)) 49.51 (10.43) 41.69 (6.33) 53.92 (9.81) <0.001 | ||
bili (median [IQR]) 0.90 [0.60, 1.60] 3.10 [1.30, 3.50] 3.20 [1.40, 7.10] <0.001 | ||
chol (median [IQR]) 292.00 [245.25, 360.00] 343.50 [311.50, 445.50] 339.00 [257.50, 454.00] 0.004 | ||
albumin (mean (sd)) 3.59 (0.36) 3.49 (0.46) 3.36 (0.47) <0.001 | ||
copper (median [IQR]) 52.00 [33.50, 77.50] 102.00 [69.00, 129.50] 111.00 [63.50, 199.25] <0.001 | ||
alk.phos (median [IQR]) 1107.50 [794.00, 1641.00] 1345.00 [1028.50, 1777.50] 1664.00 [1029.00, 2468.00] <0.001 | ||
ast (mean (sd)) 107.29 (52.79) 130.12 (36.95) 141.93 (58.38) <0.001 | ||
trig (median [IQR]) 104.00 [80.00, 133.50] 124.00 [85.75, 145.75] 122.00 [91.00, 171.00] 0.006 | ||
platelet (mean (sd)) 261.16 (88.61) 309.60 (102.65) 242.49 (107.88) 0.011 | ||
protime (median [IQR]) 10.40 [9.90, 10.80] 10.30 [10.00, 10.70] 11.00 [10.47, 11.80] <0.001 | ||
## Make categorical variables factors | ||
> varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") | ||
> pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) | ||
## Create a variable list. Use dput(names(pbc)) | ||
> vars <- c("time","status","age","sex","ascites","hepato", | ||
+ "spiders","edema","bili","chol","albumin", | ||
+ "copper","alk.phos","ast","trig","platelet", | ||
+ "protime","stage") | ||
## Create Table 1 stratified by trt (omit strata argument for overall table) | ||
> tableOne <- CreateTableOne(vars = vars, strata = "trt", data = pbc) | ||
## Just typing the object name will invoke the print.TableOne method | ||
## Tests are by oneway.test/t.test for continuous, chisq.test for categorical | ||
> tableOne | ||
Stratified by trt | ||
1 2 p test | ||
n 158 154 | ||
time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 | ||
status (%) 0.894 | ||
0 83 (52.5) 85 (55.2) | ||
1 10 ( 6.3) 9 ( 5.8) | ||
2 65 (41.1) 60 (39.0) | ||
age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 | ||
sex = f (%) 137 (86.7) 139 (90.3) 0.421 | ||
ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 | ||
hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 | ||
spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 | ||
edema (%) 0.877 | ||
0 132 (83.5) 131 (85.1) | ||
0.5 16 (10.1) 13 ( 8.4) | ||
1 10 ( 6.3) 10 ( 6.5) | ||
bili (mean (sd)) 2.87 (3.63) 3.65 (5.28) 0.131 | ||
chol (mean (sd)) 365.01 (209.54) 373.88 (252.48) 0.748 | ||
albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 | ||
copper (mean (sd)) 97.64 (90.59) 97.65 (80.49) 0.999 | ||
alk.phos (mean (sd)) 2021.30 (2183.44) 1943.01 (2101.69) 0.747 | ||
ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 | ||
trig (mean (sd)) 124.14 (71.54) 125.25 (58.52) 0.886 | ||
platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 | ||
protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 | ||
stage (%) 0.201 | ||
1 12 ( 7.6) 4 ( 2.6) | ||
2 35 (22.2) 32 (20.8) | ||
3 56 (35.4) 64 (41.6) | ||
4 55 (34.8) 54 (35.1) | ||
``` | ||
|
||
**Categorical variables** | ||
|
||
For categorical variables, levels are handled in decent ways. For two-level variables, only the upper level is shown to avoid redundant information (change factor level to reverse). For multi-category variables, the level names come under the variable name for easy viewing. Frequency and/or percentage can be chosen for format. | ||
``` | ||
> print(catTable2, exact = exactVars) | ||
Stratified by status | ||
0 1 2 p test | ||
n 232 25 161 | ||
trt = 2 (%) 85 (50.6) 9 (47.4) 60 (48.0) 0.894 | ||
sex = f (%) 215 (92.7) 22 (88.0) 137 (85.1) 0.053 | ||
ascites = 1 (%) 1 ( 0.6) 0 ( 0.0) 23 (18.4) <0.001 exact | ||
hepato = 1 (%) 60 (35.7) 12 (63.2) 88 (70.4) <0.001 | ||
spiders = 1 (%) 33 (19.6) 5 (26.3) 52 (41.6) <0.001 | ||
edema (%) <0.001 exact | ||
0 216 (93.1) 22 (88.0) 116 (72.0) | ||
0.5 15 ( 6.5) 3 (12.0) 26 (16.1) | ||
1 1 ( 0.4) 0 ( 0.0) 19 (11.8) | ||
stage (%) <0.001 | ||
1 19 ( 8.3) 0 ( 0.0) 2 ( 1.3) | ||
2 64 (27.8) 5 (20.0) 23 (14.6) | ||
3 97 (42.2) 10 (40.0) 48 (30.6) | ||
4 50 (21.7) 10 (40.0) 84 (53.5) | ||
``` | ||
|
||
Installation | ||
------------------------------------------------------------------------------- | ||
|
||
This is a piece of software in active development. Please do not rely on this in a production environment. | ||
Installing tableone | ||
-------------------- | ||
The tableone package for R is still in development, and is not available from the CRAN, yet. You can install it using one of the following ways. | ||
|
||
The archive file for point releases are available from the following URL: | ||
|
||
- https://github.com/kaz-yos/tableone/releases | ||
|
||
**Console method** | ||
In OS X and Linux, after downloading this .tar.gz file, it can be installed from the terminal (Mac: Terminal.app) by doing: | ||
|
||
Your contribution is appreciated. Please report bugs, request feasures, and send improvement suggestions. | ||
``` | ||
$ R CMD install tableone_0.2.0_20140214.tar.gz # (or what ever the current version is) | ||
``` | ||
|
||
In Windows, you should be able to do the same in the console. If it does not work please install the Rtools (http://cran.r-project.org/bin/windows/Rtools/). | ||
|
||
The source tar.gz file for the point release is available at: | ||
``` | ||
> R CMD install tableone_0.2.0_20140214.tar.gz | ||
``` | ||
|
||
https://github.com/kaz-yos/tableone/releases | ||
**R method 1** | ||
From within R, you can also use the install.packages() function as follows. | ||
|
||
On Mac (and Linux system?), you can then do the following in the Terminal. | ||
``` | ||
R CMD INSTALL tableone_ver.tar.gz | ||
> install.packages("~/statistics/package_development/tableone_0.2.0_20140214.tar.gz", repos = NULL, type = "source") | ||
``` | ||
|
||
Alternatively, you can use the devtools to install from github directly. | ||
```r | ||
You need to change "~/statistics/package_development/tableone_0.2.0_20140214.tar.gz" part to the directory where you have the file.edit | ||
|
||
**R method 2** | ||
Yet another way to install it is installation from github repository. You first need to install the devtools package to do the following. You can choose from the latest stable version and the latest development version. | ||
``` | ||
## Install devtools (if you do not have it already) | ||
install.packages("devtools") | ||
> install.packages("devtools") | ||
## Load devtools | ||
library(devtools) | ||
> library(devtools) | ||
## Install directly from github (master (stable) branch) | ||
install_github(repo = "kaz-yos/tableone") | ||
> install_github(repo = "kaz-yos/tableone") | ||
## Install directly from github (develop branch) | ||
install_github(repo = "kaz-yos/tableone", ref = "develop") | ||
## Load | ||
library(tableone) | ||
> install_github(repo = "kaz-yos/tableone", ref = "develop") # If you want the latest | ||
``` | ||
|
||
Using devtools requires some preparation, please see the following link for information. | ||
|
||
http://www.rstudio.com/projects/devtools/ |