Skip to content

Commit 4900882

Browse files
committed
docs
1 parent 3d0e2a1 commit 4900882

7 files changed

Lines changed: 31 additions & 8 deletions

File tree

R/estimate_contrasts.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
#' [this website](https://marginaleffects.com/bonus/hypothesis.html) and
3434
#' section _Comparison options_ below.
3535
#' * String: One of `"pairwise"`, `"reference"`, `"sequential"`, `"meandev"`
36-
#' `"meanotherdev"`, `"poly"`, `"helmert"`, or `"trt_vs_ctrl"`. To test
37-
#' multiple hypotheses jointly (usually used for factorial designs),
36+
#' `"meanotherdev"`, `"poly"`, `"helmert"`, `"slope"` or `"trt_vs_ctrl"`.
37+
#' The `"slope"` option calculcates contrasts between average slopes and can
38+
#' also be used to calculate "context" effects, which is the difference of
39+
#' within- and between-effects (see
40+
#' https://statisticalhorizons.com/between-within-contextual-effects/). To
41+
#' test multiple hypotheses jointly (usually used for factorial designs),
3842
#' `comparison` can also be `"joint"`. In this case, use the `test` argument
3943
#' to specify which test should be conducted: `"F"` (default) or `"Chi2"`.
4044
#' * String: Special string options are `"inequality"`, `"inequality_ratio"`,

R/format.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ format.estimate_contrasts <- function(
1616
}
1717
# change parameter name for context effects
1818
if (isTRUE(attributes(x)$context_effects)) {
19-
x$Parameter <- "Context effect"
19+
x$Parameter <- "Average slope"
2020
}
2121

2222
# don't print columns of adjusted_for variables

R/get_inequalitycontrasts.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@
260260
return(out)
261261
}
262262
}
263+
# handle special value: contrasting average slopes (context effects)
264+
if (identical(comparison, "slope")) {
265+
comparison <- "context"
266+
}
263267
comparison
264268
}
265269

R/get_marginalcontrasts.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ get_marginalcontrasts <- function(
108108
# sanity check - contrast for slopes only makes sense when we have a "by" argument
109109
if (is.null(my_args$by)) {
110110
insight::format_error(
111-
"Please specify the `by` argument to calculate contrasts of slopes."
111+
"Please specify the `by` argument to calculate contrasts of slopes. If you want to calculate the average contrast between two slopes, use `comparison = \"slope\"` instead."
112112
)
113113
}
114114
# call slopes with hypothesis argument

man/estimate_contrasts.Rd

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

man/get_emmeans.Rd

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

tests/testthat/test-estimate_contrasts_context.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ test_that("estimate_contrast, context effects, glm", {
3737
)
3838
expect_equal(out$Estimate, exp(b[1] - b[2]), tolerance = 1e-4, ignore_attr = TRUE)
3939

40+
out <- modelbased::estimate_contrasts(
41+
m,
42+
c("bill_len_between", "bill_len_within"),
43+
comparison = "slope"
44+
)
45+
expect_equal(out$Estimate, exp(b[1] - b[2]), tolerance = 1e-4, ignore_attr = TRUE)
46+
4047
out <- modelbased::estimate_contrasts(
4148
m,
4249
c("bill_len_between", "bill_len_within"),

0 commit comments

Comments
 (0)