s_count_abnormal_lab_worsen_by_baseline()R/abnormal_lab_worsen_by_baseline.R
h_worsen_counter.RdHelper function to count the number of patients and the fraction of patients according to
highest post-baseline lab grade variable .var, baseline lab grade variable baseline_var,
and the direction of interest specified in direction_var.
h_worsen_counter(df, id, .var, baseline_var, direction_var)(data.frame)
data set containing all analysis variables.
(string)
subject variable name.
(string)
single variable name that is passed by rtables when requested
by a statistics function.
(string)
name of the baseline lab grade variable.
(string)
name of the direction variable specifying the direction of the shift table of
interest. Only lab records flagged by L, H or B are included in the shift table.
L: low direction only
H: high direction only
B: both low and high directions
The counts and fraction of patients whose worst post-baseline lab grades are worse than their baseline grades, for post-baseline worst grades "1", "2", "3", "4" and "Any".
library(dplyr)
# The direction variable, GRADDR, is based on metadata
adlb <- tern_ex_adlb %>%
mutate(
GRADDR = case_when(
PARAMCD == "ALT" ~ "B",
PARAMCD == "CRP" ~ "L",
PARAMCD == "IGA" ~ "H"
)
) %>%
filter(SAFFL == "Y" & ONTRTFL == "Y" & GRADDR != "")
df <- h_adlb_worsen(
adlb,
worst_flag_low = c("WGRLOFL" = "Y"),
worst_flag_high = c("WGRHIFL" = "Y"),
direction_var = "GRADDR"
)
# `h_worsen_counter`
h_worsen_counter(
df %>% filter(PARAMCD == "CRP" & GRADDR == "Low"),
id = "USUBJID",
.var = "ATOXGR",
baseline_var = "BTOXGR",
direction_var = "GRADDR"
)
#> $fraction
#> $fraction$`1`
#> num denom
#> 25 180
#>
#> $fraction$`2`
#> num denom
#> 15 186
#>
#> $fraction$`3`
#> num denom
#> 18 191
#>
#> $fraction$`4`
#> num denom
#> 17 196
#>
#> $fraction$Any
#> num denom
#> 75 196
#>
#>