Last updated: 2020-04-04

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 file has unstaged changes. 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/

Unstaged changes:
    Modified:   analysis/simulation-WTCCC.Rmd
    Modified:   analysis/simulation-WTCCC2.Rmd

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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
Rmd f43fd46 simingz 2020-03-24 fix results display bug
html f43fd46 simingz 2020-03-24 fix results display bug
Rmd 5a4a588 simingz 2020-03-13 v1.0 simulate expression using separate data 20191127
html 5a4a588 simingz 2020-03-13 v1.0 simulate expression using separate data 20191127

Use WTCCC data obtained from Peter on CRI.

The difference between this analysis and previous run: used 500 samples from cad.RData from WTCCC to simulate expression, then train expression model using cv.glmnet. We impute expression in using bd.RData from WTCCC.

Simulation of phenotype: use the same weights as used in simulate expression using the 'cad.RData dataset, simulate phenotype according to:

\[Y = G\alpha\gamma + G\theta + \epsilon\]. For \(\alpha\), we used the same as used in simulating expression (Thus, not \(\tilde{X}\)). \(\gamma \sim N(0,\sigma_\gamma^2), \theta \sim N(0, \sigma_\theta^2), \epsilon \sim N (0,1)\).

The genotype data and other settings are the same.

Simulate expression

We simulate expression based on the following model, using 500 samples from cad in WTCCC:

\[ X = G\alpha + \xi\] For each gene, we sample \(L\) eQTLs for this gene, for eQTL \(k\), we have \[ \alpha_k \sim N(0,\sigma_\alpha^2) \] \[ \xi \sim N(0,1) \] Then we have the heritability of the gene:

\[\begin{aligned} h^2_{eQTL} &= \frac{var(G\alpha)}{var(G\alpha)+var(\xi)} \\ &= \frac{\Sigma_kvar(G_k) \alpha_k^2}{\Sigma_kvar(G_k) \alpha_k^2 + var(\xi)}\\ &= \frac{\Sigma_k\alpha_k^2}{\Sigma_k\alpha_k^2 + var(\xi)}\\ &\approx \frac{\Sigma_k\sigma_\alpha^2}{\Sigma_k\sigma_\alpha^2 + var(\xi)} \\ &=\frac{K\sigma_\alpha^2}{1+K\sigma_\alpha^2} \end{aligned}\]

Here, we use scaled genotype data, so \(var(G)=1\). We also have \(\alpha^2_k \approx E(\alpha_k^2)=var(\alpha_k^2)=\sigma_\alpha^2\). Usually, \(K\) ranges from 1 to 5, let \(\sigma_\alpha = 0.3\), then \(h^2_{eQTL}\) ranges from 0.08 to 0.31, this is consistent with gene cis-heritability in reality.

Simulate quantitative phenotype

We simulate phenotype using bd data from WTCCC following \[Y = G\alpha\gamma + G\theta + \epsilon\]. For \(\alpha\), we used the same as used in simulating expression. \(\gamma \sim N(0,\sigma_\gamma^2), \theta \sim N(0, \sigma_\theta^2), \epsilon \sim N (0,1)\).

\[\begin{align} PVE_{SNP} = &\frac{var(G\theta)}{var(G\theta) + var(\tilde{X}\gamma) + \sigma_e^2}\\ \approx &\frac{M\sigma_\theta^2}{M\sigma_\theta^2 + \Sigma_jvar(\tilde{X_j})\gamma_j^2+ \sigma_e^2}\\ \approx &\frac{M\sigma_\theta^2}{M\sigma_\theta^2 + Jvar(\tilde{X})\sigma_\gamma^2+ \sigma_e^2}\\ \end{align}\]

\[ PVE_{expr} \approx \frac{Jvar(\tilde{X})\sigma_\gamma^2}{M\sigma_\theta^2 + Jvar(\tilde{X})\sigma_\gamma^2+ \sigma_e^2}\]

Here, \(var(\tilde{X})\) is the cis-heratbility of gene expression. \(M\) and \(J\) are numbers of causal SNP and gene respectively.

Thus in order to get desired \(PVE_{SNP}\) and \(PVE_{expr}\), we set \(\sigma_\theta^2\) and \(\sigma_\gamma^2\) based on the following formula:

\[\sigma_\theta^2 = \frac{PVE_{SNP}}{M(1-PVE_{SNP} - PVE_{expr})}\] \[\sigma_\gamma^2 = \frac{PVE_{expr}}{Jvar(\tilde{X})(1-PVE_{SNP} - PVE_{expr})}\]

simudir <- "/home/simingz/causalTWAS/simulations/simulation_WTCCC_20191127/"
load("/home/simingz/causalTWAS/WTCCC/bd.toy.RData")
Gvar <- mean(apply(X,2,var))
show_res <- function(simutag){
  load(Sys.glob(paste0(simudir,simutag,"*phenotype.Rd")))
  outdf1 <- data.frame(truth = c(sigma_gamma^2*J.c, sigma_theta^2*M.c/Gvar , 1))
  row.names(outdf1) <- c("sigma_gamma^2","sigma_theta^2","sigma_e^2")
  res <- readLines(paste0(simudir, simutag, "_VC/output/", simutag, ".log.txt"))
  outdf1$est <- as.numeric(strsplit(res[24], "  ")[[1]][2:4])
  outdf1$est.se <- as.numeric(strsplit(res[25], "  ")[[1]][2:4])
  print(outdf1)
  outdf2 <- data.frame("est"= c(as.numeric(strsplit(res[20], "  ")[[1]][2:3]), as.numeric(strsplit(res[22], "=")[[1]][2])))
  row.names(outdf2) <- c("PVE.expr","PVE.snp","PVE.total")
  outdf2$est.se <- c(as.numeric(strsplit(res[21], "  ")[[1]][2:3]), as.numeric(strsplit(res[23], "=")[[1]][2]))
  print(outdf2)
}

Simulation 1: \(M\) = No. of all SNPs, \(J\) = No. all genes

We simulate quantitative phenotype under several scenarios. First we make all genes with imputed gene expression as causal genes and all SNPs as causal SNPs. This matches our polygenic version of the model.

1.1 \(PVE_{SNP} \approx 0.1\), \(PVE_{expr} \approx 0.1\)

show_res("S1.1")
                  truth         est     est.se
sigma_gamma^2 0.5451204 0.000225689 0.00021374
sigma_theta^2 0.4365506 0.872810000 0.23609300
sigma_e^2     1.0000000 1.018880000 0.07640700
                 est     est.se
PVE.expr  0.00412807 0.00390952
PVE.snp   0.21549800 0.05829160
PVE.total 0.21962600 0.05852090

1.2 \(PVE_{SNP}\approx 0.4\), \(PVE_{expr}\approx 0.1\)

show_res("S1.2")
                  truth         est      est.se
sigma_gamma^2 0.8721927 0.000321793 0.000292108
sigma_theta^2 2.7939238 2.839750000 0.427679000
sigma_e^2     1.0000000 1.153150000 0.138334000
                 est     est.se
PVE.expr  0.00370128 0.00335983
PVE.snp   0.44090200 0.06640170
PVE.total 0.44460300 0.06662640

Simulation 2: \(M\) = No. of all SNPs, \(J\) = ~10% all genes (J=2000)

2.1 \(PVE_{SNP} \approx 0.1\), \(PVE_{expr} \approx 0.1\)

show_res("S2.1")
                  truth         est      est.se
sigma_gamma^2 0.5451204 0.000111696 0.000139882
sigma_theta^2 0.4365506 0.528777000 0.208465000
sigma_e^2     1.0000000 1.060910000 0.067136400
                 est     est.se
PVE.expr  0.00216157 0.00270702
PVE.snp   0.13813100 0.05445660
PVE.total 0.14029200 0.05440400

2.2 \(PVE_{SNP} \approx 0.4\), \(PVE_{expr} \approx 0.1\)

show_res("S2.2")
                  truth         est      est.se
sigma_gamma^2 0.8721927 0.000258743 0.000278473
sigma_theta^2 2.7939238 2.144150000 0.372914000
sigma_e^2     1.0000000 1.301840000 0.120221000
                 est     est.se
PVE.expr  0.00309079 0.00332647
PVE.snp   0.34573400 0.06013060
PVE.total 0.34882500 0.06013430

Simulation 3: \(M\) = ~ 1% all SNPs (M=5000), \(J\) = No. all genes

3.1 \(PVE_{SNP} \approx 0.1\), \(PVE_{expr} \approx 0.1\)

show_res("S3.1")
                  truth         est      est.se
sigma_gamma^2 0.5451204 8.28456e-06 7.35267e-05
sigma_theta^2 0.4365506 5.06254e-01 2.20805e-01
sigma_e^2     1.0000000 1.10084e+00 7.12064e-02
                  est     est.se
PVE.expr  0.000156494 0.00138891
PVE.snp   0.129088000 0.05630220
PVE.total 0.129244000 0.05632350

3.2 \(PVE_{SNP} \approx 0.4\), \(PVE_{expr} \approx 0.1\)

show_res("S3.2")
                  truth         est      est.se
sigma_gamma^2 0.8721927 0.000185945 0.000246806
sigma_theta^2 2.7939238 2.467070000 0.407404000
sigma_e^2     1.0000000 1.227570000 0.131413000
                est     est.se
PVE.expr  0.0021904 0.00290734
PVE.snp   0.3922910 0.06478150
PVE.total 0.3944810 0.06482130

Discussion

In this analysis, we see the PVE estimation for expression is much under estimated, this is because many of the gene expression training model has low \(R^2\), especially for low heritability ones. For a polygenic model, because we are estimating the total herability explained by expression, the ones with low \(R^2\) will affect this estimation. We are moving to model with a sparse prior for expression.


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     

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