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

.by argument works incorrectly for factor level groups. #140

Open
jgaeb opened this issue Mar 6, 2024 · 0 comments
Open

.by argument works incorrectly for factor level groups. #140

jgaeb opened this issue Mar 6, 2024 · 0 comments

Comments

@jgaeb
Copy link

jgaeb commented Mar 6, 2024

The problem

Calibrating by group errors when the group is a factor, since no data is passed to the calibration model. The problem appears to be with how split_dplyr_groups() works.

Reproducible example

library(probably)
#> 
#> Attaching package: 'probably'
#> The following objects are masked from 'package:base':
#> 
#>     as.factor, as.ordered
library(tidymodels)
library(tidyverse)

df <- tibble(
  p = runif(100),
  y = factor(runif(100) <= log(p / (1 - p)), levels = c(TRUE, FALSE)),
  z = factor(sample(letters[1:3], 100, replace = TRUE))
)

m <- logistic_reg() %>%
  set_engine("glm") %>%
  set_mode("classification") %>%
  fit(y ~ p, data = df)

# This works
m_calib <- m %>%
  predict(new_data = df, type = "prob") %>%
  bind_cols(df) %>%
  mutate(z = as.character(z)) %>%
  cal_estimate_logistic(truth = y, .by = z)

# This errors
m_calib <- m %>%
  predict(new_data = df, type = "prob") %>%
  bind_cols(df) %>%
  cal_estimate_logistic(truth = y, .by = z)
#> Error in mgcv::gam(f_model, data = .data, family = "binomial", ...): Not enough (non-NA) data to do anything meaningful

Created on 2024-03-06 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31)
#>  os       macOS Sonoma 14.2.1
#>  system   aarch64, darwin23.0.0
#>  ui       unknown
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/New_York
#>  date     2024-03-06
#>  pandoc   3.1.11.1 @ /opt/homebrew/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version    date (UTC) lib source
#>  backports      1.4.1      2021-12-13 [1] CRAN (R 4.3.1)
#>  broom        * 1.0.5      2023-06-09 [1] CRAN (R 4.3.1)
#>  butcher        0.3.3      2023-08-23 [1] CRAN (R 4.3.1)
#>  class          7.3-22     2023-05-03 [1] CRAN (R 4.3.1)
#>  cli            3.6.2      2023-12-11 [1] CRAN (R 4.3.1)
#>  codetools      0.2-19     2023-02-01 [1] CRAN (R 4.3.1)
#>  colorspace     2.1-0      2023-01-23 [1] CRAN (R 4.3.1)
#>  data.table     1.14.8     2023-02-17 [1] CRAN (R 4.3.1)
#>  dials        * 1.2.0      2023-04-03 [1] CRAN (R 4.3.0)
#>  DiceDesign     1.9        2021-02-13 [1] CRAN (R 4.3.0)
#>  digest         0.6.34     2024-01-11 [1] CRAN (R 4.3.1)
#>  dplyr        * 1.1.4      2023-11-17 [1] CRAN (R 4.3.1)
#>  evaluate       0.23       2023-11-01 [1] CRAN (R 4.3.1)
#>  fansi          1.0.6      2023-12-08 [1] CRAN (R 4.3.1)
#>  fastmap        1.1.1      2023-02-24 [1] CRAN (R 4.3.1)
#>  forcats      * 1.0.0      2023-01-29 [1] CRAN (R 4.3.1)
#>  foreach        1.5.2      2022-02-02 [1] CRAN (R 4.3.0)
#>  fs             1.6.3      2023-07-20 [1] CRAN (R 4.3.1)
#>  furrr          0.3.1      2022-08-15 [1] CRAN (R 4.3.1)
#>  future         1.33.0     2023-07-01 [1] CRAN (R 4.3.1)
#>  future.apply   1.11.0     2023-05-21 [1] CRAN (R 4.3.1)
#>  generics       0.1.3      2022-07-05 [1] CRAN (R 4.3.1)
#>  ggplot2      * 3.4.2      2023-04-03 [1] CRAN (R 4.3.1)
#>  globals        0.16.2     2022-11-21 [1] CRAN (R 4.3.1)
#>  glue           1.7.0      2024-01-09 [1] CRAN (R 4.3.1)
#>  gower          1.0.1      2022-12-22 [1] CRAN (R 4.3.0)
#>  GPfit          1.0-8      2019-02-08 [1] CRAN (R 4.3.0)
#>  gtable         0.3.3      2023-03-21 [1] CRAN (R 4.3.1)
#>  hardhat        1.3.0      2023-03-30 [1] CRAN (R 4.3.0)
#>  hms            1.1.3      2023-03-21 [1] CRAN (R 4.3.1)
#>  htmltools      0.5.5      2023-03-23 [1] CRAN (R 4.3.1)
#>  infer        * 1.0.4      2022-12-02 [1] CRAN (R 4.3.0)
#>  ipred          0.9-14     2023-03-09 [1] CRAN (R 4.3.0)
#>  iterators      1.0.14     2022-02-05 [1] CRAN (R 4.3.0)
#>  knitr          1.43       2023-05-25 [1] CRAN (R 4.3.1)
#>  lattice        0.21-8     2023-04-05 [1] CRAN (R 4.3.1)
#>  lava           1.7.2.1    2023-02-27 [1] CRAN (R 4.3.0)
#>  lhs            1.1.6      2022-12-17 [1] CRAN (R 4.3.0)
#>  lifecycle      1.0.4      2023-11-07 [1] CRAN (R 4.3.1)
#>  listenv        0.9.0      2022-12-16 [1] CRAN (R 4.3.1)
#>  lubridate    * 1.9.2      2023-02-10 [1] CRAN (R 4.3.1)
#>  magrittr       2.0.3      2022-03-30 [1] CRAN (R 4.3.1)
#>  MASS           7.3-60     2023-05-04 [1] CRAN (R 4.3.1)
#>  Matrix         1.6-0      2023-07-08 [1] CRAN (R 4.3.1)
#>  mgcv           1.9-0      2023-07-11 [1] CRAN (R 4.3.1)
#>  modeldata    * 1.2.0      2023-08-09 [1] CRAN (R 4.3.1)
#>  munsell        0.5.0      2018-06-12 [1] CRAN (R 4.3.1)
#>  nlme           3.1-162    2023-01-31 [1] CRAN (R 4.3.1)
#>  nnet           7.3-19     2023-05-03 [2] CRAN (R 4.3.2)
#>  parallelly     1.36.0     2023-05-26 [1] CRAN (R 4.3.1)
#>  parsnip      * 1.1.1      2023-08-17 [1] CRAN (R 4.3.1)
#>  pillar         1.9.0      2023-03-22 [1] CRAN (R 4.3.1)
#>  pkgconfig      2.0.3      2019-09-22 [1] CRAN (R 4.3.1)
#>  probably     * 1.0.2      2023-06-29 [1] CRAN (R 4.3.1)
#>  prodlim        2023.03.31 2023-04-02 [1] CRAN (R 4.3.0)
#>  purrr        * 1.0.2      2023-08-10 [1] CRAN (R 4.3.1)
#>  R.cache        0.16.0     2022-07-21 [1] CRAN (R 4.3.1)
#>  R.methodsS3    1.8.2      2022-06-13 [1] CRAN (R 4.3.1)
#>  R.oo           1.25.0     2022-06-12 [1] CRAN (R 4.3.1)
#>  R.utils        2.12.2     2022-11-11 [1] CRAN (R 4.3.1)
#>  R6             2.5.1      2021-08-19 [1] CRAN (R 4.3.1)
#>  Rcpp           1.0.10     2023-01-22 [1] CRAN (R 4.3.1)
#>  readr        * 2.1.4      2023-02-10 [1] CRAN (R 4.3.1)
#>  recipes      * 1.0.7      2023-08-10 [1] CRAN (R 4.3.1)
#>  reprex         2.0.2      2022-08-17 [1] CRAN (R 4.3.1)
#>  rlang          1.1.3      2024-01-10 [1] CRAN (R 4.3.1)
#>  rmarkdown      2.23       2023-07-01 [1] CRAN (R 4.3.1)
#>  rpart          4.1.21     2023-10-09 [2] CRAN (R 4.3.2)
#>  rsample      * 1.1.1      2022-12-07 [1] CRAN (R 4.3.0)
#>  scales       * 1.2.1      2022-08-20 [1] CRAN (R 4.3.1)
#>  sessioninfo    1.2.2      2021-12-06 [1] CRAN (R 4.3.1)
#>  stringi        1.8.3      2023-12-11 [1] CRAN (R 4.3.1)
#>  stringr      * 1.5.1      2023-11-14 [1] CRAN (R 4.3.1)
#>  styler         1.10.1     2023-06-05 [1] CRAN (R 4.3.1)
#>  survival       3.5-7      2023-08-14 [2] CRAN (R 4.3.2)
#>  tibble       * 3.2.1      2023-03-20 [1] CRAN (R 4.3.1)
#>  tidymodels   * 1.1.0      2023-05-01 [1] CRAN (R 4.3.0)
#>  tidyr        * 1.3.0      2023-01-24 [1] CRAN (R 4.3.1)
#>  tidyselect     1.2.0      2022-10-10 [1] CRAN (R 4.3.1)
#>  tidyverse    * 2.0.0      2023-02-22 [1] CRAN (R 4.3.1)
#>  timechange     0.2.0      2023-01-11 [1] CRAN (R 4.3.1)
#>  timeDate       4022.108   2023-01-07 [1] CRAN (R 4.3.0)
#>  tune         * 1.1.1      2023-04-11 [1] CRAN (R 4.3.0)
#>  tzdb           0.4.0      2023-05-12 [1] CRAN (R 4.3.1)
#>  utf8           1.2.4      2023-10-22 [1] CRAN (R 4.3.1)
#>  vctrs          0.6.5      2023-12-01 [1] CRAN (R 4.3.1)
#>  withr          2.5.2      2023-10-30 [1] CRAN (R 4.3.1)
#>  workflows    * 1.1.3      2023-02-22 [1] CRAN (R 4.3.0)
#>  workflowsets * 1.0.1      2023-04-06 [1] CRAN (R 4.3.0)
#>  xfun           0.39       2023-04-20 [1] CRAN (R 4.3.1)
#>  yaml           2.3.7      2023-01-23 [1] CRAN (R 4.3.1)
#>  yardstick    * 1.2.0      2023-04-21 [1] CRAN (R 4.3.0)
#> 
#>  [1] /opt/homebrew/lib/R/4.3/site-library
#>  [2] /opt/homebrew/Cellar/r/4.3.2/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
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