Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix examples #309

Merged
merged 5 commits into from
Oct 8, 2023
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
4 changes: 0 additions & 4 deletions R/data_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#'
Expand Down
14 changes: 7 additions & 7 deletions R/plot.check_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
colors = colors
)
} else {
if (length(methods == 1)) {

Check warning on line 56 in R/plot.check_outliers.R

View workflow job for this annotation

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

file=R/plot.check_outliers.R,line=56,col=9,[length_test_linter] Checking the length of a logical vector is likely a mistake. Did you mean `length(methods) == 1`?
.plot_diag_outliers(x, show_labels = show_labels, size_text = size_text, rescale_distance = rescale_distance)
} else {
.plot_outliers_multimethod(x, rescale_distance)
Expand Down Expand Up @@ -97,13 +97,13 @@
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"
)

Expand Down
2 changes: 1 addition & 1 deletion R/plot.check_outliers_new.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions R/plot.compare_performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

# remove indices with missing value, comparison makes no sense here
x <- x[vapply(x, function(.x) !anyNA(.x), logical(1))]

Check warning on line 33 in R/plot.compare_performance.R

View workflow job for this annotation

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

file=R/plot.compare_performance.R,line=33,col=20,[unnecessary_lambda_linter] Pass anyNA directly as a symbol to vapply() instead of wrapping it in an unnecessary anonymous function. For example, prefer lapply(DF, sum) to lapply(DF, function(x) sum(x)).

x <- .reshape_to_long(x, names_to = "name", columns = 2:ncol(x))
x$name <- factor(x$name, levels = unique(x$name))
Expand All @@ -40,10 +40,10 @@
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")
Expand Down
2 changes: 1 addition & 1 deletion R/plot.describe_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
}
}

if (!is.null(x$highlight)) {

Check warning on line 140 in R/plot.describe_distribution.R

View workflow job for this annotation

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

file=R/plot.describe_distribution.R,line=140,col=7,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
p <- ggplot(x, aes(x = .data$x, fill = highlight))
} else {
p <- ggplot(x, aes(x = .data$x))
Expand Down Expand Up @@ -199,7 +199,7 @@
}

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) +
Expand Down
12 changes: 6 additions & 6 deletions R/plot.estimate_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions R/plot.estimate_density.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions R/plot.hdi.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
plot_title <- "Credible Interval (CI)"
}

if (!is.null(parms)) {

Check warning on line 35 in R/plot.hdi.R

View workflow job for this annotation

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

file=R/plot.hdi.R,line=35,col=7,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
params <- parms
} else {
params <- NULL
Expand All @@ -59,13 +59,13 @@
data <- data[levels_order]
dataplot <- data.frame()
for (i in names(data)) {
if (!is.null(params)) {

Check warning on line 62 in R/plot.hdi.R

View workflow job for this annotation

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

file=R/plot.hdi.R,line=62,col=11,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
dataplot <- rbind(
dataplot,
cbind(
.compute_densities_hdi(data[[i]], hdi = as.data.frame(x[x$Parameter == i, ]), name = i),
"Effects" = params$Effects[params$Parameter == i],

Check warning on line 67 in R/plot.hdi.R

View workflow job for this annotation

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

file=R/plot.hdi.R,line=67,col=13,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
"Component" = params$Component[params$Parameter == i]

Check warning on line 68 in R/plot.hdi.R

View workflow job for this annotation

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

file=R/plot.hdi.R,line=68,col=13,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
)
)
} else {
Expand Down Expand Up @@ -121,10 +121,10 @@
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))
Expand All @@ -140,8 +140,8 @@

out <- .as.data.frame_density(stats::density(x))

out$HDI_low <- sapply(out$x, .classify_hdi, hdi$CI_low, c(100, 100 * hdi$CI))

Check warning on line 143 in R/plot.hdi.R

View workflow job for this annotation

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

file=R/plot.hdi.R,line=143,col=18,[undesirable_function_linter] Function "sapply" is undesirable.
out$HDI_high <- sapply(out$x, .classify_hdi, rev(hdi$CI_high), c(rev(100 * hdi$CI), 100))

Check warning on line 144 in R/plot.hdi.R

View workflow job for this annotation

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

file=R/plot.hdi.R,line=144,col=19,[undesirable_function_linter] Function "sapply" is undesirable.
out$fill <- as.factor(pmax(out$HDI_low, out$HDI_high))
out$height <- out$y
out$y <- name
Expand All @@ -149,7 +149,7 @@
levels(out$fill) <- sprintf("%s%%", levels(out$fill))

# normalize
out$height <- as.vector((out$height - min(out$height, na.rm = TRUE)) / diff(range(out$height, na.rm = TRUE), na.rm = TRUE))

Check warning on line 152 in R/plot.hdi.R

View workflow job for this annotation

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

file=R/plot.hdi.R,line=152,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.

out
}
Expand Down
4 changes: 0 additions & 4 deletions man/data_plot.Rd

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

12 changes: 9 additions & 3 deletions vignettes/bayestestR.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading