Skip to content

Commit

Permalink
less safe
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 27, 2025
1 parent d5b87e9 commit 10a4509
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ New:
* `rvar` column from `get_draws()` is now printed by default.
* Matrix columns with 1 column are supported. Fixes errors when a variable was transformed by `scale()`, for example. Thanks to @barryrowlingson for the report.
* Much faster inference with `inferences(method="boot")`. Thanks to @nremenyi for issue #1352.
* `hypothesis=~pairwise` only errors when there are more than 300 comparisons. `options(marginaleffects_safe=FALSE)` to disable this check.

Bugs:

Expand Down
20 changes: 10 additions & 10 deletions R/hypothesis_formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ hypothesis_formula_list <- list(
pairwise = list(
ratio = list(
comparison = function(x) {
safe_mode <- getOption("marginaleffects_safe", default = TRUE)
if (length(x) > 25 && isTRUE(safe_mode)) {
msg <- "This command will generate many estimates. Set `options(marginaleffects_safe=FALSE)` to circumvent this guardrail."
stop(msg, call. = FALSE)
}
out <- outer(x, x, "/")
diag(out) <- NA
out[upper.tri(out)] <- NA # Set lower triangle to NA
out <- as.vector(out)
out <- out[!is.na(out)] # Keep only non-NA values
safe_mode <- getOption("marginaleffects_safe", default = TRUE)
if (length(out) > 25 && isTRUE(safe_mode)) {
msg <- "This command will generate many estimates. Set `options(marginaleffects_safe=FALSE)` to circumvent this guardrail."
stop(msg, call. = FALSE)
}
out
},
label = function(x) {
Expand All @@ -44,16 +44,16 @@ hypothesis_formula_list <- list(
}),
difference = list(
comparison = function(x) {
safe_mode <- getOption("marginaleffects_safe", default = TRUE)
if (length(x) > 25 && isTRUE(safe_mode)) {
msg <- "This command will generate many estimates. Set `options(marginaleffects_safe=FALSE)` to circumvent this guardrail."
stop(msg, call. = FALSE)
}
out <- outer(x, x, "-")
diag(out) <- NA
out[upper.tri(out)] <- NA # Set lower triangle to NA
out <- as.vector(out)
out <- out[!is.na(out)] # Keep only non-NA values
safe_mode <- getOption("marginaleffects_safe", default = TRUE)
if (length(out) > 25 && isTRUE(safe_mode)) {
msg <- "This command will generate many estimates. Set `options(marginaleffects_safe=FALSE)` to circumvent this guardrail."
stop(msg, call. = FALSE)
}
out
},
label = function(x) {
Expand Down

2 comments on commit 10a4509

@strengejacke
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, but isn't the number in the code still 25? Anyway, increasing from 25 to 300 is a huge step ;-) I would have been satisfied with 100, as well, or maybe 150 :-)

@vincentarelbundock
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an upper triangle of the outer product matrix, so 25*24/2=300

Please sign in to comment.