Skip to content

Commit

Permalink
updated using new array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
joonho112 committed Sep 17, 2023
1 parent 33beccb commit 26cb940
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
10 changes: 5 additions & 5 deletions education/causal_iv_one-sided/case_study_02_IV_one-sided.html
Original file line number Diff line number Diff line change
Expand Up @@ -3381,12 +3381,12 @@ <h3 data-number="4.1" class="anchored" data-anchor-id="stan-model-with-exclusion
<section id="data-block" class="level4">
<h4 class="anchored" data-anchor-id="data-block">Data block</h4>
<div class="sourceCode" id="cb3"><pre class="sourceCode stan code-with-copy"><code class="sourceCode stan"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="kw">data</span> {</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span>&lt;<span class="kw">lower</span>=<span class="dv">1</span>&gt; N; <span class="co">// Sample size N </span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span>&lt;<span class="kw">lower</span>=<span class="dv">0</span>, <span class="kw">upper</span>=<span class="dv">1</span>&gt; Z[N]; <span class="co">// Treatment assigned Z</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span>&lt;<span class="kw">lower</span>=<span class="dv">0</span>, <span class="kw">upper</span>=<span class="dv">1</span>&gt; W[N]; <span class="co">// Treatment received W </span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span>&lt;<span class="kw">lower</span>=<span class="dv">0</span>, <span class="kw">upper</span>=<span class="dv">1</span>&gt; Y[N]; <span class="co">// Outcome Y </span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span>&lt;<span class="kw">lower</span>=<span class="dv">1</span>&gt; N; <span class="co">// Sample size N </span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">array</span>[N] <span class="dt">int</span>&lt;<span class="kw">lower</span>=<span class="dv">0</span>, <span class="kw">upper</span>=<span class="dv">1</span>&gt; Z; <span class="co">// Treatment assigned Z</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">array</span>[N] <span class="dt">int</span>&lt;<span class="kw">lower</span>=<span class="dv">0</span>, <span class="kw">upper</span>=<span class="dv">1</span>&gt; W; <span class="co">// Treatment received W</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="dt">array</span>[N] <span class="dt">int</span>&lt;<span class="kw">lower</span>=<span class="dv">0</span>, <span class="kw">upper</span>=<span class="dv">1</span>&gt; Y; <span class="co">// Outcome Y</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>For the model’s data inputs, we initially encode three observed binary variables (<span class="math inline">\(Z_{i}\)</span>, <span class="math inline">\(W_{i}^{\text{obs}}\)</span>, and <span class="math inline">\(Y_{i}^{\text{obs}}\)</span>) along with the number of units in the sample (<span class="math inline">\(N\)</span>).</p>
<p>For the model’s data inputs, we initially encode three observed binary variables (<span class="math inline">\(Z_{i}\)</span>, <span class="math inline">\(W_{i}^{\text{obs}}\)</span>, and <span class="math inline">\(Y_{i}^{\text{obs}}\)</span>) along with the number of units in the sample (<span class="math inline">\(N\)</span>). With the updated Stan syntax, we have shifted to using the <code>array</code> function for array declarations, which provides a more explicit and streamlined way to denote multidimensional structures. This modern syntax not only enhances clarity but also aligns with the direction of Stan’s evolution, ensuring compatibility with future versions.</p>
</section>
<section id="parameters-block" class="level4">
<h4 class="anchored" data-anchor-id="parameters-block">Parameters block</h4>
Expand Down
10 changes: 5 additions & 5 deletions education/causal_iv_one-sided/case_study_02_IV_one-sided.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ The model-based estimation strategy offers several advantages over the moment-ba

``` stan
data {
int<lower=1> N; // Sample size N
int<lower=0, upper=1> Z[N]; // Treatment assigned Z
int<lower=0, upper=1> W[N]; // Treatment received W
int<lower=0, upper=1> Y[N]; // Outcome Y
int<lower=1> N; // Sample size N
array[N] int<lower=0, upper=1> Z; // Treatment assigned Z
array[N] int<lower=0, upper=1> W; // Treatment received W
array[N] int<lower=0, upper=1> Y; // Outcome Y
}
```

For the model's data inputs, we initially encode three observed binary variables ($Z_{i}$, $W_{i}^{\text{obs}}$, and $Y_{i}^{\text{obs}}$) along with the number of units in the sample ($N$).
For the model's data inputs, we initially encode three observed binary variables ($Z_{i}$, $W_{i}^{\text{obs}}$, and $Y_{i}^{\text{obs}}$) along with the number of units in the sample ($N$). With the updated Stan syntax, we have shifted to using the `array` function for array declarations, which provides a more explicit and streamlined way to denote multidimensional structures. This modern syntax not only enhances clarity but also aligns with the direction of Stan's evolution, ensuring compatibility with future versions.


#### Parameters block
Expand Down
9 changes: 5 additions & 4 deletions education/causal_iv_one-sided/stan/cace_with_exclusion.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
data {
int<lower=1> N; // Sample size N
int<lower=0, upper=1> Z[N]; // Treatment assigned Z
int<lower=0, upper=1> W[N]; // Treatment received W
int<lower=0, upper=1> Y[N]; // Outcome Y
int<lower=1> N; // Sample size N
array[N] int<lower=0, upper=1> Z; // Treatment assigned Z
array[N] int<lower=0, upper=1> W; // Treatment received W
array[N] int<lower=0, upper=1> Y; // Outcome Y
}

parameters {
Expand Down Expand Up @@ -57,3 +57,4 @@ model {
}
}
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
data {
int<lower=1> N; // Sample size N
int<lower=0, upper=1> Z[N]; // Treatment assigned Z
int<lower=0, upper=1> W[N]; // Treatment received W
int<lower=0, upper=1> Y[N]; // Outcome Y
int<lower=1> N; // Sample size N
array[N] int<lower=0, upper=1> Z; // Treatment assigned Z
array[N] int<lower=0, upper=1> W; // Treatment received W
array[N] int<lower=0, upper=1> Y; // Outcome Y
}

parameters {
Expand Down Expand Up @@ -59,3 +59,4 @@ model {
}
}
}

0 comments on commit 26cb940

Please sign in to comment.