Skip to content

Commit f83a7ea

Browse files
docs: comparison function improvement
1 parent 21489cc commit f83a7ea

File tree

4 files changed

+50
-38
lines changed

4 files changed

+50
-38
lines changed

R/comparisons.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@
6868
#' + [subset()] call with a single argument to select a subset of the dataset used to fit the model, ex: `newdata = subset(treatment == 1)`
6969
#' + [dplyr::filter()] call with a single argument to select a subset of the dataset used to fit the model, ex: `newdata = filter(treatment == 1)`
7070
#' @param comparison How should pairs of predictions be compared? Difference, ratio, odds ratio, or user-defined functions.
71-
#' * string: shortcuts to common contrast functions.
72-
#' - Supported shortcuts strings: `r toString(names(marginaleffects:::comparison_function_dict))`
73-
#' - See the Comparisons section below for definitions of each transformation.
71+
#' * string: shortcuts to common contrast functions. Supported shortcuts strings: `r toString(names(marginaleffects:::comparison_function_dict))`
7472
#' * function: accept two equal-length numeric vectors of adjusted predictions (`hi` and `lo`) and returns a vector of contrasts of the same length, or a unique numeric value.
75-
#' - See the Transformations section below for examples of valid functions.
73+
#' * See the "Comparison functions" section below for a list of common transformations and the definitions of available shortcuts.
7674
#' @param transform string or function. Transformation applied to unit-level estimates and confidence intervals just before the function returns results. Functions must accept a vector and return a vector of the same length. Support string shortcuts: "exp", "ln"
7775
#' @param equivalence Numeric vector of length 2: bounds used for the two-one-sided test (TOST) of equivalence, and for the non-inferiority and non-superiority tests. For bayesian models, this report the proportion of posterior draws in the interval and the ROPE. See Details section below.
7876
#' @param by Aggregate unit-level estimates (aka, marginalize, average over). Valid inputs:

man-roxygen/comparison_functions.R

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
#' @section comparison argument functions:
2-
#'
3-
#' The following transformations can be applied by supplying one of the shortcut strings to the
4-
#' `comparison` argument.
5-
6-
#' `hi` is a vector of adjusted predictions for the "high" side of the
7-
#' contrast. `lo` is a vector of adjusted predictions for the "low" side of the
8-
#' contrast. `y` is a vector of adjusted predictions for the original data. `x`
9-
#' is the predictor in the original data. `eps` is the step size to use to
10-
#' compute derivatives and elasticities.
1+
#' @section Comparison functions:
2+
#'
3+
#' Each of the quantities computed by `comparisons()` can be defined as a function of these quantities:
4+
#'
5+
#' - `hi`: vector of predictions for the "high" side of the contrast.
6+
#' - `lo`: vector of predictions for the "low" side of the contrast.
7+
#' - `y`: predictions for the original data.
8+
#' - `x`: focal predictor in the original data.
9+
#' - `w`: weights
10+
#'
11+
#' For example, the "lift" of a binary predictor is a popular quantity of
12+
#' interest, defined as the difference between predictions when the focal
13+
#' predictor \eqn{X = 1}, and predictions when the focal predictor is
14+
#' \eqn{X = 0}, normalized by the starting point. Or:
15+
#'
16+
#' \eqn{\frac{\hat{Y}_{X=1} - \hat{Y}_{X=0}}{\hat{Y}_{X=0}}}
17+
#'
18+
#' When, the argument is set to `comparison="lift"`, `marginaleffects` will compute the quantity using this function:
19+
#'
20+
#' `function(hi, lo) { (hi - lo) / lo }`
21+
#'
22+
#' Users can supply custom functions to the `comparison` argument, or use one of the many shortcuts available for common quantities of interest:
1123
#'
1224
#' ```{r, echo = FALSE, results = "asis"}
1325
#' k <- marginaleffects:::comparison_function_dict

man/comparisons.Rd

Lines changed: 24 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_comparisons.Rd

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)