# Possible Error in the Correlation Matrices (10.9) Section of the Stan Manual

**URL:** <https://discourse.mc-stan.org/t/possible-error-in-the-correlation-matrices-10-9-section-of-the-stan-manual/29671>\
**Category:** General\
**Created:** [December 1, 2022, 10:55pm UTC](https://discourse.mc-stan.org/t/possible-error-in-the-correlation-matrices-10-9-section-of-the-stan-manual/29671 "2022-12-01T22:55:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nspencer](https://avatars.discourse-cdn.com/v4/letter/n/bbe5ce/32.png) [@nspencer](https://discourse.mc-stan.org/u/nspencer)\
**Post date:** [December 1, 2022, 10:55pm UTC](https://discourse.mc-stan.org/t/possible-error-in-the-correlation-matrices-10-9-section-of-the-stan-manual/29671/1 "2022-12-01T22:55:47Z")

</div>

After spending some time playing around with implementing a modification of the LKJ prior, I believe there are errors in the statement of the “manageable expression” for W provided in the stan manual at the following link:

> **[10.9 Correlation matrices | Stan Reference Manual](https://mc-stan.org/docs/reference-manual/correlation-matrix-transform.html#correlation-matrix-inverse-transform)**
>
> Stan reference manual specifying the syntax and semantics of the Stan programming language.

The definition provided seems to assume that z has ones along the diagonal, instead of the zeros shown in the definition above. Otherwise, all diagonal entries other than the first row will be forced to 0.

Also, I believe the final line in the piecewise statement is missing a factor of 1/Z\_{i-1, j}. After making these two changes, I think the manageable expression will now agree with the “long version” above it.

Could someone please verify? Thanks.

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [December 2, 2022, 10:33am UTC](https://discourse.mc-stan.org/t/possible-error-in-the-correlation-matrices-10-9-section-of-the-stan-manual/29671/2 "2022-12-02T10:33:44Z")

</div>

@spinkney thoughts?

---

<div class="post-metadata">

**Author:** ![hhau](https://avatars.discourse-cdn.com/v4/letter/h/2bfe46/32.png) [@hhau](https://discourse.mc-stan.org/u/hhau)\
**Post date:** [December 2, 2022, 5:43pm UTC](https://discourse.mc-stan.org/t/possible-error-in-the-correlation-matrices-10-9-section-of-the-stan-manual/29671/3 "2022-12-02T17:43:08Z")

</div>

This has come up before:

- [Incorrect formula for correlation matrix transform](https://discourse.mc-stan.org/t/incorrect-formula-for-correlation-matrix-transform/24664)
- [LKJ inverse transform for correlation matrices (incorrect documentation?)](https://discourse.mc-stan.org/t/lkj-inverse-transform-for-correlation-matrices-incorrect-documentation/19312)

I think I even said I would get to the bottom of it in the first link (I definitely did not and then forgot about it, whoops). I am more confident in the formulae in 10.12: [10.12 Cholesky factors of correlation matrices | Stan Reference Manual](https://mc-stan.org/docs/reference-manual/cholesky-factors-of-correlation-matrices-1.html), and would then take the crossproduct of the result to get a correlation matrix.

---

<div class="post-metadata">

**Author:** ![nspencer](https://avatars.discourse-cdn.com/v4/letter/n/bbe5ce/32.png) [@nspencer](https://discourse.mc-stan.org/u/nspencer)\
**Post date:** [December 2, 2022, 6:11pm UTC](https://discourse.mc-stan.org/t/possible-error-in-the-correlation-matrices-10-9-section-of-the-stan-manual/29671/4 "2022-12-02T18:11:10Z")

</div>

Since this error is apparently already known, I submitted a pull request making the changes that I suggested in my above post. I didn’t dig into how it is actually implemented in stan, I just want to prevent others from falling down the same hole I did.

---

<div class="post-metadata">

**Author:** ![nspencer](https://avatars.discourse-cdn.com/v4/letter/n/bbe5ce/32.png) [@nspencer](https://discourse.mc-stan.org/u/nspencer)\
**Post date:** [December 2, 2022, 6:11pm UTC](https://discourse.mc-stan.org/t/possible-error-in-the-correlation-matrices-10-9-section-of-the-stan-manual/29671/5 "2022-12-02T18:11:27Z")

</div>

Thanks! This is good to know.

---

<div class="post-metadata">

**Author:** ![Stephen\_Martin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stephen_martin/32/7879_2.png) [@Stephen\_Martin](https://discourse.mc-stan.org/u/Stephen_Martin)\
**Post date:** [December 6, 2022, 3:01am UTC](https://discourse.mc-stan.org/t/possible-error-in-the-correlation-matrices-10-9-section-of-the-stan-manual/29671/6 "2022-12-06T03:01:17Z")

</div>

This is actually kind of funny - I _just_ encountered this on Friday (3 days ago). I was planning to submit a bug report today, and voila - it’s known already.
