Summarize results of ANCOVA. This can be used to analyze multiple endpoints and/or
multiple timepoints within the same response variable .var
.
Usage
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
- 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.- 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 isFALSE
.- interaction_item
(
character
)
name of the variable that should have interactions with arm. if the interaction is not needed, the default option isNULL
.- 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
)
character for label.- ...
additional arguments for the lower level functions.
- show_labels
(
string
)
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. Defaults to 0, which corresponds to the unmodified default behavior. Can be negative.
Value
-
s_ancova()
returns 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).
a_ancova()
returns the corresponding list with formattedrtables::CellValue()
.
summarize_ancova()
returns a layout object suitable for passing to further layouting functions, or tortables::build_table()
. Adding this function to anrtable
layout will add formatted rows containing the statistics froms_ancova()
to the table layout.
Functions
s_ancova()
: Statistics function that produces a named list of results of the investigated linear model.a_ancova()
: Formatted analysis function which is used asafun
insummarize_ancova()
.summarize_ancova()
: Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze()
.
Examples
library(dplyr)
df <- iris %>% filter(Species == "virginica")
.df_row <- iris
.var <- "Petal.Length"
variables <- list(arm = "Species", covariates = "Sepal.Length * Sepal.Width")
.ref_group <- iris %>% filter(Species == "setosa")
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
)
}
basic_table() %>%
split_cols_by("Species", ref_group = "setosa") %>%
add_colcounts() %>%
summarize_ancova(
vars = "Petal.Length",
variables = list(arm = "Species", 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 = "Petal.Length",
variables = list(arm = "Species", covariates = c("Sepal.Length", "Sepal.Width")),
table_names = "adj",
conf_level = 0.95, var_labels = "Adjusted comparison (covariates: Sepal.Length and Sepal.Width)"
) %>%
build_table(iris)
#> setosa versicolor virginica
#> (N=50) (N=50) (N=50)
#> —————————————————————————————————————————————————————————————————————————————————————————————————————
#> Unadjusted comparison
#> n 50 50 50
#> Mean 1.46 4.26 5.55
#> Difference in Means 2.80 4.09
#> 95% CI (2.63, 2.97) (3.92, 4.26)
#> p-value <0.0001 <0.0001
#> Adjusted comparison (covariates: Sepal.Length and Sepal.Width)
#> n 50 50 50
#> Adjusted Mean 2.02 4.19 5.07
#> Difference in Adjusted Means 2.17 3.05
#> 95% CI (1.96, 2.38) (2.81, 3.29)
#> p-value <0.0001 <0.0001