Skip to content

prior_summary() |> dplyr::select() alters the content in the prior column #1761

@ASKurz

Description

@ASKurz

It looks like there's a bug when you try to subset the columns from prior_summary() with dplyr::select(). Some of the information in the prior column changes. To give a sense, here's a simplified version of fit2 from the inhaler documentation.

# Load
library(tidyverse)
library(brms)

# Fit
fit2.1 <- brm(rating ~ treat + (1 | subject),
              data = inhaler, 
              family = cumulative(),
              prior = set_prior("normal(0, 5)"),
              cores = 4, seed = 1)

# Before `select()`
prior_summary(fit2.1)
                prior     class      coef   group resp dpar nlpar lb ub       source
          normal(0,5)         b                                                 user
          normal(0,5)         b     treat                               (vectorized)
 student_t(3, 0, 2.5) Intercept                                              default
 student_t(3, 0, 2.5) Intercept         1                               (vectorized)
 student_t(3, 0, 2.5) Intercept         2                               (vectorized)
 student_t(3, 0, 2.5) Intercept         3                               (vectorized)
 student_t(3, 0, 2.5)        sd                                    0         default
 student_t(3, 0, 2.5)        sd           subject                  0    (vectorized)
 student_t(3, 0, 2.5)        sd Intercept subject                  0    (vectorized)

To my eye, this all looks correct. Now see what happens when we use select().

prior_summary(fit2.1) |> 
  select(prior, class, coef, group) 
                prior     class      coef   group    source
          normal(0,5)         b                   (unknown)
               (flat)         b     treat         (unknown)
 student_t(3, 0, 2.5) Intercept                   (unknown)
               (flat) Intercept         1         (unknown)
               (flat) Intercept         2         (unknown)
               (flat) Intercept         3         (unknown)
 student_t(3, 0, 2.5)        sd                   (unknown)
               (flat)        sd           subject (unknown)
               (flat)        sd Intercept subject (unknown)

Several rows have now changed to (flat) in the prior column. The issue appears the same if you instead use the get_prior(fit2.1) or fit2.1$prior methods. It also persists if you use the base bracket notation in place of select() (prior_summary(fit2.1)[, 1:4]).

Though my primary interest is with the prior column, I find the behavior of the source column surprising, too. When I tried to drop that column with select(), it still appeared in the print output, but now with all (unknown).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions