# Negative binomial regression and right censored data not working at higher values

**URL:** <https://discourse.mc-stan.org/t/negative-binomial-regression-and-right-censored-data-not-working-at-higher-values/29150>\
**Category:** brms\
**Tags:** brms, fitting-issues\
**Created:** [October 17, 2022, 2:02pm UTC](https://discourse.mc-stan.org/t/negative-binomial-regression-and-right-censored-data-not-working-at-higher-values/29150 "2022-10-17T14:02:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wseis](https://avatars.discourse-cdn.com/v4/letter/w/65b543/32.png) [@wseis](https://discourse.mc-stan.org/u/wseis)\
**Post date:** [October 17, 2022, 2:02pm UTC](https://discourse.mc-stan.org/t/negative-binomial-regression-and-right-censored-data-not-working-at-higher-values/29150/1 "2022-10-17T14:02:48Z")

</div>

I would like to fit a negative binomial distribution to a dataset, which sometimes shows right censored data, only showing values like \> 70000. Numbers a generally very high in the dataset as it bacteria counts.

I tried to do so, by running:

```nohighlight
brm(bf(y | cens (censored) ~1), data = data)

```

I received the following error:

```nohighlight
Chain 1: Rejecting initial value:
Chain 1: Log probability evaluates to log(0), i.e. negative infinity.
Chain 1: Stan can't start sampling from this initial value.

```

To debug I created some testdata, using a Poisson, and included a single right censored indicator, like this:

```nohighlight
df <- data.frame(y = rpois(100, lambda))

df$cens <- ifelse(df$y == max(df$y), 1, 0)

model <- brm(bf(y|cens(cens) ~ 1), 
          family = "negbinomial", 
          data = d)

```

For lambda = 50 it still works, however, for lambda = 5000 it shows the same error. (I did not try to find out at which point exactly the problem starts to occur).

Does anyone know about this behaviour and how to solve it?

Best,

- Operating System: Windows 10
- brms Version: 2.16.1

---

<div class="post-metadata">

**Author:** ![JLC](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jlc/32/12520_2.png) [@JLC](https://discourse.mc-stan.org/u/JLC)\
**Post date:** [October 17, 2022, 5:23pm UTC](https://discourse.mc-stan.org/t/negative-binomial-regression-and-right-censored-data-not-working-at-higher-values/29150/2 "2022-10-17T17:23:18Z")

</div>

You may have to specify some initial values for key parameters.

---

<div class="post-metadata">

**Author:** ![LucC](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/lucc/32/4475_2.png) [@LucC](https://discourse.mc-stan.org/u/LucC)\
**Post date:** [October 17, 2022, 8:20pm UTC](https://discourse.mc-stan.org/t/negative-binomial-regression-and-right-censored-data-not-working-at-higher-values/29150/3 "2022-10-17T20:20:26Z")

</div>

Agreed, you probably need a higher mean for your NB or Poisson distribution for initialisation so the very-close-to-zero probability of an extremely high, censored value doesn’t underflow to negative infinity on the log-probability scale.

---

<div class="post-metadata">

**Author:** ![JLC](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jlc/32/12520_2.png) [@JLC](https://discourse.mc-stan.org/u/JLC)\
**Post date:** [October 18, 2022, 2:48pm UTC](https://discourse.mc-stan.org/t/negative-binomial-regression-and-right-censored-data-not-working-at-higher-values/29150/4 "2022-10-18T14:48:30Z")

</div>

@Solomon wrote up a [very nice post](https://solomonkurz.netlify.app/post/2021-06-05-don-t-forget-your-inits/) about how to set initial values for `brms`.
