# \#integrator

**URL:** https://discourse.mc-stan.org/tag/integrator/114.md

[Latest](https://discourse.mc-stan.org/latest.md) · [Categories](https://discourse.mc-stan.org/categories.md) · [Tags](https://discourse.mc-stan.org/tags.md)

---

## [Using integrate\_1d to specify Newdistribution\_lcdf for a new distribution in the Brms package](https://discourse.mc-stan.org/t/using-integrate-1d-to-specify-newdistribution-lcdf-for-a-new-distribution-in-the-brms-package/33050)

<div class="topic-metadata">

**Author:** [@wizkid04](https://discourse.mc-stan.org/u/wizkid04)\
**Replies:** 6\
**Last updated:** [October 14, 2023, 9:29pm UTC](https://discourse.mc-stan.org/t/using-integrate-1d-to-specify-newdistribution-lcdf-for-a-new-distribution-in-the-brms-package/33050 "2023-10-14T21:29:24Z")

</div>

All, This seems to be an easy problem to me but I don’t seem to be able to find a solution. I am not sure if I should share the full code. But I decided to just share a small part. I can share more if needed. Thank you…

---

## [Little question about the error of int ( In a large longitudinal model)](https://discourse.mc-stan.org/t/little-question-about-the-error-of-int-in-a-large-longitudinal-model/31481)

<div class="topic-metadata">

**Author:** [@Steve](https://discourse.mc-stan.org/u/Steve)\
**Replies:** 2\
**Last updated:** [May 23, 2023, 3:40pm UTC](https://discourse.mc-stan.org/t/little-question-about-the-error-of-int-in-a-large-longitudinal-model/31481 "2023-05-23T15:40:59Z")

</div>

this is my stan code: data { int\<lower=1\> I; // Total number of observations int\<lower=1\> Q; // Total numbers of covariates int\<lower=1\> J; // Numbers of repeated measurements in time dimension int\<lower=1\> S; /…

---

## [Compilation error on using the Differential-Algebraic equation (DAE) solver on time that depends on the parameters](https://discourse.mc-stan.org/t/compilation-error-on-using-the-differential-algebraic-equation-dae-solver-on-time-that-depends-on-the-parameters/29404)

<div class="topic-metadata">

**Author:** [@jpferreira](https://discourse.mc-stan.org/u/jpferreira)\
**Replies:** 21\
**Last updated:** [November 17, 2022, 1:24pm UTC](https://discourse.mc-stan.org/t/compilation-error-on-using-the-differential-algebraic-equation-dae-solver-on-time-that-depends-on-the-parameters/29404 "2022-11-17T13:24:51Z")

</div>

Summary I’m trying to solve a system of differential equations using the dae solver which is available on Stan, but I encounter a compilation issue when I try to evaluate a system at a time that depends on the parameters…

---

## [1D integrator Stan model very slow](https://discourse.mc-stan.org/t/1d-integrator-stan-model-very-slow/28701)

<div class="topic-metadata">

**Author:** [@pankajb64](https://discourse.mc-stan.org/u/pankajb64)\
**Replies:** 3\
**Last updated:** [September 9, 2022, 5:54pm UTC](https://discourse.mc-stan.org/t/1d-integrator-stan-model-very-slow/28701 "2022-09-09T17:54:30Z")

</div>

Hi, I’m new to Stan and Bayesian Inference in general. I’m running a model on a relatively small dataset - vector of 40 elements and a 40x40 covariance matrix. My model involves doing a 1D integration, though. And its be…

---

## [Double integrate\_1d leads to other generated quantities being zero](https://discourse.mc-stan.org/t/double-integrate-1d-leads-to-other-generated-quantities-being-zero/27846)

<div class="topic-metadata">

**Author:** [@abeeisnotabug](https://discourse.mc-stan.org/u/abeeisnotabug)\
**Replies:** 3\
**Last updated:** [June 16, 2022, 11:21am UTC](https://discourse.mc-stan.org/t/double-integrate-1d-leads-to-other-generated-quantities-being-zero/27846 "2022-06-16T11:21:40Z")

</div>

Hi all, I’m encountering a bug (?) when trying to integrate out two parameters in a double integral via nested integrate\_1d calls. Specifically, doing the integration causes other generated quantities to be zero. I am n…

---

## [Unable to integrate function obtained from algebraic solver](https://discourse.mc-stan.org/t/unable-to-integrate-function-obtained-from-algebraic-solver/27194)

<div class="topic-metadata">

**Author:** [@jpferreira](https://discourse.mc-stan.org/u/jpferreira)\
**Replies:** 5\
**Last updated:** [April 21, 2022, 1:53pm UTC](https://discourse.mc-stan.org/t/unable-to-integrate-function-obtained-from-algebraic-solver/27194 "2022-04-21T13:53:03Z")

</div>

Hi there, I’m not being able to use Stan to fit a model where I have an integral of a function which has to be solved numerically, using Stan’s algebraic equation solver, that depends on the data, parameters and derived …

---

## [Algebra\_solver with integrate\_1d containing modified\_bessel\_first\_kind](https://discourse.mc-stan.org/t/algebra-solver-with-integrate-1d-containing-modified-bessel-first-kind/24715)

<div class="topic-metadata">

**Author:** [@Jacob\_Warren](https://discourse.mc-stan.org/u/Jacob_Warren)\
**Replies:** 0\
**Last updated:** [October 5, 2021, 1:04pm UTC](https://discourse.mc-stan.org/t/algebra-solver-with-integrate-1d-containing-modified-bessel-first-kind/24715 "2021-10-05T13:04:24Z")

</div>

I created a function for the PDF of an uncorrelated bivariate normal distribution as a function of radius (equation 17 from A Toolbox for the Radial and Angular Marginalization of Bivariate Normal Distributions (arxiv.or…

---

## [Vectorizing integrate\_1d](https://discourse.mc-stan.org/t/vectorizing-integrate-1d/24381)

<div class="topic-metadata">

**Author:** [@BFiles](https://discourse.mc-stan.org/u/BFiles)\
**Replies:** 1\
**Last updated:** [September 19, 2021, 10:53am UTC](https://discourse.mc-stan.org/t/vectorizing-integrate-1d/24381 "2021-09-19T10:53:43Z")

</div>

I find myself computing an integral (using integrate\_1d) of the same function with several different upper limits. I would like to speed this process up. To be concrete, here is a code snippet: for (i in 1:n\_trial) { …

---

## [Getting the normalizing constant by integration: positive infinity doesn't work](https://discourse.mc-stan.org/t/getting-the-normalizing-constant-by-integration-positive-infinity-doesnt-work/20907)

<div class="topic-metadata">

**Author:** [@bnicenboim](https://discourse.mc-stan.org/u/bnicenboim)\
**Replies:** 18\
**Last updated:** [March 27, 2021, 10:08pm UTC](https://discourse.mc-stan.org/t/getting-the-normalizing-constant-by-integration-positive-infinity-doesnt-work/20907 "2021-03-27T22:08:22Z")

</div>

Hi, I have here a model to fit the approximated sum of dependent variables with a gamma distribution with the same coefficient of variation (cv or tau) and thus a different rate. (I got to this monstrosity with the sadd…

---

## [Integrate\_1d() error: "The sinh\_sinh quadrature evaluated your function at a singular point, leading to the value nan."](https://discourse.mc-stan.org/t/integrate-1d-error-the-sinh-sinh-quadrature-evaluated-your-function-at-a-singular-point-leading-to-the-value-nan/20614)

<div class="topic-metadata">

**Author:** [@karimn](https://discourse.mc-stan.org/u/karimn)\
**Replies:** 16\
**Last updated:** [February 11, 2021, 8:48pm UTC](https://discourse.mc-stan.org/t/integrate-1d-error-the-sinh-sinh-quadrature-evaluated-your-function-at-a-singular-point-leading-to-the-value-nan/20614 "2021-02-11T20:48:04Z")

</div>

Hi, I previously had a thread on some similar issues with integrate\_1d() here. https://discourse.mc-stan.org/t/calling-integrate-1d-reports-parsing-error-parser-expected/19611 I’m starting a new thread since the previ…

---

## [Integrate\_1d in likelihood computation produces NaNs in the gradient](https://discourse.mc-stan.org/t/integrate-1d-in-likelihood-computation-produces-nans-in-the-gradient/20506)

<div class="topic-metadata">

**Author:** [@abeeisnotabug](https://discourse.mc-stan.org/u/abeeisnotabug)\
**Replies:** 18\
**Last updated:** [February 5, 2021, 5:02pm UTC](https://discourse.mc-stan.org/t/integrate-1d-in-likelihood-computation-produces-nans-in-the-gradient/20506 "2021-02-05T17:02:46Z")

</div>

Dear Stan Community, I am trying to use the integrate\_1d function to integrate parameters out of my likelihood, but I get the error Exception: gradient\_of\_f: The gradient of f is nan for parameter 0. I vastly simplifie…

---

## [Source code for integrate\_1d](https://discourse.mc-stan.org/t/source-code-for-integrate-1d/19812)

<div class="topic-metadata">

**Author:** [@abeeisnotabug](https://discourse.mc-stan.org/u/abeeisnotabug)\
**Replies:** 6\
**Last updated:** [December 16, 2020, 12:50am UTC](https://discourse.mc-stan.org/t/source-code-for-integrate-1d/19812 "2020-12-16T00:50:06Z")

</div>

Dear all, to my great shame I have to admit that I couldn’t find the source code for the integrate\_1d function in the stan-dev GitHub repo and I would be really glad if someone could point my to it or just paste it here…

---

## [Calling integrate\_1d() reports parsing error (PARSER EXPECTED ")")](https://discourse.mc-stan.org/t/calling-integrate-1d-reports-parsing-error-parser-expected/19611)

<div class="topic-metadata">

**Author:** [@karimn](https://discourse.mc-stan.org/u/karimn)\
**Replies:** 24\
**Last updated:** [December 9, 2020, 4:22am UTC](https://discourse.mc-stan.org/t/calling-integrate-1d-reports-parsing-error-parser-expected/19611 "2020-12-09T04:22:13Z")

</div>

Is it permitted to call integrate\_1d() inside a function called by algebra\_solver()? My code is below. I’m getting this error error in '/takeup\_header.stan' at line 102, column 139 included from 'model14806083057\_take…

---

## [Problem computing integrals](https://discourse.mc-stan.org/t/problem-computing-integrals/17887)

<div class="topic-metadata">

**Author:** [@evihas](https://discourse.mc-stan.org/u/evihas)\
**Replies:** 5\
**Last updated:** [September 18, 2020, 8:21pm UTC](https://discourse.mc-stan.org/t/problem-computing-integrals/17887 "2020-09-18T20:21:38Z")

</div>

Hi all, This is my first program using Rstan and I am trying to do parameter estimation using attached code herewith and data table. Here K=3 , tstar = 62, n is the number of rows and m is the number of columns of data …

---

## [Integrate\_1d errors in stan](https://discourse.mc-stan.org/t/integrate-1d-errors-in-stan/17975)

<div class="topic-metadata">

**Author:** [@evihas](https://discourse.mc-stan.org/u/evihas)\
**Replies:** 8\
**Last updated:** [September 17, 2020, 10:47pm UTC](https://discourse.mc-stan.org/t/integrate-1d-errors-in-stan/17975 "2020-09-17T22:47:39Z")

</div>

Hi all, I am trying to run following stan code with CmdStanR to estimate parameters. These are the several equations in my model D\_{1,t\_{0}}=\\beta(t\_{0})\\int\_{0}^{t\_{0}}w(x)Q(t\_{0}-x)dx D\_{k,t\_{0}}=\\beta(t\_{k-1})\\Big…

---

## [Using integration to fit the difference of gamma distributed random variable](https://discourse.mc-stan.org/t/using-integration-to-fit-the-difference-of-gamma-distributed-random-variable/16039)

<div class="topic-metadata">

**Author:** [@bnicenboim](https://discourse.mc-stan.org/u/bnicenboim)\
**Replies:** 15\
**Last updated:** [July 4, 2020, 6:36am UTC](https://discourse.mc-stan.org/t/using-integration-to-fit-the-difference-of-gamma-distributed-random-variable/16039 "2020-07-04T06:36:48Z")

</div>

Hi, I’m trying to fit data that represents the difference between latent random variable that are gamma distributed (with the same rate). I’m obviously not succeeding. I generate my data like this in r. Basically I wa…

---

## [Integrator\_1d relative tolerance argument error](https://discourse.mc-stan.org/t/integrator-1d-relative-tolerance-argument-error/16106)

<div class="topic-metadata">

**Author:** [@sanketrane](https://discourse.mc-stan.org/u/sanketrane)\
**Replies:** 10\
**Last updated:** [July 3, 2020, 10:58pm UTC](https://discourse.mc-stan.org/t/integrator-1d-relative-tolerance-argument-error/16106 "2020-07-03T22:58:45Z")

</div>

I am trying to use integrator\_1d in Rstan but it fails to run and keeps asking for the seventh argument, which I think is relative tolerance and according to the manual definition is optional. y\_solve = integrate\_1d(in…

---

## [The result of integrate\_1d is confusing](https://discourse.mc-stan.org/t/the-result-of-integrate-1d-is-confusing/15391)

<div class="topic-metadata">

**Author:** [@wwguo](https://discourse.mc-stan.org/u/wwguo)\
**Replies:** 2\
**Last updated:** [June 3, 2020, 8:15am UTC](https://discourse.mc-stan.org/t/the-result-of-integrate-1d-is-confusing/15391 "2020-06-03T08:15:43Z")

</div>

I use the normal\_density function provided by stan-users-guide: real normal\_density(real x, real xc, real\[\] theta, real\[\] x\_r, int\[\] x\_i) { real mu = theta\[1\]; real sigma = theta\[2\]; return 1 / (sqrt(2 \* pi()) \* s…

---

## [Using 1D numerical integration for doubly-intractable distributions](https://discourse.mc-stan.org/t/using-1d-numerical-integration-for-doubly-intractable-distributions/14154)

<div class="topic-metadata">

**Author:** [@Ellis\_Scharfenaker](https://discourse.mc-stan.org/u/Ellis_Scharfenaker)\
**Replies:** 3\
**Last updated:** [April 7, 2020, 5:22pm UTC](https://discourse.mc-stan.org/t/using-1d-numerical-integration-for-doubly-intractable-distributions/14154 "2020-04-07T17:22:25Z")

</div>

I am trying to fit the following four-parameter distribution in Stan, which is similar to the Subbotin distribution, but doesn’t have a closed-form expression. The kernel is: f(x|\\mu, T, \\gamma, \\phi) \\propto \\left(\\fra…
