"Error: Duplicate variable names are not allowed in draws objects."

I fitted a brms model, for which both fixef(model) and as_draws_array(model) yield:

Error: Duplicate variable names are not allowed in draws objects.
The following variable names are duplicates:
{'prior_cor_Subject'}

The model has two random correlation parameters (between intercept and slope), one for mean and one for sigma. The prior on the correlation parameters is:

set_prior("lkj(2)", class="cor")

It seems that posterior_samples(model) works fine (besides a warning that it is deprecated).

Thanks!

  • Operating System: Linux 5.11.0-37-generic #41~20.04.2-Ubuntu
  • brms Version: 2.16.1

can you provide a minimal reproducible example please? I guess it is a bug in brms or something similar.

Here it is.
This is the data generation (all random effects are 0, but doesnt really matter):

nsubjs <- 20
ntrials <- 10
mu1 <- 500
mu2 <- 550
sigma1 <- 100
sigma2 <- 150
mydata <- data.frame(Condition=rep(rep(c("A", "B"), each=nsubjs*ntrials)),
                     Subject=rep(rep(seq(nsubjs), each=ntrials), 2),
                     Trial=rep(seq(ntrials), nsubjs*2),
                     DV=c(rnorm(nsubjs*ntrials, mu1, sigma1), rnorm(nsubjs*ntrials, mu2, sigma2)))

And the model (I’m going with the default priors):

m <- brm(bf(DV ~ (1+Condition|Subject) + Condition,
                    sigma ~ (1+Condition|Subject) + Condition),
                 sample_prior="yes",
                 mydata)
summary(m)
fixef(m)

In this case, even summary(m) produced the same error, which was a surprise:

Error: Duplicate variable names are not allowed in draws objects.
The following variable names are duplicates:
{'prior_sd_Subject', 'prior_cor_Subject'}

Also of note: This seems to happen only when the prior is sampled (I guess because those variable names aren’t in the fit otherwise).

Hi,

I got exactly the same error when I tried to fit the following model:

m2 <- brm(bf(mvbind(Resp1, Resp2, Resp3, Resp4) ~  trt + (1|donor))+
            set_rescor(TRUE),
          data = d0A, sample_prior = "yes",
          chains = 4,
          iter = 2000,
          warmup = 1000,
          cores = 4,
          init_r =0.5,  
          control = list(adapt_delta=0.8,max_treedepth =20), seed = 123)

I couldn’t get summary or calculate contrasts with emmeans

Error: Duplicate variable names are not allowed in draws objects.
The following variable names are duplicates:
{'prior_sd_donor'}

@jverissimo I think, I found a solution. When I use get_prior() instead of sample_prior = "yes" I do not get the error any more

Thanks! Removing sample_prior="yes" does seem to work. But I imagine there are situations in which sampling from the prior is necessary and get_prior() doesn’t cut it? (e.g., prior predictive checks, Savage-Dickey Bayes factors)

did you try with the latest dev version of brms from github? I have had the feeling of having fixed this issue already at some point.

1 Like

EDIT:
Yes, it’s been fixed, thanks! (I was loading a previously fitted model, hence the error was still there.)
Refitting with 2.16.2 works, as the prior sample variables are named differently:

> names(m$fit)[grep("prior_cor", names(m$fit))]
[1] "prior_cor_Subject"    "prior_cor_Subject__1"

Thanks, Paul.
Still there:

> packageVersion("brms")
[1] ‘2.16.2’
> fixef(m)
Error: Duplicate variable names are not allowed in draws objects.
The following variable names are duplicates:
{'prior_cor_Subject'}