# Stan's integral estimates exceeds the given relative tolerance times norm of integral

**URL:** https://discourse.mc-stan.org/t/stans-integral-estimates-exceeds-the-given-relative-tolerance-times-norm-of-integral/40225
**Category:** Modeling
**Created:** [August 20, 2025, 3:12am UTC](https://discourse.mc-stan.org/t/stans-integral-estimates-exceeds-the-given-relative-tolerance-times-norm-of-integral/40225 "2025-08-20T03:12:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RuimingDiao](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ruimingdiao/32/20903_2.png) [@RuimingDiao](https://discourse.mc-stan.org/u/RuimingDiao)
#### Post date: [August 20, 2025, 3:12am UTC](https://discourse.mc-stan.org/t/stans-integral-estimates-exceeds-the-given-relative-tolerance-times-norm-of-integral/40225/1 "2025-08-20T03:12:03Z")

</div>

In my stan program integrals are involved, and stan returns errors like

```no-highlight
integrate: error estimate of integral 1.4822e-323 exceeds the given relative tolerance times norm of integral

```

I have tried to set rather loose relative tolerance, like 10^{-2}

```no-highlight
integrate_1d(functionintegrand, 1e-6,x,{mu, lambda}, {1.0}, x_i,1e-2)

```

But then the error still exists, and this time the error estimate becomes larger, like

```no-highlight
integrate: error estimate of integral 0.0018877 exceeds the given relative tolerance times norm of integral

```

Is this caused by looser relative tolerance causes Stan to execute Gauss–Kronrod algorithm also in a ‘looser‘ way and therefore producing larger error estimate? Would it be possible to use other ways to solve the error of error estimate of integral exceeding given relative tolerance times norm of integral?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![kaskogsholm](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/kaskogsholm/32/19209_2.png) [@kaskogsholm](https://discourse.mc-stan.org/u/kaskogsholm)
#### Post date: [August 20, 2025, 4:54pm UTC](https://discourse.mc-stan.org/t/stans-integral-estimates-exceeds-the-given-relative-tolerance-times-norm-of-integral/40225/2 "2025-08-20T16:54:40Z")

</div>

I believe, based on [this](https://github.com/stan-dev/math/blob/develop/stan/math/prim/functor/integrate_1d.hpp) source code, that Stan uses double-exponential quadrature for integrate\_1d with implementation provided by Boost. Docs on those functions here: [Overview](https://www.boost.org/doc/libs/1_66_0/libs/math/doc/html/math_toolkit/double_exponential/de_overview.html)

Can you share more of your code, particularly the function you are integrating and enough of the other blocks to deduce the values of the parameters and integration ranges.

I’m no expert, but the first error, with the error estimate at a ridiculously low number, indicates that either the relative tolerance was set ridiculously low, or the norm of the integral is essentially 0, for some reason.

---

<div class="post-metadata">

### Author: ![RuimingDiao](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ruimingdiao/32/20903_2.png) [@RuimingDiao](https://discourse.mc-stan.org/u/RuimingDiao)
#### Post date: [August 20, 2025, 8:02pm UTC](https://discourse.mc-stan.org/t/stans-integral-estimates-exceeds-the-given-relative-tolerance-times-norm-of-integral/40225/3 "2025-08-20T20:02:11Z")

</div>

Thanks! After checking the code, I found that the problem is caused by computing c.d.f. of inverse Gaussian distribution by integrating its p.d.f., instead of using the closed form c.d.f. . After I computed the c.d.f. by closed form directly the error disappeared.
