Skip to content

Commit

Permalink
Clean up some lints
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Sep 8, 2023
1 parent ccc1787 commit 1e3e2fa
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion R/geom_binomdensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ geom_binomdensity <- function(data,
insight::check_if_installed(c("ggplot2", "ggdist"))

# Sanitize y (e.g., if levels with no values, etc.)
if (is.factor(data[[y]]) && length(levels(data[[y]])) > 2L) {
if (is.factor(data[[y]]) && nlevels(data[[y]]) > 2L) {
data[[y]] <- droplevels(data[[y]])
}

Expand Down
7 changes: 1 addition & 6 deletions R/plot.equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ plot.see_equivalence_test <- function(x,
tmp <- merge(tmp, cp, by = "predictor")
tmp$predictor <- factor(tmp$predictor, levels = rev(unique(tmp$predictor)))

has_multiple_panels <-
(!"Effects" %in% names(tmp) || length(unique(tmp$Effects)) <= 1L) &&
(!"Component" %in% names(tmp) || length(unique(tmp$Component)) <= 1L)

# check if we have multiple panels
if (has_multiple_panels) {
if (.has_multiple_panels(tmp)) {
n_columns <- NULL
}

Expand Down
10 changes: 7 additions & 3 deletions R/plot.estimate_density.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ plot.see_estimate_density <- function(x,


if (!inherits(x, "data_plot")) {
x <- data_plot(x, data = model, centrality = centrality, ci = ci, ...)
x <- data_plot(x,
data = model,
centrality = centrality,
ci = ci,
...
)
}

if ((!"Effects" %in% names(x) || length(unique(x$Effects)) <= 1) &&
(!"Component" %in% names(x) || length(unique(x$Component)) <= 1)) {
if (.has_multiple_panels(x)) {
n_columns <- NULL
}

Expand Down
4 changes: 1 addition & 3 deletions R/plot.p_direction.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ plot.see_p_direction <- function(x,
x <- data_plot(x, data = data, show_intercept = show_intercept)
}

# check if we have multiple panels
if ((!"Effects" %in% names(x) || length(unique(x$Effects)) <= 1) &&
(!"Component" %in% names(x) || length(unique(x$Component)) <= 1)) {
if (.has_multiple_panels(x)) {
n_columns <- NULL
}

Expand Down
4 changes: 1 addition & 3 deletions R/plot.p_significance.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ plot.see_p_significance <- function(x,
x <- data_plot(x, data = data, show_intercept = show_intercept)
}

# check if we have multiple panels
if ((!"Effects" %in% names(x) || length(unique(x$Effects)) <= 1L) &&
(!"Component" %in% names(x) || length(unique(x$Component)) <= 1L)) {
if (.has_multiple_panels(x)) {
n_columns <- NULL
}

Expand Down
4 changes: 1 addition & 3 deletions R/plot.rope.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ plot.see_rope <- function(x,
x <- data_plot(x, data = data, show_intercept = show_intercept)
}

# check if we have multiple panels
if ((!"Effects" %in% names(x) || length(unique(x$Effects)) <= 1) &&
(!"Component" %in% names(x) || length(unique(x$Component)) <= 1)) {
if (.has_multiple_panels(x)) {
n_columns <- NULL
}

Expand Down
4 changes: 3 additions & 1 deletion R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ plots <- function(...,

# Add tags
if (!is.null(tags)) {
if (length(tags) == 1) {
if (length(tags) == 1L) {
if (isTRUE(tags)) {
tags <- "A"
} else if (isFALSE(tags) || is.na(tags)) {
Expand Down Expand Up @@ -100,13 +100,15 @@ plots <- function(...,
msg_display1 <- "\n- To fix this issue, please make the window larger."
msg_display3 <- "\n- If this still doesn't resolve your problems, you may check whether your apps are rescaled. On Windows, this can be done in the display settings (Start > Settings > System > Display, \"Scale and layout\"). Reduce the scaling and try again."
msg_display4 <- "\n- Finally, you can try to decrease the base font-size of your theme before plotting. Load `library(ggplot2)` and run: `theme_set(theme_classic(base_size = 6))`"

if (Sys.getenv("RSTUDIO") == "1") {
msg <- "The RStudio 'Plots' window is too small to show this set of plots."
msg_display2 <- "\n- If this doesn't help, try to reset your zoom settings. In RStudio, go to Menu \"View > Actual Size\" and then retry."
} else {
msg <- "The viewport is too small to show this set of plots."
msg_display2 <- "\n- If this doesn't help, try to reset the zoom settings of your IDE and then retry."
}

msg <- paste(msg, "You may try one of the following steps to resolve this problem.")
insight::format_error(msg, msg_display1, msg_display2, msg_display3, msg_display4)
}
Expand Down
19 changes: 12 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
as.numeric(as.character(x))
}


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

.clean_parameter_names <- function(params, grid = FALSE) {
params <- unique(params)
Expand Down Expand Up @@ -91,23 +94,25 @@
.fix_facet_names <- function(x) {
if ("Component" %in% names(x)) {
x$Component <- as.character(x$Component)
if (!"Effects" %in% names(x)) {
x$Component[x$Component == "conditional"] <- "Conditional"
x$Component[x$Component == "zero_inflated"] <- "Zero-Inflated"
x$Component[x$Component == "dispersion"] <- "Dispersion"
x$Component[x$Component == "simplex"] <- "Monotonic Effects"
} else {
if ("Effects" %in% names(x)) {
x$Component[x$Component == "conditional"] <- "(Conditional)"
x$Component[x$Component == "zero_inflated"] <- "(Zero-Inflated)"
x$Component[x$Component == "dispersion"] <- "(Dispersion)"
x$Component[x$Component == "simplex"] <- "(Monotonic Effects)"
} else {
x$Component[x$Component == "conditional"] <- "Conditional"
x$Component[x$Component == "zero_inflated"] <- "Zero-Inflated"
x$Component[x$Component == "dispersion"] <- "Dispersion"
x$Component[x$Component == "simplex"] <- "Monotonic Effects"
}
}

if ("Effects" %in% names(x)) {
x$Effects <- as.character(x$Effects)
x$Effects[x$Effects == "fixed"] <- "Fixed Effects"
x$Effects[x$Effects == "random"] <- "Random Effects"
}

x
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-plot.estimate_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ test_that("`plot.see_estimate_contrasts()` works", {

model <- stan_glm(Sepal.Width ~ Species, data = iris, refresh = 0)
contrasts <- modelbased::estimate_contrasts(model, contrast = "Species")
means <- modelbased::estimate_means(model, at = c("Species"))
means <- modelbased::estimate_means(model, at = "Species")
expect_s3_class(plot(contrasts, means), "gg")
})
30 changes: 18 additions & 12 deletions vignettes/parameters.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,27 @@ plot(result)

## Bayesian Meta-Analysis using brms

```{r}
# We download the model to save computation time. Here is the code
# to refit the exact model used below...
We download the model to save computation time, but here is the code to refit the exact model used below:

```{r, eval=FALSE}
# Data from
# https://github.com/MathiasHarrer/Doing-Meta-Analysis-in-R/blob/master/_data/Meta_Analysis_Data.RData
# set.seed(123)
# priors <- c(prior(normal(0,1), class = Intercept),
# prior(cauchy(0,0.5), class = sd))
#
# model <-
# brm(TE|se(seTE) ~ 1 + (1|Author),
# data = Meta_Analysis_Data,
# prior = priors,
# iter = 4000)
set.seed(123)
priors <- c(
prior(normal(0, 1), class = Intercept),
prior(cauchy(0, 0.5), class = sd)
)
model <- brm(
TE | se(seTE) ~ 1 + (1 | Author),
data = Meta_Analysis_Data,
prior = priors,
iter = 4000
)
```


```{r}
library(brms)
model <- insight::download_model("brms_meta_1")
result <- model_parameters(model)
Expand Down

0 comments on commit 1e3e2fa

Please sign in to comment.