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
5 changes: 3 additions & 2 deletions 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.28.2
Version: 0.28.2.3
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -224,10 +224,11 @@ 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
Config/Needs/website: easystats/easystatstemplate
Config/Needs/check: stan-dev/cmdstanr
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/insight, easystats/modelbased
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -137,6 +140,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)
Expand Down Expand Up @@ -237,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)
Expand Down Expand Up @@ -788,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)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
101 changes: 100 additions & 1 deletion R/equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,98 @@
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) > 1) {
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
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 ====

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)
params <- insight::get_parameters(x)

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
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
}

#' @export
equivalence_test.estimate_contrasts <- equivalence_test.estimate_means

#' @export
equivalence_test.estimate_slopes <- equivalence_test.estimate_means


# Special classes -------------------------

#' @export
Expand Down Expand Up @@ -407,6 +499,14 @@

#' @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)) {
Expand Down Expand Up @@ -439,7 +539,6 @@
ci <- ci[1]
}


# ==== check degrees of freedom ====

df_column <- grep("(df|df_error)", colnames(x))
Expand Down Expand Up @@ -579,12 +678,12 @@

#' @keywords internal
.equivalence_test_numeric <- function(ci = 0.95,
ci_wide,

Check warning on line 681 in R/equivalence_test.R

View workflow job for this annotation

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

file=R/equivalence_test.R,line=681,col=39,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
ci_narrow,

Check warning on line 682 in R/equivalence_test.R

View workflow job for this annotation

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

file=R/equivalence_test.R,line=682,col=39,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
range_rope,

Check warning on line 683 in R/equivalence_test.R

View workflow job for this annotation

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

file=R/equivalence_test.R,line=683,col=39,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
rule,

Check warning on line 684 in R/equivalence_test.R

View workflow job for this annotation

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

file=R/equivalence_test.R,line=684,col=39,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
dof = Inf,
verbose) {

Check warning on line 686 in R/equivalence_test.R

View workflow job for this annotation

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

file=R/equivalence_test.R,line=686,col=39,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
final_ci <- NULL

# ==== HDI+ROPE decision rule, by Kruschke ====
Expand Down Expand Up @@ -685,7 +784,7 @@
# same range / limits as the confidence interval, thus indeed representing a
# normally distributed confidence interval. We then calculate the probability
# mass of this interval that is inside the ROPE.
.rope_coverage <- function(ci = 0.95, range_rope, ci_range, dof = Inf) {

Check warning on line 787 in R/equivalence_test.R

View workflow job for this annotation

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

file=R/equivalence_test.R,line=787,col=51,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 787 in R/equivalence_test.R

View workflow job for this annotation

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

file=R/equivalence_test.R,line=787,col=39,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
out <- .generate_posterior_from_ci(ci, ci_range, dof = dof)
# compare: ci_range and range(out)
# The SGPV refers to the proportion of the confidence interval inside the
Expand All @@ -695,7 +794,7 @@
}


.generate_posterior_from_ci <- function(ci = 0.95, ci_range, dof = Inf, precision = 10000) {

Check warning on line 797 in R/equivalence_test.R

View workflow job for this annotation

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

file=R/equivalence_test.R,line=797,col=52,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
# this function creates an approximate normal distribution that covers the
# CI-range, i.e. we "simulate" a posterior distribution from a frequentist CI

Expand Down
56 changes: 56 additions & 0 deletions R/methods_modelbased.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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(x, ...) {
params <- insight::get_parameters(x)

ci_value <- attributes(x)$ci
if (is.null(ci_value)) {
ci_value <- 0.95
}

data.frame(
Parameter = params$Parameter,
CI = ci_value,
CI_low = x$CI_low,
CI_high = x$CI_high,
stringsAsFactors = FALSE
)
}

#' @export
ci.estimate_slopes <- ci.estimate_means

#' @export
ci.estimate_contrasts <- ci.estimate_means
34 changes: 24 additions & 10 deletions R/n_clusters_easystats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}


Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ mgcv
mhurdle
mlogit
mmrm
modelbased
modelsummary
multcomp
multicollinearity
Expand Down
2 changes: 1 addition & 1 deletion man/bootstrap_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/bootstrap_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ci.default.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cluster_discrimination.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/compare_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/convert_efa_to_cfa.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/degrees_of_freedom.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/display.parameters_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/dominance_analysis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading