table1 패키지

2018/06/01

table1은 HTML 형식의 표를 쉽게 만들어 주는 패키지로 보고서 작성할 때 유용할 것 같습니다. (Rich 2018)

library(table1)
dat <- expand.grid(id=1:10, sex=c("Male", "Female"), treat=c("Treated", "Placebo"))
dat$age <- runif(nrow(dat), 10, 50)
dat$age[3] <- NA  # Add a missing value
dat$wt <- exp(rnorm(nrow(dat), log(70), 0.2))

label(dat$sex) <- "Sex"
label(dat$age) <- "Age"
label(dat$treat) <- "Treatment Group"
label(dat$wt) <- "Weight"

units(dat$age) <- "years"
units(dat$wt) <- "kg"

# One level of stratification
table1(~ sex + age + wt | treat, data=dat)
Treated
(n=20)
Placebo
(n=20)
Overall
(n=40)
Sex
Male 10 (50.0%) 10 (50.0%) 20 (50.0%)
Female 10 (50.0%) 10 (50.0%) 20 (50.0%)
Age (years)
Mean (SD) 28.8 (13.0) 30.5 (13.9) 29.7 (13.3)
Median [Min, Max] 27.3 [11.8, 49.8] 27.3 [10.2, 48.6] 27.3 [10.2, 49.8]
Missing 1 (5.0%) 0 (0.0%) 1 (2.5%)
Weight (kg)
Mean (SD) 71.6 (14.6) 70.8 (14.6) 71.2 (14.4)
Median [Min, Max] 68.9 [51.0, 106] 66.9 [44.6, 102] 68.0 [44.6, 106]

아래는 Theoph 농도 자료를 NonCompart (Bae 2018) 패키지를 사용하여 약동학 파라메터를 구하고 표를 만든 것입니다.

library(tidyverse)
library(NonCompart)
dat_Theoph <- tblNCA(Theoph, key="Subject", dose=320, concUnit="mg/L") %>% 
  as.tibble() %>% 
  mutate_all(funs(as.numeric)) %>% 
  mutate(treat = ifelse(Subject <= 6, 'Treated', 'Placebo')) %>% 
  select(Subject, CMAX, TMAX, AUCLST, LAMZHL, CLFO, treat)

table1(~ CMAX + TMAX + AUCLST + LAMZHL + CLFO | treat, data = dat_Theoph)
Placebo
(n=6)
Treated
(n=6)
Overall
(n=12)
CMAX
Mean (SD) 8.61 (1.25) 8.91 (1.78) 8.76 (1.47)
Median [Min, Max] 8.52 [7.09, 10.2] 8.47 [6.44, 11.4] 8.47 [6.44, 11.4]
TMAX
Mean (SD) 2.36 (1.34) 1.21 (0.351) 1.79 (1.11)
Median [Min, Max] 2.75 [0.630, 3.55] 1.10 [1.00, 1.92] 1.14 [0.630, 3.55]
AUCLST
Mean (SD) 101 (23.1) 107 (25.9) 104 (23.6)
Median [Min, Max] 89.7 [80.1, 138] 103 [73.8, 149] 95.4 [73.8, 149]
LAMZHL
Mean (SD) 7.93 (1.04) 8.43 (2.93) 8.18 (2.12)
Median [Min, Max] 8.13 [6.29, 9.25] 7.44 [6.66, 14.3] 7.87 [6.29, 14.3]
CLFO
Mean (SD) 2.88 (0.614) 2.73 (0.794) 2.81 (0.681)
Median [Min, Max] 3.08 [1.88, 3.59] 2.81 [1.48, 3.80] 3.00 [1.48, 3.80]

참고문헌

Bae, Kyun-Seop. 2018. NonCompart: Noncompartmental Analysis for Pharmacokinetic Data. https://CRAN.R-project.org/package=NonCompart.

Rich, Benjamin. 2018. Table1: Tables of Descriptive Statistics in Html. https://CRAN.R-project.org/package=table1.