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

Feature request: for a multivariate ordinal model, [add]_epred_draws returns response variables somewhere #305

Open
Fumeng-Yang opened this issue Dec 16, 2022 · 1 comment

Comments

@Fumeng-Yang
Copy link

Fumeng-Yang commented Dec 16, 2022

For a multivariate ordinal model, brms still uses .category for ordinal responses; therefore, it seems that response variables
are not included in [add]_epred_draws (and [add]_epred_rvars?)

It would be nice to have the response variables somewhere, at least when resp = ... is specified.

A minimal reproducible example

set.seed(1234)
simulated_data <- 
  tibble(
    likert1 = sample(1:5, 100, replace = TRUE),
    likert2 = sample(1:5, 100, replace = TRUE)
  ) 
mvo <- brm(
       bf(mvbind(
          likert1, 
          likert2
           ) ~ 1) 
       + set_rescor(FALSE), # set correlation in residuals to FALSE
       data = simulated_data, 
       refresh = 2000, # don't want lots of messages
       backend = 'cmdstanr',
       family = cumulative('logit')
       )
add_epred_draws(object = mvo,
                                   # need some placeholders
                newdata = tibble(likert1 = -1, likert2 = -1),
                resp = c('likert1', 'likert2'),
                draw_ids = 100:102
                )

The output is

likert1 likert2 .row .chain .iteration .draw .category .epred
-1 -1 1 NA NA 1 1 0.1159525
-1 -1 1 NA NA 2 1 0.1254349
-1 -1 1 NA NA 3 1 0.2474628
-1 -1 1 NA NA 1 2 0.1834422
-1 -1 1 NA NA 2 2 0.2435328
-1 -1 1 NA NA 3 2 0.1387139
-1 -1 1 NA NA 1 3 0.2417583
-1 -1 1 NA NA 2 3 0.2418615
-1 -1 1 NA NA 3 3 0.1800300
-1 -1 1 NA NA 1 4 0.3103983
-1 -1 1 NA NA 2 4 0.1766087
-1 -1 1 NA NA 3 4 0.2802388
-1 -1 1 NA NA 1 5 0.1484487
-1 -1 1 NA NA 2 5 0.2125622
-1 -1 1 NA NA 3 5 0.1535545

Verify the output of brms:posterior_epred

dimnames(brms::posterior_epred(
    mvo,
    newdata = simulated_data[1,],
    draw_ids = 100:102
  ))

The output is

[[1]]
[1] "1" "2" "3"

[[2]]
NULL

[[3]]
 [1] "1" "2" "3" "4" "5" "1" "2" "3" "4" "5"
@Fumeng-Yang Fumeng-Yang changed the title Feature request: for a multivariate ordinal model, [add]_epred_draws returns response variable somewhere Feature request: for a multivariate ordinal model, [add]_epred_draws returns response variables somewhere Dec 16, 2022
@Fumeng-Yang
Copy link
Author

Fumeng-Yang commented Dec 16, 2022

[add_][predicted|linpred]_draws appears to return response variables.

add_predicted_draws(object = mvo,
                # need some placeholders
                newdata = tibble(likert1 = -1, likert2 = -1),
                resp = c('likert1', 'likert2'),
                draw_ids = 100:102
                )

The output is

likert1 likert2 .row .chain .iteration .draw .category .prediction
-1 -1 1 NA NA 1 likert1 3
-1 -1 1 NA NA 2 likert1 5
-1 -1 1 NA NA 3 likert1 4
-1 -1 1 NA NA 1 likert2 3
-1 -1 1 NA NA 2 likert2 1
-1 -1 1 NA NA 3 likert2 5

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