Biostatistic 2 Exam Preparations NAIMUR RAHMAN 24316007
library(gtsummary)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
data("trial")
#Generate a univariate summary for age, grade, and trt
trial %>%
tbl_summary()
| Characteristic | N = 2001 |
|---|---|
| Chemotherapy Treatment | |
| Drug A | 98 (49%) |
| Drug B | 102 (51%) |
| Age | 47 (38, 57) |
| Unknown | 11 |
| Marker Level (ng/mL) | 0.64 (0.22, 1.41) |
| Unknown | 10 |
| T Stage | |
| T1 | 53 (27%) |
| T2 | 54 (27%) |
| T3 | 43 (22%) |
| T4 | 50 (25%) |
| Grade | |
| I | 68 (34%) |
| II | 68 (34%) |
| III | 64 (32%) |
| Tumor Response | 61 (32%) |
| Unknown | 7 |
| Patient Died | 112 (56%) |
| Months to Death/Censor | 22.4 (15.9, 24.0) |
| 1 n (%); Median (Q1, Q3) | |
trial1 <- trial %>%
select(trt, age, grade)
trial1
#Select variables
trial2 <- trial %>%
select(trt, age, grade)
#Descriptive table
trial2 %>%
tbl_summary()
| Characteristic | N = 2001 |
|---|---|
| Chemotherapy Treatment | |
| Drug A | 98 (49%) |
| Drug B | 102 (51%) |
| Age | 47 (38, 57) |
| Unknown | 11 |
| Grade | |
| I | 68 (34%) |
| II | 68 (34%) |
| III | 64 (32%) |
| 1 n (%); Median (Q1, Q3) | |
#Cross Table Summary
trial %>%
tbl_summary(
by = trt)
| Characteristic | Drug A N = 981 |
Drug B N = 1021 |
|---|---|---|
| Age | 46 (37, 60) | 48 (39, 56) |
| Unknown | 7 | 4 |
| Marker Level (ng/mL) | 0.84 (0.23, 1.60) | 0.52 (0.18, 1.21) |
| Unknown | 6 | 4 |
| T Stage | ||
| T1 | 28 (29%) | 25 (25%) |
| T2 | 25 (26%) | 29 (28%) |
| T3 | 22 (22%) | 21 (21%) |
| T4 | 23 (23%) | 27 (26%) |
| Grade | ||
| I | 35 (36%) | 33 (32%) |
| II | 32 (33%) | 36 (35%) |
| III | 31 (32%) | 33 (32%) |
| Tumor Response | 28 (29%) | 33 (34%) |
| Unknown | 3 | 4 |
| Patient Died | 52 (53%) | 60 (59%) |
| Months to Death/Censor | 23.5 (17.4, 24.0) | 21.2 (14.5, 24.0) |
| 1 Median (Q1, Q3); n (%) | ||
#Bi variate Analysis (Add P Value)
trial %>%
tbl_summary(by = trt) %>%
add_p() %>%
add_overall() %>%
add_n()
| Characteristic | N | Overall N = 2001 |
Drug A N = 981 |
Drug B N = 1021 |
p-value2 |
|---|---|---|---|---|---|
| Age | 189 | 47 (38, 57) | 46 (37, 60) | 48 (39, 56) | 0.7 |
| Unknown | 11 | 7 | 4 | ||
| Marker Level (ng/mL) | 190 | 0.64 (0.22, 1.41) | 0.84 (0.23, 1.60) | 0.52 (0.18, 1.21) | 0.085 |
| Unknown | 10 | 6 | 4 | ||
| T Stage | 200 | 0.9 | |||
| T1 | 53 (27%) | 28 (29%) | 25 (25%) | ||
| T2 | 54 (27%) | 25 (26%) | 29 (28%) | ||
| T3 | 43 (22%) | 22 (22%) | 21 (21%) | ||
| T4 | 50 (25%) | 23 (23%) | 27 (26%) | ||
| Grade | 200 | 0.9 | |||
| I | 68 (34%) | 35 (36%) | 33 (32%) | ||
| II | 68 (34%) | 32 (33%) | 36 (35%) | ||
| III | 64 (32%) | 31 (32%) | 33 (32%) | ||
| Tumor Response | 193 | 61 (32%) | 28 (29%) | 33 (34%) | 0.5 |
| Unknown | 7 | 3 | 4 | ||
| Patient Died | 200 | 112 (56%) | 52 (53%) | 60 (59%) | 0.4 |
| Months to Death/Censor | 200 | 22.4 (15.9, 24.0) | 23.5 (17.4, 24.0) | 21.2 (14.5, 24.0) | 0.14 |
| 1 Median (Q1, Q3); n (%) | |||||
| 2 Wilcoxon rank sum test; Pearson’s Chi-squared test | |||||
#logistic regression model
model <- lm(response ~ trt+age, data = trial)
# Create a summary table
tbl_regression(model)
| Characteristic | Beta | 95% CI | p-value |
|---|---|---|---|
| Chemotherapy Treatment | |||
| Drug A | — | — | |
| Drug B | 0.03 | -0.11, 0.16 | 0.7 |
| Age | 0.00 | 0.00, 0.01 | 0.095 |
| Abbreviation: CI = Confidence Interval | |||
#egression output using tbl_regression
model <- glm(death ~ trt + age, data = trial, family = "binomial")
# Create a summary table
tbl_regression(model)
| Characteristic | log(OR) | 95% CI | p-value |
|---|---|---|---|
| Chemotherapy Treatment | |||
| Drug A | — | — | |
| Drug B | 0.30 | -0.27, 0.88 | 0.3 |
| Age | 0.01 | -0.01, 0.03 | 0.3 |
| Abbreviations: CI = Confidence Interval, OR = Odds Ratio | |||
#odds ratio with confidence intervals
exp(cbind(OR = coef(model), confint(model)))
## Waiting for profiling to be done...
## OR 2.5 % 97.5 %
## (Intercept) 0.6221615 0.2173766 1.748544
## trtDrug B 1.3559218 0.7628798 2.419382
## age 1.0106203 0.9904519 1.031601