modified: Sat Jan 20 08:18:27 2018 compiled: Tue Oct 29 21:52:28 2019

1 Introduction

bacon can be used to remove inflation and bias often observed in epigenome- and transcriptome-wide association studies (Iterson, Zwet, and Heijmans 2017).

To this end bacon constructs an empirical null distribution using a Gibbs Sampling algorithm by fitting a three-component normal mixture on z-scores. One component is forced, using prior knowledge, to represent the null distribution with mean and standard deviation representing the bias and inflation. The other two components are necessary to capture the amount of true associations present in the data, which we assume unknown but small.

bacon provides functionality to inspect the output of the Gibbs Sampling algorithm, i.e., plots of traces, posterior distributions and the mixture fit, are provided. Furthermore, inflation- and bias-corrected test-statistics or P-values are extracted easily. In addition, functionality for performing fixed-effect meta-analysis are provided as well.

The function bacon requires a vector or a matrix of z-scores, e.g., those extracted from association analyses using a linear regression approach. For fixed-effect meta-analysis a matrix of effect-sizes and standard-errors is required.

This vignette illustrates the use of bacon using simulated z-scores, effect-sizes and standard errors to avoid long run-times. If multiple sets of test-statisics or effect-sizes and standard-errors are provided, the Gibbs Sampler algorithm can be executed in parallel to reduce computation time using functionality provide by BiocParallel-package.

2 A single set of test-statistics

A vector containing \(5000\) z-scores is generated from a normal mixture distribution, \(90\%\) of the z-scores were drawn from a biased and inflated null distribution, \(\mathcal{N}(0.2, 1.3)\), and the remaining z-scores from \(\mathcal{N}(\mu, 1)\), where \(\mu \sim \mathcal{N}(4, 1)\). The rnormmix-function provided by Bacon generates a vector of random test-statistics described above optionally with different parameters.

y <- rnormmix(5000, c(0.9, 0.2, 1.3, 1, 4, 1))

The function bacon executes the Gibbs Sampler algorithm and stores all in- and out-put in an object of class Bacon. Several accessor-functions are available to access data contained in the Bacon-object, e.g. for obtaining the estimated parameters of the mixture fit or explicitly the bias and inflation. Actually, the latter two are the mean and standard deviation of the null component (mu.0 and sigma.0).

bc <- bacon(y)
bc
## Bacon-object containing 1 set(s) of 5000 test-statistics.
## ...estimated bias: 0.14.
## ...estimated inflation: 1.3.
## 
## Empirical null estimates are based on 5000 iterations with a burnin-period of 2000.
estimates(bc)
##        p.0    p.1    p.2  mu.0 mu.1  mu.2 sigma.0 sigma.1 sigma.2
## [1,] 0.902 0.0672 0.0305 0.136  3.1 -3.02    1.31    2.89    2.33
inflation(bc)
## sigma.0 
##    1.31
bias(bc)
##  mu.0 
## 0.136

Several methods are provided to inspect the output of the Gibbs Sampler algorithm, such as traces-plots of all estimates, plots of posterior distributions, provide as a scatter plot between two parameters, and the actual fit of the three component mixture to the histogram of z-scores.

traces(bc, burnin=FALSE)
Plot of Gibbs Sampling traces. Each panel represent of one the estimated parameters. Default plot shows the burin-in period as well.

Figure 1: Plot of Gibbs Sampling traces
Each panel represent of one the estimated parameters. Default plot shows the burin-in period as well.

posteriors(bc)
Gibbs Sampling posterior distributions of two estimated parameters the inflation (sigma 0) and proportion of null features (pi0 0). Posterior plots of the other parameters can be generated by using the `thetas` argument. The ellipical curves corresponding to a 75%, 90% and 95% probability regions for a bivariate normal distribution with mean and covariance estimated form the scatter-plot.

Figure 2: Gibbs Sampling posterior distributions of two estimated parameters the inflation (sigma 0) and proportion of null features (pi0 0)
Posterior plots of the other parameters can be generated by using the thetas argument. The ellipical curves corresponding to a 75%, 90% and 95% probability regions for a bivariate normal distribution with mean and covariance estimated form the scatter-plot.

fit(bc, n=100)
Fit to the data as estimated using the Gibbs Sampling algorithm. Black line represent to overall fit, red the fit of the null distribution and blue and green the alternatives.

Figure 3: Fit to the data as estimated using the Gibbs Sampling algorithm
Black line represent to overall fit, red the fit of the null distribution and blue and green the alternatives.

The previous three plots can be use as diagnostic tools to inspect the Gibbs sampling process.

There is also a generic plot function that can generate two types of plots; a histogram of the z-scores and a qq-plot. The histogram of the z-scores shows on top the standard normal distribution and the Gibbs Sampling estimated empirical null distribution. The quantile-quantile plot shows the \(-log_{10}\) transformed P-values. Default values are raw, not controlled for bias and inflation, z-scores and P-values.

plot(bc, type="hist")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Histogram of z-scores. With on top standard normal (black) and estimated empirical null distribution (red).

Figure 4: Histogram of z-scores
With on top standard normal (black) and estimated empirical null distribution (red).

plot(bc, type="qq")
Quantile-quantile plot of $-log_{10}$ transformed P-values. Left panel using uncorrected P-values and right panel using bacon bias and inflation corrected P-values.

Figure 5: Quantile-quantile plot of \(-log_{10}\) transformed P-values
Left panel using uncorrected P-values and right panel using bacon bias and inflation corrected P-values.

3 Multiple sets of test-statistics

Matrices containing \(5000\times6\) effect-sizes and standard errors are generated to simulated data for a fixed-effect meta-analyses. This is a toy-example just to illustrate the capabilities of bacon in handling multiple sets of test-statics.

set.seed(12345)
biases <- runif(6, -0.2, 0.2)
inflations <- runif(6, 1, 1.3)
es <- matrix(nrow=5000, ncol=6)
for(i in 1:6)
    es[,i] <- rnormmix(5000, c(0.9, biases[i], inflations[i], 0, 4, 1), shuffle=FALSE)
se <- replicate(6, 0.8*sqrt(4/rchisq(5000,df=4)))
colnames(es) <- colnames(se) <- LETTERS[1:ncol(se)]
rownames(es) <- rownames(se) <- 1:5000
head(rownames(es))
## [1] "1" "2" "3" "4" "5" "6"
head(colnames(es))
## [1] "A" "B" "C" "D" "E" "F"

By default the function bacon detects the number of cores/nodes registered, as described in the BiocParallel, to perform bacon in parallel. To run the vignette in general we set it here for convenience to 1 node.

library(BiocParallel)
register(MulticoreParam(1, log=TRUE))
bc <- bacon(NULL, es, se)
## Did you registered a biocparallel back-end?
##  Continuing serial!
bc
## Bacon-object containing 6 set(s) of 5000 test-statistics.
## ...estimated bias: 0.064,0.093,0.089,0.054,0.017,-0.075.
## ...estimated inflation: 1.2,1.3,1.3,1.3,1.1,1.1.
## 
## Empirical null estimates are based on 5000 iterations with a burnin-period of 2000.
knitr::kable(estimates(bc))
p.0 p.1 p.2 mu.0 mu.1 mu.2 sigma.0 sigma.1 sigma.2
A 0.868 0.073 0.059 0.064 2.62 -2.68 1.19 3.64 3.21
B 0.878 0.070 0.052 0.093 2.83 -2.71 1.30 3.01 3.74
C 0.855 0.079 0.066 0.089 2.66 -2.75 1.30 3.22 3.37
D 0.831 0.056 0.113 0.054 3.03 -1.09 1.33 1.51 4.58
E 0.881 0.059 0.060 0.017 2.69 -2.62 1.15 4.02 3.45
F 0.859 0.061 0.079 -0.075 2.76 -2.64 1.15 3.55 3.24
inflation(bc)
##    A    B    C    D    E    F 
## 1.19 1.30 1.30 1.33 1.15 1.15
bias(bc)
##       A       B       C       D       E       F 
##  0.0638  0.0926  0.0889  0.0542  0.0175 -0.0754
knitr::kable(tstat(bc)[1:5,])
A B C D E F
-0.669 0.608 -0.613 -0.725 0.183 -0.989
0.361 0.260 0.242 -3.217 -0.783 2.522
-0.488 -0.036 -0.134 -0.807 0.794 -0.273
0.116 -2.718 -0.910 -1.589 0.462 0.296
0.569 0.908 1.920 0.840 2.026 -1.194
knitr::kable(pval(bc)[1:5,])
A B C D E F
0.504 0.543 0.540 0.468 0.855 0.323
0.718 0.795 0.809 0.001 0.433 0.012
0.626 0.971 0.893 0.420 0.427 0.785
0.907 0.007 0.363 0.112 0.644 0.767
0.569 0.364 0.055 0.401 0.043 0.232
knitr::kable(se(bc)[1:5,])
A B C D E F
1.057 0.918 1.892 1.809 1.255 0.897
0.856 1.666 1.951 1.043 0.898 0.800
1.342 1.450 0.883 1.278 1.036 1.079
2.066 1.239 1.708 0.758 0.799 2.263
2.526 1.182 0.682 0.737 0.825 0.981
knitr::kable(es(bc)[1:5,])
A B C D E F
-0.707 0.558 -1.159 -1.311 0.229 -0.887
0.309 0.434 0.472 -3.357 -0.703 2.018
-0.654 -0.052 -0.119 -1.031 0.822 -0.295
0.241 -3.367 -1.554 -1.205 0.369 0.670
1.438 1.073 1.309 0.619 1.671 -1.171

The accessor-function return as expected matrices of estimates. For the plotting functions an additional index of the ith study or z-score is required.

traces(bc, burnin=FALSE, index=3)
Plot of Gibbs Sampling traces. Each panel represent of one the estimated parameters. Default plot shows the burin-in period as well.

Figure 6: Plot of Gibbs Sampling traces
Each panel represent of one the estimated parameters. Default plot shows the burin-in period as well.

posteriors(bc, index=3)
Gibbs Sampling posterior distributions of two estimated parameters the inflation (sigma 0) and proportion of null features (pi0 0). Posterior plots of the other parameters can be generated by using the `thetas` argument. The ellipical curves corresponding to a 75%, 90% and 95% probability regions for a bivariate normal distribution with mean and covariance estimated form the scatter-plot.

Figure 7: Gibbs Sampling posterior distributions of two estimated parameters the inflation (sigma 0) and proportion of null features (pi0 0)
Posterior plots of the other parameters can be generated by using the thetas argument. The ellipical curves corresponding to a 75%, 90% and 95% probability regions for a bivariate normal distribution with mean and covariance estimated form the scatter-plot.

fit(bc, n=100, index=3)
Fit to the data as estimated using the Gibbs Sampling algorithm. Black line represent to overall fit, red the fit of the null distribution and blue and green the alternatives.

Figure 8: Fit to the data as estimated using the Gibbs Sampling algorithm
Black line represent to overall fit, red the fit of the null distribution and blue and green the alternatives.

plot(bc, type="hist")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Histogram of z-scores. With on top standard normal (black) and estimated empirical null distribution (red).

Figure 9: Histogram of z-scores
With on top standard normal (black) and estimated empirical null distribution (red).

plot(bc, type="qq")
Quantile-quantile plot of $-log_{10}$ transformed P-values. Left panel using uncorrected P-values and right panel using bacon bias and inflation corrected P-values.

Figure 10: Quantile-quantile plot of \(-log_{10}\) transformed P-values
Left panel using uncorrected P-values and right panel using bacon bias and inflation corrected P-values.

4 Fixed-effect meta-analysis

The following code chunk shows how to perform fixed-effect meta-analysis and the inspection of results.

bcm <- meta(bc)
head(pval(bcm))
##       A       B      C      D      E      F   meta
## 1 0.504 0.54320 0.5402 0.4685 0.8550 0.3229 0.4385
## 2 0.718 0.79461 0.8088 0.0013 0.4335 0.0117 0.9659
## 3 0.626 0.97141 0.8932 0.4199 0.4272 0.7848 0.7621
## 4 0.907 0.00656 0.3630 0.1122 0.6444 0.7674 0.0621
## 5 0.569 0.36385 0.0548 0.4009 0.0427 0.2325 0.0227
## 6 0.279 0.18897 0.7681 0.5630 0.0229 0.3051 0.0111
print(topTable(bcm))
##      eff.size.meta std.err.meta pval.adj.meta pval.org.meta tstat.meta
## 4976         -5.87        0.359      2.40e-56      4.81e-60      -16.3
## 4820          4.20        0.322      2.86e-35      5.72e-39       13.1
## 4617          5.27        0.404      3.60e-35      7.19e-39       13.0
## 4520          3.89        0.321      3.32e-30      6.65e-34       12.1
## 4804          5.26        0.437      1.35e-29      2.71e-33       12.0
## 4919          4.55        0.378      1.48e-29      2.95e-33       12.0
## 4562          4.58        0.384      4.31e-29      8.61e-33       11.9
## 4918         -4.20        0.366      9.56e-27      1.91e-30      -11.5
## 4585         -3.43        0.312      2.60e-24      5.21e-28      -11.0
## 4567         -4.32        0.394      2.86e-24      5.72e-28      -11.0
##      eff.size.A std.err.A   pval.A tstat.A eff.size.B std.err.B   pval.B
## 4976    -0.6564     1.399 6.39e-01 -0.4691     -2.803     1.596 7.90e-02
## 4820     2.1481     0.805 7.61e-03  2.6689     -5.913     0.935 2.52e-10
## 4617     7.6376     0.947 7.39e-16  8.0639      1.248     0.977 2.01e-01
## 4520     0.6483     1.561 6.78e-01  0.4154      0.755     0.700 2.80e-01
## 4804     4.0387     1.029 8.69e-05  3.9246     -0.754     2.332 7.46e-01
## 4919     8.1051     0.571 9.51e-46 14.1974     -0.605     1.429 6.72e-01
## 4562     2.8171     0.848 8.90e-04  3.3231      8.665     0.608 3.75e-46
## 4918    -0.4032     1.466 7.83e-01 -0.2750     -7.779     1.047 1.09e-13
## 4585    -2.7338     0.966 4.64e-03 -2.8307      1.968     0.880 2.54e-02
## 4567     0.0709     1.886 9.70e-01  0.0376     -6.144     0.862 1.03e-12
##      tstat.B eff.size.C std.err.C   pval.C tstat.C eff.size.D std.err.D
## 4976  -1.756    -7.0714     1.339 1.27e-07 -5.2827      2.890     1.017
## 4820  -6.326    -9.1409     0.969 3.85e-21 -9.4367      1.065     2.110
## 4617   1.278    -2.2208     1.394 1.11e-01 -1.5935     -0.363     1.950
## 4520   1.079     1.3991     1.604 3.83e-01  0.8722     -0.503     0.671
## 4804  -0.323     1.7006     1.234 1.68e-01  1.3778      9.844     0.866
## 4919  -0.423     1.8061     0.850 3.35e-02  2.1257     -3.255     1.173
## 4562  14.262     5.7232     2.166 8.24e-03  2.6421      3.653     1.535
## 4918  -7.430    -1.4110     1.806 4.35e-01 -0.7813     -3.418     0.761
## 4585   2.235     5.1211     0.929 3.49e-08  5.5151      1.532     1.246
## 4567  -7.126    -0.0978     1.638 9.52e-01 -0.0597     -5.256     0.704
##        pval.D tstat.D eff.size.E std.err.E    pval.E tstat.E eff.size.F
## 4976 4.50e-03   2.841     -11.24     0.539  1.77e-96  -20.84      -2.26
## 4820 6.14e-01   0.505      10.65     0.454 1.38e-121   23.45       2.29
## 4617 8.52e-01  -0.186       5.17     0.861  1.96e-09    6.00       9.09
## 4520 4.54e-01  -0.749      10.24     0.526  2.26e-84   19.46      -0.35
## 4804 6.00e-30  11.369       5.76     0.840  7.14e-12    6.85       2.04
## 4919 5.53e-03  -2.774       5.30     1.034  2.93e-07    5.13       5.50
## 4562 1.73e-02   2.380      -4.46     1.363  1.06e-03   -3.27       2.19
## 4918 7.10e-06  -4.491      -6.21     0.636  1.59e-22   -9.76      -1.49
## 4585 2.19e-01   1.229      -7.20     0.425  2.30e-64  -16.94      -3.27
## 4567 8.49e-14  -7.463      -9.74     0.841  4.93e-31  -11.58       4.87
##      std.err.F   pval.F tstat.F
## 4976     0.728 1.91e-03   -3.10
## 4820     1.103 3.77e-02    2.08
## 4617     0.737 5.86e-35   12.34
## 4520     0.973 7.19e-01   -0.36
## 4804     1.198 8.91e-02    1.70
## 4919     1.623 7.07e-04    3.39
## 4562     0.813 7.07e-03    2.69
## 4918     0.796 6.11e-02   -1.87
## 4585     1.344 1.51e-02   -2.43
## 4567     1.001 1.15e-06    4.86
plot(bcm, type="qq")
Quantile-quantile plot of $-log_{10}$ transformed P-values for each cohort and the meta-analysis P-values. Left panel using uncorrected P-values and right panel using bacon bias and inflation corrected P-values.

Figure 11: Quantile-quantile plot of \(-log_{10}\) transformed P-values for each cohort and the meta-analysis P-values
Left panel using uncorrected P-values and right panel using bacon bias and inflation corrected P-values.

5 Session Info

Here is the output of sessionInfo() on the system on which this document was compiled:

## R version 3.6.1 (2019-07-05)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.10-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.10-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] bacon_1.14.0        ellipse_0.4.1       BiocParallel_1.20.0
## [4] ggplot2_3.2.1       BiocStyle_2.14.0   
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.2         pillar_1.4.2       compiler_3.6.1    
##  [4] BiocManager_1.30.9 highr_0.8          tools_3.6.1       
##  [7] digest_0.6.22      evaluate_0.14      tibble_2.1.3      
## [10] gtable_0.3.0       pkgconfig_2.0.3    rlang_0.4.1       
## [13] yaml_2.2.0         parallel_3.6.1     xfun_0.10         
## [16] withr_2.1.2        dplyr_0.8.3        stringr_1.4.0     
## [19] knitr_1.25         grid_3.6.1         tidyselect_0.2.5  
## [22] glue_1.3.1         R6_2.4.0           rmarkdown_1.16    
## [25] bookdown_0.14      purrr_0.3.3        magrittr_1.5      
## [28] scales_1.0.0       htmltools_0.4.0    assertthat_0.2.1  
## [31] colorspace_1.4-1   labeling_0.3       stringi_1.4.3     
## [34] lazyeval_0.2.2     munsell_0.5.0      crayon_1.3.4

References

Iterson, M. van, E. W. van Zwet, and B. T. Heijmans. 2017. “Controlling bias and inflation in epigenome- and transcriptome-wide association studies using the empirical null distribution.” Genome Biol. 18 (1):19.