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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.26.0.1
Version: 0.26.0.2
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -227,3 +227,4 @@ Config/testthat/parallel: true
Config/Needs/website: easystats/easystatstemplate
Config/Needs/check: stan-dev/cmdstanr
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/insight, easystats/bayestestR
3 changes: 2 additions & 1 deletion R/methods_brms.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ model_parameters.brmsfit <- function(model,
exponentiate,
ci_method = ci_method,
group_level = group_level,
modelinfo = modelinfo,
verbose = verbose,
...
)

attr(params, "parameter_info") <- insight::clean_parameters(model)
attr(params, "parameter_info") <- .get_cleaned_parameters(params, model)
attr(params, "object_name") <- insight::safe_deparse_symbol(substitute(model))
attr(params, "dpars") <- insight::find_auxiliary(model, verbose = FALSE)
class(params) <- unique(c("parameters_model", "see_parameters_model", class(params)))
Expand Down
5 changes: 4 additions & 1 deletion R/methods_glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ model_parameters.glmmTMB <- function(model,
c("all", "conditional", "zi", "zero_inflated", "dispersion")
)

modelinfo <- insight::model_info(model, verbose = FALSE)

# group level estimates =================================================
# =======================================================================

Expand Down Expand Up @@ -238,7 +240,7 @@ model_parameters.glmmTMB <- function(model,

# fix argument, if model has only conditional component
cs <- stats::coef(summary(model))
has_zeroinf <- insight::model_info(model, verbose = FALSE)$is_zero_inflated
has_zeroinf <- modelinfo$is_zero_inflated
has_disp <- is.list(cs) && !is.null(cs$disp)

if (!has_zeroinf && !has_disp && component != "conditional") {
Expand Down Expand Up @@ -348,6 +350,7 @@ model_parameters.glmmTMB <- function(model,
group_level = group_level,
include_info = include_info,
wb_component = wb_component,
modelinfo = modelinfo,
...
)

Expand Down
2 changes: 1 addition & 1 deletion R/methods_rstanarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ model_parameters.stanreg <- function(model,
...
)

attr(params, "parameter_info") <- insight::clean_parameters(model)
attr(params, "parameter_info") <- .get_cleaned_parameters(params, model)
attr(params, "object_name") <- insight::safe_deparse_symbol(substitute(model))
class(params) <- c("parameters_model", "see_parameters_model", class(params))

Expand Down
27 changes: 25 additions & 2 deletions R/utils_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @keywords internal
#' @noRd
.add_model_parameters_attributes <- function(params,

Check warning on line 7 in R/utils_model_parameters.R

View workflow job for this annotation

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

file=R/utils_model_parameters.R,line=7,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 41 to at most 40.
model,
ci,
exponentiate = FALSE,
Expand All @@ -16,12 +16,17 @@
verbose = TRUE,
group_level = FALSE,
wb_component = FALSE,
modelinfo = NULL,
...) {
# capture additional arguments
dot.arguments <- list(...)

# model info
info <- .safe(suppressWarnings(insight::model_info(model, verbose = FALSE)))
if (is.null(modelinfo)) {
info <- .safe(suppressWarnings(insight::model_info(model, verbose = FALSE)))
} else {
info <- modelinfo
}

if (is.null(info)) {
info <- list(family = "unknown", link_function = "unknown")
Expand Down Expand Up @@ -249,7 +254,7 @@
#'
#' @keywords internal
#' @noRd
.find_coefficient_type <- function(info, exponentiate, model = NULL) {

Check warning on line 257 in R/utils_model_parameters.R

View workflow job for this annotation

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

file=R/utils_model_parameters.R,line=257,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this expression from 57 to at most 40.
# column name for coefficients
coef_col <- "Coefficient"
if (!is.null(model) && inherits(model, "emmGrid")) {
Expand Down Expand Up @@ -359,6 +364,23 @@
}


#' this function extracts the table with cleaned parameter names, extracted
#' from `insight::clean_parameters()`. it first checks whether this object
#' is saved as attribute, and if not, calls `insight::clean_parameters()`.
#'
#' @keywords internal
#' @noRd
.get_cleaned_parameters <- function(params, model) {
# check if we have cleaned parameters as attributes
cp <- attributes(params)$clean_parameters
# if not, add
if (is.null(cp)) {
cp <- insight::clean_parameters(model)
}
cp
}


#' this function extract "prettified" parameter names, using
#' `insight::clean_parameters()`, and matches them with the parameter names.
#' the result is a named vector, added as attributes to the output
Expand All @@ -367,7 +389,8 @@
#' @noRd
.add_pretty_names <- function(params, model) {
attr(params, "model_class") <- class(model)
cp <- insight::clean_parameters(model)
# check if we have cleaned parameters as attributes
cp <- .get_cleaned_parameters(params, model)
clean_params <- cp[cp$Parameter %in% params$Parameter, ]

named_clean_params <- stats::setNames(
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-model_parameters.mediate.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@
test_that("model_parameters.mediate-1", {
params <- model_parameters(m1)
expect_equal(params$Estimate, c(-0.01488, -0.04753, -0.06242, 0.16635), tolerance = 1e-2)
expect_equal(params$Parameter, c("ACME", "ADE", "Total Effect", "Prop. Mediated"))

Check warning on line 21 in tests/testthat/test-model_parameters.mediate.R

View workflow job for this annotation

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

file=tests/testthat/test-model_parameters.mediate.R,line=21,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
})

test_that("model_parameters.mediate-2", {
params <- model_parameters(m2)
expect_equal(params$Estimate, c(0.02484, -0.05793, -0.03309, -0.27914), tolerance = 1e-2)
expect_equal(params$Parameter, c("ACME", "ADE", "Total Effect", "Prop. Mediated"))

Check warning on line 27 in tests/testthat/test-model_parameters.mediate.R

View workflow job for this annotation

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

file=tests/testthat/test-model_parameters.mediate.R,line=27,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
})


test_that("model_parameters.mediate-3", {
skip_on_cran()

## FIXME: bug in the latest CRAN version of the mediation package
# maintainer contacted on 13. June 2025
skip_if(TRUE)

jobs$job_disc <- as.factor(jobs$job_disc)
b.ord <- MASS::polr(
job_disc ~ treat + econ_hard + sex + age,
Expand All @@ -51,12 +56,12 @@
0.00216, 0.00231, 0.0486, 0.04875, 0.05091, 0.03981, 0.04829,
0.00223, 0.04868, 0.04405
), tolerance = 1e-2)
expect_equal(params$Parameter, c(

Check warning on line 59 in tests/testthat/test-model_parameters.mediate.R

View workflow job for this annotation

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

file=tests/testthat/test-model_parameters.mediate.R,line=59,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
"ACME (control)", "ACME (treated)", "ADE (control)", "ADE (treated)",
"Total Effect", "Prop. Mediated (control)", "Prop. Mediated (treated)",
"ACME (average)", "ADE (average)", "Prop. Mediated (average)"
))
expect_equal(params$Component, c(

Check warning on line 64 in tests/testthat/test-model_parameters.mediate.R

View workflow job for this annotation

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

file=tests/testthat/test-model_parameters.mediate.R,line=64,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
"control", "treated", "control", "treated", "Total Effect",
"control", "treated", "average", "average", "average"
))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-pool_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ test_that("pooled parameters, glmmTMB, zero-inflated", {
ziformula = ~mined,
family = poisson()
)))
mice_summ <- summary(mice::pool(m_mice, dfcom = Inf))
mice_summ <- suppressWarnings(summary(mice::pool(m_mice, dfcom = Inf)))
expect_equal(out$Coefficient, mice_summ$estimate, tolerance = 1e-3)
expect_equal(out$SE, mice_summ$std.error, tolerance = 1e-3)
expect_equal(out$p, mice_summ$p.value, tolerance = 1e-3)
Expand Down
Loading