diff --git a/DESCRIPTION b/DESCRIPTION index 55639bf5b..388b3f9a4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -68,7 +68,7 @@ Imports: datawizard (>= 0.7.1), effectsize (>= 0.8.3), ggplot2 (>= 3.4.2), - insight (>= 0.19.2), + insight (>= 0.19.3.2), modelbased (>= 0.8.6), parameters (>= 0.21.1), performance (>= 0.10.4) @@ -116,3 +116,4 @@ Config/Needs/website: rstudio/bslib, r-lib/pkgdown, easystats/easystatstemplate +Remotes: easystats/insight diff --git a/R/plot.bayesfactor_parameters.R b/R/plot.bayesfactor_parameters.R index 2788abaee..bd470fa5f 100644 --- a/R/plot.bayesfactor_parameters.R +++ b/R/plot.bayesfactor_parameters.R @@ -32,9 +32,9 @@ plot.see_bayesfactor_parameters <- function(x, hypothesis <- attr(x, "hypothesis") # if we have intercept-only models, keep at least the intercept - intercepts_points <- which(.in_intercepts(d_points$ind)) + intercepts_points <- which(.is_intercept(d_points$ind)) if (length(intercepts_points) && (nrow(d_points) > length(intercepts_points)) && !show_intercept) { - intercepts_data <- which(.in_intercepts(plot_data$ind)) + intercepts_data <- which(.is_intercept(plot_data$ind)) plot_data <- plot_data[-intercepts_data, ] d_points <- d_points[-intercepts_points, ] } diff --git a/R/plot.compare_parameters.R b/R/plot.compare_parameters.R index f2a73f318..99b1ac775 100644 --- a/R/plot.compare_parameters.R +++ b/R/plot.compare_parameters.R @@ -77,7 +77,7 @@ plot.see_compare_parameters <- function(x, if (!show_intercept) { - x <- x[!.in_intercepts(x$Parameter), ] + x <- x[!.is_intercept(x$Parameter), ] } if (isTRUE(sort) || (!is.null(sort) && sort == "ascending")) { diff --git a/R/plot.equivalence_test.R b/R/plot.equivalence_test.R index 7006379b8..57cdca810 100644 --- a/R/plot.equivalence_test.R +++ b/R/plot.equivalence_test.R @@ -48,13 +48,13 @@ plot.see_equivalence_test <- function(x, } # if we have intercept-only models, keep at least the intercept - intercepts <- which(.in_intercepts(x$Parameter)) + intercepts <- which(.is_intercept(x$Parameter)) if (length(intercepts) && nrow(x) > length(intercepts) && !show_intercept) { x <- x[-intercepts, ] } cp <- insight::clean_parameters(model) - intercepts <- which(.in_intercepts(cp$Parameter)) + intercepts <- which(.is_intercept(cp$Parameter)) if (length(intercepts) && nrow(x) > length(intercepts) && !show_intercept) { cp <- cp[-intercepts, ] } @@ -380,7 +380,7 @@ plot.see_equivalence_test_lm <- function(x, } # if we have intercept-only models, keep at least the intercept - intercepts <- which(.in_intercepts(x$Parameter)) + intercepts <- which(.is_intercept(x$Parameter)) if (length(intercepts) && nrow(x) > length(intercepts) && !show_intercept) { x <- x[-intercepts, ] } diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index 04bf29a94..4c1eee6cb 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -131,6 +131,9 @@ plot.see_estimate_density <- function(x, n_columns <- NULL } + # get parameter names for filtering + params <- unique(x$y) + # get labels labels <- .clean_parameter_names(x$Parameter, grid = !is.null(n_columns)) @@ -152,6 +155,7 @@ plot.see_estimate_density <- function(x, p <- p + .add_prior_layer_ridgeline( model, + parameter = params, show_intercept = show_intercept, priors_alpha = priors_alpha, show_ridge_line = FALSE diff --git a/R/plot.hdi.R b/R/plot.hdi.R index dae9b18b7..490289b24 100644 --- a/R/plot.hdi.R +++ b/R/plot.hdi.R @@ -108,7 +108,7 @@ data_plot.bayestestR_eti <- data_plot.hdi groups <- unique(dataplot$y) if (!show_intercept) { dataplot <- .remove_intercept(dataplot, column = "y", show_intercept) - groups <- unique(setdiff(groups, .intercepts())) + groups <- unique(setdiff(groups, .intercept_names)) } if (length(groups) == 1) { diff --git a/R/plot.p_direction.R b/R/plot.p_direction.R index 0e6cf9102..112c7b19b 100644 --- a/R/plot.p_direction.R +++ b/R/plot.p_direction.R @@ -95,7 +95,7 @@ data_plot.p_direction <- function(x, data = NULL, show_intercept = FALSE, ...) { groups <- unique(dataplot$y) if (!show_intercept) { dataplot <- .remove_intercept(dataplot, column = "y", show_intercept) - groups <- unique(setdiff(groups, .intercepts())) + groups <- unique(setdiff(groups, .intercept_names)) } if (length(groups) == 1) { @@ -180,6 +180,9 @@ plot.see_p_direction <- function(x, n_columns <- NULL } + # get parameter names for filtering + params <- unique(x$y) + # get labels labels <- .clean_parameter_names(x$y, grid = !is.null(n_columns)) @@ -203,6 +206,7 @@ plot.see_p_direction <- function(x, if (priors) { p <- p + .add_prior_layer_ridgeline( model, + parameter = params, show_intercept = show_intercept, priors_alpha = priors_alpha ) diff --git a/R/plot.p_significance.R b/R/plot.p_significance.R index c1d631d43..216f617f8 100644 --- a/R/plot.p_significance.R +++ b/R/plot.p_significance.R @@ -103,7 +103,7 @@ data_plot.p_significance <- function(x, groups <- unique(dataplot$y) if (!show_intercept) { dataplot <- .remove_intercept(dataplot, column = "y", show_intercept) - groups <- unique(setdiff(groups, .intercepts())) + groups <- unique(setdiff(groups, .intercept_names)) } if (length(groups) == 1) { @@ -192,6 +192,9 @@ plot.see_p_significance <- function(x, n_columns <- NULL } + # get parameter names for filtering + params <- unique(x$y) + # get labels labels <- .clean_parameter_names(x$y, grid = !is.null(n_columns)) @@ -216,6 +219,7 @@ plot.see_p_significance <- function(x, p <- p + .add_prior_layer_ridgeline( model, + parameter = params, show_intercept = show_intercept, priors_alpha = priors_alpha ) + diff --git a/R/plot.parameters_model.R b/R/plot.parameters_model.R index ffd7e78e6..0b4ec0fe1 100644 --- a/R/plot.parameters_model.R +++ b/R/plot.parameters_model.R @@ -306,10 +306,10 @@ plot.see_parameters_model <- function(x, } - if (!show_intercept && length(.in_intercepts(x$Parameter)) > 0L) { - x <- x[!.in_intercepts(x$Parameter), ] + if (!show_intercept && length(.is_intercept(x$Parameter)) > 0L) { + x <- x[!.is_intercept(x$Parameter), ] if (show_density && (is_bayesian || is_bootstrap)) { - data <- data[!.in_intercepts(data$Parameter), ] + data <- data[!.is_intercept(data$Parameter), ] density_layer$data <- data } } diff --git a/R/plot.point_estimates.R b/R/plot.point_estimates.R index b3479cbe8..72aefdb62 100644 --- a/R/plot.point_estimates.R +++ b/R/plot.point_estimates.R @@ -132,7 +132,7 @@ plot.see_point_estimate <- function(x, x_lab <- "Parameter Value" } - if (!show_intercept && .has_intercept(x_lab)) { + if (!show_intercept && .is_intercept(x_lab)) { return(NULL) } diff --git a/R/plot.rope.R b/R/plot.rope.R index 9ed3d46a4..dd7b71493 100644 --- a/R/plot.rope.R +++ b/R/plot.rope.R @@ -42,7 +42,7 @@ data_plot.rope <- function(x, data = NULL, show_intercept = FALSE, ...) { groups <- unique(dataplot$y) if (!show_intercept) { dataplot <- .remove_intercept(dataplot, column = "y", show_intercept = show_intercept) - groups <- unique(setdiff(groups, .intercepts())) + groups <- unique(setdiff(groups, .intercept_names)) } if (length(groups) == 1) { diff --git a/R/plot.si.R b/R/plot.si.R index 2ddbdae25..85fee8a56 100644 --- a/R/plot.si.R +++ b/R/plot.si.R @@ -32,9 +32,9 @@ plot.see_si <- function(x, x$ind <- x$Parameter # if we have intercept-only models, keep at least the intercept - intercepts_data <- which(.in_intercepts(plot_data$ind)) + intercepts_data <- which(.is_intercept(plot_data$ind)) if (length(intercepts_data) && (nrow(plot_data) > length(intercepts_data)) && !show_intercept) { - intercepts_si <- which(.in_intercepts(x$ind)) + intercepts_si <- which(.is_intercept(x$ind)) x <- x[-intercepts_si, ] plot_data <- plot_data[-intercepts_data, ] } diff --git a/R/utils.R b/R/utils.R index aa3b495bc..2b0360238 100644 --- a/R/utils.R +++ b/R/utils.R @@ -113,7 +113,7 @@ -.intercepts <- function() { +.intercept_names <- c( "(intercept)_zi", "intercept (zero-inflated)", @@ -123,21 +123,16 @@ "b_intercept", "b_zi_intercept" ) -} -.has_intercept <- function(x) { +.is_intercept <- function(x) { x <- tolower(x) - x %in% .intercepts() | !is.na(x) & startsWith(x, "intercept") + x %in% .intercept_names | grepl("(?i)intercept[^a-zA-Z]", x) } - -.in_intercepts <- .has_intercept - - .remove_intercept <- function(x, column = "Parameter", show_intercept = FALSE) { if (!show_intercept) { - remove <- which(.in_intercepts(x[[column]])) + remove <- which(.is_intercept(x[[column]])) if (length(remove)) x <- x[-remove, ] } x