-
Notifications
You must be signed in to change notification settings - Fork 0
/
FisherVsStouffer.html
662 lines (557 loc) · 25.9 KB
/
FisherVsStouffer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="author" content="Timothy Daley" />
<meta name="date" content="2020-11-29" />
<title>Fisher vs Stouffer</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/yeti.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/anchor-sections-1.0/anchor-sections.css" rel="stylesheet" />
<script src="site_libs/anchor-sections-1.0/anchor-sections.js"></script>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<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>
<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%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
</style>
<style type="text/css">
/* padding for bootstrap navbar */
body {
padding-top: 45px;
padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar) */
.section h1 {
padding-top: 50px;
margin-top: -50px;
}
.section h2 {
padding-top: 50px;
margin-top: -50px;
}
.section h3 {
padding-top: 50px;
margin-top: -50px;
}
.section h4 {
padding-top: 50px;
margin-top: -50px;
}
.section h5 {
padding-top: 50px;
margin-top: -50px;
}
.section h6 {
padding-top: 50px;
margin-top: -50px;
}
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #ffffff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</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>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
background: white;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "";
border: none;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
.code-folding-btn { margin-bottom: 4px; }
</style>
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.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;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- 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">HOME</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="FisherVsStouffer.html">Fisher vs Stouffer</a>
</li>
<li>
<a href="twoGroupsBackground.html">2 groups</a>
</li>
<li>
<a href="empiricalFDR.html">empirical estimation of FDRs</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<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">Fisher vs Stouffer</h1>
<h4 class="author">Timothy Daley</h4>
<h4 class="date">11/29/2020</h4>
</div>
<p>The most common way to coalesce <span class="math inline">\(p\)</span>-values is Fisher’s method (<a href="https://en.wikipedia.org/wiki/Fisher%27s_method" class="uri">https://en.wikipedia.org/wiki/Fisher%27s_method</a>). The basic idea is to log transform your <span class="math inline">\(p\)</span>-values, then <span class="math inline">\(-2\)</span> times the sum is chi-square distributed. Specifically, for <span class="math inline">\(p\)</span>-values <span class="math inline">\(p_{1}, \ldots, p_{n}\)</span>, Fisher’s method calculates the combined test statistic as <span class="math display">\[
t_{\text{Fisher}} = -2 \sum_{i = 1}^{n} \log p_{i}.
\]</span> Under the null that the <span class="math inline">\(p\)</span>-values are independent uniformly distributed, the test statistic <span class="math inline">\(t_{\text{Fisher}}\)</span> will be <span class="math inline">\(\chi^{2}_{2n}\)</span> distributed. The common wisdom is that Fisher’s method tend to values low p-values, instead of consistently low <span class="math inline">\(p\)</span>-values.</p>
<p>An alternative to Fisher’s method is Stouffer’s method. The idea is to transform the <span class="math inline">\(p\)</span>-values to <span class="math inline">\(z\)</span>-scores, then compute a combined <span class="math inline">\(z\)</span>-score by averaging the individual <span class="math inline">\(z\)</span>-scores. E.g. if <span class="math inline">\(\Phi(\cdot)\)</span> is the standard normal cdf, then the test statistic is <span class="math display">\[
t_{\text{Stouffer}} = \frac{1}{\sqrt{k}} \sum_{i = 1}^{n} \Phi^{-1} (p_{i}).
\]</span> Under the null this is distributed as a negative standard normal variable (negative because <span class="math inline">\(\Phi^{-1}\)</span> of small <span class="math inline">\(p\)</span>-values will be less than zero). The prevailing wisdom is that this method values consistently small <span class="math inline">\(p\)</span>-values. To ensure that effects have the same sign, we can define <span class="math display">\[
t_{\text{Stouffer}} = \frac{1}{\sqrt{k}} \sum_{i = 1}^{n} \text{sign}(x_{i}) \Phi^{-1} (p_{i})
\]</span> as the test statistic so that effect sizes (<span class="math inline">\(x_{i}\)</span>) of the same sign are valued. This has a null distribution of standard normal.</p>
<p>I first learned about Stouffer’s method through a <a href="https://projecteuclid.org/download/pdfview_1/euclid.aos/1256303530">paper by Art Owen</a> which discusses different meta-analysis techniques. In particular, he says “In the Fisher test, if the first <span class="math inline">\(m−1\)</span> <span class="math inline">\(p\)</span>-values already yield a test statistic exceeding the <span class="math inline">\(\chi^2_{2m}\)</span> significance threshold, then the <span class="math inline">\(m\)</span>th test statistic cannot undo it. The Stouffer test is different. Any large but finite value of <span class="math inline">\(\sum_{j = 1}^{m-1} \Phi^{-1}(p_{j})\)</span> can be canceled by an opposing value of <span class="math inline">\(\Phi^{-1}(p_{m})\)</span>.” Thus indicating that Stouffer’s method will tend to pick up more small but consistent effects, and will be more robust in the presence of rare outliers. On the other hand, because Fisher’s method can be significant due to just one very small <span class="math inline">\(p\)</span>-value then it is likely not as robust to outliers. To test this let’s compare the methods in two situations: small-tailed null and long-tailed null, where the latter will simulate the presence of outlier effects. I expect that Fisher’s method will have higher false positive in the presence of long tails.</p>
<div id="simulation" class="section level1">
<h1>Simulation</h1>
<p>The simulation I’ll run is the standard 2-groups model (e.g. see <a href="https://projecteuclid.org/download/pdfview_1/euclid.ss/1215441276">Efron 2008</a>). For aggregation purposes, we’ll have 5 effect sizes (I’m leaving effect size undefined on purpose) to merge. In the motivating application, the individual effect sizes and <span class="math inline">\(p\)</span>-values arise from differential expression analysis of guide RNAs, with aggregation done at the gene level (as guide RNAs target specific genes). Consistent effects are not guaranteed because of variable guide efficiency (e.g. see <a href="https://link.springer.com/article/10.1186/s13059-018-1538-6">my previous paper on this topic</a>).</p>
<pre class="r"><code>library(reticulate)
# you need to edit RETICULATE_PYTHON in .Renviron
# for some reason I need to make a venv for each project
Sys.setenv(RETICULATE_PYTHON = "/Users/tim.daley/blog/FisherVsStouffer/venv/bin/python3")
use_python('/Users/tim.daley/blog/FisherVsStouffer/venv/bin/python3')
#reticulate::py_config()</code></pre>
<pre class="python"><code>import numpy as np
# set seed
np.random.seed(12345)
n_genes = 20000
# 2% of genes are non-null
p = 0.05
gene_labels = np.random.binomial(n = 1, p = p, size = (n_genes, ))
print("number of genes: ", n_genes)</code></pre>
<pre><code>## number of genes: 20000</code></pre>
<pre class="python"><code>print("number of non-null genes: ", sum(gene_labels))</code></pre>
<pre><code>## number of non-null genes: 1029</code></pre>
<div id="small-tail" class="section level2">
<h2>Small tail</h2>
<p>For the small-tailed case, let’s assume that null gene-effects are equal to <span class="math inline">\(0\)</span> and the non-null gene effects are distributed <span class="math inline">\(\mathcal{N}(3, 1)\)</span>.</p>
<pre class="python"><code>import seaborn
gene_effects = gene_labels*np.random.normal(loc = 3, scale = 1, size = (n_genes, ))
seaborn.histplot(gene_effects, color = 'black')</code></pre>
<p><img src="FisherVsStouffer_files/figure-html/unnamed-chunk-2-1.png" width="672" /></p>
<p>You can see the long tail on the right is the gene effects. Now let’s assume 5 observations (guide RNAs) per gene. These are gonna be normally distributed with mean equal to gene effect size, and standard deviation 1.</p>
<pre class="python"><code>import itertools
import pandas as pd
lst = range(n_genes)
guide2gene_map = list(itertools.chain.from_iterable(itertools.repeat(x, 5) for x in lst))
n_guides = 5*n_genes
assert(len(guide2gene_map) == n_guides)
guide_effects = pd.DataFrame({'guide2gene': guide2gene_map})
guide_effects['guide_effect'] = guide_effects['guide2gene'].map(lambda i: np.random.normal(loc = gene_effects[i], scale = 1))
guide_effects['label'] = guide_effects['guide2gene'].map(lambda i: gene_labels[i])
seaborn.histplot(x = 'guide_effect', hue = 'label', data = guide_effects).set_title('guide effect distribution')</code></pre>
<p><img src="FisherVsStouffer_files/figure-html/unnamed-chunk-3-1.png" width="672" /></p>
<p>Now let’s look at combining <span class="math inline">\(p\)</span>-values with Fisher vs Stouffer.</p>
<pre class="python"><code>from scipy.stats import norm, chi2
from math import sqrt
def stouffer_pval(z):
stouffer_zval = sum(z)/sqrt(len(z))
stouffer_pval = norm.cdf(-stouffer_zval)
return stouffer_pval
def fisher_pval(z):
# 1-sided p-val
pvals = norm.cdf(-z)
fisher_val = -2*sum(np.log(pvals))
fisher_pval = 1.0 - chi2.cdf(fisher_val, df = 2*len(z))
return fisher_pval
gene_pvals = pd.DataFrame({'gene': range(n_genes),
'gene_label': gene_labels})
gene_pvals['fisher'] = gene_pvals['gene'].map(lambda i: fisher_pval(guide_effects[guide_effects['guide2gene'] == gene_pvals['gene'][i]]['guide_effect']))
gene_pvals['stouffer'] = gene_pvals['gene'].map(lambda i: stouffer_pval(guide_effects[guide_effects['guide2gene'] == gene_pvals['gene'][i]]['guide_effect']))
gene_pvals.head()</code></pre>
<pre><code>## gene gene_label fisher stouffer
## 0 0 0 0.620273 0.508737
## 1 1 0 0.873517 0.868306
## 2 2 0 0.509792 0.379961
## 3 3 0 0.372420 0.446334
## 4 4 0 0.398732 0.542383</code></pre>
<pre class="python"><code>import matplotlib.pyplot as plt
seaborn.histplot(gene_pvals['fisher'], bins = 30, color = 'black', label = 'Fisher p-vals')
plt.show()</code></pre>
<p><img src="FisherVsStouffer_files/figure-html/unnamed-chunk-5-1.png" width="672" /></p>
<pre class="python"><code>seaborn.histplot(gene_pvals['stouffer'], bins = 30, color = 'black', label = 'Stouffer p-vals')
plt.show()</code></pre>
<p><img src="FisherVsStouffer_files/figure-html/unnamed-chunk-5-2.png" width="672" /></p>
<p>Now let’s compute Benjamini-Hochberg FDRs and compare them to the empirical FDR.</p>
<pre class="python"><code>from statsmodels.stats.multitest import fdrcorrection
_, gene_pvals['fisher_fdr'] = fdrcorrection(gene_pvals['fisher'], method = 'indep')
_, gene_pvals['stouffer_fdr'] = fdrcorrection(gene_pvals['stouffer'], method = 'indep')
gene_pvals.head()</code></pre>
<pre><code>## gene gene_label fisher stouffer fisher_fdr stouffer_fdr
## 0 0 0 0.620273 0.508737 0.970138 0.953773
## 1 1 0 0.873517 0.868306 0.990323 0.991374
## 2 2 0 0.509792 0.379961 0.956906 0.921007
## 3 3 0 0.372420 0.446334 0.920225 0.940338
## 4 4 0 0.398732 0.542383 0.926149 0.956265</code></pre>
<p>Now let’s compute the empirical FDRs.</p>
<pre class="python"><code>def compute_empirical_fdr(labels, fdrs, fdr_thresh):
mask = (fdrs < fdr_thresh)
R = np.sum(mask)
if R > 0:
return np.sum(1 - labels[mask])/float(R)
else:
return 0
empirical_fdr = pd.DataFrame({'fdr_thresh': np.linspace(0, 1, num = 1000)})
empirical_fdr['fisher'] = empirical_fdr['fdr_thresh'].map(lambda x: compute_empirical_fdr(gene_pvals['gene_label'], gene_pvals['fisher_fdr'], x))
empirical_fdr['stouffer'] = empirical_fdr['fdr_thresh'].map(lambda x: compute_empirical_fdr(gene_pvals['gene_label'], gene_pvals['stouffer_fdr'], x))
empirical_fdr.head()</code></pre>
<pre><code>## fdr_thresh fisher stouffer
## 0 0.000000 0.000000 0.000000
## 1 0.001001 0.001147 0.001121
## 2 0.002002 0.002227 0.003293
## 3 0.003003 0.004410 0.004362
## 4 0.004004 0.007650 0.007559</code></pre>
<pre class="python"><code>empirical_fdr.tail()</code></pre>
<pre><code>## fdr_thresh fisher stouffer
## 995 0.995996 0.945746 0.945044
## 996 0.996997 0.946220 0.945427
## 997 0.997998 0.948362 0.947968
## 998 0.998999 0.948434 0.948398
## 999 1.000000 0.948550 0.948550</code></pre>
<pre class="python"><code>df = pd.DataFrame({'estimated_fdr': empirical_fdr['fdr_thresh'].tolist() + empirical_fdr['fdr_thresh'].tolist(),
'empirical_fdr': empirical_fdr['fisher'].tolist() + empirical_fdr['stouffer'].tolist(),
'condition': ['fisher']*empirical_fdr.shape[0] + ['stouffer']*empirical_fdr.shape[0]})
plt.plot([0, 1], [0, 1], '--', color = 'black')</code></pre>
<pre><code>## [<matplotlib.lines.Line2D object at 0x7ffd20a440d0>]</code></pre>
<pre class="python"><code>seaborn.lineplot(x = 'estimated_fdr', y = 'empirical_fdr', hue = 'condition', data = df)</code></pre>
<pre><code>## <AxesSubplot:xlabel='estimated_fdr', ylabel='empirical_fdr'></code></pre>
<pre class="python"><code>plt.show()</code></pre>
<p><img src="FisherVsStouffer_files/figure-html/unnamed-chunk-9-1.png" width="672" /></p>
</div>
<div id="long-tail" class="section level2">
<h2>Long tail</h2>
<p>Now what happens if the null is a long-tailed distribution? We’ll use a t-distribution with a finite variance as the long tailed, and we’ll normalize it so that the standard deviation is equal to 1.</p>
<pre class="python"><code>import pandas as pd
from math import sqrt
long_tailed_guide_effects = pd.DataFrame({'guide2gene': guide2gene_map})
deg_fred = 5
sd = sqrt(deg_fred/float(deg_fred - 2))
# divide by sd to normalize
long_tailed_guide_effects['guide_effect'] = long_tailed_guide_effects['guide2gene'].map(lambda i: gene_effects[i] + np.random.standard_t(df = deg_fred)/sd)
long_tailed_guide_effects['label'] = long_tailed_guide_effects['guide2gene'].map(lambda i: gene_labels[i])
seaborn.histplot(x = 'guide_effect', hue = 'label', data = long_tailed_guide_effects)</code></pre>
<pre><code>## <AxesSubplot:xlabel='guide_effect', ylabel='Count'></code></pre>
<pre class="python"><code>plt.show()</code></pre>
<p><img src="FisherVsStouffer_files/figure-html/unnamed-chunk-10-1.png" width="672" /></p>
<pre class="python"><code>long_tailed_gene_pvals = pd.DataFrame({'gene': range(n_genes),
'gene_label': gene_labels})
long_tailed_gene_pvals['fisher'] = long_tailed_gene_pvals['gene'].map(lambda i: fisher_pval(long_tailed_guide_effects[long_tailed_guide_effects['guide2gene'] == long_tailed_gene_pvals['gene'][i]]['guide_effect']))
long_tailed_gene_pvals['stouffer'] = long_tailed_gene_pvals['gene'].map(lambda i: stouffer_pval(long_tailed_guide_effects[long_tailed_guide_effects['guide2gene'] == long_tailed_gene_pvals['gene'][i]]['guide_effect']))
_, long_tailed_gene_pvals['fisher_fdr'] = fdrcorrection(long_tailed_gene_pvals['fisher'], method = 'indep')
_, long_tailed_gene_pvals['stouffer_fdr'] = fdrcorrection(long_tailed_gene_pvals['stouffer'], method = 'indep')
long_tailed_empirical_fdr = pd.DataFrame({'fdr_thresh': np.linspace(0, 1, num = 1000)})
long_tailed_empirical_fdr['fisher'] = long_tailed_empirical_fdr['fdr_thresh'].map(lambda x: compute_empirical_fdr(long_tailed_gene_pvals['gene_label'], long_tailed_gene_pvals['fisher_fdr'], x))
long_tailed_empirical_fdr['stouffer'] = long_tailed_empirical_fdr['fdr_thresh'].map(lambda x: compute_empirical_fdr(long_tailed_gene_pvals['gene_label'], long_tailed_gene_pvals['stouffer_fdr'], x))
df = pd.DataFrame({'estimated_fdr': long_tailed_empirical_fdr['fdr_thresh'].tolist() + long_tailed_empirical_fdr['fdr_thresh'].tolist(),
'empirical_fdr': long_tailed_empirical_fdr['fisher'].tolist() + long_tailed_empirical_fdr['stouffer'].tolist(),
'condition': ['fisher']*long_tailed_empirical_fdr.shape[0] + ['stouffer']*long_tailed_empirical_fdr.shape[0]})</code></pre>
<pre class="python"><code>plt.plot([0, 1], [0, 1], '--', color = 'black')</code></pre>
<pre><code>## [<matplotlib.lines.Line2D object at 0x7ffd1083e070>]</code></pre>
<pre class="python"><code>seaborn.lineplot(x = 'estimated_fdr', y = 'empirical_fdr', hue = 'condition', data = df)</code></pre>
<pre><code>## <AxesSubplot:xlabel='estimated_fdr', ylabel='empirical_fdr'></code></pre>
<pre class="python"><code>plt.show()</code></pre>
<p><img src="FisherVsStouffer_files/figure-html/unnamed-chunk-12-1.png" width="672" /></p>
<p>We see here that Fisher’s method has a higher false positive rate, particularly in the lower region where we usually set the false discovery rate. This inidicates that Fisher’s method is much more susceptible to false positives in the presence of long tails. If we correctly specify the null model, then this will be less of an issue, but we saw above that both methods perform similarly when the model is correctly specified. Therefore, this simple experiment indicates that there can be significant benefits to using Stouffer’s method in place of Fisher’s method, particularly when long-tailed or off-target effects can be present in the null distribution and are difficult to accurately model.</p>
</div>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open')
});
});
</script>
<!-- code folding -->
<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, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = true;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</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>