Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language selection #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ website:
sidebar:
collapse-level: 1
contents:
- text: |
<div id="sidebar-content">
<select id="language-selector">
<option value="pymc">PyMC</option>
<option value="stan">Stan</option>
</select>
</div>
- section: "Regression"
contents:
- gen_linear_regression/gen_linear_regression_overview.qmd
Expand Down Expand Up @@ -58,6 +65,9 @@ website:
format:
html:
theme: cosmo
include-after-body:
- text: |
<script src="/scripts/language_select.js"></script>
css: styles.css
toc: true
code-fold: true
Expand Down
2 changes: 2 additions & 0 deletions gen_linear_regression/bernoulli_logit.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion gen_linear_regression/gr2.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
```
:::
4 changes: 3 additions & 1 deletion gen_linear_regression/l1_ball.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
```
:::
9 changes: 7 additions & 2 deletions gen_linear_regression/r2d2.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}

:::
4 changes: 3 additions & 1 deletion hierarchical_regression/r2d2m2.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
```
:::
31 changes: 31 additions & 0 deletions scripts/language_select.js
Original file line number Diff line number Diff line change
@@ -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();
});