1.Packages Load
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.1
## ✔ ggplot2 4.0.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.0.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(gtsummary)
library(dplyr)
library(tidyr)
data <- ("trial.csv")
2.Univariate Summary Generation:
trial %>%
select(age, grade, trt) %>%
tbl_summary()
| Characteristic | N = 2001 |
|---|---|
| Age | 47 (38, 57) |
| Unknown | 11 |
| Grade | |
| I | 68 (34%) |
| II | 68 (34%) |
| III | 64 (32%) |
| Chemotherapy Treatment | |
| Drug A | 98 (49%) |
| Drug B | 102 (51%) |
| 1 Median (Q1, Q3); n (%) | |
trial %>%
tbl_summary(by = trt) %>%
add_p() %>%
add_overall()
| Characteristic | Overall N = 2001 |
Drug A N = 981 |
Drug B N = 1021 |
p-value2 |
|---|---|---|---|---|
| Age | 47 (38, 57) | 46 (37, 60) | 48 (39, 56) | 0.7 |
| Unknown | 11 | 7 | 4 | |
| Marker Level (ng/mL) | 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 | 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 | 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 | 61 (32%) | 28 (29%) | 33 (34%) | 0.5 |
| Unknown | 7 | 3 | 4 | |
| Patient Died | 112 (56%) | 52 (53%) | 60 (59%) | 0.4 |
| Months to Death/Censor | 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 | ||||
model <- glm( factor(death) ~ trt + age, data = trial, family = binomial)
summary(model)
##
## Call:
## glm(formula = factor(death) ~ trt + age, family = binomial, data = trial)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.47456 0.52918 -0.897 0.370
## trtDrug B 0.30448 0.29390 1.036 0.300
## age 0.01056 0.01033 1.022 0.307
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 260.48 on 188 degrees of freedom
## Residual deviance: 258.32 on 186 degrees of freedom
## (11 observations deleted due to missingness)
## AIC: 264.32
##
## Number of Fisher Scoring iterations: 4
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 | |||
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