Skip to content

Commit 58c5e2e

Browse files
Merge pull request #432 from easystats/strengejacke/issue430
CRAN update before 2025-03-24
2 parents 136c07a + 2535f8a commit 58c5e2e

21 files changed

+64
-37
lines changed

DESCRIPTION

+1-2
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.9.0.42
4+
Version: 0.10.0
55
Authors@R:
66
c(person(given = "Dominique",
77
family = "Makowski",
@@ -102,4 +102,3 @@ Roxygen: list(markdown = TRUE)
102102
Config/Needs/check: stan-dev/cmdstanr
103103
Config/Needs/website: easystats/easystatstemplate
104104
LazyData: true
105-
Remotes: easystats/see, easystats/parameters, easystats/insight

NEWS.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# modelbased (devel)
1+
# modelbased 0.10.0
22

33
## Breaking Changes
44

@@ -39,6 +39,10 @@
3939
* The `print()` method is now explicitly documented and gets some new options
4040
to customize the output for tables.
4141

42+
* `estimate_grouplevel()` gets a new option, `type = "total"`, to return the
43+
sum of fixed and random effects (similar to what `coef()` returns for (Bayesian)
44+
mixed models).
45+
4246
* New option `"esarey"` for the `p_adjust` argument. The `"esarey"` option is
4347
specifically for the case of Johnson-Neyman intervals, i.e. when calling
4448
`estimate_slopes()` with two numeric predictors in an interaction term.
@@ -74,6 +78,8 @@
7478

7579
* Fixed issues in `estimate_contrasts()` when filtering numeric values in `by`.
7680

81+
* Fixed issues in `estimate_grouplevel()`.
82+
7783
* Fixed issue in `estimate_slopes()` for models from package *lme4*.
7884

7985
# modelbased 0.9.0

R/describe_nonlinear.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe_nonlinear.estimate_predicted <- function(data,
4141
#' @export
4242
describe_nonlinear.numeric <- function(data, x = NULL, ...) {
4343
if (is.null(x)) {
44-
x <- seq_len(length(data))
44+
x <- seq_along(data)
4545
}
4646

4747
describe_nonlinear(data.frame(x = x, y = data), x = "x", y = "y")

R/estimate_grouplevel.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
#' the sum of the random effect and its corresponding fixed effects, which
1717
#' internally relies on the `coef()` method (see `?coef.merMod`). Note that
1818
#' `type = "total"` yet does not return uncertainty indices (such as SE and CI)
19-
#' for models from *lme4* or *glmmTMB*, as these are not computable. However, for
20-
#' Bayesian models, it is possible to compute them.
19+
#' for models from *lme4* or *glmmTMB*, as the necessary information to
20+
#' compute them is not yet available. However, for Bayesian models, it is
21+
#' possible to compute them.
2122
#' @param ... Other arguments passed to or from other methods.
2223
#'
2324
#' @details
@@ -94,7 +95,7 @@ estimate_grouplevel <- function(model, type = "random", ...) {
9495
# Save brms name (just in case)
9596
random$Name <- random$Parameter
9697
# Filter out non-random effects
97-
random <- random[grepl("^r_", random$Parameter), ]
98+
random <- random[startsWith(random$Parameter, "r_"), ]
9899
# Remove Group from Level
99100
random$Level <- sapply(1:nrow(random), function(i) gsub(paste0("^", random$Group[i], "\\."), "", random$Level[i]))
100101
# Find the group name (what follows "r_" and before the first "[" or "__")

R/estimate_slopes.R

+1-4
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ estimate_slopes <- function(model,
158158
info <- attributes(estimated)
159159

160160
# Table formatting
161-
table_footer <- paste("\nMarginal effects estimated for", info$trend)
162-
if (!is.null(attributes(trends)$slope)) {
163-
table_footer <- paste0(table_footer, "\nType of slope was ", attributes(trends)$slope)
164-
}
161+
table_footer <- .table_footer_slopes(trends, model = model, info = info)
165162
attr(trends, "table_title") <- c("Estimated Marginal Effects", "blue")
166163
attr(trends, "table_footer") <- c(table_footer, "yellow")
167164

R/smoothing.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ smoothing.numeric <- function(x, method = "loess", strength = 0.25, ...) {
4141
{
4242
stats::predict(stats::loess(
4343
paste0("y ~ x"),
44-
data = data.frame(y = x, x = seq_len(length(x))),
44+
data = data.frame(y = x, x = seq_along(x)),
4545
span = strength
4646
))
4747
},
@@ -55,7 +55,7 @@ smoothing.numeric <- function(x, method = "loess", strength = 0.25, ...) {
5555
)
5656
stats::predict(stats::loess(
5757
paste0("y ~ x"),
58-
data = data.frame(y = x, x = seq_len(length(x))),
58+
data = data.frame(y = x, x = seq_along(x)),
5959
span = strength
6060
))
6161
}

R/standardize_methods.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ standardize.estimate_predicted <- function(x, include_response = TRUE, ...) {
1010
x[names(data)] <- datawizard::standardize(as.data.frame(x)[names(data)], reference = data, ...)
1111

1212
# Standardize response
13-
if (include_response == TRUE && insight::model_info(attributes(x)$model)$is_linear) {
13+
if (include_response && insight::model_info(attributes(x)$model)$is_linear) {
1414
resp <- insight::get_response(attributes(x)$model)
1515
disp <- attributes(datawizard::standardize(resp, ...))$scale
1616

R/table_footer.R

+26
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,29 @@
141141

142142
c(paste0(table_footer, "\n"), "yellow")
143143
}
144+
145+
146+
# Table footer slopes =========================================================
147+
148+
149+
.table_footer_slopes <- function(x, model = NULL, info = NULL) {
150+
model_info <- info$model_info
151+
# make sure we definitely have model information
152+
if (is.null(model_info) && !is.null(model)) {
153+
model_info <- insight::model_info(model)
154+
}
155+
transform <- info$transform
156+
157+
table_footer <- paste("\nMarginal effects estimated for", info$trend)
158+
if (!is.null(attributes(x)$slope)) {
159+
table_footer <- paste0(table_footer, "\nType of slope was ", attributes(x)$slope)
160+
}
161+
if (isTRUE(model_info$is_linear) && !isTRUE(transform)) {
162+
# add information about response transformation
163+
trans_fun <- .safe(insight::find_transformation(model))
164+
if (!is.null(trans_fun) && trans_fun != "identity") {
165+
table_footer <- paste0(table_footer, "\nSlopes are on the ", trans_fun, "-scale (consider `transform=TRUE`).")
166+
}
167+
}
168+
table_footer
169+
}

R/visualisation_recipe_internal.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294

295295
# Uncertainty -----------------------------------
296296
if (!identical(ribbon, "none") && aes$type == "ribbon" && is.null(aes$alpha)) {
297-
for (i in seq_len(length(aes$ymin))) {
297+
for (i in seq_along(aes$ymin)) {
298298
# base list elements
299299
aes_list <- list(
300300
y = aes$y,

R/zero_crossings.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
#'
1212
#' @examples
1313
#' x <- sin(seq(0, 4 * pi, length.out = 100))
14-
#' plot(x, type = "b")
14+
#' # plot(x, type = "b")
1515
#'
16-
#' zero_crossings(x)
17-
#' find_inversions(x)
16+
#' modelbased::zero_crossings(x)
17+
#' modelbased::find_inversions(x)
1818
#' @export
1919
zero_crossings <- function(x) {
2020
# Estimate gradient
21-
zerocrossings <- .uniroot.all(stats::approxfun(seq_len(length(x)), x), interval = range(seq_len(length(x))))
21+
zerocrossings <- .uniroot.all(stats::approxfun(seq_along(x), x), interval = range(seq_along(x)))
2222
if (length(zerocrossings) == 0) {
2323
return(NA)
2424
}

R/zzz.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.onLoad <- function(libname, pkgname) {
22
# CRAN OMP THREAD LIMIT
3-
Sys.setenv("OMP_THREAD_LIMIT" = 2)
3+
Sys.setenv(OMP_THREAD_LIMIT = 2)
44
}

cran-comments.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
## R CMD check results
2-
3-
0 errors | 0 warnings | 0 note
1+
This release fixes CRAN check failures.

man/estimate_grouplevel.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/zero_crossings.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-backtransform_invlink.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ skip_if_not_installed("glmmTMB")
55
test_that("estimate_means correct inverse link for glmmTMB", {
66
data(mtcars)
77
d <- mtcars
8-
d$count <- rep(c(0, 0, 0, 0, 1, 2, 4), length.out = nrow(mtcars))
8+
d$count <- rep_len(c(0, 0, 0, 0, 1, 2, 4), nrow(mtcars))
99
m <- glmmTMB::glmmTMB(
1010
count ~ cyl,
1111
data = datawizard::data_modify(d, cyl = as.factor(cyl)),
@@ -50,7 +50,7 @@ test_that("estimate_means correct inverse link for glmer", {
5050
data(efc, package = "modelbased")
5151

5252
x <- which(efc$negc7d == 1 & efc$c172code == 3)
53-
efc$negc7d[x[sample(1:length(x), round(length(x) / 1.1))]] <- 0
53+
efc$negc7d[x[sample.int(length(x), round(length(x) / 1.1))]] <- 0
5454
efc$c172code <- as.factor(efc$c172code)
5555
fit <- lme4::glmer(
5656
negc7d ~ c12hour + e42dep + c161sex + c172code + (1 | grp),

tests/testthat/test-estimate_contrasts-average.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test_that("estimate_contrast, filterin in `by` and `contrast`", {
4545

4646
out <- estimate_contrasts(
4747
m,
48-
c("e42dep=c('independent','slightly dependent','moderately dependent')"),
48+
"e42dep=c('independent','slightly dependent','moderately dependent')",
4949
by = "c172code",
5050
estimate = "average"
5151
)

tests/testthat/test-estimate_contrasts.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ test_that("estimate_contrast, filterin in `by` and `contrast`", {
873873

874874
out <- estimate_contrasts(
875875
m,
876-
c("e42dep=c('independent','slightly dependent','moderately dependent')"),
876+
"e42dep=c('independent','slightly dependent','moderately dependent')",
877877
by = "c172code"
878878
)
879879
expect_identical(dim(out), c(9L, 10L))

vignettes/introduction_comparisons_1.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,6 @@ Let's replicate this step-by-step:
314314

315315
# Conclusion
316316

317-
While the current implementation in `estimate_contrasts()` already covers many common use cases for testing contrasts and pairwise comparison, there still might be the need for more sophisticated comparisons. In this case, we recommend using the [*marginaleffects*](https://marginaleffects.com/) package directly. Some further related recommended readings are the vignettes about [Comparisons](https://marginaleffects.com/vignettes/comparisons.html) or [Hypothesis Tests](https://marginaleffects.com/vignettes/hypothesis.html).
317+
While the current implementation in `estimate_contrasts()` already covers many common use cases for testing contrasts and pairwise comparison, there still might be the need for more sophisticated comparisons. In this case, we recommend using the [*marginaleffects*](https://marginaleffects.com/) package directly. Some further related recommended readings are the vignettes about [Comparisons](https://marginaleffects.com/chapters/comparisons.html) or [Hypothesis Tests](https://marginaleffects.com/chapters/hypothesis.html).
318318

319319
[Go to next vignette: **Comparisons of Slopes, Floodlight and Spotlight Analysis (Johnson-Neyman Intervals)**](https://easystats.github.io/modelbased/articles/introduction_comparisons_2.html)

vignettes/practical_causality.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pkgs <- c("glmmTMB", "marginaleffects", "ggplot2", "see", "brms")
2727
if (!all(insight::check_if_installed(pkgs, quietly = TRUE))) {
2828
knitr::opts_chunk$set(eval = FALSE)
2929
}
30-
if (!getRversion() >= "4.1.0") {
30+
if (getRversion() < "4.1.0") {
3131
knitr::opts_chunk$set(eval = FALSE)
3232
}
3333
```

vignettes/practical_intersectionality.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pkgs <- c(
3636
if (!all(insight::check_if_installed(pkgs, quietly = TRUE))) {
3737
knitr::opts_chunk$set(eval = FALSE)
3838
}
39-
if (!getRversion() >= "4.1.0") {
39+
if (getRversion() < "4.1.0") {
4040
knitr::opts_chunk$set(eval = FALSE)
4141
}
4242
```

vignettes/workflow_modelbased.Rmd

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ knitr::opts_chunk$set(
2020
collapse = TRUE,
2121
comment = "#>",
2222
warning = FALSE,
23-
message = TRUE,
24-
package.startup.message = FALSE
23+
message = TRUE
2524
)
2625
options(knitr.kable.NA = "", digits = 2, width = 800, modelbased_join_dots = FALSE)
2726
pkgs <- c("ggplot2", "marginaleffects", "collapse", "Formula")

0 commit comments

Comments
 (0)