<!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" /> <title>MASH v FLASH simulation results</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/cosmo.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/jqueryui-1.11.4/jquery-ui.min.js"></script> <link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" /> <script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script> <script src="site_libs/navigation-1.1/tabsets.js"></script> <script src="site_libs/navigation-1.1/codefolding.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> <link href="site_libs/font-awesome-4.5.0/css/font-awesome.min.css" rel="stylesheet" /> <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; } 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 --> <style type="text/css"> .code-folding-btn { margin-bottom: 4px; } </style> <script> $(document).ready(function () { window.initializeCodeFolding("hide" === "show"); }); </script> <script> $(document).ready(function () { // move toc-ignore selectors from section div to header $('div.section.toc-ignore') .removeClass('toc-ignore') .children('h1,h2,h3,h4,h5').addClass('toc-ignore'); // establish options var options = { selectors: "h1,h2,h3", theme: "bootstrap3", context: '.toc-content', hashGenerator: function (text) { return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase(); }, ignoreSelector: ".toc-ignore", scrollTo: 0 }; options.showAndHide = true; options.smoothScroll = true; // tocify var toc = $("#TOC").tocify(options).data("toc-tocify"); }); </script> <style type="text/css"> #TOC { margin: 25px 0px 20px 0px; } @media (max-width: 768px) { #TOC { position: relative; width: 100%; } } .toc-content { padding-left: 30px; padding-right: 40px; } div.main-container { max-width: 1200px; } div.tocify { width: 20%; max-width: 260px; max-height: 85%; } @media (min-width: 768px) and (max-width: 991px) { div.tocify { width: 25%; } } @media (max-width: 767px) { div.tocify { width: 100%; max-width: none; } } .tocify ul, .tocify li { line-height: 20px; } .tocify-subheader .tocify-item { font-size: 0.90em; padding-left: 25px; text-indent: 0; } .tocify .list-group-item { border-radius: 0px; } </style> <!-- setup 3col/9col grid for toc_float and main content --> <div class="row-fluid"> <div class="col-xs-12 col-sm-4 col-md-3"> <div id="TOC" class="tocify"> </div> </div> <div class="toc-content col-xs-12 col-sm-8 col-md-9"> <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">MASHvFLASH</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li> <a href="index.html">Home</a> </li> <li> <a href="about.html">About</a> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li> <a href="https://github.com/willwerscheid/MASHvFLASH"> <span class="fa fa-github"></span> </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> <div class="fluid-row" id="header"> <div class="btn-group pull-right"> <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button> <ul class="dropdown-menu" style="min-width: 50px;"> <li><a id="rmd-show-all-code" href="#">Show All Code</a></li> <li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li> </ul> </div> <h1 class="title toc-ignore">MASH v FLASH simulation results</h1> </div> <p><strong>Last updated:</strong> 2018-07-22</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(20180609)</code> </summary></p> <p>The command <code>set.seed(20180609)</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/willwerscheid/MASHvFLASH/tree/3abd505e1c42acd32d1e7c9f8901f8f50efc9335" target="_blank">3abd505</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: .DS_Store Ignored: .Rhistory Ignored: .Rproj.user/ Ignored: docs/.DS_Store Ignored: docs/images/.DS_Store Ignored: output/.DS_Store Unstaged changes: Modified: code/gtex2.R Modified: code/sims2.R Modified: output/README.md Modified: output/gtex2flfit.rds Modified: output/gtex2lfsr.rds Modified: output/gtex2mfit.rds Modified: output/gtex2mrandfit.rds Modified: output/gtexrandomfit.rds Modified: output/gtexstrongfit.rds </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/willwerscheid/MASHvFLASH/blob/3abd505e1c42acd32d1e7c9f8901f8f50efc9335/analysis/MASHvFLASHsims.Rmd" target="_blank">3abd505</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-07-22 </td> <td style="text-align:left;"> wflow_publish(c(“analysis/MASHvFLASHsims.Rmd”, </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/36a39f6841360fa0e59164042c3f7ae97935cddf/docs/MASHvFLASHsims.html" target="_blank">36a39f6</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-07-22 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/179099b4e78b6f5586b08e6aab9526e18ddd683e/analysis/MASHvFLASHsims.Rmd" target="_blank">179099b</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-07-22 </td> <td style="text-align:left;"> wflow_publish(c(“analysis/MASHvFLASHgtex.Rmd”, </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/b7181f2440ca7b53cbc4c4bb890424ac93b5abf1/docs/MASHvFLASHsims.html" target="_blank">b7181f2</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-07-22 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/7f05edf0d238cdf6673bab50cefaba3a4d244a0a/analysis/MASHvFLASHsims.Rmd" target="_blank">7f05edf</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-07-22 </td> <td style="text-align:left;"> wflow_publish(“analysis/MASHvFLASHsims.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/69cecbc60b8616a3ceaf513a6f169f249bcca6d4/docs/MASHvFLASHsims.html" target="_blank">69cecbc</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-20 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/abf0f70d7c77ab8cba395605aab7ea8116103c02/analysis/MASHvFLASHsims.Rmd" target="_blank">abf0f70</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-20 </td> <td style="text-align:left;"> workflowr::wflow_publish(c(“analysis/intro.Rmd”, </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/2d8f0919dae1dceed3cd1a6caeaa50c117dfb277/docs/MASHvFLASHsims.html" target="_blank">2d8f091</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-20 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/eda9441e8c6499985d528f54c57489e3fe37414d/analysis/MASHvFLASHsims.Rmd" target="_blank">eda9441</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-20 </td> <td style="text-align:left;"> wflow_publish(“analysis/MASHvFLASHsims.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/90dd57894e8dd3267d38f69155ac0f01be63fef9/docs/MASHvFLASHsims.html" target="_blank">90dd578</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-19 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/3cf7f0ce18e03e5e81a0f66c56c65029b8a7a8cd/analysis/MASHvFLASHsims.Rmd" target="_blank">3cf7f0c</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-19 </td> <td style="text-align:left;"> wflow_publish(“analysis/MASHvFLASHsims.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/6fd3720392531d915c7d21cf984f0dba4eb03afc/docs/MASHvFLASHsims.html" target="_blank">6fd3720</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-19 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/358412a77652ea852898bb1b735918b20f7e4b41/docs/MASHvFLASHsims.html" target="_blank">358412a</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/a9a9e11a53e9b935379d8d4ce0c76537328d93d7/analysis/MASHvFLASHsims.Rmd" target="_blank">a9a9e11</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> wflow_publish(“analysis/MASHvFLASHsims.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/726168a9cec3280d38929ce716dcb7483b7af67c/docs/MASHvFLASHsims.html" target="_blank">726168a</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/aa46b383b5ef586461f9e8ee43d9adf1c5cb24d8/docs/MASHvFLASHsims.html" target="_blank">aa46b38</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/d3f8191a4d8323b10f600574ea8fefbb74b071ac/analysis/MASHvFLASHsims.Rmd" target="_blank">d3f8191</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> wflow_publish(“analysis/MASHvFLASHsims.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/c2699a6b3a91bf348a7780f395328f175ec3c759/docs/MASHvFLASHsims.html" target="_blank">c2699a6</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/3554f17e60c34ba45c678226295c81b8804294e5/analysis/MASHvFLASHsims.Rmd" target="_blank">3554f17</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> wflow_publish(“analysis/MASHvFLASHsims.Rmd”) </td> </tr> <tr> <td style="text-align:left;"> html </td> <td style="text-align:left;"> <a href="https://cdn.rawgit.com/willwerscheid/MASHvFLASH/03dc24a7944aca134747c0bdfdb5bfd6875ea2dd/docs/MASHvFLASHsims.html" target="_blank">03dc24a</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> Build site. </td> </tr> <tr> <td style="text-align:left;"> Rmd </td> <td style="text-align:left;"> <a href="https://github.com/willwerscheid/MASHvFLASH/blob/0c0d6b22487b32387084dd31b4353c782cc56c3b/analysis/MASHvFLASHsims.Rmd" target="_blank">0c0d6b2</a> </td> <td style="text-align:left;"> Jason Willwerscheid </td> <td style="text-align:left;"> 2018-06-15 </td> <td style="text-align:left;"> wflow_publish(“analysis/MASHvFLASHsims.Rmd”) </td> </tr> </tbody> </table> </ul> <p></details></p> <hr /> <div id="introduction" class="section level2"> <h2>Introduction</h2> <p>Here I compare MASH and FLASH fits to data simulated from various MASH and FLASH models. In addition to comparing the performance of the various FLASH fits, I was interested in seeing how FLASH performed on data generated from a MASH model (and vice versa). For the code used in this analysis, see <a href="#code">below</a>.</p> </div> <div id="fitting-methods" class="section level2"> <h2>Fitting methods</h2> <p>The MASH fit is produced following the recommendations in the MASH vignettes (using both canonical matrices and data-driven matrices).</p> <p>Five FLASH fits are produced. The first two serve as baselines. The “Vanilla” FLASH fit uses the default method to fit a flash object, adding up to ten factors greedily and then backfitting. The “Zero” fit does the same, but sets <code>var_type = "zero"</code> rather than using the default parameter option <code>var_type = "by_column"</code>. That is, the “Vanilla” fit estimates the residual variances, with the constraint that the variances are identical across any given column, while the “Zero” fit fixes the standard errors at their known values (here, <code>S = 1</code>).</p> <p>The remaining three fits also use parameter option <code>var_type = "zero"</code>. FLASH-OHL (for “one-hots last”) adds up to ten factors greedily, then adds a one-hot vector for each row in the data matrix, then backfits the whole thing. As described in the <a href="intro.html">vignette</a>, the purpose of the one-hot vectors is to account for certain “canonical” covariance structures.</p> <p>FLASH-OHF (for “one-hots first”) adds the one-hot vectors first, then backfits, then greedily adds up to ten factors. These greedily added factors are not subsequently backfit, so FLASH-OHF can be much faster than FLASH-OHL. FLASH-OHF+ begins with the FLASH-OHF fit and then performs a second backfitting.</p> </div> <div id="simulations" class="section level2"> <h2>Simulations</h2> <p>All simulated datasets <span class="math inline">\(Y\)</span> are of dimension 25 x 1000. In each case, <span class="math inline">\(Y = X + E\)</span>, where <span class="math inline">\(X\)</span> is the matrix of “true” effects and <span class="math inline">\(E\)</span> is a matrix of <span class="math inline">\(N(0, 1)\)</span> noise. One simulation is from the null model, three are generated according to a MASH model, and three are generated from a FLASH model. See the individual sections below for details.</p> <p>The MASH fits are evaluated using built-in functions <code>get_pm()</code> to calculate MSE, <code>get_psd()</code> to calculate confidence intervals, and <code>get_lfsr()</code> to calculate true and false positive rates.</p> <p>For the FLASH fits, only MSE is calculated using a built-in function (<code>flash_get_fitted_values()</code>). Confidence intervals and true and false positive rates are calculated by sampling from the posterior using function <code>flash_sampler()</code>. For details, see the code below.</p> </div> <div id="results-overview" class="section level2"> <h2>Results overview</h2> <p>Without the one-hot vectors, the Vanilla and Zero FLASH fits perform poorly on the MASH simulations (see the ROC curves below). The other FLASH fits all perform similarly to one another. They are outperformed by MASH, especially at low FPR thresholds, but this is expected since the data are, after all, generated from the MASH model. Of these three FLASH methods, OHF is (as expected) the fastest, and is about twice as fast as the slowest method, OHF+.</p> <p>The Vanilla and Zero fits do much better on the FLASH simulations (again, as expected, since the data are now generated from the FLASH model). More surprisingly, the MASH fit does nearly as well (and, in some cases, better) than the FLASH fits. OHF is again the fastest of the three FLASH fits that include one-hot vectors, but it performs much more poorly than the other two methods. On the rank-5 model, OHF+ also performs poorly relative to OHL.</p> <p>Overall, the OHL method consistently performs best among the three FLASH methods that include one-hot vectors. It is slower than OHF, and sometimes even slower than OHF+, but the performance gains on the FLASH data are substantial.</p> </div> <div id="null-model" class="section level2"> <h2>Null model</h2> <p>Here the entries of <span class="math inline">\(X\)</span> are all zero.</p> <table> <thead> <tr class="header"> <th></th> <th align="right">MASH</th> <th align="right">Vanilla</th> <th align="right">Zero</th> <th align="right">OHL</th> <th align="right">OHF</th> <th align="right">OHFp</th> </tr> </thead> <tbody> <tr class="odd"> <td>MSE</td> <td align="right">0.003</td> <td align="right">0</td> <td align="right">0</td> <td align="right">0.003</td> <td align="right">0.003</td> <td align="right">0.003</td> </tr> <tr class="even"> <td>95% CI cov</td> <td align="right">0.864</td> <td align="right">1</td> <td align="right">1</td> <td align="right">1.000</td> <td align="right">1.000</td> <td align="right">1.000</td> </tr> </tbody> </table> <div class="figure"> <img src="images/sim1time.png" /> </div> </div> <div id="model-with-independent-effects" class="section level2"> <h2>Model with independent effects</h2> <p>Now the columns <span class="math inline">\(X_{:, j}\)</span> are either identically zero (with probability 0.8) or identically nonzero. In the latter case, the entries of the <span class="math inline">\(j\)</span>th column of <span class="math inline">\(X\)</span> are i.i.d. <span class="math inline">\(N(0, 1)\)</span>.</p> <table> <thead> <tr class="header"> <th></th> <th align="right">MASH</th> <th align="right">Vanilla</th> <th align="right">Zero</th> <th align="right">OHL</th> <th align="right">OHF</th> <th align="right">OHFp</th> </tr> </thead> <tbody> <tr class="odd"> <td>MSE</td> <td align="right">0.016</td> <td align="right">0.019</td> <td align="right">0.017</td> <td align="right">0.019</td> <td align="right">0.020</td> <td align="right">0.020</td> </tr> <tr class="even"> <td>95% CI cov</td> <td align="right">0.991</td> <td align="right">0.981</td> <td align="right">0.981</td> <td align="right">0.985</td> <td align="right">0.985</td> <td align="right">0.985</td> </tr> </tbody> </table> <p><img src="images/sim2ROC.png" /> <img src="images/sim2time.png" /></p> </div> <div id="model-with-independent-and-shared-effects" class="section level2"> <h2>Model with independent and shared effects</h2> <p>Again 80% of the columns of <span class="math inline">\(X\)</span> are identically zero. But now, only half of the nonzero columns have entries that are i.i.d. <span class="math inline">\(N(0, 1)\)</span>. The other half have entries that are identical across rows, with a value that is drawn from the <span class="math inline">\(N(0, 1)\)</span> distribution. (In other words, the covariance matrix for these columns is a matrix of all ones.)</p> <table> <thead> <tr class="header"> <th></th> <th align="right">MASH</th> <th align="right">Vanilla</th> <th align="right">Zero</th> <th align="right">OHL</th> <th align="right">OHF</th> <th align="right">OHFp</th> </tr> </thead> <tbody> <tr class="odd"> <td>MSE</td> <td align="right">0.015</td> <td align="right">0.019</td> <td align="right">0.015</td> <td align="right">0.018</td> <td align="right">0.020</td> <td align="right">0.019</td> </tr> <tr class="even"> <td>95% CI cov</td> <td align="right">0.989</td> <td align="right">0.979</td> <td align="right">0.981</td> <td align="right">0.985</td> <td align="right">0.985</td> <td align="right">0.984</td> </tr> </tbody> </table> <p><img src="images/sim3ROC.png" /> <img src="images/sim3time.png" /></p> </div> <div id="model-with-independent-shared-and-unique-effects" class="section level2"> <h2>Model with independent, shared, and unique effects</h2> <p>This model is similar to the above two, but now only a third of the nonnull columns have independently distributed entries and a third have shared entries. The other third have a unique nonzero entry. (This corresponds, for example, to a gene that is only expressed in a single condition.) The unique effects are distributed uniformly across rows.</p> <table> <thead> <tr class="header"> <th></th> <th align="right">MASH</th> <th align="right">Vanilla</th> <th align="right">Zero</th> <th align="right">OHL</th> <th align="right">OHF</th> <th align="right">OHFp</th> </tr> </thead> <tbody> <tr class="odd"> <td>MSE</td> <td align="right">0.017</td> <td align="right">0.023</td> <td align="right">0.019</td> <td align="right">0.020</td> <td align="right">0.021</td> <td align="right">0.020</td> </tr> <tr class="even"> <td>95% CI cov</td> <td align="right">0.989</td> <td align="right">0.975</td> <td align="right">0.977</td> <td align="right">0.982</td> <td align="right">0.982</td> <td align="right">0.982</td> </tr> </tbody> </table> <p><img src="images/sim4ROC.png" /> <img src="images/sim4time.png" /></p> </div> <div id="rank-1-flash-model" class="section level2"> <h2>Rank 1 FLASH model</h2> <p>This is the FLASH model <span class="math inline">\(X = LF\)</span>, where <span class="math inline">\(L\)</span> is an <span class="math inline">\(n\)</span> by <span class="math inline">\(k\)</span> matrix and <span class="math inline">\(F\)</span> is a <span class="math inline">\(k\)</span> by <span class="math inline">\(p\)</span> matrix. In this first simulation, <span class="math inline">\(k = 1\)</span>. 80% of the entries in <span class="math inline">\(F\)</span> and 50% of the entries in <span class="math inline">\(L\)</span> are equal to zero. The other entries are i.i.d. <span class="math inline">\(N(0, 1)\)</span>.</p> <table> <thead> <tr class="header"> <th></th> <th align="right">MASH</th> <th align="right">Vanilla</th> <th align="right">Zero</th> <th align="right">OHL</th> <th align="right">OHF</th> <th align="right">OHFp</th> </tr> </thead> <tbody> <tr class="odd"> <td>MSE</td> <td align="right">0.023</td> <td align="right">0.016</td> <td align="right">0.015</td> <td align="right">0.017</td> <td align="right">0.035</td> <td align="right">0.018</td> </tr> <tr class="even"> <td>95% CI cov</td> <td align="right">0.974</td> <td align="right">0.931</td> <td align="right">0.934</td> <td align="right">0.950</td> <td align="right">0.968</td> <td align="right">0.950</td> </tr> </tbody> </table> <p><img src="images/sim5ROC.png" /> <img src="images/sim5time.png" /></p> </div> <div id="rank-5-flash-model" class="section level2"> <h2>Rank 5 FLASH model</h2> <p>This is the same as above with <span class="math inline">\(k = 5\)</span> and with only 20% of the entries in <span class="math inline">\(L\)</span> equal to zero.</p> <table> <thead> <tr class="header"> <th></th> <th align="right">MASH</th> <th align="right">Vanilla</th> <th align="right">Zero</th> <th align="right">OHL</th> <th align="right">OHF</th> <th align="right">OHFp</th> </tr> </thead> <tbody> <tr class="odd"> <td>MSE</td> <td align="right">0.115</td> <td align="right">0.083</td> <td align="right">0.077</td> <td align="right">0.077</td> <td align="right">0.284</td> <td align="right">0.184</td> </tr> <tr class="even"> <td>95% CI cov</td> <td align="right">0.929</td> <td align="right">0.880</td> <td align="right">0.894</td> <td align="right">0.905</td> <td align="right">0.937</td> <td align="right">0.876</td> </tr> </tbody> </table> <p><img src="images/sim6ROC.png" /> <img src="images/sim6time.png" /></p> </div> <div id="rank-3-flash-model-with-uv" class="section level2"> <h2>Rank 3 FLASH model with UV</h2> <p>This is similar to the above with <span class="math inline">\(k = 3\)</span> and with 30% of the rows in <span class="math inline">\(L\)</span> equal to zero. In addition, a dense rank-one matrix <span class="math inline">\(W\)</span> is added to <span class="math inline">\(X\)</span> to mimic the effects of unwanted variation. Here, <span class="math inline">\(W = UV\)</span>, with <span class="math inline">\(U\)</span> an <span class="math inline">\(n\)</span> by 1 vector and <span class="math inline">\(V\)</span> a 1 by <span class="math inline">\(p\)</span> vector, both of which have entries distributed <span class="math inline">\(N(0, 0.25)\)</span>.</p> <table> <thead> <tr class="header"> <th></th> <th align="right">MASH</th> <th align="right">Vanilla</th> <th align="right">Zero</th> <th align="right">OHL</th> <th align="right">OHF</th> <th align="right">OHFp</th> </tr> </thead> <tbody> <tr class="odd"> <td>MSE</td> <td align="right">0.086</td> <td align="right">0.083</td> <td align="right">0.080</td> <td align="right">0.081</td> <td align="right">0.169</td> <td align="right">0.101</td> </tr> <tr class="even"> <td>95% CI cov</td> <td align="right">0.936</td> <td align="right">0.878</td> <td align="right">0.892</td> <td align="right">0.900</td> <td align="right">0.950</td> <td align="right">0.907</td> </tr> </tbody> </table> <p><img src="images/sim7ROC.png" /> <img src="images/sim7time.png" /></p> </div> <div id="code" class="section level2"> <h2>Code</h2> <p>for simulating datasets…</p> <pre class="r"><code>## SIMULATION FUNCTIONS ------------------------------------------------- # n is number of conditions, p is number of genes # Noise is i.i.d. N(0, 1) get_E <- function(n, p, sd = 1) { matrix(rnorm(n * p, 0, sd), n, p) } # Simulate from null model ---------------------------------------------- null_sim <- function(n, p, seed = NULL) { set.seed(seed) Y <- get_E(n, p) true_Y <- matrix(0, n, p) list(Y = Y, true_Y = true_Y) } # Simulate from MASH model ---------------------------------------------- # Sigma is list of covariance matrices # pi[j] is probability that effect j has covariance Sigma[[j]] # s is sparsity (percentage of null effects) mash_sim <- function(n, p, Sigma, pi = NULL, s = 0.8, seed = NULL) { set.seed(NULL) if (is.null(pi)) { pi = rep(1, length(Sigma)) # default to uniform distribution } assertthat::are_equal(length(pi), length(Sigma)) for (j in length(Sigma)) { assertthat::are_equal(dim(Sigma[j]), c(n, n)) } pi <- pi / sum(pi) # normalize pi to sum to one which_sigma <- sample(1:length(pi), p, replace=TRUE, prob=pi) nonnull_fx <- sample(1:p, floor((1 - s)*p), replace=FALSE) X <- matrix(0, n, p) for (j in nonnull_fx) { X[, j] <- MASS::mvrnorm(1, rep(0, n), Sigma[[which_sigma[j]]]) } Y <- X + get_E(n, p) list(Y = Y, true_Y = X) } # Simulate from FLASH model --------------------------------------------- # fs is sparsity of factors (percentage of null effects) # fvar is variance of effects (generated from normal distribution) # ls is sparsity of loadings # lvar is variance of loadings # UVvar is variance of dense rank-one matrix included to mimic something # like unwanted variation (set it to 0 to ignore it) flash_sim <- function(n, p, k, fs, fvar, ls, lvar, UVvar = 0, seed = NULL) { set.seed(seed) nonnull_ll <- matrix(sample(c(0, 1), n*k, TRUE, c(ls, 1 - ls)), n, k) LL <- nonnull_ll * matrix(rnorm(n*k, 0, sqrt(lvar)), n, k) nonnull_ff <- matrix(sample(c(0, 1), k*p, TRUE, c(fs, 1 - fs)), k, p) FF <- nonnull_ff * matrix(rnorm(k*p, 0, sqrt(fvar)), k, p) X <- LL %*% FF Y <- X + get_E(n, p) # add unwanted variation Y <- Y + outer(rnorm(n, 0, sqrt(UVvar)), rnorm(p, 0, sqrt(UVvar))) list(Y = Y, true_Y = X) } ## SIMULATIONS ---------------------------------------------------------- # Functions to generate seven types of datasets. One is null; three are # from the MASH model; three are from the FLASH model. sim_fns <- function(n, p, s, mashvar, fvar, lvar, UVvar) { # 1. Everything is null sim_null <- function(){ null_sim(n, p) } Sigma <- list() Sigma[[1]] <- diag(rep(mashvar, n)) # 2. Effects are independent across conditions sim_ind <- function(){ mash_sim(n, p, Sigma) } Sigma[[2]] <- matrix(mashvar, n, n) # 3. Effects are either independent or shared sim_indsh <- function(){ mash_sim(n, p, Sigma) } for (j in 1:n) { Sigma[[2 + j]] <- matrix(0, n, n) Sigma[[2 + j]][j, j] <- mashvar } pi <- c(n, n, rep(1, n)) # 4. Effects are independent, shared, or unique to a single condition sim_mash <- function(){ mash_sim(n, p, Sigma) } # 5. Rank one model sim_rank1 <- function(){ flash_sim(n, p, 1, s, fvar, 0.5, lvar) } # 6. Rank 5 model sim_rank5 <- function(){ flash_sim(n, p, 5, s, fvar, 0.2, lvar) } # 7. Rank 3 model with unwanted variation sim_UV <- function(){ flash_sim(n, p, 3, s, fvar, 0.3, lvar, UVvar) } c(sim_null, sim_ind, sim_indsh, sim_mash, sim_rank1, sim_rank5, sim_UV) } sim_names <- c("Null simulation", "All independent effects", "Independent and shared", "Independent, shared, and unique", "Rank 1 FLASH model", "Rank 5 FLASH model", "Rank 3 FLASH with UV")</code></pre> <p>…for fitting MASH and FLASH objects…</p> <pre class="r"><code># Fit using FLASH ------------------------------------------------------- # Methods: 1. Vanilla, 2. Zero, 3. OHL, 4. OHF, 5. OHF+ fit_flash <- function(Y, Kmax, methods=1:5, ebnm_fn="ebnm_pn") { n <- nrow(Y) fits <- list() timing <- list() # Vanilla FLASH if (1 %in% methods) { timing$Vanilla <- list() data <- flash_set_data(Y) t0 <- Sys.time() fl <- flash_add_greedy(data, Kmax, var_type="by_column", ebnm_fn=ebnm_fn) t1 <- Sys.time() timing$Vanilla$greedy <- t1 - t0 fits$Vanilla <- flash_backfit(data, fl, var_type="by_column", ebnm_fn=ebnm_fn) timing$Vanilla$backfit <- Sys.time() - t1 } data <- flash_set_data(Y, S = 1) # Zero and OHL if (2 %in% methods || 3 %in% methods) { t0 <- Sys.time() fl <- flash_add_greedy(data, Kmax, var_type="zero", ebnm_fn=ebnm_fn) t1 <- Sys.time() if (2 %in% methods) { timing$Zero <- list() timing$Zero$greedy <- t1 - t0 fits$Zero <- flash_backfit(data, fl, nullcheck=F, var_type="zero", ebnm_fn=ebnm_fn) timing$Zero$backfit <- Sys.time() - t1 } if (3 %in% methods) { timing$OHL <- list() timing$OHL$greedy <- t1 - t0 fl <- flash_add_fixed_l(data, diag(rep(1, n)), fl) t2 <- Sys.time() fits$OHL <- flash_backfit(data, fl, nullcheck=F, var_type="zero", ebnm_fn=ebnm_fn) timing$OHL$backfit <- Sys.time() - t2 } } # OHF and OHF+ if (4 %in% methods || 5 %in% methods) { t0 <- Sys.time() fl <- flash_add_fixed_l(data, diag(rep(1, n))) fl <- flash_backfit(data, fl, nullcheck=F, var_type="zero", ebnm_fn=ebnm_fn) t1 <- Sys.time() fl <- flash_add_greedy(data, Kmax, fl, var_type="zero", ebnm_fn=ebnm_fn) t2 <- Sys.time() if (4 %in% methods) { fits$OHF <- fl timing$OHF$backfit <- t1 - t0 timing$OHF$greedy <- t2 - t1 } if (5 %in% methods) { fits$OHFp <- flash_backfit(data, fl, nullcheck=F, var_type="zero", ebnm_fn=ebnm_fn) timing$OHFp$backfit <- (t1 - t0) + (Sys.time() - t2) timing$OHFp$greedy <- t2 - t1 } } # timing$total <- Reduce(`+`, timing) list(fits = fits, timing = timing) } # Fit using MASH ------------------------------------------------------- fit_mash <- function(Y, ed=T) { data <- mash_set_data(t(Y)) timing <- list() # time to create canonical matrices is negligible U = cov_canonical(data) if (ed) { t0 <- Sys.time() m.1by1 <- mash_1by1(data) strong <- get_significant_results(m.1by1, 0.05) U.pca <- cov_pca(data, 5, strong) U.ed <- cov_ed(data, U.pca, strong) U <- c(U, U.ed) timing$ed <- Sys.time() - t0 } t0 <- Sys.time() m <- mash(data, U) timing$mash <- Sys.time() - t0 # timing$total <- Reduce(`+`, timing) list(m = m, timing = timing) }</code></pre> <p>…for evaluating performance…</p> <pre class="r"><code># Evaluate methods based on MSE, CI coverage, and TPR vs. FPR ----------- flash_diagnostics <- function(fl, Y, true_Y, nsamp) { MSE <- flash_mse(fl, true_Y) # Sample from FLASH fit to estimate CI coverage and TPR vs. FPR fl_sampler <- flash_sampler(Y, fl, fixed="loadings") fl_samp <- fl_sampler(nsamp) CI <- flash_ci(fl_samp, true_Y) ROC <- flash_roc(fl, fl_samp, true_Y) list(MSE = MSE, CI = CI, TP = ROC$TP, FP = ROC$FP, n_nulls = ROC$n_nulls, n_nonnulls = ROC$n_nonnulls) } mash_diagnostics <- function(m, true_Y) { MSE <- mash_mse(m, true_Y) CI <- mash_ci(m, true_Y) ROC <- mash_roc(m, true_Y) list(MSE = MSE, CI = CI, TP = ROC$TP, FP = ROC$FP, n_nulls = ROC$n_nulls, n_nonnulls = ROC$n_nonnulls) } # MSE of posterior means (FLASH) ---------------------------------------- flash_mse <- function(fl, true_Y) { mean((flash_get_fitted_values(fl) - true_Y)^2) } # MSE for MASH ---------------------------------------------------------- mash_mse <- function(m, true_Y) { mean((get_pm(m) - t(true_Y))^2) } # 95% CI coverage for FLASH --------------------------------------------- flash_ci <- function(fl_samp, true_Y) { n <- nrow(true_Y) p <- ncol(true_Y) nsamp <- length(fl_samp) flat_samp <- matrix(0, nrow=n*p, ncol=nsamp) for (i in 1:nsamp) { flat_samp[, i] <- as.vector(fl_samp[[i]]) } CI <- t(apply(flat_samp, 1, function(x) {quantile(x, c(0.025, 0.975))})) mean((as.vector(true_Y) >= CI[, 1]) & (as.vector(true_Y) <= CI[, 2])) } # 95% CI coverage for MASH ---------------------------------------------- mash_ci <- function(m, true_Y) { Y <- t(true_Y) mean((Y > get_pm(m) - 1.96 * get_psd(m)) & (Y < get_pm(m) + 1.96 * get_psd(m))) } # LFSR for FLASH -------------------------------------------------------- flash_lfsr <- function(fl_samp) { nsamp <- length(fl_samp) n <- nrow(fl_samp[[1]]) p <- ncol(fl_samp[[1]]) pp <- matrix(0, nrow=n, ncol=p) pn <- matrix(0, nrow=n, ncol=p) for (i in 1:nsamp) { pp <- pp + (fl_samp[[i]] > 0) pn <- pn + (fl_samp[[i]] < 0) } 1 - pmax(pp, pn) / nsamp } # Quantities for plotting ROC curves ----------------------------------- flash_roc <- function(fl, fl_samp, true_Y, step=0.01) { roc_data(flash_get_fitted_values(fl), true_Y, flash_lfsr(fl_samp), step) } mash_roc <- function(m, true_Y, step=0.01) { roc_data(get_pm(m), t(true_Y), get_lfsr(m), step) } roc_data <- function(pm, true_Y, lfsr, step) { correct_sign <- pm * true_Y > 0 is_null <- true_Y == 0 n_nulls <- sum(is_null) n_nonnulls <- length(true_Y) - n_nulls ts <- seq(0, 1, by=step) tp <- rep(0, length(ts)) fp <- rep(0, length(ts)) for (t in 1:length(ts)) { signif <- lfsr <= ts[t] tp[t] <- sum(signif & correct_sign) fp[t] <- sum(signif & is_null) } list(ts = ts, TP = tp, FP = fp, n_nulls = n_nulls, n_nonnulls = n_nonnulls) } # empirical false sign rate vs. local false sign rate # efsr_by_lfsr <- function(pm, true_Y, lfsr, step) { # pred_signs <- sign(pm) # pred_zeros <- pred_signs == 0 # pred_signs[pred_zeros] <- sample(c(0, 1), length(pred_zeros), replace=T) # # gotitright <- (pred_signs == sign(true_Y)) # # nsteps <- floor(.5 / step) # efsr_by_lfsr <- rep(0, nsteps) # for (k in 1:nsteps) { # idx <- (lfsr >= (step * (k - 1)) & lfsr < (step * k)) # efsr_by_lfsr[k] <- ifelse(sum(idx) == 0, NA, # 1 - sum(gotitright[idx]) / sum(idx)) # } # efsr_by_lfsr # }</code></pre> <p>…for running simulations and plotting results…</p> <pre class="r"><code>run_sims <- function(sim_fn, nsims, plot_title, fpath) { #suppressMessages( #suppressWarnings( #capture.output( if (nsims == 1) { res = run_one_sim(sim_fn) } else { res = run_many_sims(sim_fn, nsims) } #) #) #) saveRDS(output_res_mat(res), paste0(fpath, "res.rds")) if (!(plot_title == "Null simulation")) { png(paste0(fpath, "ROC.png")) plot_ROC(res, plot_title) dev.off() } png(paste0(fpath, "time.png")) plot_timing(res) dev.off() } run_many_sims <- function(sim_fn, nsims) { res <- list() combined_res <- list() for (i in 1:nsims) { res[[i]] <- run_one_sim(sim_fn) } elems <- names(res[[1]]) for (elem in elems) { combined_res[[elem]] <- list() subelems <- names(res[[1]][[elem]]) for (subelem in subelems) { combined_res[[elem]][[subelem]] <- list() subsubelems <- names(res[[1]][[elem]][[subelem]]) for (subsubelem in subsubelems) { tmp <- lapply(res, function(x) {x[[elem]][[subelem]][[subsubelem]]}) combined_res[[elem]][[subelem]][[subsubelem]] <- Reduce(`+`, tmp) / nsims } } } combined_res } run_one_sim <- function(sim_fn, Kmax = 10, nsamp=200) { data <- do.call(sim_fn, list()) # If there are no strong signals, trying to run ED throws an error, so # we need to do some error handling to fit the MASH object try(mfit <- fit_mash(data$Y)) if (!exists("mfit")) { mfit <- fit_mash(data$Y, ed=F) mfit$timing$ed = as.difftime(0, units="secs") } flfits <- fit_flash(data$Y, Kmax) message("Running MASH diagnostics") mres <- mash_diagnostics(mfit$m, data$true_Y) message("Running FLASH diagnostics") flres <- list() methods <- names(flfits$fits) for (method in methods) { flres[[method]] <- flash_diagnostics(flfits$fits[[method]], data$Y, data$true_Y, nsamp) } # Give mash and flash the same structure so we can combine multiple sims mash_timing = list() mash_timing$mash <- mfit$timing mash_res = list() mash_res$mash <- mres list(mash_timing = mash_timing, mash_res = mash_res, flash_timing = flfits$timing, flash_res = flres) } output_res_mat <- function(res) { mat <- c(res$mash_res$mash$MSE, res$mash_res$mash$CI) methods <- names(res$flash_res) for (method in methods) { mat <- cbind(mat, c(res$flash_res[[method]]$MSE, res$flash_res[[method]]$CI)) } rownames(mat) = c("MSE", "95% CI cov") colnames(mat) = c("MASH", methods) mat } plot_timing <- function(res, units="secs") { data <- as.numeric(c(res$mash_timing$mash$ed, res$mash_timing$mash$mash), units=units) methods <- names(res$flash_timing) for (method in methods) { data <- cbind(data, as.numeric(c(res$flash_timing[[method]]$greedy, res$flash_timing[[method]]$backfit), units=units)) } barplot(data, axes=T, main=paste("Average time to fit in", units), names.arg = c("MASH", methods), legend.text = c("ED/Greedy", "MASH/Backfit"), ylim = c(0, max(colSums(data))*2)) # (increasing ylim is easiest way to deal with legend getting in way) } plot_ROC <- function(res, main="ROC curve", colors=c("gold", "pink", "red", "green", "blue")) { # Number of nulls and nonnulls are identical across methods n_nonnulls <- res$mash_res$mash$n_nonnulls n_nulls <- res$mash_res$mash$n_nulls m_y <- res$mash_res$mash$TP / n_nonnulls m_x <- res$mash_res$mash$FP / n_nulls plot(m_x, m_y, xlim=c(0, 1), ylim=c(0, 1), type='l', xlab='FPR', ylab='TPR', main=main) methods <- names(res$flash_res) idx <- 0 for (method in methods) { idx <- idx + 1 y <- res$flash_res[[method]]$TP / n_nonnulls x <- res$flash_res[[method]]$FP / n_nulls lines(x, y, col=colors[idx]) } legend("bottomright", c("MASH", methods), lty=1, col=c("black", colors[1:idx])) }</code></pre> <p>…and the main function calls.</p> <pre class="r"><code># library(flashr) devtools::load_all("/Users/willwerscheid/GitHub/flashr/") library(mashr) source("./code/sims.R") source("./code/fits.R") source("./code/utils.R") source("./code/mashvflash.R") set.seed(1) # s is sparsity (prop null genes); var parameters define size of effects all_sims <- sim_fns(n=25, p=1000, s=0.8, mashvar=1, fvar=1, lvar=1, UVvar=0.25) for (i in 1:length(all_sims)) { message(paste(" Beginning simulation #", i, sep="")) res <- run_sims(all_sims[[i]], nsims=10, plot_title=sim_names[[i]], fpath = paste0("./output/sim", i)) }</code></pre> </div> <div id="session-information" class="section level2"> <h2>Session information</h2> <pre class="r"><code>sessionInfo()</code></pre> <pre><code>R version 3.4.3 (2017-11-30) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS High Sierra 10.13.1 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 loaded via a namespace (and not attached): [1] workflowr_1.0.1 Rcpp_0.12.17 digest_0.6.15 [4] rprojroot_1.3-2 R.methodsS3_1.7.1 backports_1.1.2 [7] git2r_0.21.0 magrittr_1.5 evaluate_0.10.1 [10] highr_0.6 stringi_1.1.6 whisker_0.3-2 [13] R.oo_1.21.0 R.utils_2.6.0 rmarkdown_1.8 [16] tools_3.4.3 stringr_1.3.0 yaml_2.1.17 [19] compiler_3.4.3 htmltools_0.3.6 knitr_1.20 </code></pre> </div> <!-- 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.0.1 </p> <hr> </div> </div> </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>