From 1eb1bc2d04f89373225a82b5ce98428026c3250b Mon Sep 17 00:00:00 2001 From: Mitzi Morris Date: Tue, 8 Apr 2025 20:52:40 -0400 Subject: [PATCH 1/7] more info on affine xform --- src/quarto-config | 2 +- src/reference-manual/transforms.qmd | 2 +- src/reference-manual/types.qmd | 21 +++++++++++++++ src/stan-users-guide/efficiency-tuning.qmd | 30 ++++++++++++++-------- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/quarto-config b/src/quarto-config index 12e4c0771..65904751c 160000 --- a/src/quarto-config +++ b/src/quarto-config @@ -1 +1 @@ -Subproject commit 12e4c0771ba11de259bf9298dc9f56fc9dc3e0f0 +Subproject commit 65904751c830555ec8d81d9270e609ec190c425f diff --git a/src/reference-manual/transforms.qmd b/src/reference-manual/transforms.qmd index 85083fadd..72d5069cb 100644 --- a/src/reference-manual/transforms.qmd +++ b/src/reference-manual/transforms.qmd @@ -330,7 +330,7 @@ $$ The default value for the offset $\mu$ is $0$ and for the multiplier $\sigma$ is $1$ in case not both are specified. - +For a container variable, the affine transform is applied to each element of that variable. ### Affine inverse transform {-} diff --git a/src/reference-manual/types.qmd b/src/reference-manual/types.qmd index 9e23f92e3..c645934f7 100644 --- a/src/reference-manual/types.qmd +++ b/src/reference-manual/types.qmd @@ -472,6 +472,27 @@ model { } ``` +For a container variable, the affine transform is applied to each element of that variable. +As an example, the non-centered parameterization of Neal's Funnel in the +[Stan User's Guide reparameterization section](https://mc-stan.org/docs/stan-users-guide/reparameterization.html), +$$ +p(y,x) = \textsf{normal}(y \mid 0,3) \times \prod_{n=1}^9 +\textsf{normal}(x_n \mid 0,\exp(y/2)). +$$ +can be written as: + +```stan +parameters { + real y; + vector[9] x; +} +model { + y ~ std_normal(); + x ~ std_normal(); +} +``` +where the affine transform is applied to every element of vector `x`. + ### Expressions as bounds and offset/multiplier {-} Bounds (and offset and multiplier) diff --git a/src/stan-users-guide/efficiency-tuning.qmd b/src/stan-users-guide/efficiency-tuning.qmd index af26da697..f929dac1d 100644 --- a/src/stan-users-guide/efficiency-tuning.qmd +++ b/src/stan-users-guide/efficiency-tuning.qmd @@ -266,8 +266,6 @@ funnel's neck is particularly sharp because of the exponential function applied to $y$. A plot of the log marginal density of $y$ and the first dimension $x_1$ is shown in the following plot. - - The funnel can be implemented directly in Stan as follows. ```stan @@ -327,14 +325,26 @@ model { ``` In this second model, the parameters `x_raw` and `y_raw` are -sampled as independent standard normals, which is easy for Stan. These -are then transformed into samples from the funnel. In this case, the -same transform may be used to define Monte Carlo samples directly -based on independent standard normal samples; Markov chain Monte Carlo -methods are not necessary. If such a reparameterization were used in -Stan code, it is useful to provide a comment indicating what the -distribution for the parameter implies for the distribution of the -transformed parameter. +sampled as independent standard normals, which is easy for Stan, +and then transformed into samples from the funnel. +When this reparameterization is used in Stan code, a comment indicating what the +distribution for the parameter implies for the distribution of the transformed parameter +will improve readibility and maintainability. + +As of Stan release v2.19.0, this program can be written using Stan's +[affinely transformed real type](https://mc-stan.org/docs/reference-manual/types.html#affine-transform.section). +The affine transform on the vector `x` is applied to each element of `x`. + +```stan +parameters { + real y; + vector[9] x; +} +model { + y ~ std_normal(); // implies y ~ normal(0, 3) + x ~ std_normal(); // implies x ~ normal(0, exp(y/2)) +} +``` ### Reparameterizing the Cauchy {-} From 9383f772f71c393b2b8b8ebf74f68f824682bf1c Mon Sep 17 00:00:00 2001 From: Mitzi Morris Date: Wed, 9 Apr 2025 13:17:05 -0400 Subject: [PATCH 2/7] remove submodule quarto-config --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4531c3001..e69de29bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "src/quarto-config"] - path = src/quarto-config - url = https://github.com/stan-dev/quarto-config From c9731d238b115b2123ec6769ac8a3eda06c29898 Mon Sep 17 00:00:00 2001 From: Mitzi Morris Date: Wed, 9 Apr 2025 13:21:22 -0400 Subject: [PATCH 3/7] fix submodule quarto-config --- .gitmodules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitmodules b/.gitmodules index e69de29bb..4531c3001 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/quarto-config"] + path = src/quarto-config + url = https://github.com/stan-dev/quarto-config From 168a99ec6a0a90996ec4055bc0a84554c2ee3770 Mon Sep 17 00:00:00 2001 From: Mitzi Morris Date: Wed, 9 Apr 2025 13:32:40 -0400 Subject: [PATCH 4/7] submodule cleanup --- docs/quarto-config/quarto_styles.css | 326 --------------------------- src/quarto-config | 2 +- 2 files changed, 1 insertion(+), 327 deletions(-) delete mode 100644 docs/quarto-config/quarto_styles.css diff --git a/docs/quarto-config/quarto_styles.css b/docs/quarto-config/quarto_styles.css deleted file mode 100644 index 5cd9e2db5..000000000 --- a/docs/quarto-config/quarto_styles.css +++ /dev/null @@ -1,326 +0,0 @@ -html { - scroll-padding-top: 70px; /* height of header */ -} - -/* quarto website styling */ - -@media (min-width: 1020px) { - .navbar-brand-container { - margin-right: 1em; - } -} - -@media (max-width: 1060px) and (min-width: 991.98px) { - #navbarCollapse ul:last-of-type a.nav-link { - padding-left: 0.25em; - padding-right: 0.25em; - } - - .navbar #quarto-search { - margin-left: 0.1em; - } -} -/*Remove top and bottom padding from navbar image*/ -.navbar-brand { - padding-top: 0; - padding-bottom: 0; -} - -.navbar-logo { - max-height: 44px; -} - -.btn-action-primary { - color: var(--stan-bg); - background-color: var(--stan-secondary) !important; -} - -.btn-action-primary:hover { - color: white; -} - -.btn-action { - min-width: 165px; - border-radius: 30px; - border: none; -} - -/* stan-dev custom styling */ - -a { - color: var(--stan-secondary); -} -a.nav-link.active { - color: var(--stan-secondary); -} -a.sidebar-item-text.sidebar-link.active { - color: var(--stan-secondary); -} -.sidebar.a.active { - color: var(--stan-secondary); -} - -div [data-bs-target^="#quarto-sidebar-section"] { - font-weight: bold; - font-style: italic; - color: var(--stan-secondary); -} - -code { - white-space: inherit; - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -code:not(.sourceCode) { - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -p code { - white-space: inherit; - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -p code:not(.sourceCode) { - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -li code:not(.sourceCode) { - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -td code:not(.sourceCode) { - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -pre { - word-break: normal; - word-wrap: normal; - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} -pre code { - white-space: inherit; - margin: 0; - padding: 0; - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -pre.sourceCode { - white-space: inherit; - margin: 0; - padding: 0; - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -#quarto-appendix { - color: var(--bs-dark-warm); - background-color: var(--stan-bg); -} - -.align-equations { - text-align: left; - margin-left: 2em; /* Adjust as needed */ -} - -.book .book-body .page-wrapper .page-inner section.normal pre { - font-family: "Lucida Console", Monaco, Menlo, monospaced; - margin-left: 2em; - margin-below: 0.6em; - margin-above: -0.3em; - padding: 0; -} - -.sidebar.sidebar-navigation > * { - padding-top: 0em; -} - -#quarto-sidebar - > div.sidebar-menu-container - > ul - > li:nth-child(1) - > div - > a - > span { - font-weight: bold; - font-style: italic; - font-size: 1.3em; - color: var(--stan-secondary); - margin-above: -20em; - padding: 0; -} - -/* quarto landing page styling */ - -.content-block { - padding-top: 20px; - padding-bottom: 10px; - margin-left: 30px; - margin-right: 30px; -} - -@media (min-width: 900px) { - .content-block { - margin-left: 50px; - margin-right: 50px; - } -} - -@media (min-width: 1200px) { - .content-block { - max-width: 1100px; - margin-left: auto; - margin-right: auto; - } -} - -.hero-banner { - position: relative; - display: flex; - justify-content: center; - color: var(--stan-hero); - background-color: var(--stan-hero-bg); - border: 10px solid var(--stan-secondary); -} - -.hero-banner h1 { - font-size: 2.5rem; - margin-top: 1rem; -} - -.hero-banner .content-block { - padding-top: 0; -} - -.grid-container { - display: grid; - grid-template-columns: auto repeat(4, 1fr); - gap: 0px; - width: 80%; -} -.option { - border: 1px solid var(--stan-dark); - display: flex; - justify-content: center; - align-items: center; - cursor: pointer; -} -.option.selected { - background-color: var(--stan-highlight); - color: var(--stan-dark); -} -.option.disabled { - cursor: not-allowed; - color: var(--stan-highlight); -} -.grid-item { - padding: 10px; - border: 1px solid var(--stan-dark); - color: var(--stan-dark); -} - -.flex-grid { - display: flex; - flex-wrap: wrap; - overflow: hidden; - margin-left: 1px; -} - -.flex-grid .col { - flex: 1 1 100px; - margin-top: 0.25rem; -} - -/* when we think we're all on one line, remove the double bars */ -@container (min-width: 500px) { - .grid-item + .grid-item { - border-left: none; - } -} -/* otherwise, put a little space */ -@container (max-width: 500px) { - .flex-grid { - gap: 0.25rem; - } - - .flex-grid .col { - margin-top: 0; - } -} - -.row-label { - padding: 10px; - color: var(--stan-dark); - background-color: var(--stan-bg); - font-weight: bold; - text-align: left; - width: 20%; -} - -/* on small screens */ -@container (max-width: 700px) { - /* Move the label above, rather than to the side */ - .row-label { - flex-basis: 100%; - } -} - -.highlight-box { - background-color: var(--stan-highlight); - padding-left: 10px; -} - -#install-grid, -#prerequsite-box, -#install-box { - container-type: inline-size; -} - -/* Table Styles */ -table { - width: 100%; - border-collapse: collapse; - border-top: 1px solid var(--stan-dark); /* Adds top border to the table */ - border-bottom: 1px solid var(--stan-dark); /* Adds bottom border to the table */ -} - -th, -td { - border: none; /* Removes borders from table cells */ - padding: 0.5em; /* Adjusts padding as needed */ -} - -thead th { - background-color: var(--stan-bg); - color: var(--stan-dark); -} - -tbody td:first-child { - background-color: var(--stan-bg); - color: var(--stan-dark); -} - -/* functions reference */ -.index-container { - display: flex; - flex-flow: row nowrap; - align-items: flex-end; - justify-content: space-between; -} - -a.unlink { - color: inherit; - text-decoration: none; -} - -span.detail { - font-size: small; - color: var(--quarto-text-muted); -} diff --git a/src/quarto-config b/src/quarto-config index 65904751c..12e4c0771 160000 --- a/src/quarto-config +++ b/src/quarto-config @@ -1 +1 @@ -Subproject commit 65904751c830555ec8d81d9270e609ec190c425f +Subproject commit 12e4c0771ba11de259bf9298dc9f56fc9dc3e0f0 From b3291de3629c69ae552aa55340070eec4967605b Mon Sep 17 00:00:00 2001 From: Mitzi Morris Date: Wed, 9 Apr 2025 13:37:59 -0400 Subject: [PATCH 5/7] undelete file --- docs/quarto-config/quarto_styles.css | 326 +++++++++++++++++++++++++++ 1 file changed, 326 insertions(+) create mode 100644 docs/quarto-config/quarto_styles.css diff --git a/docs/quarto-config/quarto_styles.css b/docs/quarto-config/quarto_styles.css new file mode 100644 index 000000000..5cd9e2db5 --- /dev/null +++ b/docs/quarto-config/quarto_styles.css @@ -0,0 +1,326 @@ +html { + scroll-padding-top: 70px; /* height of header */ +} + +/* quarto website styling */ + +@media (min-width: 1020px) { + .navbar-brand-container { + margin-right: 1em; + } +} + +@media (max-width: 1060px) and (min-width: 991.98px) { + #navbarCollapse ul:last-of-type a.nav-link { + padding-left: 0.25em; + padding-right: 0.25em; + } + + .navbar #quarto-search { + margin-left: 0.1em; + } +} +/*Remove top and bottom padding from navbar image*/ +.navbar-brand { + padding-top: 0; + padding-bottom: 0; +} + +.navbar-logo { + max-height: 44px; +} + +.btn-action-primary { + color: var(--stan-bg); + background-color: var(--stan-secondary) !important; +} + +.btn-action-primary:hover { + color: white; +} + +.btn-action { + min-width: 165px; + border-radius: 30px; + border: none; +} + +/* stan-dev custom styling */ + +a { + color: var(--stan-secondary); +} +a.nav-link.active { + color: var(--stan-secondary); +} +a.sidebar-item-text.sidebar-link.active { + color: var(--stan-secondary); +} +.sidebar.a.active { + color: var(--stan-secondary); +} + +div [data-bs-target^="#quarto-sidebar-section"] { + font-weight: bold; + font-style: italic; + color: var(--stan-secondary); +} + +code { + white-space: inherit; + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +code:not(.sourceCode) { + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +p code { + white-space: inherit; + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +p code:not(.sourceCode) { + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +li code:not(.sourceCode) { + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +td code:not(.sourceCode) { + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +pre { + word-break: normal; + word-wrap: normal; + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} +pre code { + white-space: inherit; + margin: 0; + padding: 0; + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +pre.sourceCode { + white-space: inherit; + margin: 0; + padding: 0; + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +#quarto-appendix { + color: var(--bs-dark-warm); + background-color: var(--stan-bg); +} + +.align-equations { + text-align: left; + margin-left: 2em; /* Adjust as needed */ +} + +.book .book-body .page-wrapper .page-inner section.normal pre { + font-family: "Lucida Console", Monaco, Menlo, monospaced; + margin-left: 2em; + margin-below: 0.6em; + margin-above: -0.3em; + padding: 0; +} + +.sidebar.sidebar-navigation > * { + padding-top: 0em; +} + +#quarto-sidebar + > div.sidebar-menu-container + > ul + > li:nth-child(1) + > div + > a + > span { + font-weight: bold; + font-style: italic; + font-size: 1.3em; + color: var(--stan-secondary); + margin-above: -20em; + padding: 0; +} + +/* quarto landing page styling */ + +.content-block { + padding-top: 20px; + padding-bottom: 10px; + margin-left: 30px; + margin-right: 30px; +} + +@media (min-width: 900px) { + .content-block { + margin-left: 50px; + margin-right: 50px; + } +} + +@media (min-width: 1200px) { + .content-block { + max-width: 1100px; + margin-left: auto; + margin-right: auto; + } +} + +.hero-banner { + position: relative; + display: flex; + justify-content: center; + color: var(--stan-hero); + background-color: var(--stan-hero-bg); + border: 10px solid var(--stan-secondary); +} + +.hero-banner h1 { + font-size: 2.5rem; + margin-top: 1rem; +} + +.hero-banner .content-block { + padding-top: 0; +} + +.grid-container { + display: grid; + grid-template-columns: auto repeat(4, 1fr); + gap: 0px; + width: 80%; +} +.option { + border: 1px solid var(--stan-dark); + display: flex; + justify-content: center; + align-items: center; + cursor: pointer; +} +.option.selected { + background-color: var(--stan-highlight); + color: var(--stan-dark); +} +.option.disabled { + cursor: not-allowed; + color: var(--stan-highlight); +} +.grid-item { + padding: 10px; + border: 1px solid var(--stan-dark); + color: var(--stan-dark); +} + +.flex-grid { + display: flex; + flex-wrap: wrap; + overflow: hidden; + margin-left: 1px; +} + +.flex-grid .col { + flex: 1 1 100px; + margin-top: 0.25rem; +} + +/* when we think we're all on one line, remove the double bars */ +@container (min-width: 500px) { + .grid-item + .grid-item { + border-left: none; + } +} +/* otherwise, put a little space */ +@container (max-width: 500px) { + .flex-grid { + gap: 0.25rem; + } + + .flex-grid .col { + margin-top: 0; + } +} + +.row-label { + padding: 10px; + color: var(--stan-dark); + background-color: var(--stan-bg); + font-weight: bold; + text-align: left; + width: 20%; +} + +/* on small screens */ +@container (max-width: 700px) { + /* Move the label above, rather than to the side */ + .row-label { + flex-basis: 100%; + } +} + +.highlight-box { + background-color: var(--stan-highlight); + padding-left: 10px; +} + +#install-grid, +#prerequsite-box, +#install-box { + container-type: inline-size; +} + +/* Table Styles */ +table { + width: 100%; + border-collapse: collapse; + border-top: 1px solid var(--stan-dark); /* Adds top border to the table */ + border-bottom: 1px solid var(--stan-dark); /* Adds bottom border to the table */ +} + +th, +td { + border: none; /* Removes borders from table cells */ + padding: 0.5em; /* Adjusts padding as needed */ +} + +thead th { + background-color: var(--stan-bg); + color: var(--stan-dark); +} + +tbody td:first-child { + background-color: var(--stan-bg); + color: var(--stan-dark); +} + +/* functions reference */ +.index-container { + display: flex; + flex-flow: row nowrap; + align-items: flex-end; + justify-content: space-between; +} + +a.unlink { + color: inherit; + text-decoration: none; +} + +span.detail { + font-size: small; + color: var(--quarto-text-muted); +} From a5dccff5f5386c6458ebecd4b7d6635199158fee Mon Sep 17 00:00:00 2001 From: Mitzi Morris Date: Wed, 9 Apr 2025 15:05:45 -0400 Subject: [PATCH 6/7] changes per code review --- src/reference-manual/transforms.qmd | 1 + src/reference-manual/types.qmd | 36 +++++++++++++++++----- src/stan-users-guide/efficiency-tuning.qmd | 30 +++++++++--------- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/reference-manual/transforms.qmd b/src/reference-manual/transforms.qmd index 72d5069cb..9fa0e69b9 100644 --- a/src/reference-manual/transforms.qmd +++ b/src/reference-manual/transforms.qmd @@ -330,6 +330,7 @@ $$ The default value for the offset $\mu$ is $0$ and for the multiplier $\sigma$ is $1$ in case not both are specified. + For a container variable, the affine transform is applied to each element of that variable. ### Affine inverse transform {-} diff --git a/src/reference-manual/types.qmd b/src/reference-manual/types.qmd index c645934f7..227f64633 100644 --- a/src/reference-manual/types.qmd +++ b/src/reference-manual/types.qmd @@ -438,8 +438,8 @@ $1$ and multiplier $2$. real x; ``` -As an example, we can give `x` a normal distribution with non-centered -parameterization as follows. +As an example, we can give `x` a normal distribution with non-centered parameterization. +In this program, the affine transform is applied to every element of vector `x`. ```stan parameters { @@ -450,7 +450,7 @@ model { } ``` -Recall that the centered parameterization is achieved with the code +Recall the Stan code for the centered parameterization of this model. ```stan parameters { @@ -461,17 +461,37 @@ model { } ``` -or equivalently +Adding the offset, multiplier transform results in the equivalent non-centered parameterization. ```stan parameters { - real x; + real x; } model { x ~ normal(mu, sigma); } ``` +With the affine transform, the sampling happens in different parameter space. +The model itself doesn’t change if we make parameter transformation, +but the geometry of the transformed space can be easier for the sampler. +The above model is equivalent to the hand-coded non-centered parameterization. + +```stan +parameters { + real x_raw; +} +transformed parameters { + real x = mu + x_raw * sigma; +} +model { + x_raw ~ std_normal(); +} +``` + +Use of the affine transform removes the overhead of declaring additional transformed parameters +and directly expresses the hierarchical relationship between parameters. + For a container variable, the affine transform is applied to each element of that variable. As an example, the non-centered parameterization of Neal's Funnel in the [Stan User's Guide reparameterization section](https://mc-stan.org/docs/stan-users-guide/reparameterization.html), @@ -484,11 +504,11 @@ can be written as: ```stan parameters { real y; - vector[9] x; + vector[9] x; } model { - y ~ std_normal(); - x ~ std_normal(); + y ~ normal(0, 3); + x ~ std_normal(0, 0.5 * y); } ``` where the affine transform is applied to every element of vector `x`. diff --git a/src/stan-users-guide/efficiency-tuning.qmd b/src/stan-users-guide/efficiency-tuning.qmd index f929dac1d..9af043392 100644 --- a/src/stan-users-guide/efficiency-tuning.qmd +++ b/src/stan-users-guide/efficiency-tuning.qmd @@ -293,13 +293,13 @@ inefficient in the body. This can be seen in the following plots. ![](img/funnel-fit.png) -Neal's funnel. (Left) The marginal density of Neal's funnel for the upper-level variable $y$ and one lower-level variable $x_1$ (see the text for the formula). The blue region has log density greater than -8, the yellow region density greater than -16, and the gray background a density less than -16. -(Right) 4000 draws are taken from a run of Stan's sampler with default settings. -Both plots are restricted to the shown window of $x_1$ and $y$ values; -some draws fell outside of the displayed area as would be expected given -the density. The samples are consistent with the marginal density -$p(y) = \textsf{normal}(y \mid 0,3)$, which has mean 0 and standard -deviation 3. +Neal's funnel. (Left) The marginal density of Neal's funnel for the upper-level variable $y$ and +one lower-level variable $x_1$ (see the text for the formula). The blue region has log density +greater than -8, the yellow region density greater than -16, and the gray background a density less +than -16. (Right) 4000 draws are taken from a run of Stan's sampler with default settings. +Both plots are restricted to the shown window of $x_1$ and $y$ values; some draws fell outside of +the displayed area as would be expected given the density. The samples are consistent with the +marginal density $p(y) = \textsf{normal}(y \mid 0,3)$, which has mean 0 and standard deviation 3. ::: In this particular instance, because the analytic form of the density @@ -312,11 +312,8 @@ parameters { vector[9] x_raw; } transformed parameters { - real y; - vector[9] x; - - y = 3.0 * y_raw; - x = exp(y/2) * x_raw; + real y = 3.0 * y_raw; + vector[9] x = exp(0.5 * y) * x_raw; } model { y_raw ~ std_normal(); // implies y ~ normal(0, 3) @@ -327,7 +324,7 @@ model { In this second model, the parameters `x_raw` and `y_raw` are sampled as independent standard normals, which is easy for Stan, and then transformed into samples from the funnel. -When this reparameterization is used in Stan code, a comment indicating what the +When this transform is used in Stan code, a comment indicating what the distribution for the parameter implies for the distribution of the transformed parameter will improve readibility and maintainability. @@ -338,14 +335,15 @@ The affine transform on the vector `x` is applied to each element of `x`. ```stan parameters { real y; - vector[9] x; + vector[9] x; } model { - y ~ std_normal(); // implies y ~ normal(0, 3) - x ~ std_normal(); // implies x ~ normal(0, exp(y/2)) + y ~ normal(0, 3); + x ~ normal(0, 0.5 * y); } ``` + ### Reparameterizing the Cauchy {-} Sampling from heavy tailed distributions such as the Cauchy is From acba64c7bf256fa11e3f516a8e153a90eef41d95 Mon Sep 17 00:00:00 2001 From: Mitzi Morris Date: Thu, 10 Apr 2025 12:23:11 -0400 Subject: [PATCH 7/7] changes per code review --- src/reference-manual/types.qmd | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/reference-manual/types.qmd b/src/reference-manual/types.qmd index 227f64633..df4dd4b22 100644 --- a/src/reference-manual/types.qmd +++ b/src/reference-manual/types.qmd @@ -472,10 +472,9 @@ model { } ``` -With the affine transform, the sampling happens in different parameter space. -The model itself doesn’t change if we make parameter transformation, -but the geometry of the transformed space can be easier for the sampler. -The above model is equivalent to the hand-coded non-centered parameterization. +Sampling is done on the unconstrained parameters. +After applying the affine transform, the unconstrained parameters are standard normal, +thus the above model is equivalent to the hand-coded non-centered parameterization. ```stan parameters {