<!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>Using parallelization • specr</title>
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" 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><meta property="og:title" content="Using parallelization">
<meta property="og:description" content="specr">
<!-- 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]-->
</head>
<body data-spy="scroll" data-target="#toc">
    

    <div class="container template-article">
      <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">specr</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">1.0.1</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../articles/getting-started.html">Getting 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 class="dropdown-header">Basics</li>
    <li>
      <a href="../articles/different-specifications.html">Setting up different types of specifications</a>
    </li>
    <li>
      <a href="../articles/custom-plot.html">Visualizing specification curve analyses</a>
    </li>
    <li>
      <a href="../articles/invest-spec.html">Investigating specific specifications</a>
    </li>
    <li>
      <a href="../articles/inferences.html">Inferences with specification curve analysis</a>
    </li>
    <li>
      <a href="../articles/parallelization.html">Parallelization</a>
    </li>
    <li class="divider">
    </li>
<li class="dropdown-header">Incorporating specific models</li>
    <li>
      <a href="../articles/measurement-models.html">Structural equation models</a>
    </li>
    <li>
      <a href="../articles/multilevel-models.html">Multilevel models</a>
    </li>
    <li>
      <a href="../articles/parallel-bayesian-models.html">Bayesian models</a>
    </li>
  </ul>
</li>
<li>
  <a href="../news/index.html">News</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://github.com/masurp/specr" class="external-link">
    <span class="fa 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 toc-ignore">
      <h1 data-toc-skip>Using parallelization</h1>
            
      
      <small class="dont-index">Source: <a href="https://github.com/masurp/specr/blob/HEAD/vignettes/parallelization.Rmd" class="external-link"><code>vignettes/parallelization.Rmd</code></a></small>
      <div class="hidden name"><code>parallelization.Rmd</code></div>

    </div>

    
    
<p>A major improvement in version 0.3.0 of specr is that we can
parallelize the computations, which can reduce fitting time. For this,
specr uses functions from the package <a href="https://furrr.futureverse.org/" class="external-link">furrr</a>. I suggest to check out
the website of the package for further information. To be to use
relevant functions, we load the package furrr upfront.</p>
<p>Before we start to run some examples, bear in mind that using
parallelization does not always mean that the computations are
automatically faster. If the overall computation time is not very long,
using parallelization may even lead to a longer fitting process as
setting up several “workers” (essentially setting up procedures on
several cores) produces a considerable “overhead”. A true reduction in
fitting time is thus only achieved when the data set is large, the
number of specification are high, and the computed models are complex. I
thus first simulate a comparatively large data set that allows to
specify more than 1000 specifications.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Load packages</span></span>
<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://tidyverse.tidyverse.org" class="external-link">tidyverse</a></span><span class="op">)</span></span>
<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://masurp.github.io/specr/" class="external-link">specr</a></span><span class="op">)</span></span>
<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://github.com/DavisVaughan/furrr" class="external-link">furrr</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Data generating function</span></span>
<span><span class="va">generate_data</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">seed</span> <span class="op">=</span> <span class="fl">42</span>, <span class="va">n</span> <span class="op">=</span> <span class="fl">1e5</span><span class="op">)</span> <span class="op">{</span></span>
<span>  <span class="kw">if</span> <span class="op">(</span><span class="op">!</span><span class="fu"><a href="https://rdrr.io/r/base/NA.html" class="external-link">is.na</a></span><span class="op">(</span><span class="va">seed</span><span class="op">)</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/Random.html" class="external-link">set.seed</a></span><span class="op">(</span><span class="va">seed</span><span class="op">)</span></span>
<span>  <span class="va">dat</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://tibble.tidyverse.org/reference/tibble.html" class="external-link">tibble</a></span><span class="op">(</span></span>
<span>    x1 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span>,</span>
<span>    x2 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span><span class="op">+</span> <span class="fl">0.9</span><span class="op">*</span><span class="va">x1</span>,</span>
<span>    x3 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span><span class="op">+</span> <span class="fl">0.9</span><span class="op">*</span><span class="va">x2</span>,</span>
<span>    x4 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span><span class="op">+</span> <span class="fl">0.9</span><span class="op">*</span><span class="va">x3</span>,</span>
<span>    y4 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/rep.html" class="external-link">rep</a></span><span class="op">(</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="fl">1</span>, <span class="fl">0</span><span class="op">)</span>, times <span class="op">=</span> <span class="va">n</span><span class="op">/</span><span class="fl">2</span><span class="op">)</span>,</span>
<span>    y1 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span> <span class="op">+</span> <span class="va">x1</span><span class="op">*</span><span class="fl">.1</span> <span class="op">*</span> <span class="fl">0.9</span><span class="op">*</span><span class="va">y4</span>,</span>
<span>    y2 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span> <span class="op">+</span> <span class="va">x1</span><span class="op">*</span><span class="fl">.2</span>,</span>
<span>    y3 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span> <span class="op">+</span> <span class="va">x1</span><span class="op">*</span><span class="fl">.2</span> <span class="op">+</span> <span class="op">-</span><span class="fl">0.4</span><span class="op">*</span><span class="va">x2</span>, </span>
<span>    c1 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span> <span class="op">+</span> <span class="va">x1</span><span class="op">*</span><span class="fl">.3</span>,</span>
<span>    c2 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span>,</span>
<span>    c3 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span> <span class="op">+</span> <span class="fl">0.9</span><span class="op">*</span><span class="va">c1</span>,</span>
<span>    c4 <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="va">n</span><span class="op">)</span>,</span>
<span>    group <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</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="st">"a"</span>, <span class="st">"b"</span>, <span class="st">"c"</span>, <span class="st">"d"</span>, <span class="st">"e"</span><span class="op">)</span>, <span class="va">n</span>, replace <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span>  <span class="op">)</span></span>
<span><span class="op">}</span></span>
<span></span>
<span><span class="co"># Generate very large data set (n = 100,000, 9.9 MB on disk)</span></span>
<span><span class="va">dat</span> <span class="op">&lt;-</span> <span class="fu">generate_data</span><span class="op">(</span><span class="fl">9</span><span class="op">)</span></span></code></pre></div>
<div class="section level2">
<h2 id="simple-parallelization-without-custom-functions">Simple parallelization without custom functions<a class="anchor" aria-label="anchor" href="#simple-parallelization-without-custom-functions"></a>
</h2>
<p>If we use standard model fitting function (e.g., “lm”) that are
included in the base package, parallelization is comparatively simple.
We only need to load the package <code>furrr</code> and specify a “plan
for how to resolve a future” (for more information see
<code><a href="https://future.futureverse.org/reference/plan.html" class="external-link">?future::plan</a></code>). In this case, I am choosing
<code>multisession</code> (resolve the computations separate R sessions
running in the background on the same machine) and specify
<code>workers = 4</code> so that it runs on 4 cores in parallel.</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Setup of specifications (number of specs = 1152)</span></span>
<span><span class="va">specs</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/setup.html">setup</a></span><span class="op">(</span>data <span class="op">=</span> <span class="va">dat</span>,            </span>
<span>               y <span class="op">=</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="st">"y1"</span>, <span class="st">"y2"</span>, <span class="st">"y3"</span><span class="op">)</span>,                    </span>
<span>               x <span class="op">=</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="st">"x1"</span>, <span class="st">"x2"</span>, <span class="st">"x3"</span>, <span class="st">"x4"</span><span class="op">)</span>,               </span>
<span>               model <span class="op">=</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="st">"lm"</span><span class="op">)</span>, </span>
<span>               controls <span class="op">=</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="st">"c1"</span>, <span class="st">"c2"</span>, <span class="st">"c3"</span>, <span class="st">"c4"</span><span class="op">)</span>,</span>
<span>               subsets <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>group <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/unique.html" class="external-link">unique</a></span><span class="op">(</span><span class="va">dat</span><span class="op">$</span><span class="va">group</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>   </span>
<span></span>
<span><span class="co"># Default: Sequential ---</span></span>
<span><span class="va">results_simple</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/specr.html">specr</a></span><span class="op">(</span><span class="va">specs</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Parallel: Multisession (only works when `furrr` is loaded!)</span></span>
<span><span class="fu"><a href="https://future.futureverse.org/reference/plan.html" class="external-link">plan</a></span><span class="op">(</span>strategy <span class="op">=</span> <span class="va">multisession</span>, workers <span class="op">=</span> <span class="fl">4</span><span class="op">)</span></span>
<span><span class="va">results_parall</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/specr.html">specr</a></span><span class="op">(</span><span class="va">specs</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Comparison</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/cat.html" class="external-link">cat</a></span><span class="op">(</span><span class="st">"Sequential: "</span>, <span class="va">results_simple</span><span class="op">$</span><span class="va">time</span>, <span class="st">"\n"</span>,</span>
<span>    <span class="st">"Parallel:   "</span>, <span class="va">results_parall</span><span class="op">$</span><span class="va">time</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## Sequential:  57.227 sec elapsed </span></span>
<span><span class="co">## Parallel:    36.781 sec elapsed</span></span></code></pre>
<p>As we can see, the default (sequential) computation took around a
minute (57.227 sec elapsed) and the parallel computation about half a
minute (36.781 sec elapsed).</p>
<p>We have to acknowledge that even with this comparatively large data
set and more than 1,000 specifications, the reduction in time not too
much. Thus, parallelization only makes sense if you have a truly large
data set and thousands of specifications <em>or</em> the type of model
you are estimating takes a really long time (e.g., a complex structural
equation model, a negative binomial model, etc.). The true power of
parallelization furthermore only come into play if you are using a
considerable number of cores.</p>
</div>
<div class="section level2">
<h2 id="parallelization-with-custom-functions-from-different-packages">Parallelization with custom functions from different packages<a class="anchor" aria-label="anchor" href="#parallelization-with-custom-functions-from-different-packages"></a>
</h2>
<p>If we use a custom function, we need to make sure that this function
is passed to the different workers. This can be done by specifying so
called <code>furrr_options</code>. We need to pass objects from the
global environment (and potentially also packages) as shown below.
Please note that we do not have to specify the “future plan” again,
because have specified it already earlier in this session (see above).
If we are unsure what plan is currently specified, we can simply run
<code><a href="https://future.futureverse.org/reference/plan.html" class="external-link">plan()</a></code> and get some information about the current
setup.</p>
<p>As computation can take a long time, it would be nice if we would see
some kind of progress indication. This can easily be done by simply
adding the argument <code>.progress = TRUE</code> to
<code><a href="../reference/specr.html">specr()</a></code>. This passes this argument to the
<code><a href="https://furrr.futureverse.org/reference/future_map2.html" class="external-link">future_pmap()</a></code> function within <code><a href="../reference/specr.html">specr()</a></code> and
prints a rudimentary progress bar during the fitting process.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Custom function</span></span>
<span><span class="va">log_model</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">formula</span>, <span class="va">data</span><span class="op">)</span> <span class="op">{</span></span>
<span>  <span class="fu"><a href="https://rdrr.io/r/stats/glm.html" class="external-link">glm</a></span><span class="op">(</span><span class="va">formula</span>, <span class="va">data</span>, family <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/stats/family.html" class="external-link">binomial</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="op">}</span></span>
<span></span>
<span><span class="co"># Setup specs</span></span>
<span><span class="va">specs</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/setup.html">setup</a></span><span class="op">(</span>data <span class="op">=</span> <span class="va">dat</span>,            </span>
<span>               y <span class="op">=</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="st">"y4"</span><span class="op">)</span>,                    </span>
<span>               x <span class="op">=</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="st">"x1"</span>, <span class="st">"x2"</span>, <span class="st">"x3"</span><span class="op">)</span>,               </span>
<span>               model <span class="op">=</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="st">"log_model"</span><span class="op">)</span>, </span>
<span>               controls <span class="op">=</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="st">"c1"</span>, <span class="st">"c2"</span><span class="op">)</span>,</span>
<span>               subsets <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>group <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/unique.html" class="external-link">unique</a></span><span class="op">(</span><span class="va">dat</span><span class="op">$</span><span class="va">group</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>   </span>
<span></span>
<span><span class="co"># Create furrr_options to be passed to specr() (only works if `furrr` is loaded)</span></span>
<span><span class="va">opts</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://furrr.futureverse.org/reference/furrr_options.html" class="external-link">furrr_options</a></span><span class="op">(</span></span>
<span>  globals <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>log_model <span class="op">=</span> <span class="va">log_model</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># What "plan" is currently specified?</span></span>
<span><span class="fu"><a href="https://future.futureverse.org/reference/plan.html" class="external-link">plan</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## multisession:</span></span>
<span><span class="co">## - args: function (..., workers = 4, envir = parent.frame())</span></span>
<span><span class="co">## - tweaked: TRUE</span></span>
<span><span class="co">## - call: plan(strategy = multisession, workers = 4)</span></span></code></pre>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Run results</span></span>
<span><span class="va">results_parall_2</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/specr.html">specr</a></span><span class="op">(</span><span class="va">specs</span>, </span>
<span>                          .options <span class="op">=</span> <span class="va">opts</span>,   <span class="co"># Pass ops to specr</span></span>
<span>                          .progress <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>  <span class="co"># To add progress bar (not shown in output)</span></span>
<span></span>
<span><span class="co"># Summarize results</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">results_parall_2</span><span class="op">)</span></span></code></pre></div>
<pre><code><span><span class="co">## Results of the specification curve analysis</span></span>
<span><span class="co">## -------------------</span></span>
<span><span class="co">## Technical details:</span></span>
<span><span class="co">## </span></span>
<span><span class="co">##   Class:                          specr.object -- version: 1.0.0 </span></span>
<span><span class="co">##   Cores used:                     4 </span></span>
<span><span class="co">##   Duration of fitting process:    37.736 sec elapsed </span></span>
<span><span class="co">##   Number of specifications:       72 </span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Descriptive summary of the specification curve:</span></span>
<span><span class="co">## </span></span>
<span><span class="co">##  median  mad   min  max q25  q75</span></span>
<span><span class="co">##    0.01 0.01 -0.02 0.03   0 0.01</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Descriptive summary of sample sizes: </span></span>
<span><span class="co">## </span></span>
<span><span class="co">##  median   min   max</span></span>
<span><span class="co">##   20038 19844 1e+05</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Head of the specification results (first 6 rows): </span></span>
<span><span class="co">## </span></span>
<span><span class="co">## # A tibble: 6 × 21</span></span>
<span><span class="co">##   x     y     model  controls subsets group formula estimate std.error statistic p.value conf.low </span></span>
<span><span class="co">##   &lt;chr&gt; &lt;chr&gt; &lt;chr&gt;  &lt;chr&gt;    &lt;chr&gt;   &lt;fct&gt; &lt;glue&gt;     &lt;dbl&gt;     &lt;dbl&gt;     &lt;dbl&gt;   &lt;dbl&gt;    &lt;dbl&gt; </span></span>
<span><span class="co">## 1 x1    y4    log_m… no cova… e       e     y4 ~ x…     0.01      0.01      0.38    0.7     -0.02 </span></span>
<span><span class="co">## 2 x1    y4    log_m… no cova… a       a     y4 ~ x…     0.01      0.01      0.62    0.54    -0.02 </span></span>
<span><span class="co">## 3 x1    y4    log_m… no cova… d       d     y4 ~ x…    -0.02      0.01     -1.17    0.24    -0.04 </span></span>
<span><span class="co">## 4 x1    y4    log_m… no cova… c       c     y4 ~ x…     0         0.01     -0.16    0.87    -0.03 </span></span>
<span><span class="co">## 5 x1    y4    log_m… no cova… b       b     y4 ~ x…     0.03      0.01      1.84    0.07     0    </span></span>
<span><span class="co">## 6 x1    y4    log_m… no cova… all     &lt;NA&gt;  y4 ~ x…     0         0.01      0.66    0.51    -0.01 </span></span>
<span><span class="co">## # … with 9 more variables: conf.high &lt;dbl&gt;, fit_null.devian… &lt;dbl&gt;, fit_df.null &lt;dbl&gt;, </span></span>
<span><span class="co">## #   fit_logLik &lt;dbl&gt;, fit_AIC &lt;dbl&gt;, fit_BIC &lt;dbl&gt;, fit_deviance &lt;dbl&gt;, fit_df.residual &lt;dbl&gt;, </span></span>
<span><span class="co">## #   fit_nobs &lt;dbl&gt;</span></span></code></pre>
<p>Note: In the technical details of the summary, we also always see how
many cores were used and how long the fitting process has taken.</p>
<p>At the end of our analysis, it makes sense to explicitly close
multisession workers by switching the plan back to sequential.</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://future.futureverse.org/reference/plan.html" class="external-link">plan</a></span><span class="op">(</span><span class="va">sequential</span><span class="op">)</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"><h2 data-toc-skip>Contents</h2>
    </nav>
</div>

</div>



      <footer><div class="copyright">
  <p></p>
<p>Developed by Philipp K. Masur, Michael Scharkow.</p>
</div>

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

      </footer>
</div>

  


  

  </body>
</html>
