title: lme4: bootstrap confidence intervals using sample data not in model
body: <p>I want to calculate the confidence interval for a model parameter (residual SD) divided by the mean of a variable not included in the model. Example:</p>
  <pre class="lang-r prettyprint-override"><code>library(lme4)
  #&gt; Loading required package: Matrix
  
  set.seed(1)
  
  mod &lt;- lmer(angle ~ recipe + (1|replicate), data = cake)
  
  calc_stats &lt;- function(model) {
      recipeA &lt;- fixef(model)[[1]] # Get intercept from model
      sd_components &lt;- as.data.frame(VarCorr(model))[['sdcor']] # Get variance components (SD)
      sd_between = sd_components[1]
      sd_within = sd_components[2]
      
      c(
          recipeA = recipeA,
          sd_between = sd_between,
          sd_within = sd_within
      )
  }
  
  confint(mod, method=&quot;boot&quot;, FUN = calc_stats, nsim = 100)
  #&gt;                2.5 %    97.5 %
  #&gt; recipeA    29.095426 36.722292
  #&gt; sd_between  3.800349  9.382943
  #&gt; sd_within   5.044569  6.078210
  </code></pre>
  <p><sup>Created on 2021-10-07 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v2.0.0)</sup></p>
  <p>I want to calculate a CI for sd_within/mean(temperature), where temperature is a variable in the dataframe, but not included in the model.</p>
  <p>The problem is that temperature is not in <code>mod@frame</code>. Therefore i cannot access it for the bootstrap refits of the model.</p>
  <p>(My first idea was to simply add it to the model object <code>mod@frame &lt;- cake</code>, but it is of cause lost when refitting the model).</p>