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

data_slice isn't handling logical variables when not specified in the slice #222

Closed
gavinsimpson opened this issue May 12, 2023 · 0 comments

Comments

@gavinsimpson
Copy link
Owner

gavinsimpson commented May 12, 2023

library("gratia")
library("mgcv")
library("dplyr")

dat <- data_sim("eg1", n = 1500, dist = "normal", scale = 20, seed = 3) |>
    mutate(fac = as.factor( sample(c("A1", "A2", "A3"), 1500, replace = TRUE) ),
           logi = as.logical( sample(c(TRUE, FALSE), 1500, replace = TRUE) ))
b <- gam(y ~ x0 + x1 + I(x1^2) + s(x2, bs = "cr", k = 12) + fac + x3:fac + I(x1*x2) + logi,
         data = dat)

# get a data slice where only `fac` varies
# hold all other variables are representative values
ds <- data_slice(b, fac = evenly(fac)) 

Note that in ds, logi has been coerced to a double:

> ds                                                                          
# A tibble: 3 × 6
  fac      x0    x1    x2  logi    x3
  <fct> <dbl> <dbl> <dbl> <dbl> <dbl>
1 A1    0.511 0.521 0.493     0 0.476
2 A2    0.511 0.521 0.493     0 0.476
3 A3    0.511 0.521 0.493     0 0.476

The issue is in typical_values()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant