2 <!-- Generated by pkgdown: do not edit by hand --><html lang=
"en">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
6 <meta http-equiv=
"X-UA-Compatible" content=
"IE=edge">
7 <meta name=
"viewport" content=
"width=device-width, initial-scale=1, shrink-to-fit=no">
8 <title>Sequential Bayes: Utilizing the Posterior Distribution • Rnaught
</title>
9 <!-- favicons --><link rel=
"icon" type=
"image/png" sizes=
"16x16" href=
"../favicon-16x16.png">
10 <link rel=
"icon" type=
"image/png" sizes=
"32x32" href=
"../favicon-32x32.png">
11 <link rel=
"apple-touch-icon" type=
"image/png" sizes=
"180x180" href=
"../apple-touch-icon.png">
12 <link rel=
"apple-touch-icon" type=
"image/png" sizes=
"120x120" href=
"../apple-touch-icon-120x120.png">
13 <link rel=
"apple-touch-icon" type=
"image/png" sizes=
"76x76" href=
"../apple-touch-icon-76x76.png">
14 <link rel=
"apple-touch-icon" type=
"image/png" sizes=
"60x60" href=
"../apple-touch-icon-60x60.png">
15 <script src=
"../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name=
"viewport" content=
"width=device-width, initial-scale=1, shrink-to-fit=no">
16 <link href=
"../deps/bootstrap-5.3.1/bootstrap.min.css" rel=
"stylesheet">
17 <script src=
"../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href=
"../deps/font-awesome-6.5.2/css/all.min.css" rel=
"stylesheet">
18 <link href=
"../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel=
"stylesheet">
19 <script src=
"../deps/headroom-0.11.0/headroom.min.js"></script><script src=
"../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src=
"../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src=
"../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src=
"../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src=
"../deps/search-1.0.0/fuse.min.js"></script><script src=
"../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src=
"../pkgdown.js"></script><meta property=
"og:title" content=
"Sequential Bayes: Utilizing the Posterior Distribution">
22 <a href=
"#main" class=
"visually-hidden-focusable">Skip to contents
</a>
25 <nav class=
"navbar navbar-expand-lg fixed-top bg-light" data-bs-theme=
"light" aria-label=
"Site navigation"><div class=
"container">
27 <a class=
"navbar-brand me-2" href=
"../index.html">Rnaught
</a>
29 <small class=
"nav-text text-muted me-auto" data-bs-toggle=
"tooltip" data-bs-placement=
"bottom" title=
"">0.1.0</small>
32 <button class=
"navbar-toggler" type=
"button" data-bs-toggle=
"collapse" data-bs-target=
"#navbar" aria-controls=
"navbar" aria-expanded=
"false" aria-label=
"Toggle navigation">
33 <span class=
"navbar-toggler-icon"></span>
36 <div id=
"navbar" class=
"collapse navbar-collapse ms-3">
37 <ul class=
"navbar-nav me-auto">
38 <li class=
"nav-item"><a class=
"nav-link" href=
"../articles/Rnaught.html">Get started
</a></li>
39 <li class=
"nav-item"><a class=
"nav-link" href=
"../reference/index.html">Reference
</a></li>
40 <li class=
"active nav-item dropdown">
41 <button class=
"nav-link dropdown-toggle" type=
"button" id=
"dropdown-articles" data-bs-toggle=
"dropdown" aria-expanded=
"false" aria-haspopup=
"true">Articles
</button>
42 <ul class=
"dropdown-menu" aria-labelledby=
"dropdown-articles">
43 <li><a class=
"dropdown-item" href=
"../articles/seq_bayes_post.html">Sequential Bayes: Utilizing the Posterior Distribution
</a></li>
44 <li><a class=
"dropdown-item" href=
"../articles/wp_serial.html">White and Pagano: Utilizing the Serial Distribution
</a></li>
48 <ul class=
"navbar-nav">
49 <li class=
"nav-item"><form class=
"form-inline" role=
"search">
50 <input class=
"form-control" type=
"search" name=
"search-input" id=
"search-input" autocomplete=
"off" aria-label=
"Search site" placeholder=
"Search for" data-search-index=
"../search.json">
52 <li class=
"nav-item"><a class=
"external-link nav-link" href=
"https://github.com/MI2YorkU/Rnaught/" aria-label=
"GitHub"><span class=
"fa fab fa-github fa-lg"></span></a></li>
58 </nav><div class=
"container template-article">
64 <main id=
"main" class=
"col-md-9"><div class=
"page-header">
65 <img src=
"../logo.svg" class=
"logo" alt=
""><h1>Sequential Bayes: Utilizing the Posterior Distribution
</h1>
68 <small class=
"dont-index">Source:
<a href=
"https://github.com/MI2YorkU/Rnaught/blob/master/vignettes/seq_bayes_post.Rmd" class=
"external-link"><code>vignettes/seq_bayes_post.Rmd
</code></a></small>
69 <div class=
"d-none name"><code>seq_bayes_post.Rmd
</code></div>
74 <p>In the Sequential Bayes method, the probability distribution of R0 is
75 updated sequentially from one case count to the next, starting from a
76 (discretized) uniform prior. By default, the function
77 <code><a href=
"../reference/seq_bayes.html">seq_bayes()
</a></code> returns the mean of the last updated posterior
78 distribution as its estimate of R0. However, by setting the parameter
79 <code>post
</code> to
<code>TRUE
</code>, it is possible to return the
80 final distribution itself:
</p>
81 <div class=
"sourceCode" id=
"cb1"><pre class=
"downlit sourceCode r">
82 <code class=
"sourceCode R"><span><span class=
"co"># Daily case counts.
</span></span>
83 <span><span class=
"va">cases
</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">4</span>,
<span class=
"fl">10</span>,
<span class=
"fl">5</span>,
<span class=
"fl">3</span>,
<span class=
"fl">4</span>,
<span class=
"fl">19</span>,
<span class=
"fl">3</span>,
<span class=
"fl">3</span>,
<span class=
"fl">14</span>,
<span class=
"fl">4</span><span class=
"op">)
</span></span>
85 <span><span class=
"va">posterior
</span> <span class=
"op"><-
</span> <span class=
"fu"><a href=
"../reference/seq_bayes.html">seq_bayes
</a></span><span class=
"op">(
</span><span class=
"va">cases
</span>, mu
<span class=
"op">=
</span> <span class=
"fl">8</span>, kappa
<span class=
"op">=
</span> <span class=
"fl">7</span>, post
<span class=
"op">=
</span> <span class=
"cn">TRUE
</span><span class=
"op">)
</span></span></code></pre></div>
86 <p>First, the distribution can be used to retrieve the original estimate
87 (had
<code>post
</code> been left to its default value of
88 <code>FALSE
</code>) by calculating its mean:
</p>
89 <div class=
"sourceCode" id=
"cb2"><pre class=
"downlit sourceCode r">
90 <code class=
"sourceCode R"><span><span class=
"co"># `supp` is the support of the distribution, and `pmf` is its probability mass
</span></span>
91 <span><span class=
"co"># function.
</span></span>
92 <span><span class=
"va">post_mean
</span> <span class=
"op"><-
</span> <span class=
"fu"><a href=
"https://rdrr.io/r/base/sum.html" class=
"external-link">sum
</a></span><span class=
"op">(
</span><span class=
"va">posterior
</span><span class=
"op">$
</span><span class=
"va">supp
</span> <span class=
"op">*
</span> <span class=
"va">posterior
</span><span class=
"op">$
</span><span class=
"va">pmf
</span><span class=
"op">)
</span></span>
93 <span><span class=
"va">post_mean
</span></span>
94 <span><span class=
"co">#
> [
1]
1.476652</span></span>
96 <span><span class=
"co"># Verify that the following is true:
</span></span>
97 <span><span class=
"va">post_mean
</span> <span class=
"op">==
</span> <span class=
"fu"><a href=
"../reference/seq_bayes.html">seq_bayes
</a></span><span class=
"op">(
</span><span class=
"va">cases
</span>, mu
<span class=
"op">=
</span> <span class=
"fl">8</span>, kappa
<span class=
"op">=
</span> <span class=
"fl">7</span><span class=
"op">)
</span></span>
98 <span><span class=
"co">#
> [
1] TRUE
</span></span></code></pre></div>
99 <p>Another use of the posterior is to obtain an alternative estimate of
100 R0. For instance, the following extracts the posterior mode rather than
102 <div class=
"sourceCode" id=
"cb3"><pre class=
"downlit sourceCode r">
103 <code class=
"sourceCode R"><span><span class=
"va">post_mode
</span> <span class=
"op"><-
</span> <span class=
"va">posterior
</span><span class=
"op">$
</span><span class=
"va">supp
</span><span class=
"op">[
</span><span class=
"fu"><a href=
"https://rdrr.io/r/base/which.min.html" class=
"external-link">which.max
</a></span><span class=
"op">(
</span><span class=
"va">posterior
</span><span class=
"op">$
</span><span class=
"va">pmf
</span><span class=
"op">)
</span><span class=
"op">]
</span></span>
104 <span><span class=
"va">post_mode
</span></span>
105 <span><span class=
"co">#
> [
1]
1.36</span></span></code></pre></div>
106 <p>Returning the posterior is suitable for visualization purposes. Below
107 is a graph containing the uniform prior, final posterior distribution,
108 posterior mean and posterior mode:
</p>
109 <p><img src=
"seq_bayes_post_files/figure-html/unnamed-chunk-5-1.png" width=
"1400"></p>
115 <footer><div class=
"pkgdown-footer-left">
116 <p>Developed by Naeem Model, Sawitree Boonpatcharanon, Jane Heffernan, Hanna Jankowski.
</p>
119 <div class=
"pkgdown-footer-right">
120 <p>Site built with
<a href=
"https://pkgdown.r-lib.org/" class=
"external-link">pkgdown
</a> 2.1.1.
</p>