Summarize results of a Poisson Negative Binomial Regression. This can be used to analyze count and/or frequency data using a linear model.
Usage
s_glm_count(
df,
.var,
.df_row,
variables,
.ref_group,
.in_ref_col,
distribution,
conf_level,
rate_mean_method,
weights,
scale = 1
)
a_glm_count(
df,
.var,
.df_row,
variables,
.ref_group,
.in_ref_col,
distribution,
conf_level,
rate_mean_method,
weights,
scale = 1
)
summarize_glm_count(
lyt,
vars,
var_labels,
...,
show_labels = "visible",
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
Arguments
- df
(
data.frame
)
data set containing all analysis variables.- .var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- .df_row
(
data.frame
)
data frame across all of the columns for the given row split.- variables
(named
list
ofstring
)
list of additional analysis variables.- .ref_group
(
data.frame
orvector
)
the data corresponding to the reference group.- .in_ref_col
(
logical
)TRUE
when working with the reference level,FALSE
otherwise.- conf_level
(
proportion
)
confidence level of the interval.- lyt
(
layout
)
input layout where analyses will be added to.- vars
(
character
)
variable names for the primary analysis variable to be iterated over.- var_labels
character for label.
- ...
additional arguments for the lower level functions.
- show_labels
label visibility: one of "default", "visible" and "hidden".
- table_names
(
character
)
this can be customized in case that the samevars
are analyzed multiple times, to avoid warnings fromrtables
.- .stats
(
character
)
statistics to select for the table.- .formats
(named
character
orlist
)
formats for the statistics.- .labels
(named
character
)
labels for the statistics (without indent).- .indent_mods
(named
integer
)
indent modifiers for the labels.
Value
A named list of 5 statistics:
- n
count of complete sample size for the group.
- rate
estimated event rate per follow-up time.
- rate_ci
confidence level for estimated rate per follow-up time.
- rate_ratio
ratio of event rates in each treatment arm to the reference arm.
- rate_ratio_ci
confidence level for the rate ratio.
- pval
p-value.
Functions
s_glm_count()
: Statistics function that produces a named list of results of the investigated poisson model.a_glm_count()
: Formatted Analysis function which can be further customized by callingrtables::make_afun()
on it. It is used asafun
inrtables::analyze()
.summarize_glm_count()
: Layout creating function which can be be used for creating summary tables for analysis of count data using generalized linear models (poisson, quasipoisson).
Examples
# Internal function - s_change_from_baseline
if (FALSE) {
s_glm_count(
df = anl %>%
filter(ARMCD == "ARM B"),
.df_row = anl,
.var = "AVAL",
.in_ref_col = TRUE,
variables = list(arm = "ARMCD", offset = "lgTMATRSK", covariates = c("REGION1")),
conf_level = 0.95,
distribution = "quasipoisson",
rate_mean_method = "ppmeans"
)
}
# Internal function - s_change_from_baseline
if (FALSE) {
a_glm_count(
df = anl %>%
filter(ARMCD == "ARM A"),
.var = "AVAL",
.df_row = anl,
variables = list(arm = "ARMCD", offset = "lgTMATRSK", covariates = c("REGION1")),
.ref_group = "ARM B", .in_ref_col = TRUE,
conf_level = 0.95,
distribution = "poisson",
rate_mean_method = "ppmeans"
)
}
library(dplyr)
anl <- tern_ex_adtte %>% filter(PARAMCD == "TNE")
anl$AVAL_f <- as.factor(anl$AVAL)
lyt <- basic_table() %>%
split_cols_by("ARM", ref_group = "B: Placebo") %>%
add_colcounts() %>%
summarize_vars(
"AVAL_f",
var_labels = "Number of exacerbations per patient",
.stats = c("count_fraction"),
.formats = c("count_fraction" = "xx (xx.xx%)"),
.label = c("Number of exacerbations per patient")
) %>%
summarize_glm_count(
vars = "AVAL",
variables = list(arm = "ARM", offset = "lgTMATRSK", covariates = NULL),
conf_level = 0.95,
distribution = "poisson",
rate_mean_method = "emmeans",
var_labels = "Unadjusted exacerbation rate (per year)",
table_names = "unadj",
.stats = c("rate"),
.labels = c(rate = "Rate")
) %>%
summarize_glm_count(
vars = "AVAL",
variables = list(arm = "ARM", offset = "lgTMATRSK", covariates = c("REGION1")),
conf_level = 0.95,
distribution = "quasipoisson",
rate_mean_method = "ppmeans",
var_labels = "Adjusted (QP) exacerbation rate (per year)",
table_names = "adj",
.stats = c("rate", "rate_ci", "rate_ratio", "rate_ratio_ci", "pval"),
.labels = c(
rate = "Rate", rate_ci = "Rate CI", rate_ratio = "Rate Ratio",
rate_ratio_ci = "Rate Ratio CI", pval = "p value"
)
)
build_table(lyt = lyt, df = anl)
#> B: Placebo A: Drug X C: Combination
#> (N=73) (N=69) (N=58)
#> ——————————————————————————————————————————————————————————————————————————————————————————————————————
#> Number of exacerbations per patient
#> 0 8 (10.96%) 3 (4.35%) 6 (10.34%)
#> 1 9 (12.33%) 11 (15.94%) 6 (10.34%)
#> 2 15 (20.55%) 18 (26.09%) 9 (15.52%)
#> 3 11 (15.07%) 14 (20.29%) 15 (25.86%)
#> 4 9 (12.33%) 10 (14.49%) 9 (15.52%)
#> 5 9 (12.33%) 7 (10.14%) 8 (13.79%)
#> 6 4 (5.48%) 4 (5.80%) 4 (6.90%)
#> 7 8 (10.96%) 2 (2.90%) 0 (0.00%)
#> 10 0 (0.00%) 0 (0.00%) 1 (1.72%)
#> Unadjusted exacerbation rate (per year)
#> Rate 9.1554 8.2061 7.8551
#> Adjusted (QP) exacerbation rate (per year)
#> Rate 10.2061 9.1386 7.6566
#> Rate CI (5.6275, 18.5099) (4.9399, 16.9060) (4.0222, 14.5749)
#> Rate Ratio 0.8954 0.7502
#> Rate Ratio CI (0.3975, 2.0170) (0.3067, 1.8348)
#> p value 0.7897 0.5288