# Problem with posterior\_predict(..., nsamples=1) for categorical brms model

**URL:** https://discourse.mc-stan.org/t/problem-with-posterior-predict-nsamples-1-for-categorical-brms-model/18463
**Category:** brms
**Tags:** posterior-predictive, bug
**Created:** [October 7, 2020, 11:57am UTC](https://discourse.mc-stan.org/t/problem-with-posterior-predict-nsamples-1-for-categorical-brms-model/18463 "2020-10-07T11:57:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pdonner](https://avatars.discourse-cdn.com/v4/letter/p/aca169/32.png) [@pdonner](https://discourse.mc-stan.org/u/pdonner)
#### Post date: [October 7, 2020, 11:57am UTC](https://discourse.mc-stan.org/t/problem-with-posterior-predict-nsamples-1-for-categorical-brms-model/18463/1 "2020-10-07T11:57:59Z")

</div>

Hi,  
I am getting this error:

> Error in insert\_refcat(eta, family = prep$family) :  
> is.matrix(eta) is not TRUE

When trying to predict **one** new sample, not with more samples, with this model:

```no-highlight
dat <- data.frame(x=as.factor(c("A", "A", "A", "B", "B", "B")),
                  y=as.factor(c("A", "A", "B", "B", "B", "A")))

mod1 <- brm(bf(y ~ x), data = dat, 
              family = categorical(link = "logit"), 
              iter=3000, warmup=1000, cores=2, chains=2, 
              control = list(max_treedepth = 11))

newdat <- data.frame(x=c("A","B"), y=c("A", "B"))
posterior_predict(mod1, newdata = newdat, scale="response", nsamples=2) # works
posterior_predict(mod1, newdata = newdat, scale="response", nsamples=1) # gives the above error

```

Perhaps, this is a bug.

- Operating System: Windows 10
- brms Version: 2.13.5
- R version: 3.6.3

---

<div class="post-metadata">

### Author: ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)
#### Post date: [October 7, 2020, 12:05pm UTC](https://discourse.mc-stan.org/t/problem-with-posterior-predict-nsamples-1-for-categorical-brms-model/18463/2 "2020-10-07T12:05:51Z")

</div>

Thanks. I will check and fix it.

---

<div class="post-metadata">

### Author: ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)
#### Post date: [October 7, 2020, 12:46pm UTC](https://discourse.mc-stan.org/t/problem-with-posterior-predict-nsamples-1-for-categorical-brms-model/18463/3 "2020-10-07T12:46:09Z")

</div>

Should be fixed on github now.
