Skip to content

Commit 1a3ffa1

Browse files
authored
Merge pull request #924 from stan-dev/wiener-cdf-docs
Documentation for the wiener cdf functions
2 parents bcd1d2e + cb1482b commit 1a3ffa1

3 files changed

Lines changed: 169 additions & 10 deletions

File tree

‎src/bibtex/all.bib‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ @article{turing:1936
274274
volume={58}, number={345-363}, pages={5}, year={1936}
275275
}
276276

277-
277+
278278
@article{kucukelbir:2015,
279279
title={Automatic variational inference in Stan}, author={Kucukelbir, Alp and
280280
Ranganath, Rajesh and Gelman, Andrew and Blei, David}, journal={Advances in
@@ -1273,7 +1273,7 @@ @article{Timonen+etal:2023:ODE-PSIS
12731273
title={An importance sampling approach for reliable and efficient inference in
12741274
{Bayesian} ordinary differential equation models}, author={Timonen, Juho and
12751275
Siccha, Nikolas and Bales, Ben and L{\"a}hdesm{\"a}ki, Harri and Vehtari,
1276-
Aki}, journal={Stat}, year={2023}, volume = 12, number = 1, pages = {e614}
1276+
Aki}, journal={Stat}, year={2023}, volume = 12, number = 1, pages = {e614}
12771277
}
12781278

12791279
@article{Vehtari+etal:2024:PSIS,
@@ -1332,3 +1332,23 @@ @article{sklar1959
13321332
journal={The Original Document and an English Translation (March 3, 2023)},
13331333
year={1959}
13341334
}
1335+
1336+
@article{Henrich2024,
1337+
author={Henrich, Franziska
1338+
and Hartmann, Raphael
1339+
and Pratz, Valentin
1340+
and Voss, Andreas
1341+
and Klauer, Karl Christoph},
1342+
title={The Seven-parameter Diffusion Model: an Implementation in Stan for Bayesian Analyses},
1343+
journal={Behavior Research Methods},
1344+
year={2024},
1345+
month={Jun},
1346+
day={01},
1347+
volume={56},
1348+
number={4},
1349+
pages={3102-3116},
1350+
issn={1554-3528},
1351+
doi={10.3758/s13428-023-02179-1},
1352+
url={https://doi.org/10.3758/s13428-023-02179-1}
1353+
}
1354+

‎src/functions-reference/functions_index.qmd‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/functions-reference/positive_lower-bounded_distributions.qmd‎

Lines changed: 135 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ For a description of argument and return types, see section
157157

158158
## Wiener First Passage Time Distribution
159159

160+
For an extended explanation of how to use the `wiener_lpdf` and
161+
`wiener_l[c]cdf_unnorm` functions, see @Henrich2024.
162+
160163
### Probability density function
161164

162165
If $\alpha \in \mathbb{R}^+$, $\tau \in \mathbb{R}^+$, $\beta \in (0, 1)$,
@@ -204,8 +207,8 @@ In the case where $s_{\delta}$, $s_{\beta}$, and $s_{\tau}$ are all $0$, this si
204207
\frac{\alpha}{(y-\tau)^{3/2}} \exp \! \left(- \delta \alpha \beta -
205208
\frac{\delta^2(y-\tau)}{2}\right) \sum_{k = - \infty}^{\infty} (2k +
206209
\beta) \phi \! \left(\frac{(2k + \beta)\alpha }{\sqrt{y - \tau}}\right),
207-
\end{equation*} where $\phi(x)$ denotes the standard normal density function;
208-
210+
\end{equation*}
211+
where $\phi(x)$ denotes the standard normal density function,
209212
and one representation that converges fast for large reaction-time values ("large time expansion"):
210213
\begin{equation*}
211214
\text{Wiener}(y|\alpha, \tau, \beta, \delta) =
@@ -215,6 +218,56 @@ and one representation that converges fast for large reaction-time values ("larg
215218
\end{equation*}
216219
see [@Feller1968], [@NavarroFuss2009].
217220

221+
### Cumulative distribution function
222+
223+
For the cumulative distribution function (cdf) there also exist two expressions
224+
depending on the reaction time.
225+
226+
Let $\alpha$, $\tau$, $\beta$, $\delta$, $s_{\delta}$, $s_{\beta}$, $s_{\tau}$
227+
and $y$ be as above.
228+
229+
The formula for the large-time cdf of decision times (excluding the additive
230+
reaction time components summarized in $\tau$ for the time being) at the upper
231+
boundary is stated as follows:
232+
233+
\begin{equation}
234+
F(y|\alpha, \beta, \delta) = P(\alpha, \beta, \delta) -
235+
\exp\left(\delta\alpha(1-\beta)-\frac{\delta^2 y}{2}\right)F_l(y|\alpha,\beta,\delta),
236+
\end{equation}
237+
where $P(\alpha,\beta,\delta)$ is the probability to hit the upper boundary, defined as
238+
239+
\begin{equation}
240+
P(\alpha, \beta, \delta) =
241+
\begin{cases}
242+
\frac{1-\exp(2\delta \alpha \beta)}{\exp(-2\delta \alpha(1-\beta)) - \exp(2\delta \alpha \beta)}, & \text{for } \delta\neq 0 \\
243+
\beta, & \text{for } \delta=0,
244+
\end{cases}
245+
\end{equation}
246+
247+
and
248+
249+
\begin{equation}
250+
F_l(y|\alpha, \beta, \delta) =
251+
\frac{2\pi}{\alpha^2}\sum_{k=1}^{\infty}{\frac{k\sin{k\pi(1-\beta)}}{\delta^2+(k\pi)^2/\alpha^2}}\exp(-\frac{k^2\pi^2y}{2\alpha^2}).
252+
\end{equation}
253+
254+
255+
The formula for the small-time cdf at the upper boundary is stated as follows:
256+
257+
\begin{equation}
258+
F(y|\alpha,\beta,\delta) = \exp\left(\delta \alpha(1-\beta) -\frac{\delta^2y}{2}\right)F_s(y|\alpha, \beta,\delta),
259+
\end{equation} where
260+
261+
\begin{equation}
262+
F_s(y|\alpha,\beta,\delta) = \sum_{k=0}^{\infty}(-1)^k\phi\left(\frac{\alpha(k+\beta^{*}_k)}
263+
{\sqrt{y}} \right) \times \left( R \left(\frac{\alpha(k+\beta^{*}_k)+\delta y}{\sqrt{y}} \right)
264+
+ R \left(\frac{\alpha(k+\beta^*_k)-\delta y}{\sqrt{y}} \right)\right),
265+
\end{equation}
266+
267+
where $\beta^*_k=(1-\beta)$ for $k$ even, $\beta^*_k=\beta$ for $k$ odd, and $R$ is Mill's ratio.
268+
269+
The cdf for the lower boundary is $F(y|\alpha,1-\beta,-\delta)$
270+
218271
### Distribution statement
219272

220273
`y ~ ` **`wiener`**`(alpha, tau, beta, delta)`
@@ -240,7 +293,7 @@ Increment target log probability density with `wiener_lupdf(y | alpha, tau, beta
240293

241294
`real` **`wiener_lpdf`**`(reals y | reals alpha, reals tau, reals beta, reals delta)`<br>\newline
242295
The log of the Wiener first passage time density of `y` given boundary
243-
separation `alpha`, non-decision time `tau`, a-priori bias `beta`, and drift
296+
separation `alpha`, non-decision time `tau`, starting point `beta`, and drift
244297
rate `delta`.
245298
{{< since 2.18 >}}
246299

@@ -249,7 +302,7 @@ rate `delta`.
249302

250303
`real` **`wiener_lpdf`**`(real y | real alpha, real tau, real beta, real delta, real var_delta)`<br>\newline
251304
The log of the Wiener first passage time density of `y` given boundary
252-
separation `alpha`, non-decision time `tau`, a-priori bias `beta`, drift
305+
separation `alpha`, non-decision time `tau`, starting point `beta`, drift
253306
rate `delta`, and inter-trial drift rate variability `var_delta`.
254307

255308
Setting `var_delta` to `0` recovers the 4-parameter signature above.
@@ -260,7 +313,7 @@ Setting `var_delta` to `0` recovers the 4-parameter signature above.
260313

261314
`real` **`wiener_lpdf`**`(real y | real alpha, real tau, real beta, real delta, real var_delta, real var_beta, real var_tau)`<br>\newline
262315
The log of the Wiener first passage time density of `y` given boundary
263-
separation `alpha`, non-decision time `tau`, a-priori bias `beta`, drift
316+
separation `alpha`, non-decision time `tau`, starting point `beta`, drift
264317
rate `delta`, inter-trial drift rate variability `var_delta`, inter-trial
265318
variability of the starting point (bias) `var_beta`, and inter-trial variability
266319
of the non-decision time `var_tau`.
@@ -273,7 +326,7 @@ Setting `var_delta`, `var_beta`, and `var_tau` to `0` recovers the 4-parameter s
273326

274327
`real` **`wiener_lupdf`**`(reals y | reals alpha, reals tau, reals beta, reals delta)`<br>\newline
275328
The log of the Wiener first passage time density of `y` given boundary
276-
separation `alpha`, non-decision time `tau`, a-priori bias `beta`, and drift
329+
separation `alpha`, non-decision time `tau`, starting point `beta`, and drift
277330
rate `delta`, dropping constant additive terms
278331
{{< since 2.25 >}}
279332

@@ -283,7 +336,7 @@ rate `delta`, dropping constant additive terms
283336

284337
`real` **`wiener_lupdf`**`(real y | real alpha, real tau, real beta, real delta, real var_delta)`<br>\newline
285338
The log of the Wiener first passage time density of `y` given boundary
286-
separation `alpha`, non-decision time `tau`, a-priori bias `beta`, drift
339+
separation `alpha`, non-decision time `tau`, starting point `beta`, drift
287340
rate `delta`, and inter-trial drift rate variability `var_delta`,
288341
dropping constant additive terms.
289342

@@ -295,14 +348,72 @@ Setting `var_delta` to `0` recovers the 4-parameter signature above.
295348

296349
`real` **`wiener_lupdf`**`(real y | real alpha, real tau, real beta, real delta, real var_delta, real var_beta, real var_tau)`<br>\newline
297350
The log of the Wiener first passage time density of `y` given boundary
298-
separation `alpha`, non-decision time `tau`, a-priori bias `beta`, drift
351+
separation `alpha`, non-decision time `tau`, starting point `beta`, drift
299352
rate `delta`, inter-trial drift rate variability `var_delta`, inter-trial
300353
variability of the starting point (bias) `var_beta`, and inter-trial variability
301354
of the non-decision time `var_tau`, dropping constant additive terms.
302355

303356
Setting `var_delta`, `var_beta`, and `var_tau` to `0` recovers the 4-parameter signature above.
304357
{{< since 2.35 >}}
305358

359+
---
360+
361+
**Note:** The `lcdf` and `lccdf` functions for the `wiener` distribution are
362+
conditional and unnormalized, meaning that the cdf does not asymptote at 1,
363+
but rather at the probability to hit the upper [boundary](#boundaries).
364+
365+
Similarly, the ccdf is defined as the probability to hit the upper boundary less
366+
the value of the cdf, as opposed to the more typical $1 - \textrm{cdf}$.
367+
368+
369+
<!-- real; wiener_lcdf_unnorm; (real y, real alpha, real tau, real beta, real delta); -->
370+
\index{{\tt \bfseries wiener\_lcdf\_unnorm }!{\tt (real y, real alpha, real tau, real beta, real delta): real}|hyperpage}
371+
372+
`real` **`wiener_lcdf_unnorm`**`(real y, real alpha, real tau, real beta, real delta)`<br>\newline
373+
374+
The log of the cumulative distribution function (cdf) of the Wiener distribution
375+
of `y` given boundary separation `alpha`, non-decision time `tau`, starting point
376+
`beta`, and drift rate `delta`.
377+
378+
{{< since 2.38 >}}
379+
380+
<!-- real; wiener_lccdf_unnorm; (real y, real alpha, real tau, real beta, real delta); -->
381+
\index{{\tt \bfseries wiener\_lccdf\_unnorm }!{\tt (real y, real alpha, real tau, real beta, real delta): real}|hyperpage}
382+
383+
`real` **`wiener_lccdf_unnorm`**`(real y, real alpha, real tau, real beta, real delta)`<br>\newline
384+
385+
The log of the complementary cumulative distribution function (ccdf) of the
386+
Wiener distribution of `y` given boundary separation `alpha`, non-decision time
387+
`tau`, starting point `beta`, and drift rate `delta`.
388+
389+
{{< since 2.38 >}}
390+
391+
<!-- real; wiener_lcdf_unnorm; (real y, real alpha, real tau, real beta, real delta, real var_delta, real var_beta, real var_tau); -->
392+
\index{{\tt \bfseries wiener\_lcdf\_unnorm }!{\tt (real y, real alpha, real tau, real beta, real delta, real var\_delta, real var\_beta, real var\_tau): real}|hyperpage}
393+
394+
`real` **`wiener_lcdf_unnorm`**`(real y, real alpha, real tau, real beta, real delta, real var_delta, real var_beta, real var_tau)`<br>\newline
395+
396+
The log of the cumulative distribution function (cdf) of the Wiener distribution
397+
of `y` given boundary separation `alpha`, non-decision time `tau`, starting point
398+
`beta`, drift rate `delta`, inter-trial drift rate variability `var_delta`,
399+
inter-trial variability of the starting point (bias) `var_beta`, and inter-trial
400+
variability of the non-decision time `var_tau`.
401+
402+
{{< since 2.38 >}}
403+
404+
405+
<!-- real; wiener_lccdf_unnorm; (real y, real alpha, real tau, real beta, real delta, real var_delta, real var_beta, real var_tau); -->
406+
\index{{\tt \bfseries wiener\_lccdf\_unnorm }!{\tt (real y, real alpha, real tau, real beta, real delta, real var\_delta, real var\_beta, real var\_tau): real}|hyperpage}
407+
408+
`real` **`wiener_lccdf_unnorm`**`(real y, real alpha, real tau, real beta, real delta, real var_delta, real var_beta, real var_tau)`<br>\newline
409+
410+
The log of the complementary cumulative distribution function (ccdf) of the
411+
Wiener distribution of `y` given boundary separation `alpha`, non-decision time
412+
`tau`, starting point `beta`, drift rate `delta`, inter-trial drift rate
413+
variability `var_delta`, inter-trial variability of the starting point (bias)
414+
`var_beta`, and inter-trial variability of the non-decision time `var_tau`.
415+
416+
{{< since 2.38 >}}
306417

307418
### Boundaries
308419

@@ -312,3 +423,19 @@ the upper boundary only. To get the result for the lower boundary, use
312423
\text{Wiener}(y | \alpha, \tau, 1 - \beta, - \delta)
313424
\end{equation*}
314425
For more details, see the appendix of @Vandekerckhove-Wabersich:2014.
426+
427+
### Vectorization
428+
429+
The 5- and 7-argument forms of the `wiener` distribution functions (listed above
430+
as recieving only `real`) are implemented in such a way where they can be
431+
fully [vectorized](conventions_for_probability_functions.qmd#prng-vectorization),
432+
but currently only versions that accept all `real` and all `vector` arguments
433+
are exposed by Stan. If there are additional signatures that would prove useful,
434+
please request them by [opening an issue](https://github.com/stan-dev/stanc3/issues/new).
435+
436+
### Tolerance tuning
437+
438+
The 5- and 7-argument forms of the `wiener` distribution functions can also
439+
accept an additional `data real` argument controlling the required precision of
440+
the gradient calculation of the function. If omitted, this defaults to `1e-4`
441+
for the density and `1e-8` for the cdf functions.

0 commit comments

Comments
 (0)