From 19d079ff1c13b7d8c1cfeac9576f1e79914aa474 Mon Sep 17 00:00:00 2001 From: n-kall <33577035+n-kall@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:37:07 +0300 Subject: [PATCH 1/3] first attempt at language selection --- _quarto.yml | 10 ++++++++++ gen_linear_regression/r2d2.qmd | 9 +++++++-- scripts/language_select.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 scripts/language_select.js diff --git a/_quarto.yml b/_quarto.yml index d568e5b..fd74829 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -6,6 +6,13 @@ website: sidebar: collapse-level: 1 contents: + - text: | + - section: "Regression" contents: - gen_linear_regression/gen_linear_regression_overview.qmd @@ -58,6 +65,9 @@ website: format: html: theme: cosmo + include-after-body: + - text: | + css: styles.css toc: true code-fold: true diff --git a/gen_linear_regression/r2d2.qmd b/gen_linear_regression/r2d2.qmd index 27c0874..26bbf2b 100644 --- a/gen_linear_regression/r2d2.qmd +++ b/gen_linear_regression/r2d2.qmd @@ -36,7 +36,12 @@ $$ Priors on $\alpha$ and $\sigma$. Hyperparameters $\xi$, $\mu_{R^2}$, $\phi_{R^2}$. -# Stan code - +# Implementation +::: {.example .stan} ```{.stan include="../stan/r2d2.stan"} ``` +::: + +::: {.example .pymc} + +::: \ No newline at end of file diff --git a/scripts/language_select.js b/scripts/language_select.js new file mode 100644 index 0000000..e51d3df --- /dev/null +++ b/scripts/language_select.js @@ -0,0 +1,31 @@ +document.addEventListener("DOMContentLoaded", function() { + const langSelector = document.getElementById("language-selector"); + + // Load the selected language from localStorage if available + const savedLang = localStorage.getItem("selectedLanguage"); + if (savedLang) { + langSelector.value = savedLang; + } + + // Function to show/hide code examples based on the selected language + function updateExamples() { + const selectedLang = langSelector.value; + + // Save the selected language to localStorage + localStorage.setItem("selectedLanguage", selectedLang); + + document.querySelectorAll(".example").forEach(function(example) { + if (example.classList.contains(selectedLang)) { + example.style.display = "block"; + } else { + example.style.display = "none"; + } + }); + } + + // Listen for changes in the dropdown menu + langSelector.addEventListener("change", updateExamples); + + // Initialize by showing the appropriate examples when the page loads + updateExamples(); +}); From 1455115e9a3b69fe598ccbfb8bd0efcbb867f759 Mon Sep 17 00:00:00 2001 From: n-kall <33577035+n-kall@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:46:14 +0300 Subject: [PATCH 2/3] mark stan examples as such --- gen_linear_regression/gr2.qmd | 4 +++- gen_linear_regression/l1_ball.qmd | 4 +++- hierarchical_regression/r2d2m2.qmd | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gen_linear_regression/gr2.qmd b/gen_linear_regression/gr2.qmd index 3e70cce..c852904 100644 --- a/gen_linear_regression/gr2.qmd +++ b/gen_linear_regression/gr2.qmd @@ -37,7 +37,9 @@ Priors on $\alpha$ and $\sigma$. Hyperparameters $\xi$, $\mu_{R^2}$, $\phi_{R^2} Prior on simplex $\phi$. -# Stan code +# Implementation +::: {.example .stan} ```{.stan include="../stan/r2d2.stan"} ``` +::: \ No newline at end of file diff --git a/gen_linear_regression/l1_ball.qmd b/gen_linear_regression/l1_ball.qmd index 5eabca1..1c1fe41 100644 --- a/gen_linear_regression/l1_ball.qmd +++ b/gen_linear_regression/l1_ball.qmd @@ -21,7 +21,9 @@ $$ Prior on the radius of the ball $r$. Prior on the unprojected $\beta$ coefficients. -# Stan code +# Implementation +::: {.example .stan} ```{.stan include="../stan/l1_ball.stan"} ``` +::: \ No newline at end of file diff --git a/hierarchical_regression/r2d2m2.qmd b/hierarchical_regression/r2d2m2.qmd index 4475f8f..722a25d 100644 --- a/hierarchical_regression/r2d2m2.qmd +++ b/hierarchical_regression/r2d2m2.qmd @@ -8,7 +8,9 @@ An extension of the R2D2 prior for multi-level models [@aguilarIntuitiveJointPri # Definition -# Stan code +# Implementation +:::{.example .stan} ```{.stan include="../stan/r2d2m2.stan"} ``` +::: \ No newline at end of file From 383c7c6343d0acbe0f61e18a3ade3f1e2bd174c8 Mon Sep 17 00:00:00 2001 From: n-kall <33577035+n-kall@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:48:49 +0300 Subject: [PATCH 3/3] mark another stan example --- gen_linear_regression/bernoulli_logit.qmd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gen_linear_regression/bernoulli_logit.qmd b/gen_linear_regression/bernoulli_logit.qmd index 995d0d1..5dd1bd0 100644 --- a/gen_linear_regression/bernoulli_logit.qmd +++ b/gen_linear_regression/bernoulli_logit.qmd @@ -62,9 +62,11 @@ logis_sigma <- function(n, q) { $p(\alpha) \propto \exp{(-\text{abs}({\alpha / \sqrt(2) \sigma})^\gamma)}$ +:::{.example .stan} ```stan target += -abs((alpha) / (sqrt(2.0) * alpha_scale))^(alpha_power); ``` +::: Similar to the method for the logistic prior, choosing $\sigma$ can be done with the following function: