tableone CreateContTable() test

What is tableone?

### Load dataset
library(survival)
data(pbc)
head(pbc)
## Group by "status" (3 groups).
## Use c("time","age","bili","chol","albumin","copper","alk.phos","ast","trig","platelet","protime")
## 
## age:       in years                                                      
## albumin:   serum albumin (g/dl)                                          
## alk.phos:  alkaline phosphotase (U/liter)                                
## ascites:   presence of ascites                                           
## ast:       aspartate aminotransferase, once called SGOT (U/ml)           
## bili:      serum bilirunbin (mg/dl)                                      
## chol:      serum cholesterol (mg/dl)                                     
## copper:    urine copper (ug/day)                                         
## edema:     0 no edema, 0.5 untreated or successfully treated             
##            1 edema despite diuretic therapy                              
## hepato:    presence of hepatomegaly or enlarged liver                    
## id:        case number                                                   
## platelet:  platelet count                                                
## protime:   standardised blood clotting time                              
## sex:       m/f                                                           
## spiders:   blood vessel malformations in the skin                        
## stage:     histologic stage of disease (needs biopsy)                    
## status:    status at endpoint, 0/1/2 for censored, transplant, dead      
## time:      number of days between registration and the earlier of death, 
##            transplantion, or study analysis in July, 1986                
## trt:       1/2/NA for D-penicillmain, placebo, not randomised            
## trig:      triglycerides (mg/dl)

## Download necessary scripts
repoUrl <- "https://raw.github.com/kaz-yos/tableone/master/R/"
fileNames <- c("CreateCatTable.R","print.CatTable.R","summary.CatTable.R")
download.file(url = paste0(repoUrl, fileNames[1]), destfile = fileNames[1], method = "wget")
download.file(url = paste0(repoUrl, fileNames[2]), destfile = fileNames[2], method = "wget")
download.file(url = paste0(repoUrl, fileNames[3]), destfile = fileNames[3], method = "wget")

## Source them
source("./CreateContTable.R")
source("./print.ContTable.R")
source("./summary.ContTable.R")


###  Define variables
vars <- c("time","age","bili","chol","albumin","copper","alk.phos","ast","trig","platelet","protime")

## Strata
strata <- "status"
strataTwoVars <- c("status","sex")
strataThreeVars <- c("sex","ascites","hepato")

## Data and variables
dataFrame <- pbc
nonNormalVars <- c("bili","chol","copper","alk.phos","trig","protime")

## Create edema strata that are of sizes 1, 2, and 3
smallDataFrame <- pbc[c(2, 3,4, 1,10,14),]
smallStrata <- "edema"


### Behaviors on correct data format (non-stratified)
## Creation
contTable1 <- CreateContTable(vars = vars, data = dataFrame)
## summary method
summary(contTable1)
## print method by default
print(contTable1, nonnormal = nonNormalVars)

### Behaviors on correct data format (stratified)
## Creation
contTable2 <- CreateContTable(vars = vars, strata = strata, data = dataFrame)
## summary method
summary(contTable2)
## print method by default
print(contTable2, nonnormal = nonNormalVars)


### Multivariable stratification
## Two variables
contTable4 <- CreateContTable(vars = vars, strata = strataTwoVars, data = dataFrame)
summary(contTable4)
print(contTable4, nonnormal = nonNormalVars)
## Three variables
contTable5 <- CreateContTable(vars = vars, strata = strataThreeVars, data = dataFrame)
summary(contTable5)
print(contTable5, nonnormal = nonNormalVars)