-
Notifications
You must be signed in to change notification settings - Fork 3
/
19_exercise.R
127 lines (101 loc) · 2.78 KB
/
19_exercise.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Group summaries
library(rtables)
library(dplyr)
ex_adsl3 <- ex_adsl |>
mutate(B1HL = factor(ifelse(BMRKR1 > mean(BMRKR1), "H", "L"), levels = c("L", "H")))
# Stage 1
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_rows_by("SEX") |>
split_rows_by("B1HL") |>
analyze("AGE", \(x) list(B = "-"))
build_table(lyt, ex_adsl3)
# Stage 2
lyt <- basic_table() |>
split_cols_by("ARM") |>
summarize_row_groups() |>
split_rows_by("SEX") |>
split_rows_by("B1HL") |>
analyze("AGE", \(x) list(B = "a"))
build_table(lyt, ex_adsl3)
# Stage 3
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_rows_by("SEX") |>
summarize_row_groups(cfun = function(x, labelstr) {
lst <- setNames(
list(rcell("s", format = "xx")),
labelstr
)
in_rows(.list = lst)
}) |>
split_rows_by("B1HL") |>
analyze("AGE", \(x) list(B = "a"))
build_table(lyt, ex_adsl3)
# note how the root label has been lost
# TODO: why
# Stage 4
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_rows_by("SEX") |>
summarize_row_groups() |>
split_rows_by("B1HL") |>
analyze("AGE", \(x) list(B = "a"))
build_table(lyt, ex_adsl3)
# Stage 5
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_rows_by("SEX") |>
split_rows_by("B1HL") |>
summarize_row_groups() |>
analyze("AGE", \(x) list(B = "a"))
build_table(lyt, ex_adsl3)
# Now all together
foo <- function(str) {
function(x, labelstr) {
lst <- setNames(
list(rcell(str, format = "xx")),
labelstr
)
in_rows(.list = lst)
}
}
lyt <- basic_table() |>
split_cols_by("ARM") |>
summarize_row_groups(cfun = foo("r")) |>
split_rows_by("SEX") |>
summarize_row_groups(cfun = foo("s")) |>
split_rows_by("B1HL") |>
summarize_row_groups(cfun = foo("bm")) |>
analyze("AGE", afun = \(x) list(B = "a"))
build_table(lyt, ex_adsl3)
# Lets look at the default group summary
lyt <- basic_table() |>
split_cols_by("ARM") |>
summarize_row_groups() |>
split_rows_by("SEX") |>
summarize_row_groups() |>
split_rows_by("B1HL") |>
summarize_row_groups() |>
analyze("AGE", afun = \(x) list(B = "a"))
build_table(lyt, ex_adsl3)
# Fix the row label for the root summary
lyt <- basic_table() |>
split_cols_by("ARM") |>
summarize_row_groups(label_fstr = "all") |>
split_rows_by("SEX") |>
summarize_row_groups() |>
split_rows_by("B1HL") |>
summarize_row_groups() |>
analyze("AGE", afun = \(x) list(B = "a"))
build_table(lyt, ex_adsl3)
# Add summary to the row label
lyt <- basic_table() |>
split_cols_by("ARM") |>
summarize_row_groups(label_fstr = "summary (all)") |>
split_rows_by("SEX") |>
summarize_row_groups(label_fstr = "summary %s") |>
split_rows_by("B1HL") |>
summarize_row_groups(label_fstr = "summary %s") |>
analyze("AGE", afun = \(x) list(B = "a"))
build_table(lyt, ex_adsl3)