<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Extract draws from a Bayesian model into tidy data frames of random variables — gather_rvars • tidybayes</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/paper/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css"><script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet"><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet"><meta property="og:title" content="Extract draws from a Bayesian model into tidy data frames of random variables — gather_rvars"><meta property="og:description" content="Extract draws from a Bayesian model for one or more variables (possibly with named
dimensions) into one of two types of long-format data frames of posterior::rvar objects."><meta property="og:image" content="https://mjskay.github.io/tidybayes/logo.svg"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--><!-- Global site tag (gtag.js) - Google Analytics --><script async src="https://www.googletagmanager.com/gtag/js?id=UA-93322-5"></script><script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-93322-5');
</script></head><body data-spy="scroll" data-target="#toc">


    <div class="container template-reference-topic">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">tidybayes</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">3.0.7</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav"><li>
  <a href="../articles/tidybayes.html">Get started</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
    Articles

    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu"><li>
      <a href="../articles/tidy-brms.html">Extracting and visualizing tidy draws from brms models</a>
    </li>
    <li>
      <a href="../articles/tidy-posterior.html">Using tidybayes with the posterior package</a>
    </li>
    <li>
      <a href="../articles/tidy-rstanarm.html">Extracting and visualizing tidy draws from rstanarm models</a>
    </li>
    <li>
      <a href="../articles/tidybayes-residuals.html">Extracting and visualizing tidy residuals from Bayesian models</a>
    </li>
  </ul></li>
<li>
  <a href="../news/index.html">Changelog</a>
</li>
      </ul><ul class="nav navbar-nav navbar-right"><li>
  <a href="https://github.com/mjskay/tidybayes/" class="external-link">
    <span class="fab fa-github fa-lg"></span>

  </a>
</li>
      </ul></div><!--/.nav-collapse -->
  </div><!--/.container -->
</div><!--/.navbar -->



      </header><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header">
    <h1>Extract draws from a Bayesian model into tidy data frames of random variables</h1>
    <small class="dont-index">Source: <a href="https://github.com/mjskay/tidybayes/blob/HEAD/R/gather_rvars.R" class="external-link"><code>R/gather_rvars.R</code></a>, <a href="https://github.com/mjskay/tidybayes/blob/HEAD/R/spread_rvars.R" class="external-link"><code>R/spread_rvars.R</code></a></small>
    <div class="hidden name"><code>spread_rvars.Rd</code></div>
    </div>

    <div class="ref-description">
    <p>Extract draws from a Bayesian model for one or more variables (possibly with named
dimensions) into one of two types of long-format data frames of <a href="https://mc-stan.org/posterior/reference/rvar.html" class="external-link">posterior::rvar</a> objects.</p>
    </div>

    <div id="ref-usage">
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">gather_rvars</span><span class="op">(</span><span class="va">model</span>, <span class="va">...</span>, ndraws <span class="op">=</span> <span class="cn">NULL</span>, seed <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">spread_rvars</span><span class="op">(</span><span class="va">model</span>, <span class="va">...</span>, ndraws <span class="op">=</span> <span class="cn">NULL</span>, seed <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span></code></pre></div>
    </div>

    <div id="arguments">
    <h2>Arguments</h2>


<dl><dt id="arg-model">model<a class="anchor" aria-label="anchor" href="#arg-model"></a></dt>
<dd><p>A supported Bayesian model fit. Tidybayes supports a variety of model objects;
for a full list of supported models, see <a href="tidybayes-models.html">tidybayes-models</a>.</p></dd>


<dt id="arg--">...<a class="anchor" aria-label="anchor" href="#arg--"></a></dt>
<dd><p>Expressions in the form of
<code>variable_name[dimension_1, dimension_2, ...]</code>. See <em>Details</em>.</p></dd>


<dt id="arg-ndraws">ndraws<a class="anchor" aria-label="anchor" href="#arg-ndraws"></a></dt>
<dd><p>The number of draws to return, or <code>NULL</code> to return all draws.</p></dd>


<dt id="arg-seed">seed<a class="anchor" aria-label="anchor" href="#arg-seed"></a></dt>
<dd><p>A seed to use when subsampling draws (i.e. when <code>ndraws</code> is not <code>NULL</code>).</p></dd>

</dl></div>
    <div id="value">
    <h2>Value</h2>
    <p>A data frame.</p>
    </div>
    <div id="details">
    <h2>Details</h2>
    <p>Imagine a JAGS or Stan fit named <code>model</code>. The model may contain a variable named
<code>b[i,v]</code> (in the JAGS or Stan language) with dimension <code>i</code> in <code>1:100</code> and
dimension <code>v</code> in <code>1:3</code>. However, the default format for draws returned from
JAGS or Stan in R will not reflect this indexing structure, instead
they will have multiple columns with names like <code>"b[1,1]"</code>, <code>"b[2,1]"</code>, etc.</p>
<p><code>spread_rvars</code> and <code>gather_rvars</code> provide a straightforward
syntax to translate these columns back into properly-indexed <code><a href="https://mc-stan.org/posterior/reference/rvar.html" class="external-link">rvar</a></code>s in two different
tidy data frame formats, optionally recovering dimension types (e.g. factor levels) as it does so.</p>
<p><code>spread_rvars</code> will spread names of variables in the model across the data frame as column names,
whereas <code>gather_rvars</code> will gather variable names into a single column named <code>".variable"</code> and place
values of variables into a column named <code>".value"</code>. To use naming schemes from other packages
(such as <code>broom</code>), consider passing
results through functions like <code><a href="http://mjskay.github.io/ggdist/reference/tidy-format-translators.html" class="external-link">to_broom_names()</a></code> or <code><a href="http://mjskay.github.io/ggdist/reference/tidy-format-translators.html" class="external-link">to_ggmcmc_names()</a></code>.</p>
<p>For example, <code>spread_rvars(model, a[i], b[i,v])</code> might return a data frame with:</p><ul><li><p>column <code>"i"</code>: value in <code>1:5</code></p></li>
<li><p>column <code>"v"</code>: value in <code>1:10</code></p></li>
<li><p>column <code>"a"</code>: <code><a href="https://mc-stan.org/posterior/reference/rvar.html" class="external-link">rvar</a></code> containing draws from <code>"a[i]"</code></p></li>
<li><p>column <code>"b"</code>: <code><a href="https://mc-stan.org/posterior/reference/rvar.html" class="external-link">rvar</a></code> containing draws from <code>"b[i,v]"</code></p></li>
</ul><p><code>gather_rvars(model, a[i], b[i,v])</code> on the same model would return a data frame with:</p><ul><li><p>column <code>"i"</code>: value in <code>1:5</code></p></li>
<li><p>column <code>"v"</code>: value in <code>1:10</code>, or <code>NA</code>
on rows where <code>".variable"</code> is <code>"a"</code>.</p></li>
<li><p>column <code>".variable"</code>: value in <code>c("a", "b")</code>.</p></li>
<li><p>column <code>".value"</code>: <code><a href="https://mc-stan.org/posterior/reference/rvar.html" class="external-link">rvar</a></code> containing draws from <code>"a[i]"</code> (when <code>".variable"</code> is <code>"a"</code>)
or <code>"b[i,v]"</code> (when <code>".variable"</code> is <code>"b"</code>)</p></li>
</ul><p><code>spread_rvars</code> and <code>gather_rvars</code> can use type information
applied to the <code>model</code> object by <code><a href="recover_types.html">recover_types()</a></code> to convert columns
back into their original types. This is particularly helpful if some of the dimensions in
your model were originally factors. For example, if the <code>v</code> dimension
in the original data frame <code>data</code> was a factor with levels <code>c("a","b","c")</code>,
then we could use <code>recover_types</code> before <code>spread_rvars</code>:</p>
<div class="sourceCode"><pre><code><span><span class="va">model</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="../reference/recover_types.html">recover_types</a></span><span class="op">(</span><span class="va">data</span><span class="op">)</span> </span>
<span> <span class="fu"><a href="../reference/spread_rvars.html">spread_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">b</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span><span class="op">)</span></span></code></pre></div>

<p>Which would return the same data frame as above, except the <code>"v"</code> column
would be a value in <code>c("a","b","c")</code> instead of <code>1:3</code>.</p>
<p>For variables that do not share the same subscripts (or share
some but not all subscripts), we can supply their specifications separately.
For example, if we have a variable <code>d[i]</code> with the same <code>i</code> subscript
as <code>b[i,v]</code>, and a variable <code>x</code> with no subscripts, we could do this:</p>
<div class="sourceCode"><pre><code><span><span class="fu"><a href="../reference/spread_rvars.html">spread_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">x</span>, <span class="va">d</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>, <span class="va">b</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span><span class="op">)</span></span></code></pre></div>

<p>Which is roughly equivalent to this:</p>
<div class="sourceCode"><pre><code><span><span class="fu"><a href="../reference/spread_rvars.html">spread_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">x</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate-joins.html" class="external-link">inner_join</a></span><span class="op">(</span><span class="fu"><a href="../reference/spread_rvars.html">spread_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">d</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate-joins.html" class="external-link">inner_join</a></span><span class="op">(</span><span class="fu"><a href="../reference/spread_rvars.html">spread_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">b</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>

<p>Similarly, this:</p>
<div class="sourceCode"><pre><code><span><span class="fu"><a href="../reference/spread_rvars.html">gather_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">x</span>, <span class="va">d</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>, <span class="va">b</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span><span class="op">)</span></span></code></pre></div>

<p>Is roughly equivalent to this:</p>
<div class="sourceCode"><pre><code><span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/bind_rows.html" class="external-link">bind_rows</a></span><span class="op">(</span></span>
<span> <span class="fu"><a href="../reference/spread_rvars.html">gather_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">x</span><span class="op">)</span>,</span>
<span> <span class="fu"><a href="../reference/spread_rvars.html">gather_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">d</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">)</span>,</span>
<span> <span class="fu"><a href="../reference/spread_rvars.html">gather_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">b</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span><span class="op">)</span></span>
<span><span class="op">)</span></span></code></pre></div>

<p>The <code>c</code> and <code>cbind</code> functions can be used to combine multiple variable names that have
the same dimensions. For example, if we have several variables with the same
subscripts <code>i</code> and <code>v</code>, we could do either of these:</p>
<div class="sourceCode"><pre><code><span><span class="fu"><a href="../reference/spread_rvars.html">spread_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="va">w</span>, <span class="va">x</span>, <span class="va">y</span>, <span class="va">z</span><span class="op">)</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span><span class="op">)</span></span></code></pre></div>
<div class="sourceCode"><pre><code><span><span class="fu"><a href="../reference/spread_rvars.html">spread_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="fu"><a href="https://rdrr.io/r/base/cbind.html" class="external-link">cbind</a></span><span class="op">(</span><span class="va">w</span>, <span class="va">x</span>, <span class="va">y</span>, <span class="va">z</span><span class="op">)</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span><span class="op">)</span>  <span class="co"># equivalent</span></span></code></pre></div>

<p>Each of which is roughly equivalent to this:</p>
<div class="sourceCode"><pre><code><span><span class="fu"><a href="../reference/spread_rvars.html">spread_rvars</a></span><span class="op">(</span><span class="va">model</span>, <span class="va">w</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span>, <span class="va">x</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span>, <span class="va">y</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span>, <span class="va">z</span><span class="op">[</span><span class="va">i</span>,<span class="va">v</span><span class="op">]</span><span class="op">)</span></span></code></pre></div>

<p>Besides being more compact, the <code><a href="https://rdrr.io/r/base/c.html" class="external-link">c()</a></code>-style syntax is currently also slightly
faster (though that may change).</p>
<p>Dimensions can be left nested in the resulting <code><a href="https://mc-stan.org/posterior/reference/rvar.html" class="external-link">rvar</a></code> objects by leaving their names
blank; e.g. <code>spread_rvars(model, b[i,])</code> will place the first index (<code>i</code>) into
rows of the data frame but leave the second index nested in the <code>b</code> column
(see <em>Examples</em> below).</p>
    </div>
    <div id="see-also">
    <h2>See also</h2>
    <div class="dont-index"><p><code><a href="spread_draws.html">spread_draws()</a></code>, <code><a href="recover_types.html">recover_types()</a></code>, <code><a href="compose_data.html">compose_data()</a></code>. See also
<code><a href="https://mc-stan.org/posterior/reference/rvar.html" class="external-link">posterior::rvar()</a></code> and <code><a href="https://mc-stan.org/posterior/reference/draws_rvars.html" class="external-link">posterior::as_draws_rvars()</a></code>, the functions that power
<code>spread_rvars</code> and <code>gather_rvars</code>.</p></div>
    </div>
    <div id="author">
    <h2>Author</h2>
    <p>Matthew Kay</p>
    </div>

    <div id="ref-examples">
    <h2>Examples</h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span></span></span>
<span class="r-in"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/utils/data.html" class="external-link">data</a></span><span class="op">(</span><span class="va">RankCorr</span>, package <span class="op">=</span> <span class="st">"ggdist"</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">RankCorr</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span>  <span class="fu">spread_rvars</span><span class="op">(</span><span class="va">b</span><span class="op">[</span><span class="va">i</span>, <span class="va">j</span><span class="op">]</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 12 × 3</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        i     j               b</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>    <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span>      <span style="color: #949494; font-style: italic;">&lt;rvar[1d]&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span>     1     1  -1.076 <span style="color: #949494;">± 0.095</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span>     2     1  -0.735 <span style="color: #949494;">± 0.146</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span>     3     1  -0.341 <span style="color: #949494;">± 0.144</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span>     1     2  -1.821 <span style="color: #949494;">± 0.140</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span>     2     2   0.101 <span style="color: #949494;">± 0.254</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span>     3     2  -0.733 <span style="color: #949494;">± 0.229</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span>     1     3   0.176 <span style="color: #949494;">± 0.071</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span>     2     3  -0.178 <span style="color: #949494;">± 0.120</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span>     3     3   0.069 <span style="color: #949494;">± 0.121</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span>     1     4  -0.101 <span style="color: #949494;">± 0.121</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">11</span>     2     4   0.268 <span style="color: #949494;">± 0.221</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">12</span>     3     4   0.084 <span style="color: #949494;">± 0.207</span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># leaving an index out nests the index in the column containing the rvar</span></span></span>
<span class="r-in"><span><span class="va">RankCorr</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span>  <span class="fu">spread_rvars</span><span class="op">(</span><span class="va">b</span><span class="op">[</span><span class="va">i</span>, <span class="op">]</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 3 × 2</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>       i          b[,1]          [,2]            [,3]           [,4]</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   <span style="color: #949494; font-style: italic;">&lt;int&gt;</span>     <span style="color: #949494; font-style: italic;">&lt;rvar[,1]&gt;</span>    <span style="color: #949494; font-style: italic;">&lt;rvar[,1]&gt;</span>      <span style="color: #949494; font-style: italic;">&lt;rvar[,1]&gt;</span>     <span style="color: #949494; font-style: italic;">&lt;rvar[,1]&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span>     1  -1.08 <span style="color: #949494;">± 0.095</span>  -1.82 <span style="color: #949494;">± 0.14</span>   0.176 <span style="color: #949494;">± 0.071</span>  -0.101 <span style="color: #949494;">± 0.12</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span>     2  -0.74 <span style="color: #949494;">± 0.146</span>   0.10 <span style="color: #949494;">± 0.25</span>  -0.178 <span style="color: #949494;">± 0.120</span>   0.268 <span style="color: #949494;">± 0.22</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span>     3  -0.34 <span style="color: #949494;">± 0.144</span>  -0.73 <span style="color: #949494;">± 0.23</span>   0.069 <span style="color: #949494;">± 0.121</span>   0.084 <span style="color: #949494;">± 0.21</span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">RankCorr</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span>  <span class="fu">spread_rvars</span><span class="op">(</span><span class="va">b</span><span class="op">[</span><span class="va">i</span>, <span class="va">j</span><span class="op">]</span>, <span class="va">tau</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>, <span class="va">u_tau</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 12 × 5</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        i     j               b         tau      u_tau</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>    <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span>      <span style="color: #949494; font-style: italic;">&lt;rvar[1d]&gt;</span>  <span style="color: #949494; font-style: italic;">&lt;rvar[1d]&gt;</span> <span style="color: #949494; font-style: italic;">&lt;rvar[1d]&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span>     1     1  -1.076 <span style="color: #949494;">± 0.095</span>  6.0 <span style="color: #949494;">± 0.53</span>  5.7 <span style="color: #949494;">± 1.0</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span>     2     1  -0.735 <span style="color: #949494;">± 0.146</span>  3.3 <span style="color: #949494;">± 0.53</span>  5.7 <span style="color: #949494;">± 1.5</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span>     3     1  -0.341 <span style="color: #949494;">± 0.144</span>  3.7 <span style="color: #949494;">± 0.52</span>  5.1 <span style="color: #949494;">± 1.3</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span>     1     2  -1.821 <span style="color: #949494;">± 0.140</span>  6.0 <span style="color: #949494;">± 0.53</span>  5.7 <span style="color: #949494;">± 1.0</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span>     2     2   0.101 <span style="color: #949494;">± 0.254</span>  3.3 <span style="color: #949494;">± 0.53</span>  5.7 <span style="color: #949494;">± 1.5</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span>     3     2  -0.733 <span style="color: #949494;">± 0.229</span>  3.7 <span style="color: #949494;">± 0.52</span>  5.1 <span style="color: #949494;">± 1.3</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span>     1     3   0.176 <span style="color: #949494;">± 0.071</span>  6.0 <span style="color: #949494;">± 0.53</span>  5.7 <span style="color: #949494;">± 1.0</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span>     2     3  -0.178 <span style="color: #949494;">± 0.120</span>  3.3 <span style="color: #949494;">± 0.53</span>  5.7 <span style="color: #949494;">± 1.5</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span>     3     3   0.069 <span style="color: #949494;">± 0.121</span>  3.7 <span style="color: #949494;">± 0.52</span>  5.1 <span style="color: #949494;">± 1.3</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span>     1     4  -0.101 <span style="color: #949494;">± 0.121</span>  6.0 <span style="color: #949494;">± 0.53</span>  5.7 <span style="color: #949494;">± 1.0</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">11</span>     2     4   0.268 <span style="color: #949494;">± 0.221</span>  3.3 <span style="color: #949494;">± 0.53</span>  5.7 <span style="color: #949494;">± 1.5</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">12</span>     3     4   0.084 <span style="color: #949494;">± 0.207</span>  3.7 <span style="color: #949494;">± 0.52</span>  5.1 <span style="color: #949494;">± 1.3</span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># gather_rvars places variables and values in a longer format data frame</span></span></span>
<span class="r-in"><span><span class="va">RankCorr</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span>  <span class="fu">gather_rvars</span><span class="op">(</span><span class="va">b</span><span class="op">[</span><span class="va">i</span>, <span class="va">j</span><span class="op">]</span>, <span class="va">tau</span><span class="op">[</span><span class="va">i</span><span class="op">]</span>, <span class="va">typical_r</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 16 × 4</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        i     j .variable          .value</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>    <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span>          <span style="color: #949494; font-style: italic;">&lt;rvar[1d]&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span>     1     1 b          -1.076 <span style="color: #949494;">± 0.095</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span>     2     1 b          -0.735 <span style="color: #949494;">± 0.146</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span>     3     1 b          -0.341 <span style="color: #949494;">± 0.144</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span>     1     2 b          -1.821 <span style="color: #949494;">± 0.140</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span>     2     2 b           0.101 <span style="color: #949494;">± 0.254</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span>     3     2 b          -0.733 <span style="color: #949494;">± 0.229</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span>     1     3 b           0.176 <span style="color: #949494;">± 0.071</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span>     2     3 b          -0.178 <span style="color: #949494;">± 0.120</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span>     3     3 b           0.069 <span style="color: #949494;">± 0.121</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span>     1     4 b          -0.101 <span style="color: #949494;">± 0.121</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">11</span>     2     4 b           0.268 <span style="color: #949494;">± 0.221</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">12</span>     3     4 b           0.084 <span style="color: #949494;">± 0.207</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">13</span>     1    <span style="color: #BB0000;">NA</span> tau         6.041 <span style="color: #949494;">± 0.530</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">14</span>     2    <span style="color: #BB0000;">NA</span> tau         3.348 <span style="color: #949494;">± 0.534</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">15</span>     3    <span style="color: #BB0000;">NA</span> tau         3.663 <span style="color: #949494;">± 0.522</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">16</span>    <span style="color: #BB0000;">NA</span>    <span style="color: #BB0000;">NA</span> typical_r   0.544 <span style="color: #949494;">± 0.144</span></span>
<span class="r-in"><span></span></span>
</code></pre></div>
    </div>
  </div>
  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
    <nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
    </nav></div>
</div>


      <footer><div class="copyright">
  <p></p><p>Developed by <a href="https://www.mjskay.com" class="external-link">Matthew Kay</a>.</p>
</div>

<div class="pkgdown">
  <p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.0.</p>
</div>

      </footer></div>






  </body></html>

