<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="pandoc" /> <meta name="author" content="Zhengrong Xing, Peter Carbonetto and Matthew Stephens" /> <title>Spikes demo</title> <script src="site_libs/jquery-1.11.3/jquery.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link href="site_libs/bootstrap-3.3.5/css/readable.min.css" rel="stylesheet" /> <script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script> <script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script> <script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script> <script src="site_libs/navigation-1.1/tabsets.js"></script> <link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" /> <script src="site_libs/highlightjs-9.12.0/highlight.js"></script> <style type="text/css">code{white-space: pre;}</style> <style type="text/css"> pre:not([class]) { background-color: white; } </style> <script type="text/javascript"> if (window.hljs) { hljs.configure({languages: []}); hljs.initHighlightingOnLoad(); if (document.readyState && document.readyState === "complete") { window.setTimeout(function() { hljs.initHighlighting(); }, 0); } } </script> <style type="text/css"> h1 { font-size: 34px; } h1.title { font-size: 38px; } h2 { font-size: 30px; } h3 { font-size: 24px; } h4 { font-size: 18px; } h5 { font-size: 16px; } h6 { font-size: 12px; } .table th:not([align]) { text-align: left; } </style> </head> <body> <style type = "text/css"> .main-container { max-width: 940px; margin-left: auto; margin-right: auto; } code { color: inherit; background-color: rgba(0, 0, 0, 0.04); } img { max-width:100%; height: auto; } .tabbed-pane { padding-top: 12px; } .html-widget { margin-bottom: 20px; } button.code-folding-btn:focus { outline: none; } </style> <style type="text/css"> /* padding for bootstrap navbar */ body { padding-top: 51px; padding-bottom: 40px; } /* offset scroll position for anchor links (for fixed navbar) */ .section h1 { padding-top: 56px; margin-top: -56px; } .section h2 { padding-top: 56px; margin-top: -56px; } .section h3 { padding-top: 56px; margin-top: -56px; } .section h4 { padding-top: 56px; margin-top: -56px; } .section h5 { padding-top: 56px; margin-top: -56px; } .section h6 { padding-top: 56px; margin-top: -56px; } </style> <script> // manage active state of menu based on current page $(document).ready(function () { // active menu anchor href = window.location.pathname href = href.substr(href.lastIndexOf('/') + 1) if (href === "") href = "index.html"; var menuAnchor = $('a[href="' + href + '"]'); // mark it active menuAnchor.parent().addClass('active'); // if it's got a parent navbar menu mark it active as well menuAnchor.closest('li.dropdown').addClass('active'); }); </script> <div class="container-fluid main-container"> <!-- tabsets --> <script> $(document).ready(function () { window.buildTabsets("TOC"); }); </script> <!-- code folding --> <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"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="index.html">smash</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li> <a href="index.html">Overview</a> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li> <a href="https://github.com/stephenslab/smash-paper">source</a> </li> </ul> </div><!--/.nav-collapse --> </div><!--/.container --> </div><!--/.navbar --> <!-- Add a small amount of space between sections. --> <style type="text/css"> div.section { padding-top: 12px; } </style> <!-- Add a small amount of space between sections. --> <style type="text/css"> div.section { padding-top: 12px; } </style> <div class="fluid-row" id="header"> <h1 class="title toc-ignore">Spikes demo</h1> <h4 class="author"><em>Zhengrong Xing, Peter Carbonetto and Matthew Stephens</em></h4> </div> <p><strong>Last updated:</strong> 2018-12-13</p> <strong>workflowr checks:</strong> <small>(Click a bullet for more information)</small> <ul> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>R Markdown file:</strong> up-to-date </summary></p> <p>Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.</p> </details> </li> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Environment:</strong> empty </summary></p> <p>Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.</p> </details> </li> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Seed:</strong> <code>set.seed(1)</code> </summary></p> <p>The command <code>set.seed(1)</code> was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.</p> </details> </li> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Session information:</strong> recorded </summary></p> <p>Great job! Recording the operating system, R version, and package versions is critical for reproducibility.</p> </details> </li> <li> <p><details> <summary> <strong style="color:blue;">✔</strong> <strong>Repository version:</strong> <a href="https://github.com/stephenslab/smash-paper/tree/d9fd3ac6851c62b4c223b2b500631add9029fddc" target="_blank">d9fd3ac</a> </summary></p> Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated. <br><br> Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use <code>wflow_publish</code> or <code>wflow_git_commit</code>). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated: <pre><code> Ignored files: Ignored: dsc/code/Wavelab850/MEXSource/CPAnalysis.mexmac Ignored: dsc/code/Wavelab850/MEXSource/DownDyadHi.mexmac Ignored: dsc/code/Wavelab850/MEXSource/DownDyadLo.mexmac Ignored: dsc/code/Wavelab850/MEXSource/FAIPT.mexmac Ignored: dsc/code/Wavelab850/MEXSource/FCPSynthesis.mexmac Ignored: dsc/code/Wavelab850/MEXSource/FMIPT.mexmac Ignored: dsc/code/Wavelab850/MEXSource/FWPSynthesis.mexmac Ignored: dsc/code/Wavelab850/MEXSource/FWT2_PO.mexmac Ignored: dsc/code/Wavelab850/MEXSource/FWT_PBS.mexmac Ignored: dsc/code/Wavelab850/MEXSource/FWT_PO.mexmac Ignored: dsc/code/Wavelab850/MEXSource/FWT_TI.mexmac Ignored: dsc/code/Wavelab850/MEXSource/IAIPT.mexmac Ignored: dsc/code/Wavelab850/MEXSource/IMIPT.mexmac Ignored: dsc/code/Wavelab850/MEXSource/IWT2_PO.mexmac Ignored: dsc/code/Wavelab850/MEXSource/IWT_PBS.mexmac Ignored: dsc/code/Wavelab850/MEXSource/IWT_PO.mexmac Ignored: dsc/code/Wavelab850/MEXSource/IWT_TI.mexmac Ignored: dsc/code/Wavelab850/MEXSource/LMIRefineSeq.mexmac Ignored: dsc/code/Wavelab850/MEXSource/MedRefineSeq.mexmac Ignored: dsc/code/Wavelab850/MEXSource/UpDyadHi.mexmac Ignored: dsc/code/Wavelab850/MEXSource/UpDyadLo.mexmac Ignored: dsc/code/Wavelab850/MEXSource/WPAnalysis.mexmac Ignored: dsc/code/Wavelab850/MEXSource/dct_ii.mexmac Ignored: dsc/code/Wavelab850/MEXSource/dct_iii.mexmac Ignored: dsc/code/Wavelab850/MEXSource/dct_iv.mexmac Ignored: dsc/code/Wavelab850/MEXSource/dst_ii.mexmac Ignored: dsc/code/Wavelab850/MEXSource/dst_iii.mexmac Ignored: dsc/results/ </code></pre> Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes. </details> </li> </ul> <details> <summary> <small><strong>Expand here to see past versions:</strong></small> </summary> <ul> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> File </th> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> <th style="text-align:left;"> Message </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/ed0d5510aff258bafc45bda78e4c0dbc35d721f6/analysis/spikesdemo.Rmd" target="_blank">ed0d551</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-12-13 </td> <td style="text-align:left;"> Moved around & deleted a bunch of files. </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/stephenslab/smash-paper/99d1f34c2a6ba39fc3b494015335c01a75eef2e4/docs/spikesdemo.html" target="_blank">99d1f34</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-12-07 </td> <td style="text-align:left;"> Re-built all the outdated workflowr webpages. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/a09d13e0da52753972ac66cc8a6af7b791d53b5e/analysis/spikesdemo.Rmd" target="_blank">a09d13e</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-09 </td> <td style="text-align:left;"> Adjusted setup steps in a few of the R Markdown files. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/27c4d0b7e2e702a0c4291b3d0dc3b5b5fffb5a3d/analysis/spikesdemo.Rmd" target="_blank">27c4d0b</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-07 </td> <td style="text-align:left;"> Small revision to setup instructions in Spikes demo. </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/stephenslab/smash-paper/507a261a6f393af417a8a733489b296be63c1f52/docs/spikesdemo.html" target="_blank">507a261</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-06 </td> <td style="text-align:left;"> Having trouble re-building spikesdemo.html. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/134b6f86550dd83f06bdd2b624906ef672208f62/analysis/spikesdemo.Rmd" target="_blank">134b6f8</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-06 </td> <td style="text-align:left;"> wflow_publish(“spikesdemo.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/stephenslab/smash-paper/acfdeb127e12f0453ebd5544bd3eac11c01cc66f/docs/spikesdemo.html" target="_blank">acfdeb1</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-06 </td> <td style="text-align:left;"> Adjustment to one of the plots in the Spikes demo. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/1e6070c1b8bd75a55920abbeeea93dab3132c858/analysis/spikesdemo.Rmd" target="_blank">1e6070c</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-06 </td> <td style="text-align:left;"> wflow_publish(“spikesdemo.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/stephenslab/smash-paper/6a67fcbc1c3ce745f4232b8b7cb5ad1388d53379/docs/spikesdemo.html" target="_blank">6a67fcb</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-06 </td> <td style="text-align:left;"> Added setup instructions to Spikes demo. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/f2e4790b8a3964136f44ddcb991b6114869af7e4/analysis/spikesdemo.Rmd" target="_blank">f2e4790</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-06 </td> <td style="text-align:left;"> wflow_publish(“spikesdemo.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/stephenslab/smash-paper/967f9c701367c2c25d630561e955437955feb31d/docs/spikesdemo.html" target="_blank">967f9c7</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-10-17 </td> <td style="text-align:left;"> Working on improved plots for chipseq.R. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/757462cb31ff4d9419459f78d6abbee39d65ab6f/analysis/spikesdemo.Rmd" target="_blank">757462c</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-10-09 </td> <td style="text-align:left;"> Working on motorcycle .Rmd example. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/1a304e7c11132261042372fb587989f16cc7bd3d/analysis/spikesdemo.Rmd" target="_blank">1a304e7</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-09-28 </td> <td style="text-align:left;"> Added back signal plot to summarize.gaussian.sims.R. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/c21eab1a2896604620842a19a383f569d0a9d99b/analysis/spikesdemo.Rmd" target="_blank">c21eab1</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-09-27 </td> <td style="text-align:left;"> Working on summarize.gaussian.sims.R revisions for manuscript. </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/stephenslab/smash-paper/4c86f87888ad0bfd5fd3d7068a554ce7415ebf12/docs/spikesdemo.html" target="_blank">4c86f87</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-09-27 </td> <td style="text-align:left;"> Re-ran wflow_publish(“spikesdemo.Rmd”) after minor revisions. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/3d5c837c730f4a9d920f9f4960d09df14ce37707/analysis/spikesdemo.Rmd" target="_blank">3d5c837</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-09-27 </td> <td style="text-align:left;"> wflow_publish(“spikesdemo.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/af743b71ce106c3260cdd79ae28432c58655890f/analysis/spikesdemo.Rmd" target="_blank">af743b7</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-09-27 </td> <td style="text-align:left;"> A few minor revisions to the spikes demo. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/c4b2d0b1dc31c513ca7b61af1c310ea9f9f13c1a/analysis/spikesdemo.Rmd" target="_blank">c4b2d0b</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> <td style="text-align:left;"> wflow_publish(“spikesdemo.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/stephenslab/smash-paper/baab6936c77974958745a833fa55da76175438a8/docs/spikesdemo.html" target="_blank">baab693</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> <td style="text-align:left;"> More minor improvements to the spikes demo. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/3f6e340b7b0a802503f7a96bad4e225b01d082b9/analysis/spikesdemo.Rmd" target="_blank">3f6e340</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> <td style="text-align:left;"> wflow_publish(“spikesdemo.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/297fcc1ab8049b72c32b2e7c8c3694b0f52ef5f1/analysis/spikesdemo.Rmd" target="_blank">297fcc1</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> <td style="text-align:left;"> wflow_publish(“spikesdemo.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/stephenslab/smash-paper/04e9900cfa04c97adda63cec4f5ef4df2ed23116/docs/spikesdemo.html" target="_blank">04e9900</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> <td style="text-align:left;"> First build of the spikesdemo example. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/93386bbd4cc52ede0cd42d1eff0a7f6ee2009e45/analysis/spikesdemo.Rmd" target="_blank">93386bb</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> <td style="text-align:left;"> wflow_publish(“spikesdemo.Rmd”) </td> </tr> </tbody> </table> </ul> <p></details></p> <hr /> <p>This small demonstration illustrates key features of the SMASH method on a small, simulated data set with spatially structured variances. This code implements the example presented in Sec. 4.1 of the paper.</p> <div id="initial-setup-instructions" class="section level2"> <h2>Initial setup instructions</h2> <p>To run this example on your own computer, please follow these setup instructions. These instructions assume you already have R and/or RStudio installed on your computer.</p> <p>Download or clone the <a href="https://github.com/stephenslab/smash-paper">git repository</a> on your computer.</p> <p>Launch R, and change the working directory to be the “analysis” folder inside your local copy of the git repository.</p> <p>Install some of the packages used here and in the code below:</p> <pre class="r"><code>install.packages(c("devtools","ggplot2","cowplot"))</code></pre> <p>Finally, install the smashr package from GitHub:</p> <pre class="r"><code>devtools::install_github("stephenslab/smashr")</code></pre> <p>See the “Session Info” at the bottom for the versions of the software and R packages that were used to generate the results shown below.</p> </div> <div id="set-up-r-environment" class="section level2"> <h2>Set up R environment</h2> <p>We begin by loading the ashr, smashr, ggplot2 and cowplot packages, as well as some additional functions used in the code below.</p> <pre class="r"><code>library(ashr) library(smashr) library(ggplot2) library(cowplot) source("../code/spikesdemo.functions.R")</code></pre> </div> <div id="define-the-spikes-mean-function" class="section level2"> <h2>Define the “spikes” mean function</h2> <p>Variable <code>mu.sp</code> defines the mean signal.</p> <pre class="r"><code>n <- 1024 t <- 1:n/n spike.f <- function (x) (0.75 * exp(-500 * (x - 0.23)^2) + 1.5 * exp(-2000 * (x - 0.33)^2) + 3 * exp(-8000 * (x - 0.47)^2) + 2.25 * exp(-16000 * (x - 0.69)^2) + 0.5 * exp(-32000 * (x - 0.83)^2)) mu.sp <- spike.f(t) mu.sp <- (1 + mu.sp)/5</code></pre> </div> <div id="simulate-data" class="section level2"> <h2>Simulate data</h2> <p>Simulate the noisy observations from the normal distribution with means that are given by the “Spikes” function, and with spatially structured variances given by the “Clipped Blocks” function.</p> <pre class="r"><code>pos <- c(0.1,0.13,0.15,0.23,0.25,0.4,0.44,0.65,0.76,0.78,0.81) hgt <- 2.88/5 * c(4,-5,3,-4,5,-4.2,2.1,4.3,-3.1,2.1,-4.2) sig.cb <- rep(0,length(t)) for (j in 1:length(pos)) sig.cb <- sig.cb + (1 + sign(t - pos[j])) * (hgt[j]/2) sig.cb[sig.cb < 0] <- 0 sig.cb <- 0.1 + (sig.cb - min(sig.cb))/max(sig.cb) rsnr <- sqrt(3) sig.cb <- sig.cb/mean(sig.cb) * sd(mu.sp)/rsnr^2 x.sim <- rnorm(n,mu.sp,sig.cb)</code></pre> <p>Plot the simulated data set.</p> <pre class="r"><code>par(cex.axis = 1,cex.lab = 1.25) plot(mu.sp,type = 'l',ylim = c(-0.05,1),xlab = "position", ylab = "",lwd = 3,xaxp = c(0,1024,4),yaxp = c(0,1,4)) lines(mu.sp + 2*sig.cb,col = "darkorange",lty = 5,lwd = 1.8) lines(mu.sp - 2*sig.cb,col = "darkorange",lty = 5,lwd = 1.8) points(x.sim,cex = 0.7,pch = 16,col = "dodgerblue")</code></pre> <p><img src="figure/spikesdemo.Rmd/plot-simulated-data-1.png" width="960" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of plot-simulated-data-1.png:</em></summary> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/acfdeb127e12f0453ebd5544bd3eac11c01cc66f/docs/figure/spikesdemo.Rmd/plot-simulated-data-1.png" target="_blank">acfdeb1</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-06 </td> </tr> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/6a67fcbc1c3ce745f4232b8b7cb5ad1388d53379/docs/figure/spikesdemo.Rmd/plot-simulated-data-1.png" target="_blank">6a67fcb</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-11-06 </td> </tr> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/baab6936c77974958745a833fa55da76175438a8/docs/figure/spikesdemo.Rmd/plot-simulated-data-1.png" target="_blank">baab693</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> </tr> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/04e9900cfa04c97adda63cec4f5ef4df2ed23116/docs/figure/spikesdemo.Rmd/plot-simulated-data-1.png" target="_blank">04e9900</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> </tr> </tbody> </table> <p></details></p> <p>This plot shows the “spikes” mean function (the black line), +/- 2 standard deviations (the orange lines), and the simulated data (the light blue points).</p> </div> <div id="run-smash-and-ti-thresholding" class="section level2"> <h2>Run SMASH and TI thresholding</h2> <p>Now we apply SMASH, as well as the translation invariant (TI) thresholding method, to the “spikes” data. Here we run the TI thresholding method twice—once when the variance is assumes to be constant (“homoskedastic”), and once when it is estimated using the RMAD algorithm. The first method yields very poor estimates, so they are not shown in the plots below.</p> <p>The SMASH method is able to estimate the variance.</p> <pre class="r"><code>sig.est <- sqrt(2/(3 * (n - 2)) * sum((1/2 * x.sim[1:(n-2)] - x.sim[2:(n-1)] + x.sim[3:n])^2/2)) mu.smash <- smash(x.sim,family = "DaubLeAsymm",filter.number = 8) mu.ti.homo <- ti.thresh(x.sim,sigma = sig.est,family = "DaubLeAsymm", filter.number = 8) mu.ti <- ti.thresh(x.sim,method = "rmad",family = "DaubLeAsymm", filter.number = 8)</code></pre> <p>It should take at the very most a few minutes to run SMASH and TI thresholding.</p> <p>Get the (true) wavelet coefficients and their variances.</p> <pre class="r"><code>wc.sim <- titable(x.sim)$difftable wc.var.sim <- titable(sig.cb^2)$sumtable wc.true <- titable(mu.sp)$difftable</code></pre> <p>Get the shrunken estimates of the wavelet coefficients.</p> <pre class="r"><code>wc.sim.shrunk <- vector("list",10) wc.pres <- vector("list",10) for(j in 0:(log2(n) - 1)){ wc.sim.shrunk[[j+1]] <- ash(wc.sim[j+2,],sqrt(wc.var.sim[j+2,]),prior = "nullbiased", pointmass = TRUE,mixsd = NULL,mixcompdist = "normal", gridmult = 2,df = NULL)$result wc.pres[[j+1]] <- 1/sqrt(wc.var.sim[j+2,]) }</code></pre> </div> <div id="summarize-results" class="section level2"> <h2>Summarize results</h2> <p>Plot the distribution of the observed wavelet coefficients at a coarser scale (scale = 1, orange) and at a finer scale (scale = 7, dark blue).</p> <pre class="r"><code>par(cex.axis = 1,cex.lab = 1.25) hist(wc.sim[4,],breaks = 2,xlab = "observed wavelet coefficients", xlim = c(-25,25),ylim = c(0,600),col = "darkblue",xaxp = c(-25,25,10), yaxp = c(0,600,6),main = "") hist(wc.sim[10,],breaks = 40,add = TRUE,col = "darkorange")</code></pre> <p><img src="figure/spikesdemo.Rmd/plot-wc-histogram-1.png" width="576" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of plot-wc-histogram-1.png:</em></summary> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/baab6936c77974958745a833fa55da76175438a8/docs/figure/spikesdemo.Rmd/plot-wc-histogram-1.png" target="_blank">baab693</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> </tr> </tbody> </table> <p></details></p> <p>Observe that the scale = 7 WCs (dark blue) are much more concentrated near zero because the signal is smoother at this finer scale.</p> <p>Plot the observed wavelet coefficients (at scales 1 and 7 only) vs. the “shrunken” wavelet coefficients estimated by adaptive shrinkage.</p> <pre class="r"><code>par(cex.axis = 1,cex.lab = 1.25) plot(c(),c(),xlab = "observed wavelet coefficients", ylab = "shrunken wavelet coefficients", xlim = c(-2.5,2.5),ylim = c(-2.5,2.5)) abline(0,1,lty = 1,col = "gray",lwd = 1) points(wc.sim[10,],wc.sim.shrunk[[9]]$PosteriorMean,pch = 20,cex = 1, col = "darkorange") points(wc.sim[4,],wc.sim.shrunk[[3]]$PosteriorMean,pch = 20,cex = 1, col = "darkblue")</code></pre> <p><img src="figure/spikesdemo.Rmd/wc-scatterplot-1.png" width="480" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of wc-scatterplot-1.png:</em></summary> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/baab6936c77974958745a833fa55da76175438a8/docs/figure/spikesdemo.Rmd/wc-scatterplot-1.png" target="_blank">baab693</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> </tr> </tbody> </table> <p></details></p> <p>Observe that the scale = 7 WCs (dark blue) are strongly shrunk toward zero, whereas the scale = 1 WCs (orange) are not shrunk nearly as much; SMASH infers from the data that the scale = 7 WCs are heavily concentrated around zero, and consequently SMASH shrinks them more strongly.</p> <p>Plot the observed wavelet coefficients (at scale 7 only) vs. the “shrunken” wavelet coefficients estimated by adaptive shrinkage in order to see how the amount of shrinkage depends on the standard error (s.e.) in the observations.</p> <pre class="r"><code>wc.sig.3 <- 1/wc.pres[[3]] p <- ggplot(data.frame(observed = wc.sim[4,], shrunken = wc.sim.shrunk[[3]]$PosteriorMean, se = wc.sig.3), aes(x = observed,y = shrunken,col = se)) + geom_point(na.rm = TRUE) + xlim(c(-1,1)) + ylim(c(-1,1)) + scale_color_gradientn(colors = c("deepskyblue","darkblue")) + theme_cowplot() print(p)</code></pre> <p><img src="figure/spikesdemo.Rmd/wc-scatterplot-2-1.png" width="480" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of wc-scatterplot-2-1.png:</em></summary> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/baab6936c77974958745a833fa55da76175438a8/docs/figure/spikesdemo.Rmd/wc-scatterplot-2-1.png" target="_blank">baab693</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> </tr> </tbody> </table> <p></details></p> <p>From this plot, it is evident that SMASH shrinks WCs differently depending on their precision; specifically, WCs that are less precise—i.e., higher standard error (s.e.)—are shrunk more strongly toward zero.</p> <p>Finally, we plot the ground-truth signal (the mean function, drawn as a black line) and the signals recovered by TI thresholding (light blue line) and SMASH (the red line).</p> <pre class="r"><code>par(cex.axis = 1) plot(mu.sp,type = "l",col = "black",lwd = 3,xlab = "position",ylab = "", ylim = c(-0.05,1),xaxp = c(0,1024,4),yaxp = c(0,1,4)) lines(mu.ti,col = "dodgerblue",lwd = 3) lines(mu.smash,col = "orangered",lwd = 3)</code></pre> <p><img src="figure/spikesdemo.Rmd/plot-mean-signal-vs-estimates-1.png" width="960" style="display: block; margin: auto;" /></p> <details> <summary><em>Expand here to see past versions of plot-mean-signal-vs-estimates-1.png:</em></summary> <table style="border-collapse:separate; border-spacing:5px;"> <thead> <tr> <th style="text-align:left;"> Version </th> <th style="text-align:left;"> Author </th> <th style="text-align:left;"> Date </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/4c86f87888ad0bfd5fd3d7068a554ce7415ebf12/docs/figure/spikesdemo.Rmd/plot-mean-signal-vs-estimates-1.png" target="_blank">4c86f87</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-09-27 </td> </tr> <tr> <td style="text-align:left;"> <a href="https://github.com/stephenslab/smash-paper/blob/baab6936c77974958745a833fa55da76175438a8/docs/figure/spikesdemo.Rmd/plot-mean-signal-vs-estimates-1.png" target="_blank">baab693</a> </td> <td style="text-align:left;"> Peter Carbonetto </td> <td style="text-align:left;"> 2018-08-23 </td> </tr> </tbody> </table> <p></details></p> <p>In this example, the smoothed signal from SMASH is noticeably more accurate than using TI thresholding (in which the variance is estimated by running the median absolute deviation, or “RMAD”, method). The TI thresholding estimate shows notable artifacts.</p> </div> <div id="session-information" class="section level2"> <h2>Session information</h2> <pre class="r"><code>sessionInfo() # R version 3.4.3 (2017-11-30) # Platform: x86_64-apple-darwin15.6.0 (64-bit) # Running under: macOS High Sierra 10.13.6 # # Matrix products: default # BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib # LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib # # locale: # [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 # # attached base packages: # [1] stats graphics grDevices utils datasets methods base # # other attached packages: # [1] cowplot_0.9.3 ggplot2_3.1.0 smashr_1.2-0 ashr_2.2-23 # # loaded via a namespace (and not attached): # [1] Rcpp_1.0.0 bindr_0.1.1 pillar_1.2.1 # [4] plyr_1.8.4 compiler_3.4.3 git2r_0.23.0 # [7] workflowr_1.1.1 R.methodsS3_1.7.1 R.utils_2.6.0 # [10] bitops_1.0-6 iterators_1.0.9 tools_3.4.3 # [13] digest_0.6.17 tibble_1.4.2 evaluate_0.11 # [16] gtable_0.2.0 lattice_0.20-35 pkgconfig_2.0.2 # [19] rlang_0.2.2 Matrix_1.2-12 foreach_1.4.4 # [22] yaml_2.2.0 parallel_3.4.3 bindrcpp_0.2.2 # [25] withr_2.1.2 dplyr_0.7.6 stringr_1.3.1 # [28] knitr_1.20 REBayes_1.3 caTools_1.17.1 # [31] tidyselect_0.2.4 rprojroot_1.3-2 grid_3.4.3 # [34] glue_1.3.0 data.table_1.11.4 R6_2.2.2 # [37] rmarkdown_1.10 purrr_0.2.5 magrittr_1.5 # [40] whisker_0.3-2 backports_1.1.2 scales_0.5.0 # [43] codetools_0.2-15 htmltools_0.3.6 MASS_7.3-48 # [46] assertthat_0.2.0 colorspace_1.4-0 labeling_0.3 # [49] wavethresh_4.6.8 stringi_1.2.4 Rmosek_8.0.69 # [52] lazyeval_0.2.1 doParallel_1.0.11 pscl_1.5.2 # [55] munsell_0.4.3 truncnorm_1.0-8 SQUAREM_2017.10-1 # [58] R.oo_1.21.0</code></pre> </div> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ "HTML-CSS": { availableFonts: ["TeX"] } }); </script> <!-- Adjust MathJax settings so that all math formulae are shown using TeX fonts only; see http://docs.mathjax.org/en/latest/configuration.html. This will make the presentation more consistent at the cost of the webpage sometimes taking slightly longer to load. Note that this only works because the footer is added to webpages before the MathJax javascript. --> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ "HTML-CSS": { availableFonts: ["TeX"] } }); </script> <hr> <p> This reproducible <a href="http://rmarkdown.rstudio.com">R Markdown</a> analysis was created with <a href="https://github.com/jdblischak/workflowr">workflowr</a> 1.1.1 </p> <hr> </div> <script> // add bootstrap table styles to pandoc tables function bootstrapStylePandocTables() { $('tr.header').parent('thead').parent('table').addClass('table table-condensed'); } $(document).ready(function () { bootstrapStylePandocTables(); }); </script> <!-- dynamically load mathjax for compatibility with self-contained --> <script> (function () { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; document.getElementsByTagName("head")[0].appendChild(script); })(); </script> </body> </html>