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)
s_ancova(df, .var, .df_row, variables, .ref_group, .in_ref_col, conf_level)
a_ancova(df, .var, .df_row, variables, .ref_group, .in_ref_col, conf_level)
summarize_ancova(
lyt,
vars,
var_labels,
...,
show_labels = "visible",
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)Arguments
- .var
(
string)
single variable name that is passed byrtableswhen requested by a statistics function.- .df_row
(
data frame)
data set that includes all the variables that are called in.varandvariables.- variables
-
(named
listofstrings)
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 ofarmvariable 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".
- df
(
data frame)
data set containing all analysis variables.- .ref_group
(
data frameorvector)
the data corresponding to the reference group.- .in_ref_col
(
logical)TRUEwhen working with the reference level,FALSEotherwise.- 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 samevarsare analyzed multiple times, to avoid warnings fromrtables.- .stats
(
character)
statistics to select for the table.- .formats
(named
characterorlist)
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 asafuninrtables::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("latest")$adsl
adqs <- synthetic_cdisc_data("latest")$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)
}
# Internal function - a_ancova
if (FALSE) {
a_ancova(df, .var, .df_row, variables, .ref_group, .in_ref_col = FALSE, conf_level)
}
library(scda)
library(rtables)
library(dplyr)
adsl <- synthetic_cdisc_data("latest")$adsl
adqs <- synthetic_cdisc_data("latest")$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
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)
}