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 | 84ad96a | simingz | 2019-11-25 | X tilde |
html | 84ad96a | simingz | 2019-11-25 | X tilde |
Rmd | eee8d19 | simingz | 2019-11-22 | simu20191111 |
html | eee8d19 | simingz | 2019-11-22 | simu20191111 |
Rmd | dd2b4ab | simingz | 2019-11-19 | simulate phenotype |
html | dd2b4ab | simingz | 2019-11-19 | simulate phenotype |
Rmd | 28a299b | simingz | 2019-11-17 | PVE |
html | 28a299b | simingz | 2019-11-17 | PVE |
Rmd | e5e3011 | simingz | 2019-11-11 | simulate expression |
html | e5e3011 | simingz | 2019-11-11 | simulate expression |
Rmd | dcd5252 | simingz | 2019-11-07 | simulate description |
html | dcd5252 | simingz | 2019-11-07 | simulate description |
Rmd | f7be05a | simingz | 2019-11-05 | gemma |
Use WTCCC data obtained from Peter on CRI.
We simulate expression based on the following model:
\[ 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.
We simulate phenotype 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)\). To choose proper \(\sigma_\gamma\) and \(\sigma_\theta\). We used the following formula:
\[\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_20191111/"
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)
}
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.
show_res("S1.1")
truth est est.se
sigma_gamma^2 0.4844631 0.576745 0.1373830
sigma_theta^2 0.4365506 0.206319 0.2265750
sigma_e^2 1.0000000 1.048360 0.0723783
est est.se
PVE.expr 0.1150480 0.0274049
PVE.snp 0.0527935 0.0579769
PVE.total 0.1678420 0.0574520
show_res("S1.2")
truth est est.se
sigma_gamma^2 0.7751409 1.02284 0.229406
sigma_theta^2 2.7939238 1.50579 0.393121
sigma_e^2 1.0000000 1.27095 0.128254
est est.se
PVE.expr 0.127666 0.0286335
PVE.snp 0.241090 0.0629421
PVE.total 0.368756 0.0637001
show_res("S2.1")
truth est est.se
sigma_gamma^2 0.4844631 0.423657 0.129243
sigma_theta^2 0.4365506 0.138791 0.205555
sigma_e^2 1.0000000 1.061920 0.064932
est est.se
PVE.expr 0.0877619 0.0267731
PVE.snp 0.0368805 0.0546217
PVE.total 0.1246420 0.0535243
show_res("S2.2")
truth est est.se
sigma_gamma^2 0.7751409 0.644789 0.209481
sigma_theta^2 2.7939238 1.510700 0.363672
sigma_e^2 1.0000000 1.307530 0.115167
est est.se
PVE.expr 0.0828177 0.0269061
PVE.snp 0.2489020 0.0599185
PVE.total 0.3317200 0.0588617
show_res("S3.1")
truth est est.se
sigma_gamma^2 0.4844631 0.4286100 0.1308600
sigma_theta^2 0.4365506 0.0860036 0.2247160
sigma_e^2 1.0000000 1.1093200 0.0704246
est est.se
PVE.expr 0.0865320 0.0264194
PVE.snp 0.0222729 0.0581962
PVE.total 0.1088050 0.0565770
show_res("S3.2")
truth est est.se
sigma_gamma^2 0.7751409 0.710255 0.220093
sigma_theta^2 2.7939238 1.592890 0.386914
sigma_e^2 1.0000000 1.339000 0.122368
est est.se
PVE.expr 0.0878836 0.0272333
PVE.snp 0.2528280 0.0614121
PVE.total 0.3407110 0.0602505
show_res("S4.1")
truth est est.se
sigma_gamma^2 0.4844631 0.4104640 0.1367470
sigma_theta^2 0.4365506 0.0964066 0.2334440
sigma_e^2 1.0000000 1.1115300 0.0738127
est est.se
PVE.expr 0.0828015 0.0275855
PVE.snp 0.0249469 0.0604076
PVE.total 0.1077480 0.0592509
show_res("S4.2")
truth est est.se
sigma_gamma^2 0.7751409 0.653871 0.224143
sigma_theta^2 2.7939238 1.958680 0.438850
sigma_e^2 1.0000000 1.191170 0.142630
est est.se
PVE.expr 0.0827021 0.0283498
PVE.snp 0.3177850 0.0712011
PVE.total 0.4004870 0.0717854
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