Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: modelbased
Title: Estimation of Model-Based Predictions, Contrasts and Means
Version: 0.13.1.2
Version: 0.13.1.3
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Fixed issue in `estimate_contrasts()` when `p_adjust = "tukey"`.

* Fixed error with truncated message when standard errors could not be calculated.

# modelbased 0.13.1

## Changes
Expand Down
7 changes: 6 additions & 1 deletion R/estimate_means.R
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,12 @@ estimate_means <- function(
}

# sanity check - did method return standard errors?
.check_standard_errors(out = means, model = model, verbose = verbose)
.check_standard_errors(
out = means,
by = attributes(means)$by,
model = model,
verbose = verbose
)
Comment on lines 467 to +473
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

This PR changes the standard-error warning behavior for estimate_means() by passing the resolved by variables into .check_standard_errors(), but there is no test asserting the warning now includes the suggested follow-up code (and no longer ends with a dangling "You may try following:"). Consider adding an expect_message() (or snapshot) for a model that yields SE = NA to prevent regressions in this user-facing output.

Copilot uses AI. Check for mistakes.

# restore attributes later
info <- attributes(estimated)
Expand Down
63 changes: 49 additions & 14 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@
#' @noRd
.brms_aux_elements <- function(model = NULL) {
out <- c(
"sigma", "mu", "nu", "shape", "beta", "phi", "hu", "ndt", "zoi", "coi",
"kappa", "bias", "bs", "zi", "alpha", "xi", "delta", "k"
"sigma",
"mu",
"nu",
"shape",
"beta",
"phi",
"hu",
"ndt",
"zoi",
"coi",
"kappa",
"bias",
"bs",
"zi",
"alpha",
"xi",
"delta",
"k"
)
unique(c(out, insight::find_auxiliary(model, verbose = FALSE)))
}
Expand All @@ -13,8 +29,17 @@
#' @noRd
.valid_coefficient_names <- function(model = NULL) {
out <- c(
"Mean", "Probability", "Difference", "Ratio", "Rate", "ZI-Probability",
"Proportion", "Median", "MAP", "Coefficient", "Odds_ratio"
"Mean",
"Probability",
"Difference",
"Ratio",
"Rate",
"ZI-Probability",
"Proportion",
"Median",
"MAP",
"Coefficient",
"Odds_ratio"
)
dpars <- insight::find_auxiliary(model, verbose = FALSE)
if (!is.null(dpars)) {
Expand Down Expand Up @@ -46,13 +71,15 @@

#' @keywords internal
#' @noRd
.check_standard_errors <- function(out,
by = NULL,
contrast = NULL,
model = NULL,
model_name = "model",
verbose = TRUE,
...) {
.check_standard_errors <- function(
out,
by = NULL,
contrast = NULL,
model = NULL,
model_name = "model",
verbose = TRUE,
...
) {
if (!verbose || is.null(out$SE)) {
return(NULL)
}
Expand Down Expand Up @@ -85,11 +112,15 @@
code_snippet <- paste0(code_snippet, "\n)")
# setup message
msg <- insight::format_message(
"Could not calculate standard errors for contrasts. This can happen when random effects are involved. You may try following:"
"Could not calculate standard errors for contrasts. This can happen when random effects are involved."
)
# add example code, if valid
if (!is.null(by_vars)) {
msg <- c(msg, insight::color_text(code_snippet, "green"), "\n")
msg <- c(
paste(msg, "You may try following:"),
insight::color_text(code_snippet, "green"),
"\n"
)
Comment thread
strengejacke marked this conversation as resolved.
}
message(msg)

Expand Down Expand Up @@ -145,7 +176,11 @@
}

# no need to check if check is disabled
if (is.null(integer_as_continuous) || is.na(integer_as_continuous) || isTRUE(integer_as_continuous)) {
if (
is.null(integer_as_continuous) ||
is.na(integer_as_continuous) ||
isTRUE(integer_as_continuous)
) {
return(FALSE)
}

Expand All @@ -156,7 +191,7 @@
# more than 2 unique values, otherwise it's assumed to be a binary variable
if (is_likert && verbose && missing_default && insight::n_unique(x) > 2) {
insight::format_alert(
"Numeric variable appears to be ordinal or Likert-scale (integer values, no more than 5 unique values) and is treated as discrete variable. Set `integer_as_continuous = TRUE` to disable this check and always treat numeric variables as continuous."

Check warning on line 194 in R/utils.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/utils.R,line=194,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 253 characters.
)
}
is_likert
Expand Down
Loading