将结果的发生率添加到 gtsummary::tbl_uvregression 单变量回归 table
Adding the prevalence of an outcome to a gtsummary::tbl_uvregression univariable regression table
我想将结果的普遍性添加到使用 gtsummary::tbl_uvregression 生成的单变量回归 table 中。有没有办法在不将 tbl_uvregression 对象转换为 table 并使用 dplyr::mutate 函数计算它的情况下执行此操作,如下例所示?
PS:Daniel Sjoberg,感谢您提供非常有用的软件包!
options(digits = 3)
library(gtsummary)
#> #BlackLivesMatter
library(tidyverse)
library(knitr)
library(geepack)
packageVersion("gtsummary")
#> [1] '1.5.1'
data(dietox, package = "geepack")
dietox %>%
mutate(big_pig = if_else(Weight > 50, 1, 0)) %>%
select(big_pig, Pig, Evit, Cu, Litter) %>%
tbl_uvregression(
y = big_pig,
method = geeglm,
method.args = list(id = Pig, family = poisson, corstr = "independence"),
include = -Pig,
exponentiate = TRUE
) %>%
add_n(location = c("level", "label")) %>%
add_nevent(location = c("level", "label")) %>%
as_tibble() %>%
mutate(Prevalence = (`**Event N**` / as.integer(`**N**`))*100) %>%
select(`**Characteristic**`,`**N**`,`**Event N**`,Prevalence, everything()) %>%
kable()
Characteristic
N
Event N
Prevalence
IRR
95% CI
p-value
Evit
861
519
60.3
NA
NA
NA
Evit000
276
167
60.5
NA
NA
NA
Evit100
286
178
62.2
1.03
0.95, 1.12
0.5
Evit200
299
174
58.2
0.96
0.88, 1.05
0.4
Cu
861
519
60.3
NA
NA
NA
Cu000
274
164
59.9
NA
NA
NA
Cu035
300
176
58.7
0.98
0.91, 1.06
0.6
Cu175
287
179
62.4
1.04
0.96, 1.13
0.3
Litter
861
519
60.3
NA
NA
NA
1
48
31
64.6
NA
NA
NA
2
36
25
69.4
1.08
0.99, 1.17
0.091
3
48
25
52.1
0.81
0.64, 1.02
0.077
4
48
29
60.4
0.94
0.86, 1.01
0.10
5
36
25
69.4
1.08
0.90, 1.28
0.4
6
48
31
64.6
1.00
0.93, 1.08
>0.9
7
24
12
50.0
0.77
0.61, 0.98
0.035
8
48
28
58.3
0.90
0.75, 1.08
0.3
9
33
18
54.5
0.84
0.72, 0.99
0.043
10
36
24
66.7
1.03
0.98, 1.09
0.3
11
36
20
55.6
0.86
0.78, 0.95
0.002
12
36
21
58.3
0.90
0.78, 1.04
0.2
13
36
21
58.3
0.90
0.86, 0.95
<0.001
16
48
32
66.7
1.03
0.93, 1.14
0.5
17
36
24
66.7
1.03
0.98, 1.09
0.3
18
36
21
58.3
0.90
0.86, 0.95
<0.001
20
48
30
62.5
0.97
0.89, 1.05
0.5
21
48
30
62.5
0.97
0.79, 1.19
0.8
22
48
27
56.2
0.87
0.74, 1.03
0.11
23
48
24
50.0
0.77
0.63, 0.95
0.016
24
36
21
58.3
0.90
0.86, 0.95
<0.001
由 reprex package (v2.0.1)
创建于 2022-02-11
gtsummary table 包含一个名为 .$table_body
的内部数据框,您可以使用 modify_table_body()
函数直接修改该数据框。在下面的示例中,我计算了流行率并将结果格式化以显示在 table 中。我还公开了已经存在的列 exposure
,这是 exposure/followup 时间的总和。编程愉快!
library(gtsummary)
library(tidyverse)
library(geepack)
packageVersion("gtsummary")
#> [1] '1.5.2'
data(dietox, package = "geepack")
tbl <-
dietox %>%
mutate(big_pig = if_else(Weight > 50, 1, 0)) %>%
select(big_pig, Pig, Evit, Cu) %>%
tbl_uvregression(
y = big_pig,
method = geeglm,
method.args = list(id = Pig, family = poisson, corstr = "independence"),
include = -Pig,
exponentiate = TRUE
) %>%
add_n(location = c("level", "label")) %>%
add_nevent(location = c("level", "label")) %>%
# calculate prev
modify_table_body(
~.x %>%
mutate(
prev = stat_nevent / stat_n * 100
) %>%
relocate(prev, exposure, .after = stat_nevent)
) %>%
# format the newly added stats
modify_header(prev = "**Prevalence**", exposure = "**Total Exposure Time**") %>%
modify_fmt_fun(list(prev = function(x) paste0(style_sigfig(x), "%"),
exposure = style_sigfig))
由 reprex package (v2.0.1)
创建于 2022-02-11
我想将结果的普遍性添加到使用 gtsummary::tbl_uvregression 生成的单变量回归 table 中。有没有办法在不将 tbl_uvregression 对象转换为 table 并使用 dplyr::mutate 函数计算它的情况下执行此操作,如下例所示?
PS:Daniel Sjoberg,感谢您提供非常有用的软件包!
options(digits = 3)
library(gtsummary)
#> #BlackLivesMatter
library(tidyverse)
library(knitr)
library(geepack)
packageVersion("gtsummary")
#> [1] '1.5.1'
data(dietox, package = "geepack")
dietox %>%
mutate(big_pig = if_else(Weight > 50, 1, 0)) %>%
select(big_pig, Pig, Evit, Cu, Litter) %>%
tbl_uvregression(
y = big_pig,
method = geeglm,
method.args = list(id = Pig, family = poisson, corstr = "independence"),
include = -Pig,
exponentiate = TRUE
) %>%
add_n(location = c("level", "label")) %>%
add_nevent(location = c("level", "label")) %>%
as_tibble() %>%
mutate(Prevalence = (`**Event N**` / as.integer(`**N**`))*100) %>%
select(`**Characteristic**`,`**N**`,`**Event N**`,Prevalence, everything()) %>%
kable()
Characteristic | N | Event N | Prevalence | IRR | 95% CI | p-value |
---|---|---|---|---|---|---|
Evit | 861 | 519 | 60.3 | NA | NA | NA |
Evit000 | 276 | 167 | 60.5 | NA | NA | NA |
Evit100 | 286 | 178 | 62.2 | 1.03 | 0.95, 1.12 | 0.5 |
Evit200 | 299 | 174 | 58.2 | 0.96 | 0.88, 1.05 | 0.4 |
Cu | 861 | 519 | 60.3 | NA | NA | NA |
Cu000 | 274 | 164 | 59.9 | NA | NA | NA |
Cu035 | 300 | 176 | 58.7 | 0.98 | 0.91, 1.06 | 0.6 |
Cu175 | 287 | 179 | 62.4 | 1.04 | 0.96, 1.13 | 0.3 |
Litter | 861 | 519 | 60.3 | NA | NA | NA |
1 | 48 | 31 | 64.6 | NA | NA | NA |
2 | 36 | 25 | 69.4 | 1.08 | 0.99, 1.17 | 0.091 |
3 | 48 | 25 | 52.1 | 0.81 | 0.64, 1.02 | 0.077 |
4 | 48 | 29 | 60.4 | 0.94 | 0.86, 1.01 | 0.10 |
5 | 36 | 25 | 69.4 | 1.08 | 0.90, 1.28 | 0.4 |
6 | 48 | 31 | 64.6 | 1.00 | 0.93, 1.08 | >0.9 |
7 | 24 | 12 | 50.0 | 0.77 | 0.61, 0.98 | 0.035 |
8 | 48 | 28 | 58.3 | 0.90 | 0.75, 1.08 | 0.3 |
9 | 33 | 18 | 54.5 | 0.84 | 0.72, 0.99 | 0.043 |
10 | 36 | 24 | 66.7 | 1.03 | 0.98, 1.09 | 0.3 |
11 | 36 | 20 | 55.6 | 0.86 | 0.78, 0.95 | 0.002 |
12 | 36 | 21 | 58.3 | 0.90 | 0.78, 1.04 | 0.2 |
13 | 36 | 21 | 58.3 | 0.90 | 0.86, 0.95 | <0.001 |
16 | 48 | 32 | 66.7 | 1.03 | 0.93, 1.14 | 0.5 |
17 | 36 | 24 | 66.7 | 1.03 | 0.98, 1.09 | 0.3 |
18 | 36 | 21 | 58.3 | 0.90 | 0.86, 0.95 | <0.001 |
20 | 48 | 30 | 62.5 | 0.97 | 0.89, 1.05 | 0.5 |
21 | 48 | 30 | 62.5 | 0.97 | 0.79, 1.19 | 0.8 |
22 | 48 | 27 | 56.2 | 0.87 | 0.74, 1.03 | 0.11 |
23 | 48 | 24 | 50.0 | 0.77 | 0.63, 0.95 | 0.016 |
24 | 36 | 21 | 58.3 | 0.90 | 0.86, 0.95 | <0.001 |
由 reprex package (v2.0.1)
创建于 2022-02-11gtsummary table 包含一个名为 .$table_body
的内部数据框,您可以使用 modify_table_body()
函数直接修改该数据框。在下面的示例中,我计算了流行率并将结果格式化以显示在 table 中。我还公开了已经存在的列 exposure
,这是 exposure/followup 时间的总和。编程愉快!
library(gtsummary)
library(tidyverse)
library(geepack)
packageVersion("gtsummary")
#> [1] '1.5.2'
data(dietox, package = "geepack")
tbl <-
dietox %>%
mutate(big_pig = if_else(Weight > 50, 1, 0)) %>%
select(big_pig, Pig, Evit, Cu) %>%
tbl_uvregression(
y = big_pig,
method = geeglm,
method.args = list(id = Pig, family = poisson, corstr = "independence"),
include = -Pig,
exponentiate = TRUE
) %>%
add_n(location = c("level", "label")) %>%
add_nevent(location = c("level", "label")) %>%
# calculate prev
modify_table_body(
~.x %>%
mutate(
prev = stat_nevent / stat_n * 100
) %>%
relocate(prev, exposure, .after = stat_nevent)
) %>%
# format the newly added stats
modify_header(prev = "**Prevalence**", exposure = "**Total Exposure Time**") %>%
modify_fmt_fun(list(prev = function(x) paste0(style_sigfig(x), "%"),
exposure = style_sigfig))