Skip to content

Commit

Permalink
revert to formula notation
Browse files Browse the repository at this point in the history
  • Loading branch information
ayogasekaram committed Mar 7, 2024
1 parent e52c6a8 commit 99b60c0
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions R/ard_aov.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 99b60c0

Please sign in to comment.