Skip to content

Commit a851917

Browse files
committed
estimate_means warning/error cut off? "Could not calculate standard errors for contrasts. This can happen when random effects are involved"
Fixes #578
1 parent dc609ea commit a851917

4 files changed

Lines changed: 58 additions & 16 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: modelbased
33
Title: Estimation of Model-Based Predictions, Contrasts and Means
4-
Version: 0.13.1.2
4+
Version: 0.13.1.3
55
Authors@R:
66
c(person(given = "Dominique",
77
family = "Makowski",

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

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

9+
* Fixed error with truncated message when standard errors could not be calculated.
10+
911
# modelbased 0.13.1
1012

1113
## Changes

R/estimate_means.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,12 @@ estimate_means <- function(
465465
}
466466

467467
# sanity check - did method return standard errors?
468-
.check_standard_errors(out = means, model = model, verbose = verbose)
468+
.check_standard_errors(
469+
out = means,
470+
by = attributes(means)$by,
471+
model = model,
472+
verbose = verbose
473+
)
469474

470475
# restore attributes later
471476
info <- attributes(estimated)

R/utils.R

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,24 @@
22
#' @noRd
33
.brms_aux_elements <- function(model = NULL) {
44
out <- c(
5-
"sigma", "mu", "nu", "shape", "beta", "phi", "hu", "ndt", "zoi", "coi",
6-
"kappa", "bias", "bs", "zi", "alpha", "xi", "delta", "k"
5+
"sigma",
6+
"mu",
7+
"nu",
8+
"shape",
9+
"beta",
10+
"phi",
11+
"hu",
12+
"ndt",
13+
"zoi",
14+
"coi",
15+
"kappa",
16+
"bias",
17+
"bs",
18+
"zi",
19+
"alpha",
20+
"xi",
21+
"delta",
22+
"k"
723
)
824
unique(c(out, insight::find_auxiliary(model, verbose = FALSE)))
925
}
@@ -13,8 +29,17 @@
1329
#' @noRd
1430
.valid_coefficient_names <- function(model = NULL) {
1531
out <- c(
16-
"Mean", "Probability", "Difference", "Ratio", "Rate", "ZI-Probability",
17-
"Proportion", "Median", "MAP", "Coefficient", "Odds_ratio"
32+
"Mean",
33+
"Probability",
34+
"Difference",
35+
"Ratio",
36+
"Rate",
37+
"ZI-Probability",
38+
"Proportion",
39+
"Median",
40+
"MAP",
41+
"Coefficient",
42+
"Odds_ratio"
1843
)
1944
dpars <- insight::find_auxiliary(model, verbose = FALSE)
2045
if (!is.null(dpars)) {
@@ -46,13 +71,15 @@
4671

4772
#' @keywords internal
4873
#' @noRd
49-
.check_standard_errors <- function(out,
50-
by = NULL,
51-
contrast = NULL,
52-
model = NULL,
53-
model_name = "model",
54-
verbose = TRUE,
55-
...) {
74+
.check_standard_errors <- function(
75+
out,
76+
by = NULL,
77+
contrast = NULL,
78+
model = NULL,
79+
model_name = "model",
80+
verbose = TRUE,
81+
...
82+
) {
5683
if (!verbose || is.null(out$SE)) {
5784
return(NULL)
5885
}
@@ -85,11 +112,15 @@
85112
code_snippet <- paste0(code_snippet, "\n)")
86113
# setup message
87114
msg <- insight::format_message(
88-
"Could not calculate standard errors for contrasts. This can happen when random effects are involved. You may try following:"
115+
"Could not calculate standard errors for contrasts. This can happen when random effects are involved."
89116
)
90117
# add example code, if valid
91118
if (!is.null(by_vars)) {
92-
msg <- c(msg, insight::color_text(code_snippet, "green"), "\n")
119+
msg <- c(
120+
paste0(msg, "You may try following:"),
121+
insight::color_text(code_snippet, "green"),
122+
"\n"
123+
)
93124
}
94125
message(msg)
95126

@@ -145,7 +176,11 @@
145176
}
146177

147178
# no need to check if check is disabled
148-
if (is.null(integer_as_continuous) || is.na(integer_as_continuous) || isTRUE(integer_as_continuous)) {
179+
if (
180+
is.null(integer_as_continuous) ||
181+
is.na(integer_as_continuous) ||
182+
isTRUE(integer_as_continuous)
183+
) {
149184
return(FALSE)
150185
}
151186

0 commit comments

Comments
 (0)