Summarize results of ANCOVA. This can be used to analyze multiple endpoints and/or
multiple timepoints within the same response variable .var
.
Usage
h_ancova(.var, .df_row, variables, interaction_item = NULL)
s_ancova(
df,
.var,
.df_row,
variables,
.ref_group,
.in_ref_col,
conf_level,
interaction_y = FALSE,
interaction_item = NULL
)
a_ancova(
df,
.var,
.df_row,
variables,
.ref_group,
.in_ref_col,
conf_level,
interaction_y = FALSE,
interaction_item = NULL
)
summarize_ancova(
lyt,
vars,
var_labels,
...,
show_labels = "visible",
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL,
interaction_y = FALSE,
interaction_item = NULL
)
Arguments
- .var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- .df_row
(
data frame
)
data set that includes all the variables that are called in.var
andvariables
.- variables
-
(named
list
ofstrings
)
list of additional analysis variables, with expected elements:arm
: (string
)
group variable, for which the covariate adjusted means of multiple groups will be summarized. Specifically, the first level ofarm
variable is taken as the reference group.covariates
: (character
)
a vector that can contain single variable names (such as"X1"
), and/or interaction terms indicated by"X1 * X2"
.
- interaction_item
(
character
)
name of the variable that should have interactions with arm. if the interaction is not needed, the default option is NULL- df
(
data frame
)
data set containing all 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.- interaction_y
(
character
)
a selected item inside of the interaction_item column which will be used to select the specific ANCOVA results. if the interaction is not needed, the default option is FALSE- 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.lsmean
: estimated marginal means in the group.lsmean_diff
: difference in estimated marginal means in comparison to the reference group. If working with the reference group, this will be empty.lsmean_diff_ci
: confidence level for difference in estimated marginal means in comparison to the reference group.pval
: p-value (not adjusted for multiple comparisons).
Functions
h_ancova()
: Helper function to return results of a linear model.s_ancova()
: Statistics function that produces a named list of results of the investigated linear model.a_ancova()
: Formatted Analysis function which can be further customized by callingrtables::make_afun()
on it. It is used asafun
inrtables::analyze()
.summarize_ancova()
: Layout creating function which can be be used for creating summary tables for analysis of covariance (ANCOVA).
Examples
h_ancova(
.var = "Sepal.Length",
.df_row = iris,
variables = list(arm = "Species", covariates = c("Petal.Length * Petal.Width", "Sepal.Width"))
)
#> Species emmean SE df lower.CL upper.CL
#> setosa 6.15 0.3371 143 5.49 6.82
#> versicolor 5.72 0.0668 143 5.59 5.85
#> virginica 5.41 0.1488 143 5.11 5.70
#>
#> Confidence level used: 0.95
library(scda)
library(dplyr)
adsl <- synthetic_cdisc_data("rcd_2022_02_28")$adsl
adqs <- synthetic_cdisc_data("rcd_2022_02_28")$adqs
adqs_single <- adqs %>%
filter(
AVISIT == "WEEK 1 DAY 8", # single time point
PARAMCD == "FKSI-FWB" # single end point
) %>%
mutate(CHG = ifelse(BMEASIFL == "Y", CHG, NA)) # only analyze evaluable population
df <- adqs_single %>%
filter(ARMCD == "ARM B")
.var <- "CHG"
.df_row <- adqs_single
variables <- list(arm = "ARMCD", covariates = "SEX * AGE")
.ref_group <- adqs_single %>%
filter(ARMCD == "ARM A")
conf_level <- 0.95
# Internal function - s_ancova
if (FALSE) {
s_ancova(
df, .var, .df_row, variables, .ref_group,
.in_ref_col = FALSE,
conf_level, interaction_y = FALSE, interaction_item = NULL
)
}
# Internal function - a_ancova
if (FALSE) {
a_ancova(
df, .var, .df_row, variables, .ref_group,
.in_ref_col = FALSE,
interaction_y = FALSE, interaction_item = NULL, conf_level
)
}
library(scda)
library(rtables)
library(dplyr)
cached_data <- synthetic_cdisc_data("rcd_2022_02_28")
adsl <- cached_data$adsl
adqs <- cached_data$adqs
adqs_single <- adqs %>%
filter(
AVISIT == "WEEK 1 DAY 8", # single time point
PARAMCD == "FKSI-FWB" # single end point
) %>%
mutate(CHG = ifelse(BMEASIFL == "Y", CHG, NA)) # only analyze evaluable population
adqs_multi <- adqs %>%
filter(AVISIT == "WEEK 1 DAY 8")
basic_table() %>%
split_cols_by("ARMCD", ref_group = "ARM A") %>%
add_colcounts() %>%
summarize_ancova(
vars = "CHG",
variables = list(arm = "ARMCD", covariates = NULL),
table_names = "unadj",
conf_level = 0.95, var_labels = "Unadjusted comparison",
.labels = c(lsmean = "Mean", lsmean_diff = "Difference in Means")
) %>%
summarize_ancova(
vars = "CHG",
variables = list(arm = "ARMCD", covariates = c("BASE", "STRATA1")),
table_names = "adj",
conf_level = 0.95, var_labels = "Adjusted comparison (covariates BASE and STRATA1)"
) %>%
build_table(adqs_single, alt_counts_df = adsl)
#> ARM A ARM B ARM C
#> (N=134) (N=134) (N=132)
#> ———————————————————————————————————————————————————————————————————————————————————————————
#> Unadjusted comparison
#> n 68 73 62
#> Mean 3.68 5.07 3.09
#> Difference in Means 1.38 -0.59
#> 95% CI (-2.76, 5.53) (-4.91, 3.73)
#> p-value 0.5113 0.7873
#> Adjusted comparison (covariates BASE and STRATA1)
#> n 68 73 62
#> Adjusted Mean 4.06 3.57 3.34
#> Difference in Adjusted Means -0.49 -0.72
#> 95% CI (-3.28, 2.29) (-3.57, 2.12)
#> p-value 0.7277 0.6165
# Another example: count the interaction between rows and columns into consideration
adsl <- cached_data$adsl
adqs <- cached_data$adqs
adqs_single <- adqs %>%
filter(AVISIT %in% c("WEEK 1 DAY 8", "WEEK 2 DAY 15", "WEEK 5 DAY 36")) %>%
droplevels() %>%
filter(PARAM == "BFI All Questions") %>%
mutate(CHG = ifelse(BMEASIFL == "Y", CHG, NA)) # only analyze evaluable population
basic_table() %>%
split_cols_by("ARMCD", ref_group = "ARM A") %>%
add_colcounts() %>%
split_rows_by("STRATA1", split_fun = drop_split_levels) %>%
summarize_ancova(
vars = "CHG",
variables = list(arm = "ARMCD", covariates = c("BASE", "AVISIT", "AVISIT*ARMCD")),
conf_level = 0.95,
var_labels = "WEEK 1 DAY 8",
table_names = "WEEK 1 DAY 8",
interaction_y = "WEEK 1 DAY 8",
interaction_item = "AVISIT"
) %>%
summarize_ancova(
vars = "CHG",
variables = list(arm = "ARMCD", covariates = c("BASE", "AVISIT", "AVISIT*ARMCD")),
conf_level = 0.95,
var_labels = "WEEK 2 DAY 15",
table_names = "WEEK 2 DAY 15",
interaction_y = "WEEK 2 DAY 15",
interaction_item = "AVISIT"
) %>%
summarize_ancova(
vars = "CHG",
variables = list(arm = "ARMCD", covariates = c("BASE", "AVISIT", "AVISIT*ARMCD")),
conf_level = 0.95,
var_labels = "WEEK 5 DAY 36",
table_names = "WEEK 5 DAY 36",
interaction_y = "WEEK 5 DAY 36",
interaction_item = "AVISIT"
) %>%
build_table(adqs_single, alt_counts_df = adsl)
#> ARM A ARM B ARM C
#> (N=134) (N=134) (N=132)
#> ——————————————————————————————————————————————————————————————————————————————
#> A
#> WEEK 1 DAY 8
#> n 14 29 10
#> Adjusted Mean 3.22 5.31 3.09
#> Difference in Adjusted Means 2.09 -0.12
#> 95% CI (-4.84, 9.02) (-8.95, 8.70)
#> p-value 0.5520 0.9780
#> WEEK 2 DAY 15
#> n 14 29 10
#> Adjusted Mean 9.02 10.73 8.89
#> Difference in Adjusted Means 1.72 -0.13
#> 95% CI (-5.21, 8.64) (-8.96, 8.70)
#> p-value 0.6252 0.9766
#> WEEK 5 DAY 36
#> n 14 29 10
#> Adjusted Mean 24.11 23.99 27.07
#> Difference in Adjusted Means -0.12 2.97
#> 95% CI (-7.04, 6.81) (-5.86, 11.79)
#> p-value 0.9734 0.5078
#> B
#> WEEK 1 DAY 8
#> n 24 22 26
#> Adjusted Mean 4.03 4.54 4.48
#> Difference in Adjusted Means 0.51 0.46
#> 95% CI (-5.12, 6.15) (-4.93, 5.84)
#> p-value 0.8580 0.8678
#> WEEK 2 DAY 15
#> n 24 22 26
#> Adjusted Mean 16.10 8.26 8.39
#> Difference in Adjusted Means -7.84 -7.71
#> 95% CI (-13.48, -2.21) (-13.10, -2.33)
#> p-value 0.0066 0.0052
#> WEEK 5 DAY 36
#> n 24 22 26
#> Adjusted Mean 21.74 23.58 27.55
#> Difference in Adjusted Means 1.84 5.81
#> 95% CI (-3.79, 7.48) (0.43, 11.20)
#> p-value 0.5199 0.0345
#> C
#> WEEK 1 DAY 8
#> n 30 22 26
#> Adjusted Mean 5.43 7.86 4.03
#> Difference in Adjusted Means 2.43 -1.40
#> 95% CI (-3.28, 8.15) (-6.87, 4.07)
#> p-value 0.4021 0.6146
#> WEEK 2 DAY 15
#> n 30 22 26
#> Adjusted Mean 12.67 14.49 12.10
#> Difference in Adjusted Means 1.83 -0.57
#> 95% CI (-3.89, 7.54) (-6.04, 4.90)
#> p-value 0.5294 0.8373
#> WEEK 5 DAY 36
#> n 30 22 26
#> Adjusted Mean 25.81 21.00 29.71
#> Difference in Adjusted Means -4.80 3.90
#> 95% CI (-10.51, 0.91) (-1.57, 9.37)
#> p-value 0.0990 0.1611
if (FALSE) {
basic_table() %>%
split_cols_by("ARMCD", ref_group = "ARM A") %>%
split_rows_by("PARAMCD") %>%
summarize_ancova(
vars = "CHG",
variables = list(arm = "ARMCD", covariates = c("BASE", "STRATA1")),
conf_level = 0.95, var_labels = "Adjusted mean"
) %>%
build_table(adqs_multi, alt_counts_df = adsl)
}