From 9ae21f9c3725f2f3614c0810f13c6bd24e0aa45f Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Sep 2025 10:06:17 +0200 Subject: [PATCH 1/8] `equivalence_test()` for modelbased-objects --- DESCRIPTION | 4 ++-- NAMESPACE | 3 +++ R/equivalence_test.R | 17 +++++++++++++++++ man/bootstrap_model.Rd | 2 +- man/bootstrap_parameters.Rd | 2 +- man/ci.default.Rd | 2 +- man/cluster_discrimination.Rd | 2 +- man/compare_parameters.Rd | 2 +- man/convert_efa_to_cfa.Rd | 2 +- man/degrees_of_freedom.Rd | 2 +- man/display.parameters_model.Rd | 4 ++-- man/dominance_analysis.Rd | 2 +- man/equivalence_test.lm.Rd | 2 +- man/factor_scores.Rd | 2 +- man/get_scores.Rd | 2 +- man/model_parameters.BFBayesFactor.Rd | 2 +- man/model_parameters.aov.Rd | 4 ++-- man/model_parameters.brmsfit.Rd | 2 +- man/model_parameters.compare.loo.Rd | 2 +- man/model_parameters.default.Rd | 2 +- man/model_parameters.glmmTMB.Rd | 2 +- man/model_parameters.hclust.Rd | 2 +- man/model_parameters.mira.Rd | 2 +- man/model_parameters.mlm.Rd | 2 +- man/model_parameters.principal.Rd | 2 +- man/model_parameters.zcpglm.Rd | 2 +- man/n_clusters.Rd | 2 +- man/n_factors.Rd | 2 +- man/p_direction.lm.Rd | 2 +- man/p_function.Rd | 2 +- man/p_significance.lm.Rd | 2 +- man/p_value.Rd | 2 +- man/pool_parameters.Rd | 2 +- man/principal_components.Rd | 2 +- man/print.compare_parameters.Rd | 2 +- man/print.parameters_model.Rd | 2 +- man/select_parameters.Rd | 2 +- man/standard_error.Rd | 2 +- man/standardize_info.Rd | 2 +- man/standardize_parameters.Rd | 4 ++-- 40 files changed, 62 insertions(+), 42 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8dff1add1e..62ff967f44 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.28.2 +Version: 0.28.2.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -224,7 +224,7 @@ VignetteBuilder: knitr Encoding: UTF-8 Language: en-US -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Roxygen: list(markdown = TRUE) Config/testthat/edition: 3 Config/testthat/parallel: true diff --git a/NAMESPACE b/NAMESPACE index 5933be9ac0..eecff96ec2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -137,6 +137,9 @@ S3method(display,parameters_simulate) S3method(display,parameters_standardized) S3method(dof_satterthwaite,lmerMod) S3method(equivalence_test,MixMod) +S3method(equivalence_test,estimate_contrasts) +S3method(equivalence_test,estimate_means) +S3method(equivalence_test,estimate_slopes) S3method(equivalence_test,feis) S3method(equivalence_test,felm) S3method(equivalence_test,gee) diff --git a/R/equivalence_test.R b/R/equivalence_test.R index a24ef73861..813aef6989 100644 --- a/R/equivalence_test.R +++ b/R/equivalence_test.R @@ -299,6 +299,15 @@ equivalence_test.zeroinfl <- equivalence_test.lm #' @export equivalence_test.rma <- equivalence_test.lm +#' @export +equivalence_test.estimate_means <- equivalence_test.lm + +#' @export +equivalence_test.estimate_contrasts <- equivalence_test.lm + +#' @export +equivalence_test.estimate_slopes <- equivalence_test.lm + # mixed models, also random effects ---------------------- @@ -407,6 +416,14 @@ equivalence_test.parameters_model <- function(x, #' @keywords internal .check_rope_range <- function(x, range, verbose) { + # for modelbased-objects, we extract the model to define the rope range + if (inherits(x, c("estimate_means", "estimate_contrasts", "estimate_slopes"))) { + x <- .safe(insight::get_model(x)) + # if not successful, return defaults + if (is.null(x)) { + return(c(-1, 1)) + } + } if (all(range == "default")) { range <- bayestestR::rope_range(x, verbose = verbose) if (is.list(range)) { diff --git a/man/bootstrap_model.Rd b/man/bootstrap_model.Rd index d030a0cb83..249b363f5d 100644 --- a/man/bootstrap_model.Rd +++ b/man/bootstrap_model.Rd @@ -70,7 +70,7 @@ to obtain non-parametric p-values. } \examples{ -\dontshow{if (require("boot", quietly = TRUE) && require("emmeans", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("boot", quietly = TRUE) && require("emmeans", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ model <- lm(mpg ~ wt + factor(cyl), data = mtcars) b <- bootstrap_model(model) diff --git a/man/bootstrap_parameters.Rd b/man/bootstrap_parameters.Rd index fcecdba27d..2272fd4860 100644 --- a/man/bootstrap_parameters.Rd +++ b/man/bootstrap_parameters.Rd @@ -78,7 +78,7 @@ to obtain non-parametric p-values. } \examples{ -\dontshow{if (require("boot", quietly = TRUE) && require("emmeans", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("boot", quietly = TRUE) && require("emmeans", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ set.seed(2) model <- lm(Sepal.Length ~ Species * Petal.Width, data = iris) diff --git a/man/ci.default.Rd b/man/ci.default.Rd index dabf34e9fe..4c4b64b90b 100644 --- a/man/ci.default.Rd +++ b/man/ci.default.Rd @@ -299,7 +299,7 @@ here. } \examples{ -\dontshow{if (require("glmmTMB") && requireNamespace("sandwich")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("glmmTMB") && requireNamespace("sandwich")) withAutoprint(\{ # examplesIf} data(qol_cancer) model <- lm(QoL ~ time + age + education, data = qol_cancer) diff --git a/man/cluster_discrimination.Rd b/man/cluster_discrimination.Rd index 161dd9dd2f..11ffab6415 100644 --- a/man/cluster_discrimination.Rd +++ b/man/cluster_discrimination.Rd @@ -20,7 +20,7 @@ determines the goodness of classification for each cluster group. See \code{MASS for details. } \examples{ -\dontshow{if (requireNamespace("MASS", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("MASS", quietly = TRUE)) withAutoprint(\{ # examplesIf} # Retrieve group classification from hierarchical cluster analysis clustering <- cluster_analysis(iris[, 1:4], n = 3) diff --git a/man/compare_parameters.Rd b/man/compare_parameters.Rd index 54770ea75d..863299c17d 100644 --- a/man/compare_parameters.Rd +++ b/man/compare_parameters.Rd @@ -236,7 +236,7 @@ Therefore, you should not use this function to compare models with interaction terms with models without interaction terms. } \examples{ -\dontshow{if (require("gt", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("gt", quietly = TRUE)) withAutoprint(\{ # examplesIf} data(iris) lm1 <- lm(Sepal.Length ~ Species, data = iris) lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris) diff --git a/man/convert_efa_to_cfa.Rd b/man/convert_efa_to_cfa.Rd index 5874fa1cf1..b31e58823c 100644 --- a/man/convert_efa_to_cfa.Rd +++ b/man/convert_efa_to_cfa.Rd @@ -40,7 +40,7 @@ Enables a conversion between Exploratory Factor Analysis (EFA) and Confirmatory Factor Analysis (CFA) \code{lavaan}-ready structure. } \examples{ -\dontshow{if (require("psych") && require("lavaan")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("psych") && require("lavaan")) withAutoprint(\{ # examplesIf} \donttest{ library(parameters) data(attitude) diff --git a/man/degrees_of_freedom.Rd b/man/degrees_of_freedom.Rd index 291bd55aae..d596186ee0 100644 --- a/man/degrees_of_freedom.Rd +++ b/man/degrees_of_freedom.Rd @@ -55,7 +55,7 @@ Furthermore, for other approximation methods like \code{"kenward"} or freedom. } \examples{ -\dontshow{if (require("lme4", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("lme4", quietly = TRUE)) withAutoprint(\{ # examplesIf} model <- lm(Sepal.Length ~ Petal.Length * Species, data = iris) dof(model) diff --git a/man/display.parameters_model.Rd b/man/display.parameters_model.Rd index 2743a20bb8..c0df36c2eb 100644 --- a/man/display.parameters_model.Rd +++ b/man/display.parameters_model.Rd @@ -40,7 +40,7 @@ knitted from rmarkdown to PDF or Word files. See for examples. } \examples{ -\dontshow{if (require("gt", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("gt", quietly = TRUE)) withAutoprint(\{ # examplesIf} model <- lm(mpg ~ wt + cyl, data = mtcars) mp <- model_parameters(model) display(mp) @@ -66,7 +66,7 @@ print_html( ) } \dontshow{\}) # examplesIf} -\dontshow{if (all(insight::check_if_installed(c("glmmTMB", "lme4", "tinytable"), quietly = TRUE))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (all(insight::check_if_installed(c("glmmTMB", "lme4", "tinytable"), quietly = TRUE))) withAutoprint(\{ # examplesIf} \donttest{ data(iris) data(Salamanders, package = "glmmTMB") diff --git a/man/dominance_analysis.Rd b/man/dominance_analysis.Rd index 18732f6062..048c1fe9fa 100644 --- a/man/dominance_analysis.Rd +++ b/man/dominance_analysis.Rd @@ -124,7 +124,7 @@ When \code{performance::r2()} returns multiple values, only the first is used by default. } \examples{ -\dontshow{if (require("domir") && require("performance")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("domir") && require("performance")) withAutoprint(\{ # examplesIf} data(mtcars) # Dominance Analysis with Logit Regression diff --git a/man/equivalence_test.lm.Rd b/man/equivalence_test.lm.Rd index 82c37c3e67..2e7bf241e2 100644 --- a/man/equivalence_test.lm.Rd +++ b/man/equivalence_test.lm.Rd @@ -266,7 +266,7 @@ documentation in \code{\link[=p_function]{p_function()}}). } \examples{ -\dontshow{if (requireNamespace("sandwich")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("sandwich")) withAutoprint(\{ # examplesIf} data(qol_cancer) model <- lm(QoL ~ time + age + education, data = qol_cancer) diff --git a/man/factor_scores.Rd b/man/factor_scores.Rd index db5ae390e8..b848f351f9 100644 --- a/man/factor_scores.Rd +++ b/man/factor_scores.Rd @@ -21,7 +21,7 @@ element from the object and converts it into a data frame. \code{\link[psych:fa]{psych::fa()}}, \code{\link[=factor_analysis]{factor_analysis()}}, or \code{\link[psych:omega]{psych::omega()}} } \examples{ -\dontshow{if (insight::check_if_installed("psych", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (insight::check_if_installed("psych", quietly = TRUE)) withAutoprint(\{ # examplesIf} data(mtcars) out <- factor_analysis(mtcars[, 1:7], n = 2) head(factor_scores(out)) diff --git a/man/get_scores.Rd b/man/get_scores.Rd index 478b1f153e..22c7111198 100644 --- a/man/get_scores.Rd +++ b/man/get_scores.Rd @@ -37,7 +37,7 @@ is on the same scale as the original, single items that were used to compute the PCA/FA. } \examples{ -\dontshow{if (insight::check_if_installed("psych", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (insight::check_if_installed("psych", quietly = TRUE)) withAutoprint(\{ # examplesIf} pca <- principal_components(mtcars[, 1:7], n = 2, rotation = "varimax") # PCA extracted two components diff --git a/man/model_parameters.BFBayesFactor.Rd b/man/model_parameters.BFBayesFactor.Rd index edede25918..b8c497249f 100644 --- a/man/model_parameters.BFBayesFactor.Rd +++ b/man/model_parameters.BFBayesFactor.Rd @@ -92,7 +92,7 @@ the \emph{g} parameters; See the \emph{Bayes Factors for ANOVAs} paper } } \examples{ -\dontshow{if (require("BayesFactor")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("BayesFactor")) withAutoprint(\{ # examplesIf} \donttest{ # Bayesian t-test model <- BayesFactor::ttestBF(x = rnorm(100, 1, 1)) diff --git a/man/model_parameters.aov.Rd b/man/model_parameters.aov.Rd index a3e4b733d9..941a2688e3 100644 --- a/man/model_parameters.aov.Rd +++ b/man/model_parameters.aov.Rd @@ -154,7 +154,7 @@ covariates are mean-centred and factors are coded with orthogonal contrasts \code{contr.helmert}, but \emph{not} by the default \code{contr.treatment}). } \examples{ -\dontshow{if (requireNamespace("effectsize", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("effectsize", quietly = TRUE)) withAutoprint(\{ # examplesIf} df <- iris df$Sepal.Big <- ifelse(df$Sepal.Width >= 3, "Yes", "No") @@ -174,7 +174,7 @@ model_parameters( model <- aov(Sepal.Length ~ Sepal.Big + Error(Species), data = df) model_parameters(model) \dontshow{\}) # examplesIf} -\dontshow{if (requireNamespace("lme4", quietly = TRUE) && requireNamespace("effectsize", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("lme4", quietly = TRUE) && requireNamespace("effectsize", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ df <- iris df$Sepal.Big <- ifelse(df$Sepal.Width >= 3, "Yes", "No") diff --git a/man/model_parameters.brmsfit.Rd b/man/model_parameters.brmsfit.Rd index 7eb30cae5a..e547b36117 100644 --- a/man/model_parameters.brmsfit.Rd +++ b/man/model_parameters.brmsfit.Rd @@ -442,7 +442,7 @@ here. } \examples{ -\dontshow{if (require("rstanarm")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("rstanarm")) withAutoprint(\{ # examplesIf} \donttest{ library(parameters) model <- suppressWarnings(stan_glm( diff --git a/man/model_parameters.compare.loo.Rd b/man/model_parameters.compare.loo.Rd index 617f36221d..d0da49d19b 100644 --- a/man/model_parameters.compare.loo.Rd +++ b/man/model_parameters.compare.loo.Rd @@ -33,7 +33,7 @@ conclude that a model is much better than another if both models make very similar predictions. } \examples{ -\dontshow{if (all(insight::check_if_installed(c("brms", "RcppEigen", "BH"), quietly = TRUE))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (all(insight::check_if_installed(c("brms", "RcppEigen", "BH"), quietly = TRUE))) withAutoprint(\{ # examplesIf} \donttest{ library(brms) diff --git a/man/model_parameters.default.Rd b/man/model_parameters.default.Rd index 1a5734677f..0406cc4462 100644 --- a/man/model_parameters.default.Rd +++ b/man/model_parameters.default.Rd @@ -337,7 +337,7 @@ which is converted into a p-value using \code{\link[bayestestR:pd_to_p]{bayestes } \examples{ -\dontshow{if (require("boot", quietly = TRUE) && require("sandwich") && require("clubSandwich") && require("brglm2")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("boot", quietly = TRUE) && require("sandwich") && require("clubSandwich") && require("brglm2")) withAutoprint(\{ # examplesIf} library(parameters) model <- lm(mpg ~ wt + cyl, data = mtcars) diff --git a/man/model_parameters.glmmTMB.Rd b/man/model_parameters.glmmTMB.Rd index 4fc5d99884..419eb0cc0d 100644 --- a/man/model_parameters.glmmTMB.Rd +++ b/man/model_parameters.glmmTMB.Rd @@ -513,7 +513,7 @@ which is converted into a p-value using \code{\link[bayestestR:pd_to_p]{bayestes } \examples{ -\dontshow{if (require("lme4") && require("glmmTMB")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("lme4") && require("glmmTMB")) withAutoprint(\{ # examplesIf} library(parameters) data(mtcars) model <- lme4::lmer(mpg ~ wt + (1 | gear), data = mtcars) diff --git a/man/model_parameters.hclust.Rd b/man/model_parameters.hclust.Rd index 2593c97862..2eaaae0751 100644 --- a/man/model_parameters.hclust.Rd +++ b/man/model_parameters.hclust.Rd @@ -20,7 +20,7 @@ rows in data).} Format cluster models obtained for example by \code{\link[=kmeans]{kmeans()}}. } \examples{ -\dontshow{if (require("factoextra", quietly = TRUE) && require("dbscan", quietly = TRUE) && require("cluster", quietly = TRUE) && require("fpc", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("factoextra", quietly = TRUE) && require("dbscan", quietly = TRUE) && require("cluster", quietly = TRUE) && require("fpc", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ # # K-means ------------------------------- diff --git a/man/model_parameters.mira.Rd b/man/model_parameters.mira.Rd index c2c4de9a5a..29f894915f 100644 --- a/man/model_parameters.mira.Rd +++ b/man/model_parameters.mira.Rd @@ -78,7 +78,7 @@ similar to \code{summary(mice::pool())}, i.e. it generates the pooled summary of multiple imputed repeated regression analyses. } \examples{ -\dontshow{if (require("mice", quietly = TRUE) && require("gee", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("mice", quietly = TRUE) && require("gee", quietly = TRUE)) withAutoprint(\{ # examplesIf} library(parameters) data(nhanes2, package = "mice") imp <- mice::mice(nhanes2) diff --git a/man/model_parameters.mlm.Rd b/man/model_parameters.mlm.Rd index c5197ebb8d..6188f995e6 100644 --- a/man/model_parameters.mlm.Rd +++ b/man/model_parameters.mlm.Rd @@ -208,7 +208,7 @@ here. } \examples{ -\dontshow{if (require("brglm2", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("brglm2", quietly = TRUE)) withAutoprint(\{ # examplesIf} data("stemcell", package = "brglm2") model <- brglm2::bracl( research ~ as.numeric(religion) + gender, diff --git a/man/model_parameters.principal.Rd b/man/model_parameters.principal.Rd index e99be2b56f..3bdfb0f64e 100644 --- a/man/model_parameters.principal.Rd +++ b/man/model_parameters.principal.Rd @@ -114,7 +114,7 @@ for \code{lavaan} models implemented in the \href{https://easystats.github.io/see/}{\strong{see}-package}. } \examples{ -\dontshow{if (all(insight::check_if_installed(c("psych", "lavaan"), quietly = TRUE))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (all(insight::check_if_installed(c("psych", "lavaan"), quietly = TRUE))) withAutoprint(\{ # examplesIf} library(parameters) \donttest{ # Principal Component Analysis (PCA) --------- diff --git a/man/model_parameters.zcpglm.Rd b/man/model_parameters.zcpglm.Rd index 06477a19e7..6e6391db4d 100644 --- a/man/model_parameters.zcpglm.Rd +++ b/man/model_parameters.zcpglm.Rd @@ -183,7 +183,7 @@ here. } \examples{ -\dontshow{if (require("pscl")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("pscl")) withAutoprint(\{ # examplesIf} data("bioChemists", package = "pscl") model <- pscl::zeroinfl( art ~ fem + mar + kid5 + ment | kid5 + phd, diff --git a/man/n_clusters.Rd b/man/n_clusters.Rd index 8a55f3a015..bdf079a546 100644 --- a/man/n_clusters.Rd +++ b/man/n_clusters.Rd @@ -167,7 +167,7 @@ if (require("mclust", quietly = TRUE) && require("NbClust", quietly = TRUE) && # n_clusters(iris[1:4], standardize = FALSE, package = "all", fast = FALSE) } } -\dontshow{if (require("see", quietly = TRUE) && require("factoextra", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("see", quietly = TRUE) && require("factoextra", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ x <- n_clusters_elbow(iris[1:4]) x diff --git a/man/n_factors.Rd b/man/n_factors.Rd index 09a88fcf14..740fded6bc 100644 --- a/man/n_factors.Rd +++ b/man/n_factors.Rd @@ -89,7 +89,7 @@ implemented in the \href{https://easystats.github.io/see/}{\strong{see}-package} \code{n_components()} is a convenient short-cut for \code{n_factors(type = "PCA")}. } \examples{ -\dontshow{if (require("PCDimension", quietly = TRUE) && require("nFactors", quietly = TRUE) && require("EGAnet", quietly = TRUE) && require("psych", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("PCDimension", quietly = TRUE) && require("nFactors", quietly = TRUE) && require("EGAnet", quietly = TRUE) && require("psych", quietly = TRUE)) withAutoprint(\{ # examplesIf} library(parameters) n_factors(mtcars, type = "PCA") diff --git a/man/p_direction.lm.Rd b/man/p_direction.lm.Rd index b5f8ef6707..1f683a89cf 100644 --- a/man/p_direction.lm.Rd +++ b/man/p_direction.lm.Rd @@ -194,7 +194,7 @@ documentation in \code{\link[=p_function]{p_function()}}). } \examples{ -\dontshow{if (requireNamespace("bayestestR") && require("see", quietly = TRUE) && requireNamespace("sandwich")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("bayestestR") && require("see", quietly = TRUE) && requireNamespace("sandwich")) withAutoprint(\{ # examplesIf} data(qol_cancer) model <- lm(QoL ~ time + age + education, data = qol_cancer) p_direction(model) diff --git a/man/p_function.Rd b/man/p_function.Rd index 9013f444c4..02da48f14b 100644 --- a/man/p_function.Rd +++ b/man/p_function.Rd @@ -432,7 +432,7 @@ For certain models (like mixed models), profiled intervals may be more accurate, however, this is currently not supported. } \examples{ -\dontshow{if (requireNamespace("see")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("see")) withAutoprint(\{ # examplesIf} model <- lm(Sepal.Length ~ Species, data = iris) p_function(model) diff --git a/man/p_significance.lm.Rd b/man/p_significance.lm.Rd index 2e8c0e3dad..8a5ed98715 100644 --- a/man/p_significance.lm.Rd +++ b/man/p_significance.lm.Rd @@ -197,7 +197,7 @@ documentation in \code{\link[=p_function]{p_function()}}). } \examples{ -\dontshow{if (requireNamespace("bayestestR") && packageVersion("bayestestR") > "0.14.0" && requireNamespace("sandwich")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("bayestestR") && packageVersion("bayestestR") > "0.14.0" && requireNamespace("sandwich")) withAutoprint(\{ # examplesIf} data(qol_cancer) model <- lm(QoL ~ time + age + education, data = qol_cancer) diff --git a/man/p_value.Rd b/man/p_value.Rd index 350b3a5cc3..cb2cedf035 100644 --- a/man/p_value.Rd +++ b/man/p_value.Rd @@ -308,7 +308,7 @@ here. } \examples{ -\dontshow{if (require("pscl", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("pscl", quietly = TRUE)) withAutoprint(\{ # examplesIf} data(iris) model <- lm(Petal.Length ~ Sepal.Length + Species, data = iris) p_value(model) diff --git a/man/pool_parameters.Rd b/man/pool_parameters.Rd index 045e4984bf..9f9a290ee5 100644 --- a/man/pool_parameters.Rd +++ b/man/pool_parameters.Rd @@ -89,7 +89,7 @@ Some model objects do not return standard errors (e.g. objects of class are returned. } \examples{ -\dontshow{if (require("mice") && require("datawizard")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("mice") && require("datawizard")) withAutoprint(\{ # examplesIf} # example for multiple imputed datasets data("nhanes2", package = "mice") imp <- mice::mice(nhanes2, printFlag = FALSE) diff --git a/man/principal_components.Rd b/man/principal_components.Rd index 82cdb24021..d5cdb1c128 100644 --- a/man/principal_components.Rd +++ b/man/principal_components.Rd @@ -269,7 +269,7 @@ data along the new feature axes. } } \examples{ -\dontshow{if (require("nFactors", quietly = TRUE) && require("sparsepca", quietly = TRUE) && require("psych", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("nFactors", quietly = TRUE) && require("sparsepca", quietly = TRUE) && require("psych", quietly = TRUE)) withAutoprint(\{ # examplesIf} library(parameters) \donttest{ diff --git a/man/print.compare_parameters.Rd b/man/print.compare_parameters.Rd index 916b5962d8..9afa7f6dd8 100644 --- a/man/print.compare_parameters.Rd +++ b/man/print.compare_parameters.Rd @@ -255,7 +255,7 @@ print unicode-chars for symbols as column names, wherever possible (e.g., } \examples{ -\dontshow{if (require("gt", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("gt", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ data(iris) lm1 <- lm(Sepal.Length ~ Species, data = iris) diff --git a/man/print.parameters_model.Rd b/man/print.parameters_model.Rd index 03c5f9e5e5..0b61bc4f4d 100644 --- a/man/print.parameters_model.Rd +++ b/man/print.parameters_model.Rd @@ -336,7 +336,7 @@ freedom. } \examples{ -\dontshow{if (require("gt", quietly = TRUE) && require("glmmTMB", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("gt", quietly = TRUE) && require("glmmTMB", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ library(parameters) model <- glmmTMB::glmmTMB( diff --git a/man/select_parameters.Rd b/man/select_parameters.Rd index 12a880eac7..aa3bdfc9b0 100644 --- a/man/select_parameters.Rd +++ b/man/select_parameters.Rd @@ -56,7 +56,7 @@ excludes random-effects until the cAIC can't be improved further. } \examples{ -\dontshow{if (requireNamespace("lme4")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("lme4")) withAutoprint(\{ # examplesIf} model <- lm(mpg ~ ., data = mtcars) select_parameters(model) diff --git a/man/standard_error.Rd b/man/standard_error.Rd index 4f0dfb306c..5618fd3a1b 100644 --- a/man/standard_error.Rd +++ b/man/standard_error.Rd @@ -86,7 +86,7 @@ For Bayesian models (from \strong{rstanarm} or \strong{brms}), the standard error is the SD of the posterior samples. } \examples{ -\dontshow{if (require("sandwich") && require("clubSandwich")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("sandwich") && require("clubSandwich")) withAutoprint(\{ # examplesIf} model <- lm(Petal.Length ~ Sepal.Length * Species, data = iris) standard_error(model) diff --git a/man/standardize_info.Rd b/man/standardize_info.Rd index 6c6e0018a4..0b0c69b854 100644 --- a/man/standardize_info.Rd +++ b/man/standardize_info.Rd @@ -51,7 +51,7 @@ parameters. This function gives a window on how standardized are obtained, i.e., by what they are divided. The "basic" method of standardization uses. } \examples{ -\dontshow{if (insight::check_if_installed("datawizard", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (insight::check_if_installed("datawizard", quietly = TRUE)) withAutoprint(\{ # examplesIf} model <- lm(mpg ~ ., data = mtcars) standardize_info(model) standardize_info(model, robust = TRUE) diff --git a/man/standardize_parameters.Rd b/man/standardize_parameters.Rd index 82cd6c2c5f..045aa4f8b2 100644 --- a/man/standardize_parameters.Rd +++ b/man/standardize_parameters.Rd @@ -198,13 +198,13 @@ standardize_parameters(model, method = "posthoc") standardize_parameters(model, method = "basic", exponentiate = TRUE) } -\dontshow{if (require("lme4", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("lme4", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ m <- lme4::lmer(mpg ~ cyl + am + vs + (1 | cyl), mtcars) standardize_parameters(m, method = "pseudo", ci_method = "satterthwaite") } \dontshow{\}) # examplesIf} -\dontshow{if (require("rstanarm", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("rstanarm", quietly = TRUE)) withAutoprint(\{ # examplesIf} \donttest{ model <- rstanarm::stan_glm(rating ~ critical + privileges, data = attitude, refresh = 0) standardize_posteriors(model, method = "refit", verbose = FALSE) From 2060ad89f9305481b7051dc6918e0fe332bbca26 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Sep 2025 10:16:55 +0200 Subject: [PATCH 2/8] ... --- R/equivalence_test.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/equivalence_test.R b/R/equivalence_test.R index 813aef6989..7e0deb8f35 100644 --- a/R/equivalence_test.R +++ b/R/equivalence_test.R @@ -456,7 +456,6 @@ equivalence_test.parameters_model <- function(x, ci <- ci[1] } - # ==== check degrees of freedom ==== df_column <- grep("(df|df_error)", colnames(x)) From 6751eced8694afd4fa9ca561ac7b85c3de8f00ac Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Sep 2025 13:50:38 +0200 Subject: [PATCH 3/8] own function --- R/equivalence_test.R | 93 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 84 insertions(+), 9 deletions(-) diff --git a/R/equivalence_test.R b/R/equivalence_test.R index 7e0deb8f35..82860b373a 100644 --- a/R/equivalence_test.R +++ b/R/equivalence_test.R @@ -299,15 +299,6 @@ equivalence_test.zeroinfl <- equivalence_test.lm #' @export equivalence_test.rma <- equivalence_test.lm -#' @export -equivalence_test.estimate_means <- equivalence_test.lm - -#' @export -equivalence_test.estimate_contrasts <- equivalence_test.lm - -#' @export -equivalence_test.estimate_slopes <- equivalence_test.lm - # mixed models, also random effects ---------------------- @@ -364,6 +355,90 @@ equivalence_test.glmmTMB <- equivalence_test.merMod equivalence_test.MixMod <- equivalence_test.merMod +# modelbased ------------------------------ + +#' @export +equivalence_test.estimate_means <- function( + x, + range = "default", + ci = 0.95, + rule = "classic", + vcov = NULL, + vcov_args = NULL, + verbose = TRUE, + ... +) { + # ==== define rope range ==== + + range <- .check_rope_range(x, range, verbose) + + if (length(ci) > 1) { + insight::format_alert("`ci` may only be of length 1. Using first ci-value now.") + ci <- ci[1] + } + + # ==== check degrees of freedom ==== + + dof <- unique(insight::get_df(x)) + if (length(dof) > 0) { + dof <- Inf + } + + # ==== requested confidence intervals ==== + + conf_int <- as.data.frame(t(x[c("CI_low", "CI_high")])) + + # ==== the "narrower" intervals (1-2*alpha) for CET-rules. ==== + + alpha <- 1 - ci + conf_int2 <- .ci_generic(x, ci = (ci - alpha), vcov = vcov, vcov_args = vcov_args, ...) + conf_int2 <- as.data.frame(t(conf_int2[, c("CI_low", "CI_high")])) + + # ==== equivalence test for each parameter ==== + + l <- Map( + function(ci_wide, ci_narrow) { + .equivalence_test_numeric( + ci = ci, + ci_wide, + ci_narrow, + range_rope = range, + rule = rule, + dof = dof, + verbose = verbose + ) + }, + conf_int, + conf_int2 + ) + + dat <- do.call(rbind, l) + if ("Component" %in% colnames(params)) { + dat$Component <- params$Component + } + + out <- data.frame( + Parameter = params$Parameter, + CI = ifelse(rule == "bayes", ci, ci - alpha), + dat, + stringsAsFactors = FALSE + ) + + # ==== (adjusted) p-values for tests ==== + + out$p <- .add_p_to_equitest(x, ci, range, vcov = vcov, vcov_args = vcov_args, ...) + + attr(out, "rope") <- range + out +} + +#' @export +equivalence_test.estimate_contrasts <- equivalence_test.estimate_means + +#' @export +equivalence_test.estimate_slopes <- equivalence_test.estimate_means + + # Special classes ------------------------- #' @export From 055c2df3eaee0d848fdb60e0d0137c9796c7ae5b Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Sep 2025 15:28:14 +0200 Subject: [PATCH 4/8] final --- NAMESPACE | 9 +++++++ R/equivalence_test.R | 20 +++++++++----- R/methods_modelbased.R | 60 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 R/methods_modelbased.R diff --git a/NAMESPACE b/NAMESPACE index eecff96ec2..ca1b69d08f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -34,6 +34,9 @@ S3method(ci,crq) S3method(ci,default) S3method(ci,deltaMethod) S3method(ci,effectsize_table) +S3method(ci,estimate_contrasts) +S3method(ci,estimate_means) +S3method(ci,estimate_slopes) S3method(ci,fixest_multi) S3method(ci,flac) S3method(ci,flic) @@ -240,6 +243,9 @@ S3method(model_parameters,draws) S3method(model_parameters,emmGrid) S3method(model_parameters,emm_list) S3method(model_parameters,epi.2by2) +S3method(model_parameters,estimate_contrasts) +S3method(model_parameters,estimate_means) +S3method(model_parameters,estimate_slopes) S3method(model_parameters,fa) S3method(model_parameters,fa.ci) S3method(model_parameters,feglm) @@ -791,6 +797,9 @@ S3method(standard_error,draws) S3method(standard_error,effectsize_table) S3method(standard_error,emmGrid) S3method(standard_error,emm_list) +S3method(standard_error,estimate_contrasts) +S3method(standard_error,estimate_means) +S3method(standard_error,estimate_slopes) S3method(standard_error,factor) S3method(standard_error,feglm) S3method(standard_error,fitdistr) diff --git a/R/equivalence_test.R b/R/equivalence_test.R index 82860b373a..0ca8d9312e 100644 --- a/R/equivalence_test.R +++ b/R/equivalence_test.R @@ -380,7 +380,7 @@ equivalence_test.estimate_means <- function( # ==== check degrees of freedom ==== dof <- unique(insight::get_df(x)) - if (length(dof) > 0) { + if (length(dof) > 1) { dof <- Inf } @@ -391,8 +391,14 @@ equivalence_test.estimate_means <- function( # ==== the "narrower" intervals (1-2*alpha) for CET-rules. ==== alpha <- 1 - ci - conf_int2 <- .ci_generic(x, ci = (ci - alpha), vcov = vcov, vcov_args = vcov_args, ...) - conf_int2 <- as.data.frame(t(conf_int2[, c("CI_low", "CI_high")])) + insight::check_if_installed("modelbased") + + # we need to call the modelbased function again, so get the call + # modify CI and evaluate that call + cl <- insight::get_call(x) + cl$ci <- ci - alpha + x2 <- eval(cl) + conf_int2 <- as.data.frame(t(x2[c("CI_low", "CI_high")])) # ==== equivalence test for each parameter ==== @@ -413,9 +419,7 @@ equivalence_test.estimate_means <- function( ) dat <- do.call(rbind, l) - if ("Component" %in% colnames(params)) { - dat$Component <- params$Component - } + params <- insight::get_parameters(x) out <- data.frame( Parameter = params$Parameter, @@ -429,6 +433,10 @@ equivalence_test.estimate_means <- function( out$p <- .add_p_to_equitest(x, ci, range, vcov = vcov, vcov_args = vcov_args, ...) attr(out, "rope") <- range + attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(x)) + attr(out, "rule") <- rule + class(out) <- c("equivalence_test_lm", "see_equivalence_test_lm", class(out)) + out } diff --git a/R/methods_modelbased.R b/R/methods_modelbased.R new file mode 100644 index 0000000000..80c302229a --- /dev/null +++ b/R/methods_modelbased.R @@ -0,0 +1,60 @@ +# model_parameters ---------------- + +#' @export +model_parameters.estimate_means <- function(model, ...) { + out <- model + class(out) <- c("parameters_model", "see_parameters_model", class(out)) + out +} + +#' @export +model_parameters.estimate_slopes <- model_parameters.estimate_means + +#' @export +model_parameters.estimate_contrasts <- model_parameters.estimate_means + + +# standard_error ---------------- + +#' @export +standard_error.estimate_means <- function(model, ...) { + params <- insight::get_parameters(model) + data.frame( + Parameter = params$Parameter, + SE = model$SE, + stringsAsFactors = FALSE + ) +} + +#' @export +standard_error.estimate_slopes <- standard_error.estimate_means + +#' @export +standard_error.estimate_contrasts <- standard_error.estimate_means + + +# ci ---------------- + +#' @export +ci.estimate_means <- function(model, ...) { + params <- insight::get_parameters(model) + + ci_value <- attributes(model)$ci + if (is.null(ci_value)) { + ci_value <- 0.95 + } + + data.frame( + Parameter = params$Parameter, + CI = ci_value, + CI_low = model$CI_low, + CI_high = model$CI_high, + stringsAsFactors = FALSE + ) +} + +#' @export +ci.estimate_slopes <- ci.estimate_means + +#' @export +ci.estimate_contrasts <- ci.estimate_means From e31fde8d9846d05eb7e12bfc1b1dd3b838484f7b Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Sep 2025 15:29:18 +0200 Subject: [PATCH 5/8] news --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 62ff967f44..b5e99baf9e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.28.2.2 +Version: 0.28.2.3 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index aee8ad3c77..266a10cbaa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# parameters 0.28.2.1 + +* `equivalence_test()` gets methods for objects from the *modelbased* package. + # parameters 0.28.2 ## Bug fixes From f1cc5cdc4f18bc472dcebc7de68e72023a3976f8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Sep 2025 15:42:13 +0200 Subject: [PATCH 6/8] fix --- R/methods_modelbased.R | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/R/methods_modelbased.R b/R/methods_modelbased.R index 80c302229a..3a431b3572 100644 --- a/R/methods_modelbased.R +++ b/R/methods_modelbased.R @@ -19,11 +19,7 @@ model_parameters.estimate_contrasts <- model_parameters.estimate_means #' @export standard_error.estimate_means <- function(model, ...) { params <- insight::get_parameters(model) - data.frame( - Parameter = params$Parameter, - SE = model$SE, - stringsAsFactors = FALSE - ) + data.frame(Parameter = params$Parameter, SE = model$SE, stringsAsFactors = FALSE) } #' @export @@ -36,10 +32,10 @@ standard_error.estimate_contrasts <- standard_error.estimate_means # ci ---------------- #' @export -ci.estimate_means <- function(model, ...) { - params <- insight::get_parameters(model) +ci.estimate_means <- function(x, ...) { + params <- insight::get_parameters(x) - ci_value <- attributes(model)$ci + ci_value <- attributes(x)$ci if (is.null(ci_value)) { ci_value <- 0.95 } From e3a868e623563c3cfd67bb3663988407ab17c83e Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Sep 2025 15:55:16 +0200 Subject: [PATCH 7/8] wordlist --- DESCRIPTION | 1 + inst/WORDLIST | 1 + 2 files changed, 2 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index b5e99baf9e..7f7a223548 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -231,3 +231,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/modelbased diff --git a/inst/WORDLIST b/inst/WORDLIST index f42bd3482e..90c8832df3 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -319,6 +319,7 @@ mgcv mhurdle mlogit mmrm +modelbased modelsummary multcomp multicollinearity From f8e24131a7b9bcf5c7140754fa9756f43a77edef Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Sep 2025 16:15:03 +0200 Subject: [PATCH 8/8] fix --- R/methods_modelbased.R | 4 ++-- R/n_clusters_easystats.R | 34 ++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/R/methods_modelbased.R b/R/methods_modelbased.R index 3a431b3572..3edc2926d7 100644 --- a/R/methods_modelbased.R +++ b/R/methods_modelbased.R @@ -43,8 +43,8 @@ ci.estimate_means <- function(x, ...) { data.frame( Parameter = params$Parameter, CI = ci_value, - CI_low = model$CI_low, - CI_high = model$CI_high, + CI_low = x$CI_low, + CI_high = x$CI_high, stringsAsFactors = FALSE ) } diff --git a/R/n_clusters_easystats.R b/R/n_clusters_easystats.R index 3c389a0ff1..204d3eb002 100644 --- a/R/n_clusters_easystats.R +++ b/R/n_clusters_easystats.R @@ -244,20 +244,34 @@ n_clusters_hclust <- function(x, # Utils ------------------------------------------------------------------- - #' @keywords internal -.n_clusters_factoextra <- function(x, - method = "wss", - standardize = TRUE, - include_factors = FALSE, - clustering_function = stats::kmeans, - n_max = 10, - ...) { - x <- .prepare_data_clustering(x, include_factors = include_factors, standardize = standardize, ...) +.n_clusters_factoextra <- function( + x, + method = "wss", + standardize = TRUE, + include_factors = FALSE, + clustering_function = stats::kmeans, + n_max = 10, + ... +) { + x <- .prepare_data_clustering( + x, + include_factors = include_factors, + standardize = standardize, + ... + ) insight::check_if_installed("factoextra") - factoextra::fviz_nbclust(x, clustering_function, method = method, k.max = n_max, verbose = FALSE)$data + suppressWarnings( + factoextra::fviz_nbclust( + x, + clustering_function, + method = method, + k.max = n_max, + verbose = FALSE + )$data + ) }