ard_emmeans: ARDs for LS Mean Difference and LS Means

ard_emmeans_contrastR Documentation

ARDs for LS Mean Difference and LS Means

Description

The ard_emmeans_contrast() function calculates least-squares mean differences using the 'emmeans' package using the following

emmeans::emmeans(object = <regression model>, specs = ~ <primary covariate>) |>
  emmeans::contrast(method = "pairwise") |>
  summary(infer = TRUE, level = <confidence level>)

The ard_emmeans_emmeans() function calculates least-squares means using the 'emmeans' package using the following

emmeans::emmeans(object = <regression model>, specs = ~ <primary covariate>) |>
  summary(emmeans, calc = c(n = ".wgt."))

The arguments data, formula, method, method.args, package are used to construct the regression model via cardx::construct_model().

Usage

ard_emmeans_contrast(
  data,
  formula,
  method,
  method.args = list(),
  package = "base",
  response_type = c("continuous", "dichotomous"),
  conf.level = 0.95,
  primary_covariate = getElement(attr(stats::terms(formula), "term.labels"), 1L)
)

ard_emmeans_emmeans(
  data,
  formula,
  method,
  method.args = list(),
  package = "base",
  response_type = c("continuous", "dichotomous"),
  conf.level = 0.95,
  primary_covariate = getElement(attr(stats::terms(formula), "term.labels"), 1L)
)

Arguments

data

(data.frame/survey.design)
a data frame or survey design object

formula

(formula)
a formula

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)
a package name that will be temporarily loaded when function specified in method is executed.

response_type

(string) string indicating whether the model outcome is 'continuous' or 'dichotomous'. When 'dichotomous', the call to emmeans::emmeans() is supplemented with argument regrid="response".

conf.level

(scalar numeric)
confidence level for confidence interval. Default is 0.95.

primary_covariate

(string)
string indicating the primary covariate (typically the dichotomous treatment variable). Default is the first covariate listed in the formula.

Value

ARD data frame

Examples


# LS Mean Difference
ard_emmeans_contrast(
  data = mtcars,
  formula = mpg ~ am + cyl,
  method = "lm"
)

ard_emmeans_contrast(
  data = mtcars,
  formula = vs ~ am + mpg,
  method = "glm",
  method.args = list(family = binomial),
  response_type = "dichotomous"
)


# LS Means
ard_emmeans_emmeans(
  data = mtcars,
  formula = mpg ~ am + cyl,
  method = "lm"
)

ard_emmeans_emmeans(
  data = mtcars,
  formula = vs ~ am + mpg,
  method = "glm",
  method.args = list(family = binomial),
  response_type = "dichotomous"
)


cardx documentation built on Dec. 4, 2025, 9:06 a.m.