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

Ordinal models no longer include level names in predict() output #838

Closed
mjskay opened this issue Jan 25, 2020 · 2 comments
Closed

Ordinal models no longer include level names in predict() output #838

mjskay opened this issue Jan 25, 2020 · 2 comments
Labels
bug
Milestone

Comments

@mjskay
Copy link

@mjskay mjskay commented Jan 25, 2020

In previous versions of brms (up to 2.10 at least), output of predict() on an ordinal model would include the level names from the response variable in column names when summary = TRUE and would include a "levels" attribute for column names when summary = FALSE, which is very useful for plotting / interpreting model output. E.g.:

library(brms)
#> Loading required package: Rcpp
#> Loading 'brms' package (version 2.10.0). Useful instructions
#> can be found by typing help('brms'). A more detailed introduction
#> to the package is available through vignette('brms_overview').

d = data.frame(
  x = ordered(c(rep("a", 20), rep("b", 10), rep("c", 5)))
)

m = brm(x ~ 1, data = d, family = cumulative)
#> Compiling the C++ model
#> Start sampling
#> 
#> [...]

str(predict(m))
#>  num [1:35, 1:3] 0.563 0.568 0.571 0.559 0.568 ...
#>  - attr(*, "dimnames")=List of 2
#>   ..$ : NULL
#>   ..$ : chr [1:3] "P(Y = a)" "P(Y = b)" "P(Y = c)"
str(predict(m, summary = FALSE))
#>  num [1:4000, 1:35] 1 2 2 1 3 1 3 2 1 2 ...
#>  - attr(*, "dimnames")=List of 2
#>   ..$ : NULL
#>   ..$ : NULL
#>  - attr(*, "levels")= chr [1:3] "a" "b" "c"

Created on 2020-01-25 by the reprex package (v0.3.0)

As of the version of CRAN (2.11) and the current github version (reprex below), I no longer see level names in the output, only numbers. E.g.:

library(brms)
#> Loading required package: Rcpp
#> Loading 'brms' package (version 2.11.4). Useful instructions
#> can be found by typing help('brms'). A more detailed introduction
#> to the package is available through vignette('brms_overview').
#> 
#> Attaching package: 'brms'
#> The following object is masked from 'package:stats':
#> 
#>     ar

d = data.frame(
  x = ordered(c(rep("a", 20), rep("b", 10), rep("c", 5)))
)

m = brm(x ~ 1, data = d, family = cumulative)
#> Compiling the C++ model
#> Start sampling
#> 
#> [...]

str(predict(m))
#>  num [1:35, 1:3] 0.575 0.562 0.577 0.561 0.563 ...
#>  - attr(*, "dimnames")=List of 2
#>   ..$ : NULL
#>   ..$ : chr [1:3] "P(Y = 1)" "P(Y = 2)" "P(Y = 3)"
str(predict(m, summary = FALSE))
#>  num [1:4000, 1:35] 1 1 2 1 1 1 2 1 1 2 ...
#>  - attr(*, "dimnames")=List of 2
#>   ..$ : NULL
#>   ..$ : NULL

Created on 2020-01-25 by the reprex package (v0.3.0)

Is this a bug, or is there another way to retrieve the level names? Thanks!

@paul-buerkner
Copy link
Owner

@paul-buerkner paul-buerkner commented Jan 27, 2020

Thanks! In 2.11 I decoupled the handling of categorical and ordinal models much more than before, which now makes the internals easier to handle. Unfortunately, I overlooked that response category names are still beneficial to store in ordinal models. This should be fixed now.

@paul-buerkner paul-buerkner added the bug label Jan 27, 2020
@paul-buerkner paul-buerkner added this to the brms 2.11.1++ milestone Jan 27, 2020
@mjskay
Copy link
Author

@mjskay mjskay commented Jan 27, 2020

Awesome, thanks!

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.