Last updated: 2018-12-13

workflowr checks: (Click a bullet for more information)
  • R Markdown file: up-to-date

    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.

  • Environment: empty

    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.

  • Seed: set.seed(1)

    The command set.seed(1) 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.

  • Session information: recorded

    Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

  • Repository version: fe6e6f8

    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.

    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 wflow_publish or wflow_git_commit). 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:
    
    Ignored files:
        Ignored:    .DS_Store
        Ignored:    .Rhistory
        Ignored:    .Rproj.user/
        Ignored:    analysis/.DS_Store
        Ignored:    analysis/.Rhistory
        Ignored:    analysis/include/.DS_Store
        Ignored:    code/.DS_Store
        Ignored:    data/.DS_Store
        Ignored:    docs/.DS_Store
        Ignored:    output/.DS_Store
        Ignored:    output/.sos/
    
    Untracked files:
        Untracked:  analysis/Classify.Rmd
        Untracked:  analysis/EstimateCorHeterR50.Rmd
        Untracked:  analysis/EstimateCorMash.Rmd
        Untracked:  analysis/EstimateCorMaxGD.Rmd
        Untracked:  analysis/EstimateCorMaxMCMash.Rmd
        Untracked:  analysis/HierarchicalFlashSim.Rmd
        Untracked:  analysis/MashLowSignalGTEx4.Rmd
        Untracked:  analysis/Mash_GTEx.Rmd
        Untracked:  analysis/MeanAsh.Rmd
        Untracked:  analysis/OutlierDetection.Rmd
        Untracked:  analysis/OutlierDetection2.Rmd
        Untracked:  analysis/OutlierDetection3.Rmd
        Untracked:  analysis/OutlierDetection4.Rmd
        Untracked:  analysis/mash_missing_row.Rmd
        Untracked:  code/GTExNullModel.R
        Untracked:  code/MashClassify.R
        Untracked:  code/MashCorResult.R
        Untracked:  code/MashCormVResult.R
        Untracked:  code/MashNULLCorResult.R
        Untracked:  code/MashSource.R
        Untracked:  code/Weight_plot.R
        Untracked:  code/addemV.R
        Untracked:  code/dsc-differentV/
        Untracked:  code/dsc-differentV_signal/
        Untracked:  code/estimate_cor.R
        Untracked:  code/generateDataV.R
        Untracked:  code/johnprocess.R
        Untracked:  code/mV.R
        Untracked:  code/sim_mean_sig.R
        Untracked:  code/summary.R
        Untracked:  data/Blischak_et_al_2015/
        Untracked:  data/scale_data.rds
        Untracked:  docs/figure/Classify.Rmd/
        Untracked:  docs/figure/OutlierDetection.Rmd/
        Untracked:  docs/figure/OutlierDetection2.Rmd/
        Untracked:  docs/figure/OutlierDetection3.Rmd/
        Untracked:  docs/figure/Test.Rmd/
        Untracked:  docs/figure/mash_missing_whole_row_5.Rmd/
        Untracked:  docs/include/
        Untracked:  output/AddEMV/
        Untracked:  output/CovED_UKBio_strong.rds
        Untracked:  output/CovED_UKBio_strong_Z.rds
        Untracked:  output/EstCorMLECompare/
        Untracked:  output/Flash_UKBio_strong.rds
        Untracked:  output/GTExNULLres/
        Untracked:  output/GTEx_2.5_nullData.rds
        Untracked:  output/GTEx_2.5_nullModel.rds
        Untracked:  output/GTEx_2.5_nullPermData.rds
        Untracked:  output/GTEx_2.5_nullPermModel.rds
        Untracked:  output/GTEx_3.5_nullData.rds
        Untracked:  output/GTEx_3.5_nullModel.rds
        Untracked:  output/GTEx_3.5_nullPermData.rds
        Untracked:  output/GTEx_3.5_nullPermModel.rds
        Untracked:  output/GTEx_3_nullData.rds
        Untracked:  output/GTEx_3_nullModel.rds
        Untracked:  output/GTEx_3_nullPermData.rds
        Untracked:  output/GTEx_3_nullPermModel.rds
        Untracked:  output/GTEx_4.5_nullData.rds
        Untracked:  output/GTEx_4.5_nullModel.rds
        Untracked:  output/GTEx_4.5_nullPermData.rds
        Untracked:  output/GTEx_4.5_nullPermModel.rds
        Untracked:  output/GTEx_4_nullData.rds
        Untracked:  output/GTEx_4_nullModel.rds
        Untracked:  output/GTEx_4_nullPermData.rds
        Untracked:  output/GTEx_4_nullPermModel.rds
        Untracked:  output/MASH.10.em2.result.rds
        Untracked:  output/MASH.10.mle.result.rds
        Untracked:  output/MashCorSim--midway/
        Untracked:  output/Mash_EE_Cov_0_plusR1.rds
        Untracked:  output/UKBio_mash_model.rds
        Untracked:  output/diff_v/
        Untracked:  output/diff_v_signal/
        Untracked:  output/dsc-mashr-est_v/
        Untracked:  output/mVIterations/
        Untracked:  output/mVMLEsubset/
        Untracked:  output/mVUlist/
        Untracked:  output/result.em.rds
    
    Unstaged changes:
        Modified:   analysis/EstimateCorMaxMVSample.Rmd
        Modified:   analysis/Mash_UKBio.Rmd
        Modified:   analysis/mash_missing_samplesize.Rmd
        Modified:   output/Flash_T2_0.rds
        Modified:   output/Flash_T2_0_mclust.rds
        Modified:   output/Mash_model_0_plusR1.rds
        Modified:   output/PresiAddVarCol.rds
    
    
    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.
Expand here to see past versions:
    File Version Author Date Message
    Rmd fe6e6f8 zouyuxin 2018-12-13 wflow_publish(“analysis/EstimateCorHeter.Rmd”)
    html 27b0d6d zouyuxin 2018-12-09 Build site.
    Rmd f33b26f zouyuxin 2018-12-09 wflow_publish(“analysis/EstimateCorHeter.Rmd”)
    html 66be60b zouyuxin 2018-12-07 Build site.
    Rmd af556c8 zouyuxin 2018-12-07 wflow_publish(“analysis/EstimateCorHeter.Rmd”)


rrmse = function(data, model){
  sqrt(mean((data$B - model$result$PosteriorMean)^2)/mean((data$B - data$Bhat)^2))
}

ROC.table = function(data, model){
  sign.test = data*model$result$PosteriorMean
  thresh.seq = seq(0, 1, by=0.005)[-1]
  m.seq = matrix(0,length(thresh.seq), 2)
  colnames(m.seq) = c('TPR', 'FPR')
  for(t in 1:length(thresh.seq)){
    m.seq[t,] = c(sum(sign.test>0 & model$result$lfsr <= thresh.seq[t])/sum(data!=0),
                  sum(data==0 & model$result$lfsr <=thresh.seq[t])/sum(data==0))
  }
  return(m.seq)
}

library(knitr)
library(kableExtra)

Common noise correlation

We simulate null data which has common noise correlation structure. We fit mash model without and with the estimated correlation structure. There are lots of false positives in the model without the correlation structure. The posterior mean is far from the truth.

library(mvtnorm)
library(mashr)
Loading required package: ashr
set.seed(1)
n = 10000; p = 5
B = matrix(0,n,p)
V = matrix(0.75, p, p); diag(V) = 1
Bhat = rmvnorm(n, sigma = V)
simdata = list(B = B, Bhat = Bhat, Shat = 1)
data = mash_set_data(Bhat, Shat=1)
U.c = cov_canonical(data)
m.ignore = mash(data, U.c, verbose = FALSE)

V.current = estimate_null_correlation(data, U.c)
m.current = V.current$mash.model

data.true = mash_update_data(data, V = V)
m.true = mash(data.true, U.c, verbose = FALSE)
ign = c(get_loglik(m.ignore), length(get_significant_results(m.ignore)))

current = c(get_loglik(m.current), length(get_significant_results(m.current)))

true = c(get_loglik(m.true), length(get_significant_results(m.true)))

tmp = rbind(ign, current, true)
row.names(tmp) = c('ignore', 'current', 'true')
colnames(tmp) = c('loglik', '# signif')
tmp %>% kable() %>% kable_styling()
loglik # signif
ignore -62970.94 2930
current -50426.33 0
true -50432.44 0

RRMSE:

tmp = c(rrmse(simdata, m.ignore), rrmse(simdata, m.current), rrmse(simdata, m.true))
barplot(tmp, names.arg = c('ignore', 'current', 'true'))

Expand here to see past versions of unnamed-chunk-5-1.png:
Version Author Date
66be60b zouyuxin 2018-12-07

Two different noise correlations

Now, we simulate data with 2 noise correlation structures. Half of the null data have no noise correlation, the other half have noise correlation.

Bhat1 = rmvnorm(n/2, sigma = diag(p))
Bhat2 = rmvnorm(n/2, sigma = V)
Bhat = rbind(Bhat1, Bhat2)
simdata = list(B = B, Bhat = Bhat, Shat = 1)

data = mash_set_data(Bhat, Shat=1)
U.c = cov_canonical(data)
m.I = mash(data, U.c, verbose = FALSE)

data.V = mash_update_data(data, V = V)
m.V = mash(data.V, U.c, verbose = FALSE)

V.current = estimate_null_correlation(data, U.c)
m.current = V.current$mash.model

Vtrue = array(0,dim=c(p,p,n))
Vtrue[,,1:(n/2)] = diag(p)
Vtrue[,,(n/2+1): n] = V
data.true = mash_update_data(data, V = Vtrue)
m.true = mash(data.true, U.c, verbose = FALSE, algorithm.version = 'R')

The estimated V is

V.current$V
          [,1]      [,2]      [,3]      [,4]      [,5]
[1,] 1.0000000 0.3866502 0.4018458 0.3783971 0.3990991
[2,] 0.3866502 1.0000000 0.3913344 0.3688566 0.3936946
[3,] 0.4018458 0.3913344 1.0000000 0.4172119 0.3878397
[4,] 0.3783971 0.3688566 0.4172119 1.0000000 0.3830625
[5,] 0.3990991 0.3936946 0.3878397 0.3830625 1.0000000
Ionly = c(get_loglik(m.I), length(get_significant_results(m.I)))

Vonly = c(get_loglik(m.V), length(get_significant_results(m.V)))

current = c(get_loglik(m.current), length(get_significant_results(m.current)))

true = c(get_loglik(m.true), length(get_significant_results(m.true)))

tmp = rbind(Ionly, Vonly, current, true)
row.names(tmp) = c('I only', 'V only', 'current', 'true')
colnames(tmp) = c('loglik', '# signif')
tmp %>% kable() %>% kable_styling()
loglik # signif
I only -67844.31 597
V only -65457.36 1904
current -65793.59 28
true -60618.07 0

RRMSE:

tmp = c(rrmse(simdata, m.I), rrmse(simdata, m.V), rrmse(simdata, m.current), rrmse(simdata, m.true))
barplot(tmp, names.arg = c('I only', 'V only', 'current', 'true'))

Expand here to see past versions of unnamed-chunk-9-1.png:
Version Author Date
66be60b zouyuxin 2018-12-07

Data with signals

set.seed(2018)
B1 = matrix(0, n/2, p)
V.1 = matrix(0,p,p); V.1[1,1] = 1
B2 = rmvnorm(n/2, sigma = V.1)
B = rbind(B1, B2)

V.random = array(0, dim=c(p,p,n))
ind = sample(1:n, n/2)
V.random[,,ind] = V
V.random[,,-ind] = diag(p)

Ehat = matrix(0, n, p)
Ehat[ind,] = rmvnorm(n/2, sigma = V)
Ehat[-ind,] = rmvnorm(n/2, sigma = diag(p))

Bhat = B + Ehat
simdata = list(B = B, Bhat=Bhat, Shat = 1)
data = mash_set_data(Bhat, Shat=1)
U.c = cov_canonical(data)
m.I = mash(data, U.c, verbose = FALSE)

data.V = mash_update_data(data, V = V)
m.V = mash(data.V, U.c, verbose = FALSE)
Warning in REBayes::KWDual(A, rep(1, k), normalize(w), control = control): estimated mixing distribution has some negative values:
               consider reducing rtol
Warning in mixIP(matrix_lik = structure(c(0.110553314193142,
0.153957533037059, : Optimization step yields mixture weights that are
either too small, or negative; weights have been corrected and renormalized
after the optimization.
V.current = estimate_null_correlation(data, U.c)
m.current = V.current$mash.model

data.true = mash_update_data(data, V = V.random)
m.true = mash(data.true, U.c, verbose = FALSE, algorithm.version = 'R')

The estimated V is

V.current$V
          [,1]      [,2]      [,3]      [,4]      [,5]
[1,] 1.0000000 0.3546903 0.3429767 0.3490963 0.3441630
[2,] 0.3546903 1.0000000 0.3990047 0.3829697 0.3814803
[3,] 0.3429767 0.3990047 1.0000000 0.3706125 0.3784724
[4,] 0.3490963 0.3829697 0.3706125 1.0000000 0.3832408
[5,] 0.3441630 0.3814803 0.3784724 0.3832408 1.0000000
Ionly = c(get_loglik(m.I), length(get_significant_results(m.I)), sum(get_significant_results(m.I) <= n/2))

Vonly = c(get_loglik(m.V), length(get_significant_results(m.V)), sum(get_significant_results(m.V) <= n/2))

current = c(get_loglik(m.current), length(get_significant_results(m.current)), sum(get_significant_results(m.current) <= n/2))

true = c(get_loglik(m.true), length(get_significant_results(m.true)), sum(get_significant_results(m.true) <= n/2))

tmp = rbind(Ionly, Vonly, current, true)
row.names(tmp) = c('I only', 'V only', 'current', 'true')
colnames(tmp) = c('loglik', '# signif', 'false positive')
tmp %>% kable() %>% kable_styling()
loglik # signif false positive
I only -70068.62 741 344
V only -68333.69 2588 999
current -68468.46 114 16
true -63908.31 340 5

RRMSE:

tmp = c(rrmse(simdata, m.I), rrmse(simdata, m.V), rrmse(simdata, m.current), rrmse(simdata, m.true))
barplot(tmp, names.arg = c('I only', 'V only', 'current', 'true'))

Expand here to see past versions of unnamed-chunk-14-1.png:
Version Author Date
66be60b zouyuxin 2018-12-07

ROC:

roc.seq = ROC.table(simdata$B, m.true)
plot(roc.seq[,'FPR'], roc.seq[,'TPR'], type='l', xlab = 'FPR', ylab='TPR',
       main=paste0(' True Pos vs False Pos'), cex=1.5, lwd = 1.5, col = 'cyan')
roc.seq = ROC.table(simdata$B, m.current)
lines(roc.seq[,'FPR'], roc.seq[,'TPR'], col='purple', lwd = 1.5)
roc.seq = ROC.table(simdata$B, m.I)
lines(roc.seq[,'FPR'], roc.seq[,'TPR'], col='red', lwd = 1.5)
roc.seq = ROC.table(simdata$B, m.V)
lines(roc.seq[,'FPR'], roc.seq[,'TPR'], col='darkolivegreen4', lwd = 1.5)
legend('bottomright', c('oracle','current', 'I only', 'V only'), col=c('cyan','purple','red','darkolivegreen4'),
           lty=c(1,1,1,1), lwd=c(1.5,1.5,1.5,1.5))

Expand here to see past versions of unnamed-chunk-15-1.png:
Version Author Date
66be60b zouyuxin 2018-12-07

Session information

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14.1

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mashr_0.2.19.0555 ashr_2.2-23       mvtnorm_1.0-8     kableExtra_0.9.0 
[5] knitr_1.20       

loaded via a namespace (and not attached):
 [1] lattice_0.20-35   Rmosek_8.0.69     colorspace_1.3-2 
 [4] htmltools_0.3.6   viridisLite_0.3.0 yaml_2.2.0       
 [7] rlang_0.3.0.1     R.oo_1.22.0       pillar_1.3.0     
[10] R.utils_2.7.0     REBayes_1.3       foreach_1.4.4    
[13] plyr_1.8.4        stringr_1.3.1     munsell_0.5.0    
[16] workflowr_1.1.1   rvest_0.3.2       R.methodsS3_1.7.1
[19] codetools_0.2-15  evaluate_0.12     doParallel_1.0.14
[22] pscl_1.5.2        parallel_3.5.1    highr_0.7        
[25] Rcpp_1.0.0        readr_1.1.1       scales_1.0.0     
[28] backports_1.1.2   rmeta_3.0         truncnorm_1.0-8  
[31] abind_1.4-5       hms_0.4.2         digest_0.6.18    
[34] stringi_1.2.4     grid_3.5.1        rprojroot_1.3-2  
[37] tools_3.5.1       magrittr_1.5      tibble_1.4.2     
[40] crayon_1.3.4      whisker_0.3-2     pkgconfig_2.0.2  
[43] MASS_7.3-50       Matrix_1.2-14     SQUAREM_2017.10-1
[46] xml2_1.2.0        assertthat_0.2.0  rmarkdown_1.10   
[49] httr_1.3.1        rstudioapi_0.8    iterators_1.0.10 
[52] R6_2.3.0          git2r_0.23.0      compiler_3.5.1   

This reproducible R Markdown analysis was created with workflowr 1.1.1