• Simulation of data
  • Run susie

Last updated: 2020-05-28

Checks: 6 1

Knit directory: causal-TWAS/

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


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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(20191103) 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 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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    .ipynb_checkpoints/
    Ignored:    code/.ipynb_checkpoints/
    Ignored:    data/

Untracked files:
    Untracked:  analysis/simulation-simpleveb-boost2-ukbchr22.Rmd
    Untracked:  analysis/simulation_simpleveb-boost2.Rmd
    Untracked:  analysis/simulation_susie.Rmd
    Untracked:  code/run_test_mr.ash2s.R
    Untracked:  code/run_test_susie.R

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   analysis/simulation_simpleveb-boost.Rmd
    Modified:   code/mr.ash2.R
    Modified:   code/run_test_mr.ash2.R
    Modified:   code/workflow-ashtest.ipynb

Staged changes:
    Renamed1:   code/simple_vebboost.R
    Renamed2:   code/mr.ash2.R
    Renamed1:   code/run_test_veb-boost.R
    Renamed2:   code/run_test_mr.ash2.R

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.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


Simulation of data

20 blocks:

  • Each block has either gene or SNP effect
  • Each block has 99 SNPs and 1 gene. Each gene is linear sum of the previous 3 SNPs.
  • Each block, either the gene or the last eQTL has non-zero effect on trait

The first 4 blocks have gene effect.

set.seed(1)
N <- 4000
nblocks <- 20
block.size <- 100
p <- nblocks * block.size
n.eQTL <- 3  # number of eQTLs per gene
sigma.eQTL <- 0.5 # eQTL effect size
sigma.SNP <- 0.1 # effect size of causal SNP on trait
sigma.gene <- 0.1 # effect size of causal gene on trait
X <- matrix(rep(0,0), nrow=N, ncol=0)
gamma.gene <- rep(0, nblocks) # indicator of genes
gamma.gene[1:4] <- 1 
beta <- numeric(0)
SNP.idx <- numeric(0)
for (i in 1:nblocks) {
  # sample SNP data
  X.block.SNP <- matrix(rnorm(N*(block.size-1)), nrow=N, ncol=block.size-1)
  SNP.idx <- c(SNP.idx, 1:(block.size-1) + (i-1)*block.size)
  
  # generate gene data: use the previous few SNPs as eQTL
  effects.eQTL <- rnorm(n.eQTL, 0, sigma.eQTL)
  X.block.gene <- X.block.SNP[, (block.size - n.eQTL):(block.size - 1)] %*% effects.eQTL
  X.block = cbind(X.block.SNP, X.block.gene)
  X <- cbind(X, X.block)
  
  # sample beta
  if (gamma.gene[i] == 1) { # gene effect in this block
    beta.SNP <- rep(0, block.size - 1)
    beta.gene <- rnorm(1, 0, sigma.gene)
  } else { # SNP effect in this block
    beta.SNP <- c(rep(0, block.size - 2), rnorm(1, 0, sigma.SNP))
    beta.gene <- 0
  }
  beta.block <- c(beta.SNP, beta.gene)
  beta <- c(beta, beta.block)
}
sigma.e <- 1
y <- X %*% beta + rnorm(N, 0, sigma.e)
gene.idx <- (1:nblocks) * block.size
plot_pip <- function(indi, pip, pipcut = 0.1) {
  x <- barplot(indi, main = "PIP")
  points(x, pip, pch=19, col="red")
  pred <- which(pip > pipcut)
  real <- which(indi==1)
  tp <- length(intersect(pred, real))/length(pred)
  fp <- 1 - tp
  fn <- length(setdiff(real, pred))/length(real)
  cat("false positive rate: ", fp, "\n")
  cat("false negative rate: ", fn, "\n")
}

Run susie

Fix prior as given, using truth.

p.snp <- length(SNP.idx)
p.gene <- length(gene.idx)

prior.SNP <- 16/2000
prior.gene <- 4/20
indi.gene <- c(rep(1,4), rep(0,16))

prior <- rep(0, dim(X)[2])
prior[gene.idx] <- prior.gene
prior[SNP.idx] <- prior.SNP

res <- susie(X,y,L=1, prior_weights=prior)

print("for gene effect: ")
[1] "for gene effect: "
plot_pip(indi.gene, res$pip[gene.idx])

false positive rate:  0 
false negative rate:  0.75 

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Scientific Linux 7.4 (Nitrogen)

Matrix products: default
BLAS/LAPACK: /software/openblas-0.2.19-el7-x86_64/lib/libopenblas_haswellp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [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] susieR_0.9.0

loaded via a namespace (and not attached):
 [1] workflowr_1.6.0 Rcpp_1.0.4.6    lattice_0.20-38 digest_0.6.18  
 [5] later_0.7.5     rprojroot_1.3-2 grid_3.5.1      R6_2.3.0       
 [9] backports_1.1.2 git2r_0.26.1    magrittr_1.5    evaluate_0.12  
[13] stringi_1.3.1   fs_1.3.1        promises_1.0.1  Matrix_1.2-15  
[17] rmarkdown_1.10  tools_3.5.1     stringr_1.4.0   glue_1.3.0     
[21] httpuv_1.4.5    yaml_2.2.0      compiler_3.5.1  htmltools_0.3.6
[25] knitr_1.20