diff --git a/R/ard_aov.R b/R/ard_aov.R index 1f1eb9cd8..bca4a6c62 100644 --- a/R/ard_aov.R +++ b/R/ard_aov.R @@ -4,32 +4,45 @@ #' Analysis results data for Analysis of Variance. #' Calculated with `aov(data[[variable]] ~ as.factor(data[[by]]), data = data, ...)` #' -#' @param x regression model object +#' @param data (`data.frame`)\cr +#' a data frame. +#' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' column name to compare by. Should be a factor variable. +#' @param variable ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' column name to be compared. Should be a continuous variable. #' #' @return ARD data frame #' @export #' #' @examples -#' lm(AGE ~ ARM, data = cards::ADSL) |> -#' ard_aov() -ard_aov <- function(x) { +#' cards::ADSL |> +#' ard_aov(by = "ARM", variable = "AGE") +ard_aov <- function(data, by, variable) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- - check_not_missing(x) + check_not_missing(data) + check_not_missing(variable) + check_not_missing(by) + check_data_frame(data) + cards::process_selectors(data, by = {{ by }}, variable = {{ variable }}) + check_scalar(by) + check_scalar(variable) # build ARD ------------------------------------------------------------------ cards::tidy_as_ard( lst_tidy = cards::eval_capture_conditions( - stats::aov(x) |> + stats::aov(stats::reformulate(by, response = variable), data = data) |> broom::tidy() |> dplyr::slice_head() ), tidy_result_names = c("term", "df", "sumsq", "meansq", "statistic", "p.value"), + fun_args_to_record = + c("formula"), formals = formals(stats::aov), - lst_ard_columns = list(context = "aov") + lst_ard_columns = list(group1 = by, variable = variable, context = "aov") ) |> dplyr::mutate( .after = "stat_name",