Skip to content

Commit f83595c

Browse files
committed
add arg to docs
1 parent c02632f commit f83595c

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

R/get_emmeans.R

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
#' @inheritParams estimate_slopes
1414
#' @inheritParams estimate_contrasts
1515
#'
16+
#' @param trend A character indicating the name of the variable for which
17+
#' to compute the slopes. To get marginal effects at specific values, use
18+
#' `trend="<variable>"` along with the `by` argument, e.g.
19+
#' `by="<variable>=c(1, 3, 5)"`, or a combination of `by` and `length`, for
20+
#' instance, `by="<variable>", length=30`. To calculate average marginal
21+
#' effects over a range of values, use `trend="<variable>=seq(1, 3, 0.1)"` (or
22+
#' similar) and omit the variable provided in `trend` from the `by` argument.
23+
#'
1624
#' @examplesIf require("emmeans", quietly = TRUE)
1725
#' model <- lm(Sepal.Length ~ Species + Petal.Width, data = iris)
1826
#'
@@ -34,12 +42,14 @@
3442
#' get_emmeans(model, by = c("Species", "Petal.Length = c(1, 3, 5)"), length = 2)
3543
#' }
3644
#' @export
37-
get_emmeans <- function(model,
38-
by = "auto",
39-
predict = NULL,
40-
keep_iterations = FALSE,
41-
verbose = TRUE,
42-
...) {
45+
get_emmeans <- function(
46+
model,
47+
by = "auto",
48+
predict = NULL,
49+
keep_iterations = FALSE,
50+
verbose = TRUE,
51+
...
52+
) {
4353
# check if available
4454
insight::check_if_installed("emmeans")
4555

@@ -50,11 +60,7 @@ get_emmeans <- function(model,
5060
predict <- .get_emmeans_type_argument(model, predict, type = "means", ...)
5161

5262
# setup arguments
53-
fun_args <- list(
54-
model,
55-
specs = my_args$emmeans_specs,
56-
at = my_args$emmeans_at
57-
)
63+
fun_args <- list(model, specs = my_args$emmeans_specs, at = my_args$emmeans_at)
5864

5965
# handle distributional parameters
6066
if (predict %in% .brms_aux_elements(model) && inherits(model, "brmsfit")) {
@@ -127,7 +133,9 @@ get_emmeans <- function(model,
127133
factors <- attributes(model_frame)$factors
128134
# if still no factors found, throw error
129135
if (is.null(factors)) {
130-
insight::format_error("Model contains no categorical factor. Please specify `by`.")
136+
insight::format_error(
137+
"Model contains no categorical factor. Please specify `by`."
138+
)
131139
}
132140
by <- factors
133141
}
@@ -219,18 +227,12 @@ get_emmeans <- function(model,
219227

220228
# Bring arguments in shape for emmeans ----------------------------------------
221229

222-
223230
#' @keywords internal
224231
.process_emmeans_arguments <- function(model, args, data, ...) {
225232
# Create the data_matrix
226233
# ---------------------------
227234
# data <- insight::get_data(model, verbose = FALSE)
228-
predictors <- insight::find_predictors(
229-
model,
230-
effects = "fixed",
231-
flatten = TRUE,
232-
...
233-
)
235+
predictors <- insight::find_predictors(model, effects = "fixed", flatten = TRUE, ...)
234236
data <- data[intersect(predictors, colnames(data))]
235237

236238
# Deal with 'at'
@@ -287,8 +289,10 @@ get_emmeans <- function(model,
287289
model_terms <- insight::find_terms(model)$conditional
288290
for (var_at in names(args$emmeans_at)) {
289291
term <- model_terms[grepl(var_at, model_terms, fixed = TRUE)]
290-
if (any(grepl(paste0("as.factor(", var_at, ")"), term, fixed = TRUE)) ||
291-
any(grepl(paste0("as.character(", var_at, ")"), term, fixed = TRUE))) {
292+
if (
293+
any(grepl(paste0("as.factor(", var_at, ")"), term, fixed = TRUE)) ||
294+
any(grepl(paste0("as.character(", var_at, ")"), term, fixed = TRUE))
295+
) {
292296
args$retransform[[var_at]] <- args$emmeans_at[[var_at]]
293297
args$emmeans_at[[var_at]] <- as.numeric(as.character(args$emmeans_at[[var_at]]))
294298
}

man/get_emmeans.Rd

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

0 commit comments

Comments
 (0)