From ef50b6bd8be4606d57819870477957f6bcda5ad4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Oct 2023 11:33:18 +0200 Subject: [PATCH] fix examples (#309) * fix examples * fix vignette * verbose = FALSE * remove annoying example * lints --------- Co-authored-by: Indrajeet Patil --- R/data_plot.R | 4 ---- R/plot.check_outliers.R | 14 +++++++------- R/plot.check_outliers_new.R | 2 +- R/plot.compare_performance.R | 8 ++++---- R/plot.describe_distribution.R | 2 +- R/plot.estimate_contrasts.R | 12 ++++++------ R/plot.estimate_density.R | 10 +++++----- R/plot.hdi.R | 8 ++++---- man/data_plot.Rd | 4 ---- vignettes/bayestestR.Rmd | 12 +++++++++--- 10 files changed, 37 insertions(+), 39 deletions(-) diff --git a/R/data_plot.R b/R/data_plot.R index 9afa86843..3b916383f 100644 --- a/R/data_plot.R +++ b/R/data_plot.R @@ -67,10 +67,6 @@ #' x <- hdi(model) #' plot(x) + theme_modern() #' -#' data <- rnorm(1000, 1) -#' x <- p_direction(data) -#' plot(x) -#' #' x <- p_direction(model, verbose = FALSE) #' plot(x) #' diff --git a/R/plot.check_outliers.R b/R/plot.check_outliers.R index 4cf04f5c8..eae2b173f 100644 --- a/R/plot.check_outliers.R +++ b/R/plot.check_outliers.R @@ -97,13 +97,13 @@ data_plot.check_outliers <- function(x, data = NULL, rescale_distance = TRUE, .. d$Id[d$Outliers == "0"] <- NA method <- switch(attr(x, "method", exact = TRUE), - "cook" = "Cook's Distance", - "pareto" = "Pareto", - "mahalanobis" = "Mahalanobis Distance", - "ics" = "Invariant Coordinate Selection", - "mcd" = "Minimum Covariance Determinant", - "optics" = "OPTICS", - "iforest" = "Isolation Forest", + cook = "Cook's Distance", + pareto = "Pareto", + mahalanobis = "Mahalanobis Distance", + ics = "Invariant Coordinate Selection", + mcd = "Minimum Covariance Determinant", + optics = "OPTICS", + iforest = "Isolation Forest", "Cook's Distance" ) diff --git a/R/plot.check_outliers_new.R b/R/plot.check_outliers_new.R index b8d895dd0..9ade11d2e 100644 --- a/R/plot.check_outliers_new.R +++ b/R/plot.check_outliers_new.R @@ -44,7 +44,7 @@ se = FALSE, color = colors[1] ) + - scale_colour_manual(values = c("OK" = colors[2], "Influential" = colors[3])) + + scale_colour_manual(values = c(OK = colors[2], Influential = colors[3])) + (if (isTRUE(show_labels)) { if (requireNamespace("ggrepel", quietly = TRUE)) { ggrepel::geom_text_repel( diff --git a/R/plot.compare_performance.R b/R/plot.compare_performance.R index 3db5c7871..c61c42fce 100644 --- a/R/plot.compare_performance.R +++ b/R/plot.compare_performance.R @@ -40,10 +40,10 @@ data_plot.compare_performance <- function(x, data = NULL, ...) { dataplot$values[dataplot$values > 1] <- 1 attr(dataplot, "info") <- list( - "xlab" = "", - "ylab" = "", - "title" = "Comparison of Model Indices", - "legend_color" = "Models" + xlab = "", + ylab = "", + title = "Comparison of Model Indices", + legend_color = "Models" ) class(dataplot) <- c("data_plot", "see_compare_performance", "data.frame") diff --git a/R/plot.describe_distribution.R b/R/plot.describe_distribution.R index 4f3012b72..653c594a0 100644 --- a/R/plot.describe_distribution.R +++ b/R/plot.describe_distribution.R @@ -199,7 +199,7 @@ plot.see_parameters_distribution <- function(x, } names(highlight_color) <- highlight - highlight_color <- c(highlight_color, "no_highlight" = "grey70") + highlight_color <- c(highlight_color, no_highlight = "grey70") p <- p + scale_fill_manual(values = highlight_color) + diff --git a/R/plot.estimate_contrasts.R b/R/plot.estimate_contrasts.R index d2f329b89..2dbfbbfeb 100644 --- a/R/plot.estimate_contrasts.R +++ b/R/plot.estimate_contrasts.R @@ -16,9 +16,9 @@ data_plot.estimate_contrasts <- function(x, data = NULL, ...) { dataplot <- .data_contrasts_and_means(x, means, x_name = x_name, y_name = y_name) attr(dataplot, "info") <- list( - "xlab" = x_name, - "ylab" = y_name, - "title" = paste0("Estimated ", y_name, "s and Contrasts") + xlab = x_name, + ylab = y_name, + title = paste0("Estimated ", y_name, "s and Contrasts") ) class(dataplot) <- c("data_plot", "see_estimate_contrasts", class(dataplot)) @@ -45,9 +45,9 @@ data_plot.estimate_contrasts <- function(x, data = NULL, ...) { polygons <- merge(polygons, data_means[c("Level2", "Mean2")], by = "Level2") polygons <- rbind( - cbind(polygons, data.frame("x" = polygons$Level1, "y" = polygons$Mean1)), - cbind(polygons, data.frame("x" = polygons$Level2, "y" = polygons$Mean1 - polygons$CI_low)), - cbind(polygons, data.frame("x" = polygons$Level2, "y" = polygons$Mean1 - polygons$CI_high)) + cbind(polygons, data.frame(x = polygons$Level1, y = polygons$Mean1)), + cbind(polygons, data.frame(x = polygons$Level2, y = polygons$Mean1 - polygons$CI_low)), + cbind(polygons, data.frame(x = polygons$Level2, y = polygons$Mean1 - polygons$CI_high)) ) list( diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index f472bcad7..ad431a8c6 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -51,11 +51,11 @@ data_plot.estimate_density <- function(x, attr(dataplot, "summary") <- summary attr(dataplot, "info") <- list( - "xlab" = "Values", - "ylab" = "Density", - "legend_fill" = "Parameter", - "legend_color" = "Parameter", - "title" = "Estimated Density Function" + xlab = "Values", + ylab = "Density", + legend_fill = "Parameter", + legend_color = "Parameter", + title = "Estimated Density Function" ) class(dataplot) <- c("data_plot", "see_estimate_density", class(dataplot)) diff --git a/R/plot.hdi.R b/R/plot.hdi.R index bab66afe9..03b33e79c 100644 --- a/R/plot.hdi.R +++ b/R/plot.hdi.R @@ -121,10 +121,10 @@ data_plot.bayestestR_eti <- data_plot.hdi dataplot <- .fix_facet_names(dataplot) attr(dataplot, "info") <- list( - "xlab" = "Possible parameter values", - "ylab" = ylab, - "legend_fill" = legend_title, - "title" = plot_title + xlab = "Possible parameter values", + ylab = ylab, + legend_fill = legend_title, + title = plot_title ) class(dataplot) <- c("data_plot", "see_hdi", class(dataplot)) diff --git a/man/data_plot.Rd b/man/data_plot.Rd index 4daef23d7..af31261df 100644 --- a/man/data_plot.Rd +++ b/man/data_plot.Rd @@ -81,10 +81,6 @@ plot(x) x <- hdi(model) plot(x) + theme_modern() -data <- rnorm(1000, 1) -x <- p_direction(data) -plot(x) - x <- p_direction(model, verbose = FALSE) plot(x) diff --git a/vignettes/bayestestR.Rmd b/vignettes/bayestestR.Rmd index 9d71a0b88..57cf7b851 100644 --- a/vignettes/bayestestR.Rmd +++ b/vignettes/bayestestR.Rmd @@ -66,10 +66,10 @@ theme_set(theme_modern()) ```{r} set.seed(123) # model with fixed effects only -model <- rstanarm::stan_glm(Sepal.Length ~ Petal.Width * Species, data = iris, refresh = 0) +model <<- rstanarm::stan_glm(Sepal.Length ~ Petal.Width * Species, data = iris, refresh = 0) # model with fixed and random effects as well as zero-inflation component -model2 <- insight::download_model("brms_zi_3") +model2 <<- insight::download_model("brms_zi_3") ``` ## Density Estimation @@ -335,7 +335,13 @@ plot(result) + ``` ```{r fig.width=11, fig.height=9} -result <- equivalence_test(model2, ci = c(0.89, 0.95), effects = "all", component = "all") +result <- equivalence_test( + model2, + ci = c(0.89, 0.95), + effects = "all", + component = "all", + verbose = FALSE +) result