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 brms model, when draw_ids are specified, [add_]epred_draws returns draw_ids in .draw. #304

Open
Fumeng-Yang opened this issue Dec 16, 2022 · 2 comments

Comments

@Fumeng-Yang
Copy link

Fumeng-Yang commented Dec 16, 2022

When draw_ids are specified to get a subset of the draws, [add_]epred_draws still returns 1, 2, ..., row number in .draw. It would be useful to have draw_ids in .draw. Because we may want to split the draws and later combine them.

A minimal reproducible example

set.seed(1234)

# need a minimal model
m <- brm(
       x ~ 1, 
       data = tibble(x = rnorm(100, 0, 1)),  # generate some data
       backend = 'cmdstanr',
       refresh = 2000, # don't want lots of messages
       family = gaussian()
       )
add_epred_draws(
    m,
    newdata = tibble(x = 0),
    draw_ids = 100:102 # a subset of draws
  )

The output is

x .row .chain .iteration .draw .epred
0 1 NA NA 1 0.1354060
0 1 NA NA 2 0.0083186
0 1 NA NA 3 -0.0979545

Notice that .draw is still 1,2,3 while we specified 100:102.

@Fumeng-Yang
Copy link
Author

Fumeng-Yang commented Dec 16, 2022

FYI: It seems that brms's posterior_epred returns row names for an ordinal model. Not sure whether this is used in tidybayes.

A minimal reproducible example

set.seed(1234)

c <- brm(x ~ 1, 
       data = tibble(x = sample(1:3, 100, replace = TRUE)),  # need some data
       backend = 'cmdstanr',
       refresh = 2000, # don't want lots of messages
       family = cumulative('logit')
       )
df <- brms::posterior_epred(c,
                newdata = tibble(x = 1),
                draw_ids = 100:105 # a subset of draws 
                # but don't want to be confused with the categories 
          )
dimnames(df)

The output is

[[1]]
[1] "1" "2" "3" "4" "5" "6"

[[2]]
NULL

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

where we see the first dimension has row numbers as row names.

@Fumeng-Yang
Copy link
Author

BTW: these two features should be simple to add. I can probably figure out something after I understand the structure of tidybayes....

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