easystats / modelbased

:chart_with_upwards_trend: Estimate effects, contrasts and means based on statistical models
https://easystats.github.io/modelbased/
GNU General Public License v3.0
232 stars 19 forks source link

Plotting from `estimate_means()` with a poisson model fails #231

Open pcinereus opened 11 months ago

pcinereus commented 11 months ago

I suspect the reason is that .clean_names_frequentist() should also include names(means)[names(means) == "rate"] <- "Mean".

set.seed(123)
dat <- data.frame(y =  rpois(100, 3), F =  gl(4, 20, 100))
dat_glm <- glm(y ~ F, data =  dat, family = poisson(link =  "log"))
dat_glm |> estimate_means() |> plot()
strengejacke commented 11 months ago

Can you create a reprex that includes the error message, or post the traceback?

pcinereus commented 11 months ago

Thanks for looking into this...

18: stop("Discrete value supplied to continuous scale", call. = FALSE)
17: train_continuous(x, self$range)
16: self$range$train(x)
15: train(..., self = self)
14: scales[[i]][[method]](data[[var]][scale_index[[i]]])
13: FUN(X[[i]], ...)
12: lapply(seq_along(scales), function(i) {
        scales[[i]][[method]](data[[var]][scale_index[[i]]])
    })
11: FUN(X[[i]], ...)
10: lapply(vars, function(var) {
        pieces <- lapply(seq_along(scales), function(i) {
            scales[[i]][[method]](data[[var]][scale_index[[i]]])
        })
        pieces[lengths(pieces) == 0] <- NULL
        o <- order(unlist(scale_index))[seq_len(sum(lengths(pieces)))]
        vec_c(!!!pieces)[o]
    })
9: scale_apply(layer_data, y_vars, "train", SCALE_Y, y_scales)
8: train_scales(...)
7: self$facet$train_scales(self$panel_scales_x, self$panel_scales_y, 
       layout, data, self$facet_params)
6: train_position(..., self = self)
5: layout$train_position(data, scale_x(), scale_y())
4: ggplot_build.ggplot(x)
3: ggplot_build(x)
2: print.ggplot(x)
1: (function (x, ...) 
   UseMethod("print"))(x)
strengejacke commented 8 months ago

hm, I get a completely different error here:

library(modelbased)
set.seed(123)
dat <- data.frame(y =  rpois(100, 3), FC =  gl(4, 20, 100))
dat_glm <- glm(y ~ FC, data =  dat, family = poisson(link =  "log"))
dat_glm |> estimate_means() |> plot()
#> We selected `at = c("FC")`.
#> Error in `rlang::sym()`:
#> ! Can't convert a character vector to a symbol.
#> Backtrace:
#>      ▆
#>   1. ├─base::plot(estimate_means(dat_glm))
#>   2. └─modelbased:::plot.estimate_means(estimate_means(dat_glm))
#>   3.   ├─graphics::plot(layers)
#>   4.   ├─datawizard:::plot.visualisation_recipe(layers)
#>   5.   ├─base::NextMethod()
#>   6.   └─see:::plot.see_visualisation_recipe(layers)
#>   7.     └─see::geoms_from_list(x, ...)
#>   8.       └─see::geom_from_list(x[[i]])
#>   9.         ├─base::do.call(ggplot2::aes, lapply(x$aes, .str_to_sym))
#>  10.         └─base::lapply(x$aes, .str_to_sym)
#>  11.           └─see (local) FUN(X[[i]], ...)
#>  12.             └─rlang::sym(x)
#>  13.               └─rlang:::abort_coercion(x, "a symbol")
#>  14.                 └─rlang::abort(msg, call = call)

Created on 2023-10-12 with reprex v2.0.2