ard_stats_anova: ARD ANOVA

View source: R/ard_stats_anova.R

ard_stats_anovaR Documentation

ARD ANOVA

Description

Prepare ANOVA results from the stats::anova() function. Users may pass a pre-calculated stats::anova() object or a list of formulas. In the latter case, the models will be constructed using the information passed and models will be passed to stats::anova().

Usage

ard_stats_anova(x, ...)

## S3 method for class 'anova'
ard_stats_anova(x, method_text = "ANOVA results from `stats::anova()`", ...)

## S3 method for class 'data.frame'
ard_stats_anova(
  x,
  formulas,
  method,
  method.args = list(),
  package = "base",
  method_text = "ANOVA results from `stats::anova()`",
  ...
)

Arguments

x

(anova or data.frame)
an object of class 'anova' created with stats::anova() or a data frame

...

These dots are for future extensions and must be empty.

method_text

(string)
string of the method used. Default is ⁠"ANOVA results from ⁠stats::anova()⁠"⁠. We provide the option to change this as stats::anova() can produce results from many types of models that may warrant a more precise description.

formulas

(list)
a list of formulas

method

(string)
string of function naming the function to be called, e.g. "glm". If function belongs to a library that is not attached, the package name must be specified in the package argument.

method.args

(named list)
named list of arguments that will be passed to method.

Note that this list may contain non-standard evaluation components. If you are wrapping this function in other functions, the argument must be passed in a way that does not evaluate the list, e.g. using rlang's embrace operator {{ . }}.

package

(string)
string of package name that will be temporarily loaded when function specified in method is executed.

Details

When a list of formulas is supplied to ard_stats_anova(), these formulas along with information from other arguments, are used to construct models and pass those models to stats::anova().

The models are constructed using rlang::exec(), which is similar to do.call().

rlang::exec(.fn = method, formula = formula, data = data, !!!method.args)

The above function is executed in withr::with_namespace(package), which allows for the use of ard_stats_anova(method) from packages, e.g. package = 'lme4' must be specified when method = 'glmer'. See example below.

Value

ARD data frame

Examples


anova(
  lm(mpg ~ am, mtcars),
  lm(mpg ~ am + hp, mtcars)
) |>
  ard_stats_anova()

ard_stats_anova(
  x = mtcars,
  formulas = list(am ~ mpg, am ~ mpg + hp),
  method = "glm",
  method.args = list(family = binomial)
)

ard_stats_anova(
  x = mtcars,
  formulas = list(am ~ 1 + (1 | vs), am ~ mpg + (1 | vs)),
  method = "glmer",
  method.args = list(family = binomial),
  package = "lme4"
)


cardx documentation built on Sept. 11, 2024, 9:12 p.m.