# \#mixed-model

**URL:** https://discourse.mc-stan.org/tag/mixed-model/100.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)

---

## [Correlated posterior - Sum to zero constraint for varying intercepts?!](https://discourse.mc-stan.org/t/correlated-posterior-sum-to-zero-constraint-for-varying-intercepts/25608)

<div class="topic-metadata">

**Author:** [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)\
**Replies:** 21\
**Last updated:** [August 22, 2026, 4:55am UTC](https://discourse.mc-stan.org/t/correlated-posterior-sum-to-zero-constraint-for-varying-intercepts/25608 "2026-08-22T04:55:54Z")

</div>

Hi, so here’s an issue I’ve ran into in a couple analyses where simple uses of varying (random) intercepts resulted in problematic posterior distributions. In particular, the posterior for the overall intercept is negat…

---

## [Extremely slow phylogenetic mixed model in brms](https://discourse.mc-stan.org/t/extremely-slow-phylogenetic-mixed-model-in-brms/41437)

<div class="topic-metadata">

**Author:** [@Anoban](https://discourse.mc-stan.org/u/Anoban)\
**Replies:** 5\
**Last updated:** [July 20, 2026, 12:46am UTC](https://discourse.mc-stan.org/t/extremely-slow-phylogenetic-mixed-model-in-brms/41437 "2026-07-20T00:46:30Z")

</div>

Hi folks, I have the following multiresponse phylogenetic mixed model in brms : model \<- brms::brm(brms::brmsformula(mvbind(t1, t2, t3) ~ state + (1|p|gr(binominal, cov = corrmat)) + (1|q|taxa)) + set\_rescor(TRUE), dat…

---

## [Why does changing the reference level wildly change the predicted probabilities?](https://discourse.mc-stan.org/t/why-does-changing-the-reference-level-wildly-change-the-predicted-probabilities/41399)

<div class="topic-metadata">

**Author:** [@FeliOtte](https://discourse.mc-stan.org/u/FeliOtte)\
**Replies:** 1\
**Last updated:** [June 26, 2026, 2:21pm UTC](https://discourse.mc-stan.org/t/why-does-changing-the-reference-level-wildly-change-the-predicted-probabilities/41399 "2026-06-26T14:21:31Z")

</div>

Hello everyone, I’m having some modelling issues and I’m hoping the answer to the question above might help. I am running a multinomial/categorical model in brms and am getting results that do not make sense for my data…

---

## [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.…

---

## [Bayesian mixture of GEV](https://discourse.mc-stan.org/t/bayesian-mixture-of-gev/40072)

<div class="topic-metadata">

**Author:** [@Sara\_Ponzo](https://discourse.mc-stan.org/u/Sara_Ponzo)\
**Replies:** 2\
**Last updated:** [August 5, 2025, 6:32pm UTC](https://discourse.mc-stan.org/t/bayesian-mixture-of-gev/40072 "2025-08-05T18:32:02Z")

</div>

Hi! I am new to Stan and I am trying to perform a Bayesian mixture of GEV. However, the model seems to have a problem with convergence. Any help is appreciated! gev\_mix\_model\<- "functions { // GEV real gev\_lpdf(re…

---

## [Multivariate mixed-effect modeling](https://discourse.mc-stan.org/t/multivariate-mixed-effect-modeling/36539)

<div class="topic-metadata">

**Author:** [@morgan](https://discourse.mc-stan.org/u/morgan)\
**Replies:** 1\
**Last updated:** [September 21, 2024, 8:17am UTC](https://discourse.mc-stan.org/t/multivariate-mixed-effect-modeling/36539 "2024-09-21T08:17:12Z")

</div>

Hi all, I am attempting to use the R package “brms” to evaluate a bivariate mixed-model regression model (specifically, looking at continuous outcomes for both left and right eyes over time). In applying your model to m…

---

## [Determining optimal response distribution for modeling growth curves of NFL players' fantasy football points in brms](https://discourse.mc-stan.org/t/determining-optimal-response-distribution-for-modeling-growth-curves-of-nfl-players-fantasy-football-points-in-brms/38302)

<div class="topic-metadata">

**Author:** [@itpetersen](https://discourse.mc-stan.org/u/itpetersen)\
**Replies:** 6\
**Last updated:** [February 6, 2025, 11:01pm UTC](https://discourse.mc-stan.org/t/determining-optimal-response-distribution-for-modeling-growth-curves-of-nfl-players-fantasy-football-points-in-brms/38302 "2025-02-06T23:01:07Z")

</div>

I’m trying to model age-related trajectories (i.e., growth curves) of National Football League (NFL) players’ fantasy points using a mixed model in brms. In brief, fantasy points reflect a weighted sum of performance acr…

---

## [Specifying the variance of the random effect means for brms model](https://discourse.mc-stan.org/t/specifying-the-variance-of-the-random-effect-means-for-brms-model/38564)

<div class="topic-metadata">

**Author:** [@Dreamspan](https://discourse.mc-stan.org/u/Dreamspan)\
**Replies:** 1\
**Last updated:** [January 31, 2025, 6:35pm UTC](https://discourse.mc-stan.org/t/specifying-the-variance-of-the-random-effect-means-for-brms-model/38564 "2025-01-31T18:35:55Z")

</div>

I have been using brms to make a mixed-effects model, that tries to calculate the hospital random effect intercepts, to determine the effect of each hospital on the mortality of patients. The variable Risk Adjustment ju…

---

## [How to deal with "total ordering" in practice under label switching](https://discourse.mc-stan.org/t/how-to-deal-with-total-ordering-in-practice-under-label-switching/37577)

<div class="topic-metadata">

**Author:** [@steakdream](https://discourse.mc-stan.org/u/steakdream)\
**Replies:** 29\
**Last updated:** [January 20, 2025, 7:02pm UTC](https://discourse.mc-stan.org/t/how-to-deal-with-total-ordering-in-practice-under-label-switching/37577 "2025-01-20T19:02:22Z")

</div>

Suppose I have a simple MSVAR model with 1 lag and 2 variables and 2 regimes, where VAR term is regime-independent: Regime 1: y^{1} = y^1\_{t-1} \\cdot \\gamma\_{0,1} + y^{2}\_{t-1} \\cdot \\gamma\_{0,2} + \\gamma\_{1,1} y^{2} …

---

## [How to vectorize the stan code to reduce the run time](https://discourse.mc-stan.org/t/how-to-vectorize-the-stan-code-to-reduce-the-run-time/37554)

<div class="topic-metadata">

**Author:** [@Samip\_Tandon](https://discourse.mc-stan.org/u/Samip_Tandon)\
**Replies:** 7\
**Last updated:** [December 10, 2024, 9:42pm UTC](https://discourse.mc-stan.org/t/how-to-vectorize-the-stan-code-to-reduce-the-run-time/37554 "2024-12-10T21:42:42Z")

</div>

I have this below STAN code for marketing mix modelling application with thousands records and hundreds of media/control variables. Using\*\* pystan version 2.19.1.1\*\* I am new to stan. This current setup is taking 10-12 h…

---

## [Account for relationships between species in a multivariate brms model](https://discourse.mc-stan.org/t/account-for-relationships-between-species-in-a-multivariate-brms-model/32566)

<div class="topic-metadata">

**Author:** [@LukianAdams](https://discourse.mc-stan.org/u/LukianAdams)\
**Replies:** 1\
**Last updated:** [November 15, 2024, 7:12pm UTC](https://discourse.mc-stan.org/t/account-for-relationships-between-species-in-a-multivariate-brms-model/32566 "2024-11-15T19:12:10Z")

</div>

Hi all. I am currently working with a dataset containing 30 years of fish abundance for 12 fish taxa across 5 river systems, and I would like to construct joint species distribution models to determine where artificial b…

---

## [NLME model in STAN for missing + unbalanced longitudinal data](https://discourse.mc-stan.org/t/nlme-model-in-stan-for-missing-unbalanced-longitudinal-data/36703)

<div class="topic-metadata">

**Author:** [@michael3](https://discourse.mc-stan.org/u/michael3)\
**Replies:** 20\
**Last updated:** [October 21, 2024, 6:54pm UTC](https://discourse.mc-stan.org/t/nlme-model-in-stan-for-missing-unbalanced-longitudinal-data/36703 "2024-10-21T18:54:31Z")

</div>

Divergent issues; R-hat issues; ESS issues. Any tips/advice is much appreciated. My thoughts on potential issues: Maybe it’s how I’m dealing with unbalanced longitudinal data portion i.e. if (i != previous\\\_id)? I tho…

---

## [How to use cauchy distribution in varying intercepts model](https://discourse.mc-stan.org/t/how-to-use-cauchy-distribution-in-varying-intercepts-model/36002)

<div class="topic-metadata">

**Author:** [@radicalprotenns](https://discourse.mc-stan.org/u/radicalprotenns)\
**Replies:** 8\
**Last updated:** [July 27, 2024, 1:08am UTC](https://discourse.mc-stan.org/t/how-to-use-cauchy-distribution-in-varying-intercepts-model/36002 "2024-07-27T01:08:19Z")

</div>

I am reading McElreath’s book on Statistical Rethinking but I am following the code in Solomon Kurz’ e-book https://bookdown.org/content/4857/ as I want to be more proficient with brms. Kurz has the following code for t…

---

## [Group random effects for two between-subject factors](https://discourse.mc-stan.org/t/group-random-effects-for-two-between-subject-factors/35413)

<div class="topic-metadata">

**Author:** [@nahorp](https://discourse.mc-stan.org/u/nahorp)\
**Replies:** 2\
**Last updated:** [June 16, 2024, 1:17pm UTC](https://discourse.mc-stan.org/t/group-random-effects-for-two-between-subject-factors/35413 "2024-06-16T13:17:36Z")

</div>

Hello! I’m aware of the usage of gr() to estimate seperate variance-covariance matrices for each level of a between-subject factor as per here. Using the third example there, fit3 \<- brm(count ~ Trt + (1|gr(patient, by…

---

## [Syntax error for multivariate mixed effects model using cmdstanr backend](https://discourse.mc-stan.org/t/syntax-error-for-multivariate-mixed-effects-model-using-cmdstanr-backend/34509)

<div class="topic-metadata">

**Author:** [@QMmmmLiu](https://discourse.mc-stan.org/u/QMmmmLiu)\
**Replies:** 2\
**Last updated:** [March 15, 2024, 9:10pm UTC](https://discourse.mc-stan.org/t/syntax-error-for-multivariate-mixed-effects-model-using-cmdstanr-backend/34509 "2024-03-15T21:10:26Z")

</div>

Here is the r code. Loaded newest version of brms, cmdstanr, and cmdstan bfs=bf(phasic|mi()~mi(rum.state.lag1)+mi(tonic.state.lag1)+mi(phasic.state.lag1)+mi(imean.tonic)+mi(imean.rum)+(1|workerid))+ bf(tonic|mi()~mi…

---

## [Brms hacking: linear predictors for random effect standard deviations](https://discourse.mc-stan.org/t/brms-hacking-linear-predictors-for-random-effect-standard-deviations/34162)

<div class="topic-metadata">

**Author:** [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)\
**Replies:** 5\
**Last updated:** [February 19, 2024, 1:54pm UTC](https://discourse.mc-stan.org/t/brms-hacking-linear-predictors-for-random-effect-standard-deviations/34162 "2024-02-19T13:54:18Z")

</div>

Hi all, I have a new blog showcasing the immense hackability of brms by extending a random intercept model with linear predictors on the standard deviation of the random intercept. Should you do it? Most likely not, but…

---

## [Two-armed bandit hierarchical reinforcement learning model - simplify to random intercept only](https://discourse.mc-stan.org/t/two-armed-bandit-hierarchical-reinforcement-learning-model-simplify-to-random-intercept-only/33853)

<div class="topic-metadata">

**Author:** [@milena\_musial](https://discourse.mc-stan.org/u/milena_musial)\
**Replies:** 3\
**Last updated:** [February 12, 2024, 12:47pm UTC](https://discourse.mc-stan.org/t/two-armed-bandit-hierarchical-reinforcement-learning-model-simplify-to-random-intercept-only/33853 "2024-02-12T12:47:31Z")

</div>

Hi there, Data as mentioned in my previous post, I want to fit a hierarchical reinforcement learning (RL) model (a Pearce-Hall model according to Diederen et al. ) to 2-armed bandit choice (0/1) data of 71 subjects. E…

---

## [Varying standard deviations for varying intercepts?](https://discourse.mc-stan.org/t/varying-standard-deviations-for-varying-intercepts/33802)

<div class="topic-metadata">

**Author:** [@swalmsley](https://discourse.mc-stan.org/u/swalmsley)\
**Replies:** 0\
**Last updated:** [January 11, 2024, 9:26pm UTC](https://discourse.mc-stan.org/t/varying-standard-deviations-for-varying-intercepts/33802 "2024-01-11T21:26:29Z")

</div>

I’m interested in modelling how the variability of varying intercepts (e.g., one for each year) changes over time (year), having accounted for several fixed effects. The data I’m working with are sightings of different …

---

## [Different prior settings for within and between-group variance](https://discourse.mc-stan.org/t/different-prior-settings-for-within-and-between-group-variance/33755)

<div class="topic-metadata">

**Author:** [@FreddieMckendrick](https://discourse.mc-stan.org/u/FreddieMckendrick)\
**Replies:** 5\
**Last updated:** [January 11, 2024, 9:01am UTC](https://discourse.mc-stan.org/t/different-prior-settings-for-within-and-between-group-variance/33755 "2024-01-11T09:01:41Z")

</div>

Hi, I was just interested to know if anyone had any insight into a model I am currently trying to run. In brief I am interested in seeing how the mean and variance in behaviour (in this case animals) might be correlated …

---

## [Combining item response theory and growth curve estimation in same model](https://discourse.mc-stan.org/t/combining-item-response-theory-and-growth-curve-estimation-in-same-model/16407)

<div class="topic-metadata">

**Author:** [@itpetersen](https://discourse.mc-stan.org/u/itpetersen)\
**Replies:** 5\
**Last updated:** [November 10, 2023, 11:09am UTC](https://discourse.mc-stan.org/t/combining-item-response-theory-and-growth-curve-estimation-in-same-model/16407 "2023-11-10T11:09:36Z")

</div>

I’d like to combine item response theory (IRT) and growth curve estimation in the same model. Basically, I’d like to estimate a 2-parameter logistic item response model (difficulty and discrimination) and growth curves …

---

## [How to enter discrete data to stan model and modelling mixed posterior probability?](https://discourse.mc-stan.org/t/how-to-enter-discrete-data-to-stan-model-and-modelling-mixed-posterior-probability/31283)

<div class="topic-metadata">

**Author:** [@Meqdad\_Hasan](https://discourse.mc-stan.org/u/Meqdad_Hasan)\
**Replies:** 3\
**Last updated:** [October 13, 2023, 5:43pm UTC](https://discourse.mc-stan.org/t/how-to-enter-discrete-data-to-stan-model-and-modelling-mixed-posterior-probability/31283 "2023-10-13T17:43:56Z")

</div>

Hello stan users; I am new to stan. I still can not use \<I got the whole concept of stan language. However, I am in a hurry to answer one of my main questions. I am trying to model 46 nodes with almost 82 connections Ba…

---

## [BRMS model fails- Multivariate Mixed Model and Hurdle model](https://discourse.mc-stan.org/t/brms-model-fails-multivariate-mixed-model-and-hurdle-model/32397)

<div class="topic-metadata">

**Author:** [@megsrupp\_unbc](https://discourse.mc-stan.org/u/megsrupp_unbc)\
**Replies:** 5\
**Last updated:** [August 24, 2023, 6:59pm UTC](https://discourse.mc-stan.org/t/brms-model-fails-multivariate-mixed-model-and-hurdle-model/32397 "2023-08-24T18:59:07Z")

</div>

I have a GAMM that’s multivariate. It’s also a hurdle\_gamma() model due to the presence of 0’s throughout the dataset. I continuously get errors when attempting to run the model and I’m not sure where they are coming fro…

---

## [Confusion on difference between posterior\_epred() and posterior\_predict() in a mixed effects modelling context](https://discourse.mc-stan.org/t/confusion-on-difference-between-posterior-epred-and-posterior-predict-in-a-mixed-effects-modelling-context/28813)

<div class="topic-metadata">

**Author:** [@isabellaghement](https://discourse.mc-stan.org/u/isabellaghement)\
**Replies:** 6\
**Last updated:** [July 27, 2023, 9:26pm UTC](https://discourse.mc-stan.org/t/confusion-on-difference-between-posterior-epred-and-posterior-predict-in-a-mixed-effects-modelling-context/28813 "2023-07-27T21:26:27Z")

</div>

Hi everyone, This is my first time posting to this forum but I am hopeful someone here can help me understand the difference between the functions posterior\_epred() and posterior\_predict() in the context of mixed effect…

---

## [Joint model specification, simple question](https://discourse.mc-stan.org/t/joint-model-specification-simple-question/30868)

<div class="topic-metadata">

**Author:** [@Wolsing](https://discourse.mc-stan.org/u/Wolsing)\
**Replies:** 2\
**Last updated:** [March 28, 2023, 7:06am UTC](https://discourse.mc-stan.org/t/joint-model-specification-simple-question/30868 "2023-03-28T07:06:43Z")

</div>

I want to include longitudinal information from a secondary endpoint into a primary binary endpoint. To do this, we have the following model As suggested in “Bayesian Workflow” (Gelman et. al 2020) I have of course f…

---

## [Advice on speeding up non-linear multi-level in brms?](https://discourse.mc-stan.org/t/advice-on-speeding-up-non-linear-multi-level-in-brms/30799)

<div class="topic-metadata">

**Author:** [@devillemereuil](https://discourse.mc-stan.org/u/devillemereuil)\
**Replies:** 2\
**Last updated:** [March 21, 2023, 8:12am UTC](https://discourse.mc-stan.org/t/advice-on-speeding-up-non-linear-multi-level-in-brms/30799 "2023-03-21T08:12:14Z")

</div>

Hi, We are trying to estimate additive genetic variance of growth curve parameters in a continuous growth species. To do so, we use a (variance-covariance) matrix of relatedness between individuals and a model of logist…

---

## [Shouldn't I condition for all variables that cause Y in a DAG?](https://discourse.mc-stan.org/t/shouldnt-i-condition-for-all-variables-that-cause-y-in-a-dag/30663)

<div class="topic-metadata">

**Author:** [@Dan-Zapata](https://discourse.mc-stan.org/u/Dan-Zapata)\
**Replies:** 6\
**Last updated:** [March 13, 2023, 8:45am UTC](https://discourse.mc-stan.org/t/shouldnt-i-condition-for-all-variables-that-cause-y-in-a-dag/30663 "2023-03-13T08:45:29Z")

</div>

Hello everyone, I hope this is a right place to ask this: I am fairly new at trying to understand my models through the eyes of Causal Directed Acyclic Graphs (DAGs). But I have been trying to wrap my head around it bef…

---

## [What is the difference between these two models?](https://discourse.mc-stan.org/t/what-is-the-difference-between-these-two-models/29963)

<div class="topic-metadata">

**Author:** [@Yunier](https://discourse.mc-stan.org/u/Yunier)\
**Replies:** 2\
**Last updated:** [January 7, 2023, 10:59pm UTC](https://discourse.mc-stan.org/t/what-is-the-difference-between-these-two-models/29963 "2023-01-07T22:59:39Z")

</div>

Hi I have read that in the fit\_sleep1 model, the 1 at the start of the formula specifies that I want an intercept, but it can be omitted since it is included by default. Then both models should be equal. However, these…

---

## [Brms ordinal model diagnostics. DHARMa for Bayesians](https://discourse.mc-stan.org/t/brms-ordinal-model-diagnostics-dharma-for-bayesians/29458)

<div class="topic-metadata">

**Author:** [@Rtui](https://discourse.mc-stan.org/u/Rtui)\
**Replies:** 8\
**Last updated:** [November 17, 2022, 7:47am UTC](https://discourse.mc-stan.org/t/brms-ordinal-model-diagnostics-dharma-for-bayesians/29458 "2022-11-17T07:47:49Z")

</div>

Hello, I am a masters student and quite new to Bayesian statistics and would greatly appreciate your help! I am fitting mixed effect cumulative probit model in brms. I would like to check the normality and heteroscedas…

---

## [Invariant cases in mixed-effects location scale models](https://discourse.mc-stan.org/t/invariant-cases-in-mixed-effects-location-scale-models/29231)

<div class="topic-metadata">

**Author:** [@simoncolumbus](https://discourse.mc-stan.org/u/simoncolumbus)\
**Replies:** 17\
**Last updated:** [November 11, 2022, 8:57am UTC](https://discourse.mc-stan.org/t/invariant-cases-in-mixed-effects-location-scale-models/29231 "2022-11-11T08:57:56Z")

</div>

I am trying to fit a basic mixed-effects location scale model using brms. The data are from an experience sampling study (~4000 observations from ~300 participants). The outcome variable is continuous, but a bit wonky (r…

---

## [Average Marginal Effect in a Mixed Effects Models](https://discourse.mc-stan.org/t/average-marginal-effect-in-a-mixed-effects-models/28814)

<div class="topic-metadata">

**Author:** [@isabellaghement](https://discourse.mc-stan.org/u/isabellaghement)\
**Replies:** 1\
**Last updated:** [September 14, 2022, 9:58pm UTC](https://discourse.mc-stan.org/t/average-marginal-effect-in-a-mixed-effects-models/28814 "2022-09-14T21:58:18Z")

</div>

Hi everyone, Dr. Andrew Heiss has a very nice blog post on marginal effects where he illustrates the concept of an Average Marginal Effect in the context of a linear model by showing this diagram: (The blog post is …

[Next page](https://discourse.mc-stan.org/tag/mixed-model/100.md?match_all_tags=true&page=1&tags%5B%5D=mixed-model)
