&lt;-<span class="st"> </span><span class="kw">ifelse</span>(Z <span class="op">==</span><span class="st"> &quot;female&quot;</span>, <span class="dv">1</span>, <span class="dv">0</span>)</a>
<a class="sourceLine" id="cb1-9" data-line-number="9">Y &lt;-<span class="st"> </span><span class="kw">rbinom</span>(n, <span class="dv">1</span>, <span class="kw">plogis</span>(X <span class="op">-</span><span class="st"> </span>W <span class="op">+</span><span class="st"> </span><span class="dv">2</span><span class="