Last updated: 2020-07-12

Checks: 7 0

Knit directory: mmbr-rss-dsc/

This reproducible R Markdown analysis was created with workflowr (version 1.6.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


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.

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.

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

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

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 44129ac. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

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:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  output/mnm_missing_output.20200527.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.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/mmbr_missing_rss_problem2.Rmd) and HTML (docs/mmbr_missing_rss_problem2.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 44129ac zouyuxin 2020-07-12 wflow_publish(“analysis/mmbr_missing_rss_problem2.Rmd”)

There are 4 causals in this dataset.

library(mmbr)
Loading required package: mashr
Loading required package: ashr
Loading required package: susieR
X = readRDS('data/tiny_data_4.rds')
simu = readRDS('data/tiny_data_4_artificial_mixture_small_missing_2.rds')
b = simu$meta$true_coef
Z = simu$sumstats$bhat/simu$sumstats$sbhat
r = X$ld
prior = simu$meta$prior[["oracle"]]
resid_Z <- simu$meta$residual_variance
xUlist = prior$xUlist
m_init = mmbr::create_mash_prior(mixture_prior = list(matrices=xUlist, weights=prior$pi), null_weight=prior$null_weight, max_mixture_len=-1)

The total PVE for each condition is

0.15 * apply(b, 2, function(x) length(which(x!=0)))
[1] 0.60 0.45 0.15 0.15 0.15 0.15

The true effects are at 8, 147, 166, 217.

b[which(rowSums(b!=0) !=0),]
             [,1]         [,2]       [,3]       [,4]       [,5]       [,6]
[1,] -0.234593409  0.000000000  0.0000000  0.0000000  0.0000000  0.0000000
[2,] -0.652308948 -0.665991501  0.0000000  0.0000000  0.0000000  0.0000000
[3,] -0.003515702 -0.003589428 -0.3950715 -0.3702209 -0.3798235 -0.4030901
[4,] -0.147390050 -0.150481615  0.0000000  0.0000000  0.0000000  0.0000000

The Z scores at causal are

Z[which(rowSums(b!=0) !=0),]
                             [,1]       [,2]       [,3]       [,4]       [,5]
chr1_169800025_G_A_b38 -15.937812  -7.992490  -3.299558  -2.729904  -3.280382
chr1_169891058_C_T_b38 -29.279157 -27.169192 -11.346239 -11.073458 -12.410052
chr1_169912320_T_A_b38 -27.712245 -26.150895 -11.247171 -11.016281 -13.044261
chr1_169935912_G_A_b38  -1.449773   1.702469   3.248451   3.218200   3.746745
                             [,6]
chr1_169800025_G_A_b38  -3.791629
chr1_169891058_C_T_b38 -12.232690
chr1_169912320_T_A_b38 -12.845825
chr1_169935912_G_A_b38   4.380738

The model with individual level is

m_init = mmbr::create_mash_prior(mixture_prior = list(matrices=xUlist, weights=prior$pi), null_weight=prior$null_weight, max_mixture_len=-1)
result0 = mmbr::msusie(X$X, simu$Y, L = 10, 
                       prior_variance=m_init, residual_variance=resid_Z, 
                       compute_objective=T, estimate_residual_variance=F,
                       estimate_prior_variance=T, estimate_prior_method='EM', 
                       precompute_covariances=T, n_thread=1, max_iter=1000)
susie_plot(result0,y='PIP',b=b)

The model using summary data is

result = mmbr::msusie_rss(Z, r, L=10, 
                          prior_variance=m_init, residual_variance=resid_Z, 
                          compute_objective=TRUE, estimate_residual_variance=F, 
                          estimate_prior_variance=T, estimate_prior_method='EM', 
                          precompute_covariances=T, n_thread=1, max_iter=1000, track_fit = T)
susie_plot(result,y='PIP',b=b)

There is only one CS containing causal, the rest 8 CSs are all false discoveries.

Change residual variance to residual correlation matrix (encourage conservative),

result.cor = mmbr::msusie_rss(Z, r, L=10, 
                          prior_variance=m_init, residual_variance=cov2cor(resid_Z), 
                          compute_objective=TRUE, estimate_residual_variance=F, 
                          estimate_prior_variance=T, estimate_prior_method='EM', 
                          precompute_covariances=T, n_thread=1, max_iter=1000, track_fit = T)
susie_plot(result.cor,y='PIP',b=b)

The elbo becomes higher (-2.377490310^{4} vs -4.742748710^{4}).

Try initialize at truth:

init_true = list()
init_true$b1 = array(0, dim = c(4,301,6))
init_true$b1[1,8,] = (b[8,]/sqrt(diag(resid_Z))) * sqrt(837)
init_true$b1[2,147,] = (b[147,]/sqrt(diag(resid_Z))) * sqrt(837)
init_true$b1[3,166,] = (b[166,]/sqrt(diag(resid_Z))) * sqrt(837)
init_true$b1[4,217,] = (b[217,]/sqrt(diag(resid_Z))) * sqrt(837)
init_true$alpha = matrix(0, 4, 301)
init_true$alpha[1,8] = 1
init_true$alpha[2,147] = 1
init_true$alpha[3,166] = 1
init_true$alpha[4,217] = 1
xUlist.true = lapply(prior$xUlist, function(U) U * nrow(X$X))
m.init.true = mmbr::create_mash_prior(mixture_prior = list(matrices=xUlist.true, weights=prior$pi), null_weight=prior$null_weight, max_mixture_len=-1)
result.init.true = msusie_rss(Z, r, L=4, s_init = init_true,
                              prior_variance=m.init.true, residual_variance=cov2cor(resid_Z), 
                              compute_objective=TRUE, estimate_residual_variance=F, 
                              estimate_prior_variance=F, estimate_prior_method='EM', 
                              precompute_covariances=T, n_thread=1, max_iter=1000,track_fit=T)
susie_plot(result.init.true, y='PIP',b=b)

The correlation between SNP 73 and causal signals are

r[73, which(rowSums(b!=0)!=0)]
chr1_169800025_G_A_b38 chr1_169891058_C_T_b38 chr1_169912320_T_A_b38 
             0.4765622             -0.3951218             -0.3980780 
chr1_169935912_G_A_b38 
             0.5379610 

L = 1:

result.1 = mmbr::msusie_rss(Z, r, L=1, 
                            prior_variance=m_init, residual_variance=resid_Z, 
                            compute_objective=TRUE, estimate_residual_variance=F, 
                            estimate_prior_variance=T, estimate_prior_method='EM', 
                            precompute_covariances=T, n_thread=1, max_iter=1000, track_fit = T)
susie_plot(result.1,y='PIP',b=b)

L = 2:

result.2 = mmbr::msusie_rss(Z, r, L=2, 
                            prior_variance=m_init, residual_variance=resid_Z, 
                            compute_objective=TRUE, estimate_residual_variance=F, 
                            estimate_prior_variance=T, estimate_prior_method='EM', 
                            precompute_covariances=T, n_thread=1, max_iter=1000, track_fit = T)
susie_plot(result.2,y='PIP',b=b)

L = 3:

result.3 = mmbr::msusie_rss(Z, r, L=3, 
                            prior_variance=m_init, residual_variance=resid_Z, 
                            compute_objective=TRUE, estimate_residual_variance=F, 
                            estimate_prior_variance=T, estimate_prior_method='EM', 
                            precompute_covariances=T, n_thread=1, max_iter=1000, track_fit = T)
susie_plot(result.3,y='PIP',b=b)

SNP 73 appears…

L = 4:

result.4 = mmbr::msusie_rss(Z, r, L=4, 
                            prior_variance=m_init, residual_variance=resid_Z, 
                            compute_objective=TRUE, estimate_residual_variance=F, 
                            estimate_prior_variance=T, estimate_prior_method='EM', 
                            precompute_covariances=T, n_thread=1, max_iter=1000, track_fit = T)
susie_plot(result.4,y='PIP',b=b)


sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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] mmbr_0.0.1.0305 susieR_0.9.1.0  mashr_0.2.40    ashr_2.2-50    
[5] workflowr_1.6.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5         compiler_3.6.3     later_1.0.0        git2r_0.26.1      
 [5] plyr_1.8.6         prettyunits_1.1.1  progress_1.2.2     tools_3.6.3       
 [9] digest_0.6.25      evaluate_0.14      lattice_0.20-41    pkgconfig_2.0.3   
[13] rlang_0.4.6        Matrix_1.2-18      yaml_2.2.1         mvtnorm_1.1-1     
[17] xfun_0.13          invgamma_1.1       stringr_1.4.0      knitr_1.28        
[21] vctrs_0.3.1        hms_0.5.3          fs_1.4.1           rprojroot_1.3-2   
[25] grid_3.6.3         glue_1.4.1         R6_2.4.1           rmarkdown_2.1     
[29] mixsqp_0.3-44      irlba_2.3.3        rmeta_3.0          magrittr_1.5      
[33] whisker_0.4        matrixStats_0.56.0 backports_1.1.6    promises_1.1.0    
[37] htmltools_0.4.0    abind_1.4-5        assertthat_0.2.1   httpuv_1.5.2      
[41] stringi_1.4.6      truncnorm_1.0-8    SQUAREM_2020.3     crayon_1.3.4