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

Try to fix warnings in examples and vignettes #310

Merged
merged 13 commits into from
Oct 24, 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ Config/Needs/website:
rstudio/bslib,
r-lib/pkgdown,
easystats/easystatstemplate
Remotes: easystats/insight, easystats/bayestestR
Remotes: easystats/bayestestR
2 changes: 1 addition & 1 deletion R/plot.hdi.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ data_plot.bayestestR_eti <- data_plot.hdi
#' library(bayestestR)
#' set.seed(123)
#' m <- suppressWarnings(stan_glm(Sepal.Length ~ Petal.Width * Species, data = iris, refresh = 0))
#' result <- hdi(m)
#' result <- bayestestR::hdi(m)
#' result
#' plot(result)
#'
Expand Down
4 changes: 3 additions & 1 deletion R/plot.parameters_brms_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ data_plot.parameters_brms_meta <- function(x, data = NULL, normalize_height = TR
#' prior(normal(0, 1), class = Intercept),
#' prior(cauchy(0, 0.5), class = sd)
#' )
#' model <- brm(yi | se(vi) ~ 1 + (1 | author), data = dat)
#' model <- suppressWarnings(
#' brm(yi | se(vi) ~ 1 + (1 | author), data = dat)
#' )
#'
#' # result
#' mp <- model_parameters(model)
Expand Down
4 changes: 3 additions & 1 deletion R/plot.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ plot.see_parameters_model <- function(x,
} else if (has_response) {
p <- p + facet_wrap(~Response, ncol = n_columns, scales = facet_scales)
} else if (has_subgroups) {
suppressWarnings(p <- p + facet_grid(Subgroup ~ ., scales = "free", space = "free")) # nolint
suppressWarnings({
p <- p + facet_grid(Subgroup ~ ., scales = "free", space = "free")
})
}

if (length(model_attributes$parameter_names) > 1L) {
Expand Down
2 changes: 2 additions & 0 deletions R/plot.parameters_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ data_plot.parameters_pca <- function(x, data = NULL, ...) {
title <- paste0("Rotated loadings from ", title, " (", rotation_name, ")")
}

# remove missing values in y, to avoid warning
dataplot <- dataplot[!is.na(dataplot$y), ]

attr(dataplot, "info") <- list(
"xlab" = "",
Expand Down
2 changes: 1 addition & 1 deletion R/plot.si.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' library(bayestestR)
#' set.seed(123)
#' m <<- suppressWarnings(stan_glm(Sepal.Length ~ Petal.Width * Species, data = iris, refresh = 0))
#' result <- si(m)
#' result <- si(m, verbose = FALSE)
#' result
#' plot(result)
#'
Expand Down
9 changes: 4 additions & 5 deletions R/plot.visualisation_recipe.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ plot.see_visualisation_recipe <- function(x, ...) {
if (!"ggraph" %in% .packages()) {
attachNamespace("ggraph") # Needs to be attached
}
ggraph::ggraph(attributes(x)$data, layout = attributes(x)$layout) +
geoms_from_list(x)
suppressWarnings(ggraph::ggraph(attributes(x)$data, layout = attributes(x)$layout) + geoms_from_list(x))
} else {
ggplot2::ggplot(data = attributes(x)$data) +
geoms_from_list(x, ...)
suppressWarnings(ggplot2::ggplot(data = attributes(x)$data) +
geoms_from_list(x, ...))
}
}

Expand All @@ -23,7 +22,7 @@ plot.see_visualisation_recipe <- function(x, ...) {
plot.see_visualisation_recipes <- function(x, ...) {
the_plots <- list()
for (i in names(x)) {
the_plots[[i]] <- graphics::plot(x[[i]])
the_plots[[i]] <- suppressWarnings(graphics::plot(x[[i]]))
}
pw <- plots(the_plots, ...)
.safe_print_plots(pw)
Expand Down
4 changes: 2 additions & 2 deletions R/print.check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ print.see_check_model <- function(x,
# to plot(), "type" is no longer recognized as "missing()"
plot_type <- attr(x, "type")

if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) {
if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) { # nolint
type <- plot_type
} else {
type <- match.arg(type, choices = c("density", "discrete_dots", "discrete_interval", "discrete_both"))
}

suppressWarnings(suppressMessages(plot(
suppressWarnings(suppressMessages(graphics::plot(
x,
style = style,
colors = colors,
Expand Down
6 changes: 4 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
return(x)
}


.as.data.frame_density <- function(x, ...) {
data.frame(x = x$x, y = x$y)
}


# safe conversion from factor to numeric
.factor_to_numeric <- function(x) {
if (is.numeric(x)) {
Expand All @@ -27,11 +29,13 @@
as.numeric(as.character(x))
}


.has_multiple_panels <- function(x) {
(!"Effects" %in% names(x) || insight::n_unique(x$Effects) <= 1L) &&
(!"Component" %in% names(x) || insight::n_unique(x$Component) <= 1L)
}


.clean_parameter_names <- function(params, grid = FALSE) {
params <- unique(params)
labels <- params
Expand Down Expand Up @@ -90,7 +94,6 @@
}



.fix_facet_names <- function(x) {
if ("Component" %in% names(x)) {
x$Component <- as.character(x$Component)
Expand All @@ -117,7 +120,6 @@
}



.intercept_names <-
c(
"(intercept)_zi",
Expand Down
2 changes: 1 addition & 1 deletion man/plot.see_hdi.Rd

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

4 changes: 3 additions & 1 deletion man/plot.see_parameters_brms_meta.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/plot.see_si.Rd

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

2 changes: 1 addition & 1 deletion vignettes/bayestestR.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ represent the density of the null at the value - the ratio of their heights is
the value of the Savage-Dickey Bayes factor:

```{r}
result <- bayesfactor_parameters(model)
result <- bayesfactor_parameters(model, verbose = FALSE)
result
Expand Down
8 changes: 7 additions & 1 deletion vignettes/modelbased.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,18 @@ plot(result)
```


```{r slopes-poly}
```{r slopes-poly, echo=TRUE, eval=FALSE}
model <- lm(Petal.Length ~ Species * poly(Sepal.Width, 3), data = iris)
result <- estimate_slopes(model, at = c("Sepal.Width", "Species"))
plot(result)
```
```{r slopes-poly2, eval=can_evaluate, echo=FALSE}
model <- lm(Petal.Length ~ Species * poly(Sepal.Width, 3), data = iris)
result <- estimate_slopes(model, at = c("Sepal.Width", "Species"))
suppressWarnings(print(plot(result)))
```

# Estimate derivatives

Expand Down
13 changes: 10 additions & 3 deletions vignettes/parameters.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ density estimation plots [from Bayesian
models](https://easystats.github.io/see/articles/bayestestR.html).

```{r}
result <- simulate_parameters(model1)
result <<- simulate_parameters(model1)
plot(result)
```
Expand Down Expand Up @@ -245,7 +245,12 @@ estimations](https://easystats.github.io/see/articles/bayestestR.html)).
# family = zero_inflated_poisson()
# )
brms_model <- insight::download_model("brms_zi_2")
result <- model_parameters(brms_model, effects = "all", component = "all")
result <- model_parameters(
brms_model,
effects = "all",
component = "all",
verbose = FALSE
)
plot(result)
```
Expand All @@ -255,7 +260,9 @@ plot(result)
```{r}
result <- model_parameters(brms_model,
effects = "all",
component = "all", group_level = TRUE
component = "all",
group_level = TRUE,
verbose = FALSE
)
plot(result)
```
Expand Down