<!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="Lei Sun" />

<meta name="date" content="2018-02-10" />

<title>CASH Simulations</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/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">truncash</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li>
  <a href="about.html">About</a>
</li>
<li>
  <a href="license.html">License</a>
</li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li>
  <a href="https://github.com/LSun/truncash">
    <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"><code>CASH</code> Simulations</h1>
<h4 class="author"><em>Lei Sun</em></h4>
<h4 class="date"><em>2018-02-10</em></h4>

</div>


<p><strong>Last updated:</strong> 2018-05-15</p>
<strong>workflowr checks:</strong> <small>(Click a bullet for more information)</small>
<ul>
<li>
<details>
<p><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>
<details>
<p><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>
<details>
<p><summary> <strong style="color:blue;">✔</strong> <strong>Seed:</strong> <code>set.seed(12345)</code> </summary></p>
<p>The command <code>set.seed(12345)</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>
<details>
<p><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>
<details>
<p><summary> <strong style="color:blue;">✔</strong> <strong>Repository version:</strong> <a href="https://github.com/LSun/truncash/tree/388e65e06000e313c170a82f3ed57346f6024897" target="_blank">388e65e</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:    analysis/.DS_Store
    Ignored:    analysis/BH_robustness_cache/
    Ignored:    analysis/FDR_Null_cache/
    Ignored:    analysis/FDR_null_betahat_cache/
    Ignored:    analysis/Rmosek_cache/
    Ignored:    analysis/StepDown_cache/
    Ignored:    analysis/alternative2_cache/
    Ignored:    analysis/alternative_cache/
    Ignored:    analysis/ash_gd_cache/
    Ignored:    analysis/average_cor_gtex_2_cache/
    Ignored:    analysis/average_cor_gtex_cache/
    Ignored:    analysis/brca_cache/
    Ignored:    analysis/cash_deconv_cache/
    Ignored:    analysis/cash_fdr_1_cache/
    Ignored:    analysis/cash_fdr_2_cache/
    Ignored:    analysis/cash_fdr_3_cache/
    Ignored:    analysis/cash_fdr_4_cache/
    Ignored:    analysis/cash_fdr_5_cache/
    Ignored:    analysis/cash_fdr_6_cache/
    Ignored:    analysis/cash_plots_cache/
    Ignored:    analysis/cash_sim_1_cache/
    Ignored:    analysis/cash_sim_2_cache/
    Ignored:    analysis/cash_sim_3_cache/
    Ignored:    analysis/cash_sim_4_cache/
    Ignored:    analysis/cash_sim_5_cache/
    Ignored:    analysis/cash_sim_6_cache/
    Ignored:    analysis/cash_sim_7_cache/
    Ignored:    analysis/correlated_z_2_cache/
    Ignored:    analysis/correlated_z_3_cache/
    Ignored:    analysis/correlated_z_cache/
    Ignored:    analysis/create_null_cache/
    Ignored:    analysis/cutoff_null_cache/
    Ignored:    analysis/design_matrix_2_cache/
    Ignored:    analysis/design_matrix_cache/
    Ignored:    analysis/diagnostic_ash_cache/
    Ignored:    analysis/diagnostic_correlated_z_2_cache/
    Ignored:    analysis/diagnostic_correlated_z_3_cache/
    Ignored:    analysis/diagnostic_correlated_z_cache/
    Ignored:    analysis/diagnostic_plot_2_cache/
    Ignored:    analysis/diagnostic_plot_cache/
    Ignored:    analysis/efron_leukemia_cache/
    Ignored:    analysis/fitting_normal_cache/
    Ignored:    analysis/gaussian_derivatives_2_cache/
    Ignored:    analysis/gaussian_derivatives_3_cache/
    Ignored:    analysis/gaussian_derivatives_4_cache/
    Ignored:    analysis/gaussian_derivatives_5_cache/
    Ignored:    analysis/gaussian_derivatives_cache/
    Ignored:    analysis/gd-ash_cache/
    Ignored:    analysis/gd_delta_cache/
    Ignored:    analysis/gd_lik_2_cache/
    Ignored:    analysis/gd_lik_cache/
    Ignored:    analysis/gd_w_cache/
    Ignored:    analysis/knockoff_10_cache/
    Ignored:    analysis/knockoff_2_cache/
    Ignored:    analysis/knockoff_3_cache/
    Ignored:    analysis/knockoff_4_cache/
    Ignored:    analysis/knockoff_5_cache/
    Ignored:    analysis/knockoff_6_cache/
    Ignored:    analysis/knockoff_7_cache/
    Ignored:    analysis/knockoff_8_cache/
    Ignored:    analysis/knockoff_9_cache/
    Ignored:    analysis/knockoff_cache/
    Ignored:    analysis/knockoff_var_cache/
    Ignored:    analysis/marginal_z_alternative_cache/
    Ignored:    analysis/marginal_z_cache/
    Ignored:    analysis/mosek_reg_2_cache/
    Ignored:    analysis/mosek_reg_4_cache/
    Ignored:    analysis/mosek_reg_5_cache/
    Ignored:    analysis/mosek_reg_6_cache/
    Ignored:    analysis/mosek_reg_cache/
    Ignored:    analysis/pihat0_null_cache/
    Ignored:    analysis/plot_diagnostic_cache/
    Ignored:    analysis/poster_obayes17_cache/
    Ignored:    analysis/real_data_simulation_2_cache/
    Ignored:    analysis/real_data_simulation_3_cache/
    Ignored:    analysis/real_data_simulation_4_cache/
    Ignored:    analysis/real_data_simulation_5_cache/
    Ignored:    analysis/real_data_simulation_cache/
    Ignored:    analysis/rmosek_primal_dual_2_cache/
    Ignored:    analysis/rmosek_primal_dual_cache/
    Ignored:    analysis/seqgendiff_cache/
    Ignored:    analysis/simulated_correlated_null_2_cache/
    Ignored:    analysis/simulated_correlated_null_3_cache/
    Ignored:    analysis/simulated_correlated_null_cache/
    Ignored:    analysis/simulation_real_se_2_cache/
    Ignored:    analysis/simulation_real_se_cache/
    Ignored:    analysis/smemo_2_cache/
    Ignored:    data/LSI/
    Ignored:    docs/.DS_Store
    Ignored:    docs/figure/.DS_Store
    Ignored:    output/fig/

</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;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/b7cf71b4d05a1ea70fdad8da02796d7c0ddc50e8/docs/cash_plots.html" target="_blank">b7cf71b</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</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/LSun/truncash/blob/69e0c7d38485fae14d795f022ec7f718e9c2a93e/analysis/cash_plots.rmd" target="_blank">69e0c7d</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
<td style="text-align:left;">
Update to 1.0
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/69e0c7d38485fae14d795f022ec7f718e9c2a93e/docs/cash_plots.html" target="_blank">69e0c7d</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
<td style="text-align:left;">
Update to 1.0
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/cash_plots.html" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</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/LSun/truncash/blob/22ec0c112638f23411253686a24fd0c9c912011d/analysis/cash_plots.rmd" target="_blank">22ec0c1</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
more g
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/e3e4aff00a342b1c30af091c4982a9c53b5af6a2/analysis/cash_plots.rmd" target="_blank">e3e4aff</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
plots
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/49513d83d2da0916b9f9ff8730c76ca110f1f90d/analysis/cash_plots.rmd" target="_blank">49513d8</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
g3
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/208f33ef7266a482b8cd1d993a35033d75cd9d90/analysis/cash_plots.rmd" target="_blank">208f33e</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
more alternatives
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/df1077547b4483343654ed0115b1f12c454afe8f/analysis/cash_plots.rmd" target="_blank">df10775</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
bimodal
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/0eb67ffc48770b8bfe57b04e1c40d06be807a68b/docs/cash_plots.html" target="_blank">0eb67ff</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-13
</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/LSun/truncash/blob/bdd32ee0e762b459c93a3481d745f78eed646cde/analysis/cash_plots.rmd" target="_blank">bdd32ee</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
wflow_publish(“analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/ad80febdb53c015f71ec5688f858682187919fd0/analysis/cash_plots.rmd" target="_blank">ad80feb</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
plots
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/42b59ae0425d31d4af580b241d9233c88669f86b/analysis/cash_plots.rmd" target="_blank">42b59ae</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
plot size
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/9962d0703fe240be97212489abad282f80a9223a/analysis/cash_plots.rmd" target="_blank">9962d07</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
plot size
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/97317b47b519d8653ee39fdd19226cc20e758c15/analysis/cash_plots.rmd" target="_blank">97317b4</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-13
</td>
<td style="text-align:left;">
cash_pi0
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/8ac1a0704f949df2f92a410f0d04f160a73448ad/analysis/cash_plots.rmd" target="_blank">8ac1a07</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-05-12
</td>
<td style="text-align:left;">
multiple pi0
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/e05bc836b3c74dc6ebca415afb5938675d6c5436/docs/cash_plots.html" target="_blank">e05bc83</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-12
</td>
<td style="text-align:left;">
Update to 1.0
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/cc0ab8379469bc3726f1508cd81e4ecd6fef1b1a/analysis/cash_plots.rmd" target="_blank">cc0ab83</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-05-11
</td>
<td style="text-align:left;">
update
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/566a8654839abc68c26d7eeb00980e5cd89b3ab5/docs/cash_plots.html" target="_blank">566a865</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-09
</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/LSun/truncash/blob/f85ff3f95abc912244162392d4d18f73a5794c06/analysis/cash_plots.rmd" target="_blank">f85ff3f</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-09
</td>
<td style="text-align:left;">
wflow_publish(“analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/564f9cbc4a8c3126ba03c320d03add8cc56c0aad/docs/cash_plots.html" target="_blank">564f9cb</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-06
</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/LSun/truncash/blob/797cd6939f3c430497c03ce97a2093ee9b29f32c/analysis/cash_plots.rmd" target="_blank">797cd69</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-06
</td>
<td style="text-align:left;">
wflow_publish(“analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/4093362a962261caab72b6d8d091a8d75bf6aa57/docs/cash_plots.html" target="_blank">4093362</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</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/LSun/truncash/37ad45698441ee0ae5eb3202f95e0164d77ef5b7/docs/cash_plots.html" target="_blank">37ad456</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</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/LSun/truncash/blob/8c99563f2eef4e5cab124d07550cdea171d4d252/analysis/cash_plots.rmd" target="_blank">8c99563</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</td>
<td style="text-align:left;">
wflow_publish(“analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/434b541bdc15b2dc25ba567a00b400a3adca728e/analysis/cash_plots.rmd" target="_blank">434b541</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-04-13
</td>
<td style="text-align:left;">
FDP q
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/7e7b2d1056ce9271efcec0a9c683c5ead20fadcc/docs/cash_plots.html" target="_blank">7e7b2d1</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-12
</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/LSun/truncash/blob/3a1e4cccb478491f57bfcb67c445abb3ef01b754/analysis/cash_plots.rmd" target="_blank">3a1e4cc</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-12
</td>
<td style="text-align:left;">
wflow_publish(“analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/d022714b2f3ed96ed6023463e86b00853d0e4af7/docs/cash_plots.html" target="_blank">d022714</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-22
</td>
<td style="text-align:left;">
cash
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/e94c1d3faaabce53937a14402cbd7a141b7eb094/analysis/cash_plots.rmd" target="_blank">e94c1d3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-22
</td>
<td style="text-align:left;">
cash plots
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/898349224d5515a514c73d486a1ec606b8ddf32e/docs/cash_plots.html" target="_blank">8983492</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-21
</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/LSun/truncash/blob/5902dc9ac06021c1fe2118b450831535b2cd9ecb/analysis/cash_plots.rmd" target="_blank">5902dc9</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-21
</td>
<td style="text-align:left;">
wflow_publish(“~/GitHub/truncash/analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/48787a24c36b1a24e129936b2748cc52d1397d8a/analysis/cash_plots.rmd" target="_blank">48787a2</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-02-16
</td>
<td style="text-align:left;">
cash plots
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/ff78840417d28f89acda4ced9358de7dc499bf01/analysis/cash_plots.rmd" target="_blank">ff78840</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-16
</td>
<td style="text-align:left;">
cash_plots
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/e4ecc944e59aa28a6791b0064a1c4e66a539e9a6/docs/cash_plots.html" target="_blank">e4ecc94</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-16
</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/LSun/truncash/blob/2898ce9a1fd6100e144c03e810a018dcbb95a8f2/analysis/cash_plots.rmd" target="_blank">2898ce9</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-16
</td>
<td style="text-align:left;">
wflow_publish(“analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/7c34000d9661213f6beaf89c08f5385487f40c87/docs/cash_plots.html" target="_blank">7c34000</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-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/LSun/truncash/blob/cc05dc761a08501debf921040a8c82272670f4de/analysis/cash_plots.rmd" target="_blank">cc05dc7</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-15
</td>
<td style="text-align:left;">
wflow_publish(“analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/4d857f76f9fb42a3c75dd097694e2aebcd2a36b9/analysis/cash_plots.rmd" target="_blank">4d857f7</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-02-14
</td>
<td style="text-align:left;">
plots
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/f6f0ca05166b95be517673adcc3d213590001693/docs/cash_plots.html" target="_blank">f6f0ca0</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-14
</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/LSun/truncash/blob/3af89d27f95275a2cfeb3d23237e813930357c8c/analysis/cash_plots.rmd" target="_blank">3af89d2</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-02-14
</td>
<td style="text-align:left;">
wflow_publish(“analysis/cash_plots.rmd”)
</td>
</tr>
<tr>
<td style="text-align:left;">
rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/d2473f1d284215968bb9e32a89c65de7a10b877f/analysis/cash_plots.rmd" target="_blank">d2473f1</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-02-14
</td>
<td style="text-align:left;">
cash_plots
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/LSun/truncash/d2473f1d284215968bb9e32a89c65de7a10b877f/docs/cash_plots.html" target="_blank">d2473f1</a>
</td>
<td style="text-align:left;">
Lei Sun
</td>
<td style="text-align:left;">
2018-02-14
</td>
<td style="text-align:left;">
cash_plots
</td>
</tr>
</tbody>
</table>
</ul>
</details>
<hr />
<pre class="r"><code>source(&quot;../code/gdfit.R&quot;)
source(&quot;../code/gdash_lik.R&quot;)
source(&quot;../code/count_to_summary.R&quot;)
library(ashr)
library(locfdr)
library(qvalue)
library(reshape2)
library(ggplot2)
library(grid)
library(gridExtra)
library(RColorBrewer)
library(scales)
library(cowplot)
library(ggpubr)</code></pre>
<pre class="r"><code>mean_sdp &lt;- function (x) {
   m &lt;- mean(x)
   ymax &lt;- m + sd(x)
   return(c(y = m, ymax = ymax, ymin = m))
}
mad.mean &lt;- function (x) {
  return(mean(abs(x - median(x))))
}
FDP &lt;- function (FDR, qvalue, beta) {
  return(sum(qvalue &lt;= FDR &amp; beta == 0) / max(sum(qvalue &lt;= FDR), 1))
}
pFDP &lt;- function (FDR, qvalue, beta) {
  return(sum(qvalue &lt;= FDR &amp; beta == 0) / sum(qvalue &lt;= FDR))
}
power &lt;- function (FDR, qvalue, beta) {
  return(sum(qvalue &lt;= FDR &amp; beta != 0) / sum(beta != 0))
}</code></pre>
<pre class="r"><code>r &lt;- readRDS(&quot;../data/liver.rds&quot;)</code></pre>
<pre class="r"><code>top_genes_index = function (g, X) {
  return(order(rowSums(X), decreasing = TRUE)[1 : g])
}
lcpm = function (r) {
  R = colSums(r)
  t(log2(((t(r) + 0.5) / (R + 1)) * 10^6))
}</code></pre>
<pre class="r"><code>nsamp &lt;- 5
ngene &lt;- 1e4
pi0.vec &lt;- c(0.5, 0.9, 0.99)</code></pre>
<pre class="r"><code>Y = lcpm(r)
subset = top_genes_index(ngene, Y)
r = r[subset,]</code></pre>
<div id="g_1-nleft0-22right" class="section level2">
<h2><span class="math inline">\(g_1 = N\left(0, 2^2\right)\)</span></h2>
<pre class="r"><code>q.vec &lt;- seq(0.001, 0.20, by = 0.001)
method.name &lt;- c(&quot;BHq&quot;, &quot;qvalue&quot;, &quot;locfdr&quot;, &quot;ASH&quot;, &quot;CASH&quot;)</code></pre>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>q &lt;- 0.1
z.over &lt;- 1.05
z.under &lt;- 0.95
method.col &lt;- scales::hue_pal()(5)
# method.col &lt;- c(&quot;#377eb8&quot;, &quot;#984ea3&quot;, &quot;#4daf4a&quot;, &quot;#ff7f00&quot;, &quot;#e41a1c&quot;)</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g1_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-8-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-8-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/LSun/truncash/blob/0eb67ffc48770b8bfe57b04e1c40d06be807a68b/docs/figure/cash_plots.rmd/unnamed-chunk-8-1.png" target="_blank">0eb67ff</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-13
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-8-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-8-2.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/LSun/truncash/blob/0eb67ffc48770b8bfe57b04e1c40d06be807a68b/docs/figure/cash_plots.rmd/unnamed-chunk-8-2.png" target="_blank">0eb67ff</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-13
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-8-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-8-3.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/LSun/truncash/blob/0eb67ffc48770b8bfe57b04e1c40d06be807a68b/docs/figure/cash_plots.rmd/unnamed-chunk-8-3.png" target="_blank">0eb67ff</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-13
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="bimodal-g_2-0.5-nleft-2-1right-0.5-nleft2-1right" class="section level2">
<h2>Bimodal: <span class="math inline">\(g_2 = 0.5 N\left(-2, 1\right) + 0.5 N\left(2, 1\right)\)</span></h2>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g2_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-10-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-10-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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-10-1.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-10-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-10-2.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-10-2.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-10-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-10-3.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-10-3.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="spiky-g_3-0.4-nleft0-0.52right-0.2-nleft0-12right-0.2-nleft0-22right-0.2-nleft0-32right" class="section level2">
<h2>Spiky: <span class="math inline">\(g_3 = 0.4 N\left(0, 0.5^2\right) + 0.2 N\left(0, 1^2\right) + 0.2 N\left(0, 2^2\right) + 0.2 N\left(0, 3^2\right)\)</span></h2>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g3_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-12-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-12-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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-12-1.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/37ad45698441ee0ae5eb3202f95e0164d77ef5b7/docs/figure/cash_plots.rmd/unnamed-chunk-12-1.png" target="_blank">37ad456</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-12-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-12-2.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-12-2.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/37ad45698441ee0ae5eb3202f95e0164d77ef5b7/docs/figure/cash_plots.rmd/unnamed-chunk-12-2.png" target="_blank">37ad456</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-12-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-12-3.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-12-3.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="flattop-g_4-1-13-left-nleft-3-0.52right-nleft-2.5-0.52right-nleft-2-0.52right-nleft-1.5-0.52right-nleft-1-0.52right-nleft-0.5-0.52right-nleft0-0.52right-nleft0.5-0.52right-nleft1-0.52right-nleft1.5-0.52right-nleft2-0.52right-nleft2.5-0.52right-nleft3-0.52right-right" class="section level2">
<h2>Flattop: <span class="math inline">\(g_4 = 1 / 13 \left( N\left(-3, 0.5^2\right) + N\left(-2.5, 0.5^2\right) + N\left(-2, 0.5^2\right) + N\left(-1.5, 0.5^2\right) + N\left(-1, 0.5^2\right) + N\left(-0.5, 0.5^2\right) + N\left(0, 0.5^2\right) + N\left(0.5, 0.5^2\right) + N\left(1, 0.5^2\right) + N\left(1.5, 0.5^2\right) + N\left(2, 0.5^2\right) + N\left(2.5, 0.5^2\right) + N\left(3, 0.5^2\right) \right)\)</span></h2>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g4_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-14-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-14-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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-14-1.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-14-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-14-2.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-14-2.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-14-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-14-3.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-14-3.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="near-normal-g_5-0.6-nleft0-12right-0.4-nleft0-32right" class="section level2">
<h2>Near normal: <span class="math inline">\(g_5 = 0.6 N\left(0, 1^2\right) + 0.4 N\left(0, 3^2\right)\)</span></h2>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g5_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-16-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-16-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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-16-1.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-16-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-16-2.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-16-2.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-16-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-16-3.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-16-3.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="big-normal-g_6-nleft0-52right" class="section level2">
<h2>Big normal: <span class="math inline">\(g_6 = N\left(0, 5^2\right)\)</span></h2>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g6_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-18-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-18-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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-18-1.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/37ad45698441ee0ae5eb3202f95e0164d77ef5b7/docs/figure/cash_plots.rmd/unnamed-chunk-18-1.png" target="_blank">37ad456</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-18-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-18-2.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-18-2.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/37ad45698441ee0ae5eb3202f95e0164d77ef5b7/docs/figure/cash_plots.rmd/unnamed-chunk-18-2.png" target="_blank">37ad456</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-18-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-18-3.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-18-3.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="skew-g_7-14-nleft-2-22right-14-nleft-1-1.52right-13-nleft0-12right-1-6-nleft1-12right" class="section level2">
<h2>Skew: <span class="math inline">\(g_7 = 1/4 N\left(-2, 2^2\right) + 1/4 N\left(-1, 1.5^2\right) + 1/3 N\left(0, 1^2\right) + 1 / 6 N\left(1, 1^2\right)\)</span></h2>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g7_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-20-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-20-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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-20-1.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/37ad45698441ee0ae5eb3202f95e0164d77ef5b7/docs/figure/cash_plots.rmd/unnamed-chunk-20-1.png" target="_blank">37ad456</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-20-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-20-2.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-20-2.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-20-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-20-3.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/LSun/truncash/blob/27ef9e3a7d9105ef2924cfb810167a16779f2af9/docs/figure/cash_plots.rmd/unnamed-chunk-20-3.png" target="_blank">27ef9e3</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="small-normal-g_8-nleft0-12right" class="section level2">
<h2>Small normal: <span class="math inline">\(g_8 = N\left(0, 1^2\right)\)</span></h2>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g8_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-22-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-22-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/LSun/truncash/blob/b7cf71b4d05a1ea70fdad8da02796d7c0ddc50e8/docs/figure/cash_plots.rmd/unnamed-chunk-22-1.png" target="_blank">b7cf71b</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/37ad45698441ee0ae5eb3202f95e0164d77ef5b7/docs/figure/cash_plots.rmd/unnamed-chunk-22-1.png" target="_blank">37ad456</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-04-27
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-22-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-22-2.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/LSun/truncash/blob/b7cf71b4d05a1ea70fdad8da02796d7c0ddc50e8/docs/figure/cash_plots.rmd/unnamed-chunk-22-2.png" target="_blank">b7cf71b</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-22-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-22-3.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/LSun/truncash/blob/b7cf71b4d05a1ea70fdad8da02796d7c0ddc50e8/docs/figure/cash_plots.rmd/unnamed-chunk-22-3.png" target="_blank">b7cf71b</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="small-normal-g_9-nleft0-1.52right" class="section level2">
<h2>Small normal: <span class="math inline">\(g_9 = N\left(0, 1.5^2\right)\)</span></h2>
<pre class="r"><code>FDP.array &lt;- pFDP.array &lt;- power.array &lt;- array(0, dim = c(nsim, length(q.vec), length(method.name), length(pi0.vec)))
FDP.summary &lt;- array(0, dim = c(7, length(q.vec), length(method.name), length(pi0.vec)))
pFDP.summary &lt;- power.summary &lt;- array(0, dim = c(5, length(q.vec), length(method.name), length(pi0.vec)))
for (j in seq(length(pi0.vec))) {
  for (k in seq(length(method.name))) {
    for (i in seq(nsim)) {
      FDP.array[i, , k, j] &lt;- sapply(q.vec, FDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      pFDP.array[i, , k, j] &lt;- sapply(q.vec, pFDP, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
      power.array[i, , k, j] &lt;- sapply(q.vec, power, qvalue = qvalue.pi0.list[[j]][[i]][, k], beta = beta.pi0.list[[j]][[i]])
    }
    FDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(FDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(FDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(FDP.array[, , k, j])),
      q975 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE),
      q750 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.75, na.rm = TRUE),
      q250 &lt;- apply(FDP.array[, , k, j], 2, quantile, probs = 0.25, na.rm = TRUE)
    )
    pFDP.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(pFDP.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(pFDP.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(pFDP.array[, , k, j])),
      q975 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(pFDP.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
    power.summary[, , k, j] &lt;- rbind(
      avg &lt;- colMeans(power.array[, , k, j], na.rm = TRUE),
      sd &lt;- apply(power.array[, , k, j], 2, sd, na.rm = TRUE),
      n &lt;- colSums(!is.na(power.array[, , k, j])),
      q975 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.975, na.rm = TRUE),
      q025 &lt;- apply(power.array[, , k, j], 2, quantile, probs = 0.025, na.rm = TRUE)
    )
  }
}</code></pre>
<pre class="r"><code>for (j in seq(length(pi0.vec))) {
  sd.z &lt;- sapply(z.pi0.list[[j]], sd)
  Noise &lt;- cut(sd.z, breaks = c(0, quantile(sd.z, probs = 1 : 2 / 3), Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))
# Noise &lt;- cut(sd.z, breaks = c(0, z.under, z.over, Inf), labels = c(&quot;Deflated Noise&quot;, &quot;In-between&quot;, &quot;Inflated Noise&quot;))

  pi0.pi0 &lt;- matrix(unlist(pi0.pi0.list[[j]]), byrow = TRUE, length(pi0.pi0.list[[j]]))
  pi0.pi0.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, pi0.pi0), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), pi0.pi0))
  
  pi0.plot &lt;- ggplot(data = melt(pi0.pi0.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col[-1]) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = pi0.vec[j], col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name[-1]) +
  labs(x = &quot;&quot;, y = expression(hat(pi)[0])) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))

  FDP.summary.pi0 &lt;- aperm(FDP.summary[, , , j], c(2, 1, 3))
  FDP.summary.pi0.method &lt;- FDP.summary.pi0[, , 1]
  for (kk in 2 : length(method.name)) {
    FDP.summary.pi0.method &lt;- rbind.data.frame(FDP.summary.pi0.method, FDP.summary.pi0[, , kk])
  }
  FDP.summary.pi0.method &lt;- cbind.data.frame(
    rep(factor(seq(method.name)), each = dim(FDP.summary.pi0)[1]),
    rep(q.vec, length(method.name)),
    FDP.summary.pi0.method
  )
  colnames(FDP.summary.pi0.method) &lt;- c(
    &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  
  FDP.array.pi0 &lt;- aperm(FDP.array[, , , j], c(2, 1, 3))
  FDP.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, mean, na.rm = TRUE), c(2, 1, 3)))
  sd.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, sd, na.rm = TRUE), c(2, 1, 3)))
  n.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, function(x){sum(!is.na(x))}), c(2, 1, 3)))
  q975.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.975, na.rm = TRUE), c(2, 1, 3)))
  q025.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.025, na.rm = TRUE), c(2, 1, 3)))
  q750.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.75, na.rm = TRUE), c(2, 1, 3)))
  q250.pi0.noise &lt;- as.vector(aperm(apply(FDP.array.pi0, c(1, 3), tapply, Noise, quantile, probs = 0.25, na.rm = TRUE), c(2, 1, 3)))
  FDP.summary.pi0.method.noise &lt;- cbind.data.frame(
    rep(rep(levels(Noise), each = length(q.vec)), length(method.name)),
    rep(factor(seq(method.name)), each = length(levels(Noise)) * length(q.vec)),
    rep(q.vec, length(levels(Noise)) * length(method.name)),
    FDP.pi0.noise,
    sd.pi0.noise,
    n.pi0.noise,
    q975.pi0.noise,
    q025.pi0.noise,
    q750.pi0.noise,
    q250.pi0.noise
  )
  colnames(FDP.summary.pi0.method.noise) &lt;- c(
    &quot;Noise&quot;, &quot;Method&quot;, &quot;FDR&quot;, &quot;FDP&quot;, &quot;sd&quot;, &quot;n&quot;, &quot;q975&quot;, &quot;q025&quot;, &quot;q750&quot;, &quot;q250&quot;
  )
  FDP.summary.pi0.method.noise &lt;- rbind.data.frame(
    FDP.summary.pi0.method.noise,
    cbind.data.frame(Noise = rep(&quot;All&quot;, dim(FDP.summary.pi0.method)[1]), FDP.summary.pi0.method)
  )
  
  FDR.calib.plot &lt;- ggplot(data = FDP.summary.pi0.method.noise, aes(x = FDR, y = FDP, group = Method, col = Method)) +
  geom_line() +
  geom_ribbon(aes(ymin = q025, ymax = q975, fill = Method), alpha = 0.35, linetype = &quot;blank&quot;) +
  scale_color_manual(labels = method.name, values = method.col) +
  scale_fill_manual(labels = method.name, values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_abline(slope = 1, intercept = 0, linetype = &quot;dashed&quot;, size = 1, col = &quot;black&quot;) +
  labs(x = &quot;Nominal FDR&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;top&quot;, legend.text = element_text(size = 15), plot.title = element_text(hjust = 0.5, size = 15), axis.title.x = element_text(size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(angle = 45, size = 15), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  FDP.q &lt;- FDP.array[, which(round(q.vec, 4) == q), , j]
  FDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, FDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), FDP.q))

  FDR.plot &lt;- ggplot(data = melt(FDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  geom_hline(yintercept = q, col = &quot;black&quot;, linetype = &quot;dashed&quot;, size = 1) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;FDP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  TDP.q &lt;- power.array[, which(round(q.vec, 4) == q), , j]
  TDP.q.noise &lt;- rbind.data.frame(cbind.data.frame(Noise, TDP.q), cbind.data.frame(Noise = rep(&quot;All&quot;, length(Noise)), TDP.q))

  power.plot &lt;- ggplot(data = melt(TDP.q.noise, id.vars = &quot;Noise&quot;), aes(x = variable, y = value, col = variable)) +
  geom_boxplot() +
  stat_summary(fun.y = mean, geom = &quot;point&quot;, shape = 13, size = 3) +
  scale_color_manual(values = method.col) +
  facet_wrap(~Noise, nrow = 1, ncol = 4) +
  scale_x_discrete(labels = method.name) +
  labs(x = &quot;&quot;, y = &quot;TPP&quot;) +
  theme(legend.position = &quot;none&quot;, plot.title = element_text(hjust = 0.5, size = 15), axis.title.y = element_text(size = 15), axis.text.x = element_text(size = 15, angle = 45, hjust = 1), axis.text.y = element_text(size = 15), strip.text = element_text(size = 15))
  
  joint &lt;- ggarrange(FDR.calib.plot,
            pi0.plot + rremove(&quot;x.text&quot;),
            FDR.plot + rremove(&quot;x.text&quot;),
            power.plot,
            align = &quot;v&quot;, ncol = 1, nrow = 4,
            heights = c(1.5, 1, 1, 1.2)
  )
  joint &lt;- annotate_figure(joint,
    top = text_grob(bquote(pi[0] == .(pi0.vec[j])), size = 15)
  )
  print(joint)
  ggsave(paste0(&quot;../output/fig/g9_pi0_&quot;, pi0.vec[j], &quot;.pdf&quot;), joint, height = 10, width = 8)
}</code></pre>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-24-1.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-24-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/LSun/truncash/blob/b7cf71b4d05a1ea70fdad8da02796d7c0ddc50e8/docs/figure/cash_plots.rmd/unnamed-chunk-24-1.png" target="_blank">b7cf71b</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/LSun/truncash/blob/564f9cbc4a8c3126ba03c320d03add8cc56c0aad/docs/figure/cash_plots.rmd/unnamed-chunk-24-1.png" target="_blank">564f9cb</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-06
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-24-2.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-24-2.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/LSun/truncash/blob/b7cf71b4d05a1ea70fdad8da02796d7c0ddc50e8/docs/figure/cash_plots.rmd/unnamed-chunk-24-2.png" target="_blank">b7cf71b</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
<p><img src="figure/cash_plots.rmd/unnamed-chunk-24-3.png" width="672" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of unnamed-chunk-24-3.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/LSun/truncash/blob/b7cf71b4d05a1ea70fdad8da02796d7c0ddc50e8/docs/figure/cash_plots.rmd/unnamed-chunk-24-3.png" target="_blank">b7cf71b</a>
</td>
<td style="text-align:left;">
LSun
</td>
<td style="text-align:left;">
2018-05-14
</td>
</tr>
</tbody>
</table>
</details>
</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.4

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] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] ggpubr_0.1.6       magrittr_1.5       cowplot_0.9.2     
 [4] scales_0.5.0       RColorBrewer_1.1-2 gridExtra_2.3     
 [7] ggplot2_2.2.1      reshape2_1.4.3     qvalue_2.10.0     
[10] locfdr_1.1-8       ashr_2.2-2         Rmosek_8.0.69     
[13] CVXR_0.95          REBayes_1.2        Matrix_1.2-12     
[16] SQUAREM_2017.10-1  EQL_1.0-0          ttutils_1.0-1     
[19] PolynomF_1.0-1    

loaded via a namespace (and not attached):
 [1] purrr_0.2.4       splines_3.4.3     lattice_0.20-35  
 [4] colorspace_1.3-2  htmltools_0.3.6   yaml_2.1.18      
 [7] gmp_0.5-13.1      rlang_0.1.6       R.oo_1.21.0      
[10] pillar_1.0.1      glue_1.2.0        Rmpfr_0.6-1      
[13] R.utils_2.6.0     bit64_0.9-7       bindrcpp_0.2     
[16] bindr_0.1         scs_1.1-1         foreach_1.4.4    
[19] plyr_1.8.4        stringr_1.3.0     munsell_0.4.3    
[22] gtable_0.2.0      workflowr_1.0.1   R.methodsS3_1.7.1
[25] codetools_0.2-15  evaluate_0.10.1   labeling_0.3     
[28] knitr_1.20        doParallel_1.0.11 pscl_1.5.2       
[31] parallel_3.4.3    Rcpp_0.12.16      backports_1.1.2  
[34] truncnorm_1.0-7   bit_1.1-12        digest_0.6.15    
[37] stringi_1.1.6     dplyr_0.7.4       rprojroot_1.3-2  
[40] ECOSolveR_0.4     tools_3.4.3       lazyeval_0.2.1   
[43] tibble_1.4.1      pkgconfig_2.0.1   whisker_0.3-2    
[46] MASS_7.3-47       assertthat_0.2.0  rmarkdown_1.9    
[49] iterators_1.0.9   R6_2.2.2          git2r_0.21.0     
[52] compiler_3.4.3   </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>