Skip to content

Commit

Permalink
Error in model_parameters.aov plot() method? (#376)
Browse files Browse the repository at this point in the history
* Error in model_parameters.aov plot() method?
Fixes #286

* fix
  • Loading branch information
strengejacke authored Dec 5, 2024
1 parent e8ecf7b commit b4e1826
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: see
Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2'
Version: 0.9.0.12
Version: 0.9.0.13
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
- `plot()` for `model_parameters()` gets a `show_direction` argument, to turn
off the direction of the effect in the plot.

- `plot()` for `model_parameters()` now gives an informative error message when
trying to plot Anova tables (which does not work).

- `plot()` for `simulate_parameters()` now better copes with models that have
multiple response levels (e.g. multinomial models).

- Gains `{patchwork}` as a hard dependency given its importance for the package.

## Bug fixes
Expand Down
6 changes: 6 additions & 0 deletions R/plot.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ plot.see_parameters_model <- function(x,
# retrieve settings ----------------
model_attributes <- attributes(x)[!names(attributes(x)) %in% c("names", "row.names", "class")]

# no plot for anova
model_class <- attributes(x)$model_class
if (!is.null(model_class) && any(model_class %in% c("aov", "anova"))) {
insight::format_error("Plots cannot be created for Anova tables. Please fit a (linear) regression model and try again.") # nolint
}

# for GAMs, remove smooth terms
if (!is.null(x$Component) && any(x$Component == "smooth_terms")) {
x <- x[x$Component != "smooth_terms", ]
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-plot.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ test_that("`plot.see_parameters_model()` works", {
)
})


test_that("`plot.see_parameters_model()` errors for anova tables", {
skip_if_not_installed("parameters")
data(iris)
m <- aov(Sepal.Length ~ Species, data = iris)
mp <- parameters::model_parameters(m)
expect_error(plot(mp), regex = "Plots cannot be created")
})


test_that("`plot.see_parameters_model()` random parameters works", {
skip_if_not_installed("lme4")
skip_if_not_installed("parameters")
Expand Down

0 comments on commit b4e1826

Please sign in to comment.