<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>7 Exploring the posterior | CRABS: Congruent Rate Analyses in Birth-death Scenarios</title>
  <meta name="description" content="7 Exploring the posterior | CRABS: Congruent Rate Analyses in Birth-death Scenarios" />
  <meta name="generator" content="bookdown 0.36 and GitBook 2.6.7" />

  <meta property="og:title" content="7 Exploring the posterior | CRABS: Congruent Rate Analyses in Birth-death Scenarios" />
  <meta property="og:type" content="book" />
  
  
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="7 Exploring the posterior | CRABS: Congruent Rate Analyses in Birth-death Scenarios" />
  
  
  

<meta name="author" content="Sebastian Höhna" />
<meta name="author" content="Bjørn T. Kopperud" />
<meta name="author" content="Andrew F. Magee" />
<meta name="author" content="Jérémy Andréoletti" />


<meta name="date" content="2023-10-23" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="exploring-the-congruence-class.html"/>
<link rel="next" href="estimating-birth-death-models.html"/>
<script src="lib/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="lib/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="lib/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="lib/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="lib/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="lib/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="lib/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="lib/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />








<link href="lib/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="lib/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="lib/anchor-sections-1.1.0/anchor-sections.js"></script>


<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<style type="text/css">
  
  div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
</style>
<style type="text/css">
/* Used with Pandoc 2.11+ new --citeproc when CSL is used */
div.csl-bib-body { }
div.csl-entry {
  clear: both;
}
.hanging div.csl-entry {
  margin-left:2em;
  text-indent:-2em;
}
div.csl-left-margin {
  min-width:2em;
  float:left;
}
div.csl-right-inline {
  margin-left:2em;
  padding-left:1em;
}
div.csl-indent {
  margin-left: 2em;
}
</style>

</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li class="chapter" data-level="1" data-path="overview.html"><a href="overview.html"><i class="fa fa-check"></i><b>1</b> Overview</a></li>
<li class="chapter" data-level="2" data-path="installation.html"><a href="installation.html"><i class="fa fa-check"></i><b>2</b> Installation</a></li>
<li class="chapter" data-level="3" data-path="features.html"><a href="features.html"><i class="fa fa-check"></i><b>3</b> Features</a>
<ul>
<li class="chapter" data-level="3.1" data-path="features.html"><a href="features.html#overview-of-functions-in-crabs"><i class="fa fa-check"></i><b>3.1</b> Overview of functions in <code>CRABS</code></a></li>
<li class="chapter" data-level="3.2" data-path="features.html"><a href="features.html#samplebasic"><i class="fa fa-check"></i><b>3.2</b> <code>sample.basic.models</code></a></li>
<li class="chapter" data-level="3.3" data-path="features.html"><a href="features.html#samplejoint"><i class="fa fa-check"></i><b>3.3</b> <code>sample.basic.models.joint</code></a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="creating-the-congruence-class.html"><a href="creating-the-congruence-class.html"><i class="fa fa-check"></i><b>4</b> Creating the congruence class</a>
<ul>
<li class="chapter" data-level="4.1" data-path="creating-the-congruence-class.html"><a href="creating-the-congruence-class.html#rate-transformations"><i class="fa fa-check"></i><b>4.1</b> Rate transformations</a></li>
<li class="chapter" data-level="4.2" data-path="creating-the-congruence-class.html"><a href="creating-the-congruence-class.html#slopes-and-delta-t"><i class="fa fa-check"></i><b>4.2</b> Slopes and <span class="math inline">\(\Delta t\)</span></a></li>
<li class="chapter" data-level="4.3" data-path="creating-the-congruence-class.html"><a href="creating-the-congruence-class.html#the-model-object"><i class="fa fa-check"></i><b>4.3</b> The model object</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html"><i class="fa fa-check"></i><b>5</b> Testing alternative hypotheses</a>
<ul>
<li class="chapter" data-level="5.1" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#alt-ext"><i class="fa fa-check"></i><b>5.1</b> Testing alternative extinction rates</a>
<ul>
<li class="chapter" data-level="5.1.1" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#constant-extinction-rates"><i class="fa fa-check"></i><b>5.1.1</b> Constant extinction rates</a></li>
<li class="chapter" data-level="5.1.2" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#linearly-increasing-extinction-rates"><i class="fa fa-check"></i><b>5.1.2</b> Linearly increasing extinction rates</a></li>
<li class="chapter" data-level="5.1.3" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#exponential-increasing-extinction-rates"><i class="fa fa-check"></i><b>5.1.3</b> Exponential increasing extinction rates</a></li>
<li class="chapter" data-level="5.1.4" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#two-epoch-extinction-rates"><i class="fa fa-check"></i><b>5.1.4</b> Two-epoch extinction rates</a></li>
<li class="chapter" data-level="5.1.5" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#reversed-trend-extinction-rates"><i class="fa fa-check"></i><b>5.1.5</b> Reversed trend extinction rates</a></li>
</ul></li>
<li class="chapter" data-level="5.2" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#testing-alternative-speciation-rates"><i class="fa fa-check"></i><b>5.2</b> Testing alternative speciation rates</a>
<ul>
<li class="chapter" data-level="5.2.1" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#constant-speciation-rates"><i class="fa fa-check"></i><b>5.2.1</b> Constant speciation rates</a></li>
<li class="chapter" data-level="5.2.2" data-path="testing-alternative-hypotheses.html"><a href="testing-alternative-hypotheses.html#exponential-increasingdecreasing-speciation-rates"><i class="fa fa-check"></i><b>5.2.2</b> Exponential increasing/decreasing speciation rates</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="6" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html"><i class="fa fa-check"></i><b>6</b> Exploring the congruence class</a>
<ul>
<li class="chapter" data-level="6.1" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#assumptions-on-rates"><i class="fa fa-check"></i><b>6.1</b> Assumptions on rates</a></li>
<li class="chapter" data-level="6.2" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#independent-or-joint-rate-sampling"><i class="fa fa-check"></i><b>6.2</b> Independent or joint rate sampling</a></li>
<li class="chapter" data-level="6.3" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#sample-alternative-extinction-rates"><i class="fa fa-check"></i><b>6.3</b> Sample alternative extinction rates</a>
<ul>
<li class="chapter" data-level="6.3.1" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#temporally-autocorrelated"><i class="fa fa-check"></i><b>6.3.1</b> Temporally autocorrelated</a></li>
<li class="chapter" data-level="6.3.2" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#exponentially-decreasing"><i class="fa fa-check"></i><b>6.3.2</b> Exponentially decreasing</a></li>
<li class="chapter" data-level="6.3.3" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#linearly-increasing"><i class="fa fa-check"></i><b>6.3.3</b> Linearly increasing</a></li>
<li class="chapter" data-level="6.3.4" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#episodic"><i class="fa fa-check"></i><b>6.3.4</b> Episodic</a></li>
<li class="chapter" data-level="6.3.5" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#uniform-independent"><i class="fa fa-check"></i><b>6.3.5</b> Uniform independent</a></li>
<li class="chapter" data-level="6.3.6" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#brownian-motion-with-a-trend"><i class="fa fa-check"></i><b>6.3.6</b> Brownian motion with a trend</a></li>
</ul></li>
<li class="chapter" data-level="6.4" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#sample-alternative-speciation-rates"><i class="fa fa-check"></i><b>6.4</b> Sample alternative speciation rates</a>
<ul>
<li class="chapter" data-level="6.4.1" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#temporally-autocorrelated-1"><i class="fa fa-check"></i><b>6.4.1</b> Temporally autocorrelated</a></li>
</ul></li>
<li class="chapter" data-level="6.5" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#jointly-sample-alternative-speciation-and-extinction-rates"><i class="fa fa-check"></i><b>6.5</b> Jointly sample alternative speciation and extinction rates</a>
<ul>
<li class="chapter" data-level="6.5.1" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#constant-joint-trajectory"><i class="fa fa-check"></i><b>6.5.1</b> Constant joint trajectory</a></li>
<li class="chapter" data-level="6.5.2" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#hsmrf-joint-trajectory"><i class="fa fa-check"></i><b>6.5.2</b> HSMRF joint trajectory</a></li>
<li class="chapter" data-level="6.5.3" data-path="exploring-the-congruence-class.html"><a href="exploring-the-congruence-class.html#hsmrf-joint-trajectory-with-global-regularity-filter"><i class="fa fa-check"></i><b>6.5.3</b> HSMRF joint trajectory with global regularity filter</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="exploring-the-posterior.html"><a href="exploring-the-posterior.html"><i class="fa fa-check"></i><b>7</b> Exploring the posterior</a>
<ul>
<li class="chapter" data-level="7.1" data-path="exploring-the-posterior.html"><a href="exploring-the-posterior.html#reading-the-posterior"><i class="fa fa-check"></i><b>7.1</b> Reading the posterior</a></li>
<li class="chapter" data-level="7.2" data-path="exploring-the-posterior.html"><a href="exploring-the-posterior.html#sampling-congruent-models-in-the-posterior"><i class="fa fa-check"></i><b>7.2</b> Sampling congruent models in the posterior</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="estimating-birth-death-models.html"><a href="estimating-birth-death-models.html"><i class="fa fa-check"></i><b>8</b> Estimating birth-death models</a>
<ul>
<li class="chapter" data-level="8.1" data-path="estimating-birth-death-models.html"><a href="estimating-birth-death-models.html#reading-the-phylogenetic-tree"><i class="fa fa-check"></i><b>8.1</b> Reading the phylogenetic tree</a></li>
<li class="chapter" data-level="8.2" data-path="estimating-birth-death-models.html"><a href="estimating-birth-death-models.html#tess"><i class="fa fa-check"></i><b>8.2</b> TESS Analysis</a></li>
<li class="chapter" data-level="8.3" data-path="estimating-birth-death-models.html"><a href="estimating-birth-death-models.html#treepar"><i class="fa fa-check"></i><b>8.3</b> TreePar</a></li>
<li class="chapter" data-level="8.4" data-path="estimating-birth-death-models.html"><a href="estimating-birth-death-models.html#revbayes"><i class="fa fa-check"></i><b>8.4</b> The HSMRF model in RevBayes</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i><b>9</b> References</a></li>
</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">CRABS: Congruent Rate Analyses in Birth-death Scenarios</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="exploring-the-posterior" class="section level1 hasAnchor" number="7">
<h1><span class="header-section-number">7</span> Exploring the posterior<a href="exploring-the-posterior.html#exploring-the-posterior" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<p>Until this point, we have only considered point estimates for the fitted birth-death models. If we only consider the maximum-likelihood estimates, or the posterior median rates, it is easy to forget that there is often substantial variability in the estimated speciation and extinction rates. Previously we asked the question, if patterns in the posterior median rates are robust to the congruence class. What happens if we want to take into account the estimation error? Inspecting a series of samples in the posterior distribution is one way to assess this question.</p>
<div id="reading-the-posterior" class="section level2 hasAnchor" number="7.1">
<h2><span class="header-section-number">7.1</span> Reading the posterior<a href="exploring-the-posterior.html#reading-the-posterior" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>In <code>CRABS</code>, we have included functionality to read RevBayes log outputs.</p>
<div class="sourceCode" id="cb71"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb71-1"><a href="exploring-the-posterior.html#cb71-1" aria-hidden="true" tabindex="-1"></a><span class="fu">data</span>(primates_ebd_log)</span>
<span id="cb71-2"><a href="exploring-the-posterior.html#cb71-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb71-3"><a href="exploring-the-posterior.html#cb71-3" aria-hidden="true" tabindex="-1"></a>posterior <span class="ot">&lt;-</span> <span class="fu">read.RevBayes</span>(primates_ebd_log, <span class="at">n_times =</span> <span class="dv">1000</span>,</span>
<span id="cb71-4"><a href="exploring-the-posterior.html#cb71-4" aria-hidden="true" tabindex="-1"></a>                           <span class="at">max_t =</span> <span class="dv">65</span>, <span class="at">n_samples =</span> <span class="dv">20</span>)</span></code></pre></div>
<p>This yields a list of twenty models that are sampled from the posterior. Each sample is equally spaced on the MCMC iterations, meaning that we minimized the autocorrelation among the posterior samples. In <code>CRABS</code> we have included functionality to sample the congruence class, while also taking into account the variation in birth-death models in the posterior distribution.</p>
</div>
<div id="sampling-congruent-models-in-the-posterior" class="section level2 hasAnchor" number="7.2">
<h2><span class="header-section-number">7.2</span> Sampling congruent models in the posterior<a href="exploring-the-posterior.html#sampling-congruent-models-in-the-posterior" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>The function <code>sample.congruence.class.posterior</code> iterates over each sample from the posterior, and draws for each sample another 20 models that are congruent with their respective posterior sample. In this example, we draw 20 alternative extinction rate functions, under an autocorrelated HSMRF distribution starting at a log-normal <span class="math inline">\(\mu_0\)</span> with a median of 0.1. The rejection sampling makes sure that any models with a rate higher than 1.0 is discarded. <code>sample.congruence.class.posterior</code> is completely linked to <code>sample.basic.models</code>, and any additional parameters are directly passed to <code>sample.basic.models(...)</code>.</p>
<div class="sourceCode" id="cb72"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb72-1"><a href="exploring-the-posterior.html#cb72-1" aria-hidden="true" tabindex="-1"></a>samples <span class="ot">&lt;-</span> <span class="fu">sample.congruence.class.posterior</span>(posterior, </span>
<span id="cb72-2"><a href="exploring-the-posterior.html#cb72-2" aria-hidden="true" tabindex="-1"></a>                                             <span class="at">num.samples =</span> <span class="dv">20</span>,</span>
<span id="cb72-3"><a href="exploring-the-posterior.html#cb72-3" aria-hidden="true" tabindex="-1"></a>                                             <span class="at">rate.type =</span> <span class="st">&quot;extinction&quot;</span>,</span>
<span id="cb72-4"><a href="exploring-the-posterior.html#cb72-4" aria-hidden="true" tabindex="-1"></a>                                             <span class="at">rate0.median =</span> <span class="fl">0.1</span>,</span>
<span id="cb72-5"><a href="exploring-the-posterior.html#cb72-5" aria-hidden="true" tabindex="-1"></a>                                             <span class="at">model =</span> <span class="st">&quot;MRF&quot;</span>,</span>
<span id="cb72-6"><a href="exploring-the-posterior.html#cb72-6" aria-hidden="true" tabindex="-1"></a>                                             <span class="at">MRF.type =</span> <span class="st">&quot;HSMRF&quot;</span>,</span>
<span id="cb72-7"><a href="exploring-the-posterior.html#cb72-7" aria-hidden="true" tabindex="-1"></a>                                             <span class="at">max.rate =</span> <span class="fl">1.0</span>)</span></code></pre></div>
<p>This example yields a list of 20 congruence classes, represented by their 1 reference posterior model, and additional 20 congruent models each, totaling 420 models. First we will plot the rate functions in the posterior:</p>
<div class="sourceCode" id="cb73"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb73-1"><a href="exploring-the-posterior.html#cb73-1" aria-hidden="true" tabindex="-1"></a><span class="do">## We name each posterior sample for plotting purposes</span></span>
<span id="cb73-2"><a href="exploring-the-posterior.html#cb73-2" aria-hidden="true" tabindex="-1"></a>l <span class="ot">&lt;-</span> <span class="fu">list</span>()</span>
<span id="cb73-3"><a href="exploring-the-posterior.html#cb73-3" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="fu">seq_along</span>(posterior)){</span>
<span id="cb73-4"><a href="exploring-the-posterior.html#cb73-4" aria-hidden="true" tabindex="-1"></a>  df <span class="ot">&lt;-</span> <span class="fu">model2df</span>(posterior[[i]])  </span>
<span id="cb73-5"><a href="exploring-the-posterior.html#cb73-5" aria-hidden="true" tabindex="-1"></a>  df<span class="sc">$</span>name <span class="ot">&lt;-</span> <span class="fu">paste0</span>(<span class="st">&quot;posterior&quot;</span>, i)</span>
<span id="cb73-6"><a href="exploring-the-posterior.html#cb73-6" aria-hidden="true" tabindex="-1"></a>  l[[i]] <span class="ot">&lt;-</span> df</span>
<span id="cb73-7"><a href="exploring-the-posterior.html#cb73-7" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb73-8"><a href="exploring-the-posterior.html#cb73-8" aria-hidden="true" tabindex="-1"></a>df_posterior <span class="ot">&lt;-</span> <span class="fu">bind_rows</span>(l)</span>
<span id="cb73-9"><a href="exploring-the-posterior.html#cb73-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb73-10"><a href="exploring-the-posterior.html#cb73-10" aria-hidden="true" tabindex="-1"></a>col_lambda <span class="ot">&lt;-</span> colorspace<span class="sc">::</span><span class="fu">sequential_hcl</span>(<span class="at">palette =</span> <span class="st">&quot;Blues&quot;</span>, <span class="at">n =</span> <span class="fu">length</span>(posterior))</span>
<span id="cb73-11"><a href="exploring-the-posterior.html#cb73-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb73-12"><a href="exploring-the-posterior.html#cb73-12" aria-hidden="true" tabindex="-1"></a>p <span class="ot">&lt;-</span> <span class="fu">bind_rows</span>(df_posterior) <span class="sc">%&gt;%</span></span>
<span id="cb73-13"><a href="exploring-the-posterior.html#cb73-13" aria-hidden="true" tabindex="-1"></a>  dplyr<span class="sc">::</span><span class="fu">filter</span>(rate <span class="sc">==</span> <span class="st">&quot;Speciation&quot;</span>) <span class="sc">%&gt;%</span></span>
<span id="cb73-14"><a href="exploring-the-posterior.html#cb73-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> Time, <span class="at">y =</span> value, <span class="at">color =</span> name)) <span class="sc">+</span></span>
<span id="cb73-15"><a href="exploring-the-posterior.html#cb73-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb73-16"><a href="exploring-the-posterior.html#cb73-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_reverse</span>() <span class="sc">+</span></span>
<span id="cb73-17"><a href="exploring-the-posterior.html#cb73-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme_classic</span>() <span class="sc">+</span></span>
<span id="cb73-18"><a href="exploring-the-posterior.html#cb73-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_color_manual</span>(<span class="at">values =</span> col_lambda) <span class="sc">+</span></span>
<span id="cb73-19"><a href="exploring-the-posterior.html#cb73-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(<span class="at">x =</span> <span class="st">&quot;time before present&quot;</span>, <span class="at">y =</span> <span class="st">&quot;speciation rate&quot;</span>) <span class="sc">+</span></span>
<span id="cb73-20"><a href="exploring-the-posterior.html#cb73-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">legend.position =</span> <span class="st">&quot;none&quot;</span>)</span>
<span id="cb73-21"><a href="exploring-the-posterior.html#cb73-21" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(p)</span></code></pre></div>
<p><img src="figures/posterior-rates-1.png" width="384" style="display: block; margin: auto;" />
Evidently, the posterior rates exhibit a lot more rate variation than we saw from the posterior median. What happens if we inspect the twenty congruence classes we just explored, in a visual sense? To do so, we may use the <code>summarize.posterior</code> function. Similar to <code>summarize.trends</code>, it will plot the directional trends in the speciation rate through time. The only difference is that now, the y-axis is sorted, so that each row no longer represents a model.</p>
<div class="sourceCode" id="cb74"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb74-1"><a href="exploring-the-posterior.html#cb74-1" aria-hidden="true" tabindex="-1"></a>p <span class="ot">&lt;-</span> <span class="fu">summarize.posterior</span>(samples, <span class="at">threshold =</span> <span class="fl">0.02</span>)</span>
<span id="cb74-2"><a href="exploring-the-posterior.html#cb74-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(p)</span></code></pre></div>
<div class="figure" style="text-align: center"><span style="display:block;" id="fig:summarize-posterior"></span>
<img src="figures/summarize-posterior-1.png" alt="Summary of directional trends in 20 posterior samples, and for each of those 20 samples, 20 additional congruent models." width="576" />
<p class="caption">
Figure 7.1: Summary of directional trends in 20 posterior samples, and for each of those 20 samples, 20 additional congruent models.
</p>
</div>
<p>In contrast to the previous summaries (Section <a href="testing-alternative-hypotheses.html#alt-ext">5.1</a>), the congruence classes in the posterior samples depict a much more ambiguous patterns of the directional trends. There is still strong support for two sharp increases in speciation rate, followed by a decrease toward the near present, but the signal is not equivocal. In the end, with finite amounts of data, it may seem that non-identifiability (the congruence class) in diversification rate models is not as much of a problem as uncertainty in the estimated diversification rates themselves.</p>
</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="exploring-the-congruence-class.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="estimating-birth-death-models.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="lib/gitbook-2.6.7/js/app.min.js"></script>
<script src="lib/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="lib/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="lib/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="lib/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="lib/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="lib/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="lib/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": null,
"search": false,
"toc": {
"collapse": "subsection"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/latest.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
