# Algorithms

**URL:** https://discourse.mc-stan.org/c/algorithms/18.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)

---

## [About the Algorithms category](https://discourse.mc-stan.org/t/about-the-algorithms-category/30)

<div class="topic-metadata">

**Author:** [@betanalpha](https://discourse.mc-stan.org/u/betanalpha)\
**Replies:** 0

</div>

This category is for questions about the algorithms in Stan and how best to use them.

---

## [Models where Stan outperforms Nutpie/Walnuts](https://discourse.mc-stan.org/t/models-where-stan-outperforms-nutpie-walnuts/41095)

<div class="topic-metadata">

**Author:** [@ssp3nc3r](https://discourse.mc-stan.org/u/ssp3nc3r)\
**Replies:** 47\
**Last updated:** [July 21, 2026, 5:30am UTC](https://discourse.mc-stan.org/t/models-where-stan-outperforms-nutpie-walnuts/41095 "2026-07-21T05:30:28Z")

</div>

I think it would be incredibly valuable to add more models to posteriordb. It has a lot of small models, and a few very big but close to intractable models. Adding more big … I agree. Not sure whether this is the righ…

---

## [Monte Carlo error for Pathfinder fit](https://discourse.mc-stan.org/t/monte-carlo-error-for-pathfinder-fit/40939)

<div class="topic-metadata">

**Author:** [@fweber144](https://discourse.mc-stan.org/u/fweber144)\
**Replies:** 2\
**Last updated:** [March 1, 2026, 8:53pm UTC](https://discourse.mc-stan.org/t/monte-carlo-error-for-pathfinder-fit/40939 "2026-03-01T20:53:28Z")

</div>

When fitting a model using the Pathfinder algorithm (via cmdstanr, for example), is there a recommended way to judge the Monte Carlo error (i.e., to estimate the MCSE for a specific parameter, for example)? I’ve tried to…

---

## [Estimate time to run HMC](https://discourse.mc-stan.org/t/estimate-time-to-run-hmc/40933)

<div class="topic-metadata">

**Author:** [@bduque10](https://discourse.mc-stan.org/u/bduque10)\
**Replies:** 5\
**Last updated:** [February 19, 2026, 4:45am UTC](https://discourse.mc-stan.org/t/estimate-time-to-run-hmc/40933 "2026-02-19T04:45:29Z")

</div>

Hi. I have a computationally expensive individual-level model (~330 parameters, ~134K observations) where one of the computation chunks takes ~93% of the time. I’m using CmdStanR. Meanfield VI fits in about 30 minutes w…

---

## [Optimize (and thus Laplace) yields biased estimates](https://discourse.mc-stan.org/t/optimize-and-thus-laplace-yields-biased-estimates/40650)

<div class="topic-metadata">

**Author:** [@trinhdhk](https://discourse.mc-stan.org/u/trinhdhk)\
**Replies:** 4\
**Last updated:** [November 18, 2025, 6:46pm UTC](https://discourse.mc-stan.org/t/optimize-and-thus-laplace-yields-biased-estimates/40650 "2025-11-18T18:46:58Z")

</div>

Stan optimizing seems to yield biased MAP estimates in weighted model, especially for scale parameters. Attached is the cmdstanr model (modified from brms) together with the corresponding standata. stan-opt.Rdata (599.…

---

## [Diagnostics for Mixture IS leave-one-out cross-validation?](https://discourse.mc-stan.org/t/diagnostics-for-mixture-is-leave-one-out-cross-validation/39864)

<div class="topic-metadata">

**Author:** [@ruarai](https://discourse.mc-stan.org/u/ruarai)\
**Replies:** 1\
**Last updated:** [July 21, 2025, 6:27pm UTC](https://discourse.mc-stan.org/t/diagnostics-for-mixture-is-leave-one-out-cross-validation/39864 "2025-07-21T18:27:14Z")

</div>

Hi all, I’m currently trying to implement some model comparison metrics for a high-dimensional model. I don’t have a MWE to share, but there’s a writeup of a previous implementation of the model here: Timescales of inf…

---

## [LOO-CV for joint models](https://discourse.mc-stan.org/t/loo-cv-for-joint-models/39454)

<div class="topic-metadata">

**Author:** [@tjmckinley](https://discourse.mc-stan.org/u/tjmckinley)\
**Replies:** 8\
**Last updated:** [May 12, 2025, 7:43am UTC](https://discourse.mc-stan.org/t/loo-cv-for-joint-models/39454 "2025-05-12T07:43:23Z")

</div>

Hi all, I have been playing around with a joint model for two variables (Y, D), where the likelihood function can be written in the form f(Y | D)P(D), where Y is say Gaussian and D is say Bernoulli. I would like to use …

---

## [Is the posterior from ADVI always normal?](https://discourse.mc-stan.org/t/is-the-posterior-from-advi-always-normal/39215)

<div class="topic-metadata">

**Author:** [@fdvanleeuwen](https://discourse.mc-stan.org/u/fdvanleeuwen)\
**Replies:** 6\
**Last updated:** [April 7, 2025, 4:01pm UTC](https://discourse.mc-stan.org/t/is-the-posterior-from-advi-always-normal/39215 "2025-04-07T16:01:50Z")

</div>

While using mean-field ADVI to estimate a penalised regression model with a horseshoe prior, I obtain posteriors for the regression coefficients that are skewed. Below is the code to generate some data and run two model…

---

## [Origin of cutoff point 1000 for a divergence](https://discourse.mc-stan.org/t/origin-of-cutoff-point-1000-for-a-divergence/38601)

<div class="topic-metadata">

**Author:** [@aseyboldt](https://discourse.mc-stan.org/u/aseyboldt)\
**Replies:** 6\
**Last updated:** [March 9, 2025, 2:50pm UTC](https://discourse.mc-stan.org/t/origin-of-cutoff-point-1000-for-a-divergence/38601 "2025-03-09T14:50:11Z")

</div>

We usually say a trajectory in HMC is diverging as soon as the energy error goes above 1000. For a while now, I’ve commonly used much lower cutoff values to diagnose sampling issues. If the limit is lower, we typically …

---

## [Laplace Approximation for High-Dimensional Penalized Regression](https://discourse.mc-stan.org/t/laplace-approximation-for-high-dimensional-penalized-regression/38790)

<div class="topic-metadata">

**Author:** [@fdvanleeuwen](https://discourse.mc-stan.org/u/fdvanleeuwen)\
**Replies:** 1\
**Last updated:** [February 14, 2025, 8:39pm UTC](https://discourse.mc-stan.org/t/laplace-approximation-for-high-dimensional-penalized-regression/38790 "2025-02-14T20:39:21Z")

</div>

I am comparing some algorithms for high-dimensional penalized regression, using a regularized horseshoe prior. This is the model code: // generated with brms 2.22.0 functions { /\* Efficient computation of the horsesho…

---

## [Developing a Deeper Intuition for HMC: Connecting the Underlying Concepts with the Hamiltonian Equations](https://discourse.mc-stan.org/t/developing-a-deeper-intuition-for-hmc-connecting-the-underlying-concepts-with-the-hamiltonian-equations/38450)

<div class="topic-metadata">

**Author:** [@karl](https://discourse.mc-stan.org/u/karl)\
**Replies:** 10\
**Last updated:** [January 17, 2025, 1:32pm UTC](https://discourse.mc-stan.org/t/developing-a-deeper-intuition-for-hmc-connecting-the-underlying-concepts-with-the-hamiltonian-equations/38450 "2025-01-17T13:32:50Z")

</div>

I’m trying to develop a deeper understanding of HMC and how the sampling in Stan works, but it has proven to be difficult given the two main sources (Neal, Betancourt) that are out there. Most other tutorials are just co…

---

## [P-value from Bayesian Logistic Regression](https://discourse.mc-stan.org/t/p-value-from-bayesian-logistic-regression/37547)

<div class="topic-metadata">

**Author:** [@Agnes](https://discourse.mc-stan.org/u/Agnes)\
**Replies:** 4\
**Last updated:** [December 10, 2024, 7:41pm UTC](https://discourse.mc-stan.org/t/p-value-from-bayesian-logistic-regression/37547 "2024-12-10T19:41:50Z")

</div>

Hi all. I have run the analysis using frequentist approach logistic regression. To know whether the independent variable is significant, I will be looking into the p-value. Then, I repeat the same process by using Bayes…

---

## [Pathfinder failure without hint why it failed](https://discourse.mc-stan.org/t/pathfinder-failure-without-hint-why-it-failed/37248)

<div class="topic-metadata">

**Author:** [@Benjamin\_Kambs](https://discourse.mc-stan.org/u/Benjamin_Kambs)\
**Replies:** 12\
**Last updated:** [November 19, 2024, 8:35pm UTC](https://discourse.mc-stan.org/t/pathfinder-failure-without-hint-why-it-failed/37248 "2024-11-19T20:35:12Z")

</div>

Hello there! I am currently modifying Facebook’s Prophet to my needs. In contrast to Prophet I use the Pathfinder algorithm which works in most cases. However, I encounter an error on some occasions. The error doesn’t t…

---

## [Issues with differences between MCMC and Pathfinder results; how to make Pathfinder(or something else) more accurate?](https://discourse.mc-stan.org/t/issues-with-differences-between-mcmc-and-pathfinder-results-how-to-make-pathfinder-or-something-else-more-accurate/35992)

<div class="topic-metadata">

**Author:** [@screachingfire](https://discourse.mc-stan.org/u/screachingfire)\
**Replies:** 4\
**Last updated:** [November 12, 2024, 3:28pm UTC](https://discourse.mc-stan.org/t/issues-with-differences-between-mcmc-and-pathfinder-results-how-to-make-pathfinder-or-something-else-more-accurate/35992 "2024-11-12T15:28:03Z")

</div>

Hello! I am fitting a negative binomial model with the following code: data { int\<lower=1\> n\_obs; int\<lower=1\> n\_transcripts; array\[n\_obs\] int\<lower=1\> transcript\_id; array\[n\_obs\] int\<lower=0\> coun…

---

## [Details of initial convergence towards typical set in Hamiltonian Monte Carlo](https://discourse.mc-stan.org/t/details-of-initial-convergence-towards-typical-set-in-hamiltonian-monte-carlo/37164)

<div class="topic-metadata">

**Author:** [@boogiewoogie](https://discourse.mc-stan.org/u/boogiewoogie)\
**Replies:** 3\
**Last updated:** [November 7, 2024, 3:26pm UTC](https://discourse.mc-stan.org/t/details-of-initial-convergence-towards-typical-set-in-hamiltonian-monte-carlo/37164 "2024-11-07T15:26:37Z")

</div>

After reading the introductory HMC paper, I’m confused about the initial warm-up phase. What exactly is happening there? I’m especially interested in the mathematical details behind a) The chain rapidly approaching the…

---

## [Taking advantage of both sparse matrices and GPUs](https://discourse.mc-stan.org/t/taking-advantage-of-both-sparse-matrices-and-gpus/11486)

<div class="topic-metadata">

**Author:** [@bmacGTPM](https://discourse.mc-stan.org/u/bmacGTPM)\
**Replies:** 7\
**Last updated:** [September 19, 2024, 8:02pm UTC](https://discourse.mc-stan.org/t/taking-advantage-of-both-sparse-matrices-and-gpus/11486 "2024-09-19T20:02:52Z")

</div>

I’m currently using R, Stan, and specifically the functions extract\_sparse\_parts() and csr\_matrix\_times\_vector(), to take advantage of a having a 98.7% sparse matrix in a hierarchical linear regression model. I have als…

---

## [Summing values within group](https://discourse.mc-stan.org/t/summing-values-within-group/30548)

<div class="topic-metadata">

**Author:** [@GiKim](https://discourse.mc-stan.org/u/GiKim)\
**Replies:** 5\
**Last updated:** [August 30, 2024, 8:39pm UTC](https://discourse.mc-stan.org/t/summing-values-within-group/30548 "2024-08-30T20:39:42Z")

</div>

Hi, I am trying to write a function that does simple aggregation by group. Suppose I have two variables, groupid and values: groupid values 1 3 1 2 1 4 2 2 2 2 2 …

---

## [Is there a reason why dirichlet distribution is defined in terms of vectors, rather than simplices?](https://discourse.mc-stan.org/t/is-there-a-reason-why-dirichlet-distribution-is-defined-in-terms-of-vectors-rather-than-simplices/36058)

<div class="topic-metadata">

**Author:** [@jachymb](https://discourse.mc-stan.org/u/jachymb)\
**Replies:** 1\
**Last updated:** [July 30, 2024, 6:25pm UTC](https://discourse.mc-stan.org/t/is-there-a-reason-why-dirichlet-distribution-is-defined-in-terms-of-vectors-rather-than-simplices/36058 "2024-07-30T18:25:24Z")

</div>

We have the following signatures: real dirichlet\_lpdf (vector theta | vector alpha) vector dirichlet\_rng (vector alpha) I would expect them to instead be: real dirichlet\_lpdf (simplex theta | vector alpha) simplex d…

---

## [Extending Rstan's Simulation Based Calibration](https://discourse.mc-stan.org/t/extending-rstans-simulation-based-calibration/20135)

<div class="topic-metadata">

**Author:** [@Dashadower](https://discourse.mc-stan.org/u/Dashadower)\
**Replies:** 4\
**Last updated:** [July 25, 2024, 11:23pm UTC](https://discourse.mc-stan.org/t/extending-rstans-simulation-based-calibration/20135 "2024-07-25T23:23:43Z")

</div>

When trying to do simulation based calibration, I personally felt that having to create multiple stan files was hard to keep track, especially when you’re making small changes here and there to the model. Rstan’s sbc() …

---

## [AD with stan math, Rcpp](https://discourse.mc-stan.org/t/ad-with-stan-math-rcpp/35889)

<div class="topic-metadata">

**Author:** [@Josh\_Knecht](https://discourse.mc-stan.org/u/Josh_Knecht)\
**Replies:** 2\
**Last updated:** [July 17, 2024, 2:04pm UTC](https://discourse.mc-stan.org/t/ad-with-stan-math-rcpp/35889 "2024-07-17T14:04:52Z")

</div>

Hey Everyone, I have been trying to use the stan math library and Rcpp to use autodiff in R. At this point, I’m just trying to figure out how to make it work. I haven’t used c++ before, so I’m sure that it is just a sil…

---

## [New adaptive warmup proposal (looking for feedback)!](https://discourse.mc-stan.org/t/new-adaptive-warmup-proposal-looking-for-feedback/12039)

<div class="topic-metadata">

**Author:** [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Replies:** 50\
**Last updated:** [July 31, 2020, 6:42am UTC](https://discourse.mc-stan.org/t/new-adaptive-warmup-proposal-looking-for-feedback/12039 "2020-07-31T06:42:53Z")

</div>

There’s a new, experimental warmup algorithm on the block! It’s available as an r package here: campfire (get it? campfires are for warming up) The the big features are: Adaptive length warmup – only run warmup as lon…

---

## [Sampling with Hessian, not just gradient?](https://discourse.mc-stan.org/t/sampling-with-hessian-not-just-gradient/34962)

<div class="topic-metadata">

**Author:** [@fan455](https://discourse.mc-stan.org/u/fan455)\
**Replies:** 0\
**Last updated:** [April 30, 2024, 9:30am UTC](https://discourse.mc-stan.org/t/sampling-with-hessian-not-just-gradient/34962 "2024-04-30T09:30:28Z")

</div>

Hi, I have a log density with 30-50 dimensions. Though the normalizing constant of this density is intractable, the density is convergent. The density is fairly regular, being unimodal and asymptotically normal. The grad…

---

## [Bayesian dynamic ordered probit panel model](https://discourse.mc-stan.org/t/bayesian-dynamic-ordered-probit-panel-model/34673)

<div class="topic-metadata">

**Author:** [@Djakiss](https://discourse.mc-stan.org/u/Djakiss)\
**Replies:** 2\
**Last updated:** [April 3, 2024, 2:08pm UTC](https://discourse.mc-stan.org/t/bayesian-dynamic-ordered-probit-panel-model/34673 "2024-04-03T14:08:54Z")

</div>

I analyse the central bank reaction to the capital flows. I’m trying to apply a Bayesian approach to estimate a dynamic ordered probit in panel data. But I do not know how to use stan for panel data. I want to know if i…

---

## [Pathfinder pareto K](https://discourse.mc-stan.org/t/pathfinder-pareto-k/34064)

<div class="topic-metadata">

**Author:** [@cpfiffer](https://discourse.mc-stan.org/u/cpfiffer)\
**Replies:** 2\
**Last updated:** [February 8, 2024, 5:20pm UTC](https://discourse.mc-stan.org/t/pathfinder-pareto-k/34064 "2024-02-08T17:20:47Z")

</div>

I’m working with Pathfinder on a model that is pretty gnarly – lots of terribly geometry. We’ve been trying to reparameterize for quite a while now and it’s an ongoing project. It’s about a thousand lines of Stan code, s…

---

## [How can software such as JAGS or STAN estimate the density a posteriori by MCMC from a DAGS diagram?](https://discourse.mc-stan.org/t/how-can-software-such-as-jags-or-stan-estimate-the-density-a-posteriori-by-mcmc-from-a-dags-diagram/33586)

<div class="topic-metadata">

**Author:** [@aurelien2024](https://discourse.mc-stan.org/u/aurelien2024)\
**Replies:** 4\
**Last updated:** [December 15, 2023, 7:00pm UTC](https://discourse.mc-stan.org/t/how-can-software-such-as-jags-or-stan-estimate-the-density-a-posteriori-by-mcmc-from-a-dags-diagram/33586 "2023-12-15T19:00:29Z")

</div>

Good morning. I guess my question exceeds the specificities of STAN, and is more related to the core of the principle of using causal diagrams to model a specific phenomenon. How can software such as JAGS or STAN estima…

---

## [Change chain location if its get tilted](https://discourse.mc-stan.org/t/change-chain-location-if-its-get-tilted/33487)

<div class="topic-metadata">

**Author:** [@Ezequiel\_Alvarez](https://discourse.mc-stan.org/u/Ezequiel_Alvarez)\
**Replies:** 5\
**Last updated:** [December 6, 2023, 6:45am UTC](https://discourse.mc-stan.org/t/change-chain-location-if-its-get-tilted/33487 "2023-12-06T06:45:07Z")

</div>

Hi! I am running cmdstan and I was told (in this forum) that a slight change in the model can produce drastic changes in time of convergence. Even if is the same dataset, same number of samples, etc. The reason being …

---

## [Reduce\_sum in a Bayesian PCA](https://discourse.mc-stan.org/t/reduce-sum-in-a-bayesian-pca/33369)

<div class="topic-metadata">

**Author:** [@kokorap27](https://discourse.mc-stan.org/u/kokorap27)\
**Replies:** 7\
**Last updated:** [December 1, 2023, 4:23pm UTC](https://discourse.mc-stan.org/t/reduce-sum-in-a-bayesian-pca/33369 "2023-12-01T16:23:30Z")

</div>

Hello Stan community! This week I’ve been supporting a researcher with his implementation in Stan of a Bayesian model in which a PCA is included. Regarding the Bayesian PCA, we are assuming that \\mathbf{y}\_{n}=\\mathb…

---

## [NUTS and ridges](https://discourse.mc-stan.org/t/nuts-and-ridges/27282)

<div class="topic-metadata">

**Author:** [@PhilClemson](https://discourse.mc-stan.org/u/PhilClemson)\
**Replies:** 20\
**Last updated:** [November 21, 2023, 6:51pm UTC](https://discourse.mc-stan.org/t/nuts-and-ridges/27282 "2023-11-21T18:51:31Z")

</div>

Hi everyone, I’m currently using NUTS (not Stan but my own implementation) to sample from a distribution which describes the probability of the parameters \\theta\_n for a set of sinusoidal basis functions, given some tim…

---

## [About the regularized covariance estimation of the Euclidean metric in HMC hyperparameter](https://discourse.mc-stan.org/t/about-the-regularized-covariance-estimation-of-the-euclidean-metric-in-hmc-hyperparameter/33234)

<div class="topic-metadata">

**Author:** [@jiem](https://discourse.mc-stan.org/u/jiem)\
**Replies:** 2\
**Last updated:** [November 6, 2023, 10:49pm UTC](https://discourse.mc-stan.org/t/about-the-regularized-covariance-estimation-of-the-euclidean-metric-in-hmc-hyperparameter/33234 "2023-11-06T22:49:14Z")

</div>

Hi, I figured out that for the Euclidean metric in HMC hyperparameter, there are choices like (“unit\_e”, “diag\_e” and “dens\_e”), and the choice of the metric influences the convergence of the chains a lot. I read the ST…

---

## [On Extrinsic forecasting metrics](https://discourse.mc-stan.org/t/on-extrinsic-forecasting-metrics/32779)

<div class="topic-metadata">

**Author:** [@Francis](https://discourse.mc-stan.org/u/Francis)\
**Replies:** 5\
**Last updated:** [October 31, 2023, 11:48am UTC](https://discourse.mc-stan.org/t/on-extrinsic-forecasting-metrics/32779 "2023-10-31T11:48:35Z")

</div>

Hello everyone. I’m looking for a way to evaluate a forecasting model with an “extrinsic” metric. As part of my PhD, I developed 3 state-space models for forecasting stink bug populations in soybean crops (Redirecting)…

[Next page](https://discourse.mc-stan.org/c/algorithms/18.md?page=1)
