Skip to content

event_level argument not working for brier_class when truth is binary #515

@chloepouprom

Description

@chloepouprom

The problem

When brier_class is used on a binary outcome, only 1 column is provided for truth. The event_level argument doesn't let us specify which level from the truth argument to consider as the "event".

Note: This has previously been discussed in issue #430

Reproducible example

library(yardstick)

df <- data.frame(
  truth = as.factor(c(0, 0, 1, 1)),
  score = c(0.1, 0.4, 0.2, 0.9)
)

brier_class(df, truth, score, event_level = "second") 
#> # A tibble: 1 × 3
#>   .metric     .estimator .estimate
#>   <chr>       <chr>          <dbl>
#> 1 brier_class binary         0.505
brier_class(df, truth, score, event_level = "first")
#> # A tibble: 1 × 3
#>   .metric     .estimator .estimate
#>   <chr>       <chr>          <dbl>
#> 1 brier_class binary         0.505


# I can get the correct 'event' by switching the order of the levels
df$truth <- factor(df$truth, levels = c("1", "0"))
brier_class(df, truth, score, event_level = "second") 
#> # A tibble: 1 × 3
#>   .metric     .estimator .estimate
#>   <chr>       <chr>          <dbl>
#> 1 brier_class binary         0.205
brier_class(df, truth, score, event_level = "first") 
#> # A tibble: 1 × 3
#>   .metric     .estimator .estimate
#>   <chr>       <chr>          <dbl>
#> 1 brier_class binary         0.205

Created on 2024-09-11 with reprex v2.1.1

Session info
sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.2 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] yardstick_1.3.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] rstudioapi_0.15.0 knitr_1.45        magrittr_2.0.3    tidyselect_1.2.0 
#>  [5] R6_2.5.1          rlang_1.1.4       fastmap_1.1.1     fansi_1.0.6      
#>  [9] dplyr_1.1.4       tools_4.2.2       hardhat_1.3.1     xfun_0.41        
#> [13] utf8_1.2.4        cli_3.6.1         withr_3.0.0       htmltools_0.5.7  
#> [17] yaml_2.3.8        digest_0.6.33     tibble_3.2.1      lifecycle_1.0.4  
#> [21] vctrs_0.6.5       fs_1.6.3          glue_1.6.2        evaluate_0.23    
#> [25] rmarkdown_2.25    reprex_2.1.1      compiler_4.2.2    pillar_1.9.0     
#> [29] generics_0.1.3    pkgconfig_2.0.3

Metadata

Metadata

Assignees

Labels

bugan unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions