Last updated: 2022-10-03
Checks: 6 1
Knit directory: ctwas_applied/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). 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(20210726)
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 ed65346. 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:
Untracked files:
Untracked: workspace1.RData
Untracked: workspace2.RData
Untracked: workspace20.RData
Untracked: workspace3.RData
Untracked: z_snp_pos_ebi-a-GCST004131.RData
Untracked: z_snp_pos_ebi-a-GCST004132.RData
Untracked: z_snp_pos_ebi-a-GCST004133.RData
Untracked: z_snp_pos_scz-2018.RData
Untracked: z_snp_pos_ukb-a-360.RData
Untracked: z_snp_pos_ukb-d-30780_irnt.RData
Unstaged changes:
Modified: analysis/simulation_PMR_sparsity.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 repository in which changes were made to the R Markdown (analysis/simulation_PMR_sparsity.Rmd
) and HTML (docs/simulation_PMR_sparsity.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 |
---|---|---|---|---|
html | ed65346 | wesleycrouse | 2022-10-03 | PMR simulation |
Rmd | 4bc5961 | wesleycrouse | 2022-10-03 | updating silver standard for SCZ |
This code evaluates PMR under the null when horizontal pleiotropy is assumed to be sparse. In the PMR paper, the authors claim that the false false positive rate is controlled when horizontal pleiotropic effects are sparse (Supplementary Figure 6). In their main simulation, all variants have exactly the same horizontal pleotropic effect (\(\gamma = 0.001\)). In the supplement, they vary the effect size (0.0001, 0.0005, 0.001, 0.002) and assume that only fraction of variants are non-zero (10%, 30%, 50%, 100%). They provide some example code for their simulations and running PMR here. Their simulations hold effect size fixed and then reduce the number of variants to induce sparsity. This means that the PVE of pleiotropy is reduced in the sparse scenarios.
Our cTWAS simulations suggest that the false positive rate of PMR is not controlled. Our simulations assume SNP effects that are much sparser than the 10% in the PMR paper. I also think that the reduced PVE for sparse scenarios in their simulations masks potential issues with the false positive rate. To investigate, I adapted the code provided with the PMR paper to hold PVE fixed when the sparsity is changed, and allowed different numbers of non-zero pleiotropy effects. I also investigated the sparsity of the simulated eQTL effects, though it seemed to not make much difference in false positive rate.
library(PMR)
sparse_values <- c(50, 5, 1)
PVE_values <- c(0.0001, 0.001, 0.002, 0.01)
####################
results <- data.frame(sparsity=as.integer(rep(NA, length(sparse_values)*length(PVE_values))),
pve=as.integer(rep(NA, length(sparse_values)*length(PVE_values))),
gamma=as.integer(rep(NA, length(sparse_values)*length(PVE_values))),
gamma_hat=as.integer(rep(NA, length(sparse_values)*length(PVE_values))),
false_positive_rate=as.integer(rep(NA, length(sparse_values)*length(PVE_values))))
#load the scaled genenotype matrix in eQTL data (e.g. cis-SNPs of BACE1 gene from GEUVADIS data)
zx<-read.table("/home/wcrouse/PMR/PMR/example/zx.txt")
zx<-as.matrix(zx)
n1 = dim(zx)[1]
q = dim(zx)[2]
#load the scaled genenotype matrix in GWAS data (e.g. the same cis-SNPs from GERA data)
zy<-read.table("/home/wcrouse/PMR/PMR/example/zy.txt")
zy<-as.matrix(zy)
n2<-dim(zy)[1]
#number of iterations for each condition
nsims <- 1000
iter <- 0
for (n_effects_zy in sparse_values){
for (PVE_zy in PVE_values){
iter <- iter + 1
# print(iter)
#set number of genotype effects in gene expression
n_effects_zx <- q
#set PVE by genotypes for gene expression
PVE_zx <- 0.1
alpha_hat <- rep(NA, nsims)
gamma_hat <- rep(NA, nsims)
pvalue_alpha <- rep(NA, nsims)
pvalue_gamma <- rep(NA, nsims)
Gamma_all <- rep(NA, nsims)
for (i in 1:nsims){
# if (i %% 10 == 0){
# print(i)
# }
#get the simulated gene expression data
beta <- matrix(0, q, 1)
beta[sample(1:length(beta), n_effects_zx), 1] <- rnorm(n_effects_zx)
x_mean <- as.vector(zx%*%beta)
scaling_factor <- sqrt(PVE_zx)/sd(x_mean)
x_mean <- x_mean*scaling_factor
beta <- beta*scaling_factor #compute scaled beta
epsilon_x <- rnorm(n1)
epsilon_x <- epsilon_x/sd(epsilon_x)*sqrt(1-PVE_zx)
x <- as.matrix(x_mean + epsilon_x)
#get the simulated phenotype
Gamma <- rep(0, q)
Gamma[sample(1:length(Gamma), n_effects_zy)] <- 1
y_mean <- as.vector(zy%*%Gamma)
scaling_factor <- sqrt(PVE_zy)/sd(y_mean)
y_mean <- y_mean*scaling_factor
Gamma <- Gamma*scaling_factor #compute scaled gamma
Gamma_all[i] <- unique(Gamma[Gamma!=0]) #store scaled gamma
squaresigma_y <- 1-PVE_zy
epsilon_y <- rnorm(n2)
epsilon_y <- epsilon_y/sd(epsilon_y)*sqrt(1-PVE_zy)
y <- as.matrix(y_mean + epsilon_y)
#run the PMR model using PMR_individual function
yin=as.vector(x)
zin=as.vector(y)
x1in=zx
x2in=zy
result<-PMR_individual(yin, zin, x1in, x2in, method = "PMR_individual_Egger", max_iterin = 1000, epsin = 1e-05, Heritability_geneexpression_threshold = 1e-04)
#get the estimate of the causal effect
alpha_hat[i] <- result$causal_effect
#get the estimate of the pleiotropy effect
gamma_hat[i] <- result$pleiotropy_effect
#get the pvalue for the causal test
pvalue_alpha[i] <- result$causal_pvalue
#get the pvalue for the pleiotropy effect
pvalue_gamma[i] <- result$pleiotropy_pvalue
}
results[iter,] <- c(n_effects_zy,
PVE_zy,
mean(Gamma_all),
mean(gamma_hat),
mean(pvalue_alpha<0.05, na.rm=T))
}
}
## The estimate of gene expression heritability explained by cis-SNPs is smaller than the threshold #### The pvalue of the causal effect test was assigned to be NA ##
results
sparsity pve gamma gamma_hat false_positive_rate
1 50 1e-04 0.0004361192 0.0004448700 0.05900000
2 50 1e-03 0.0013791301 0.0013727826 0.03800000
3 50 2e-03 0.0019503845 0.0019875726 0.04900000
4 50 1e-02 0.0043611924 0.0043928085 0.03700000
5 5 1e-04 0.0035777269 0.0003369432 0.04200000
6 5 1e-03 0.0111853841 0.0010993759 0.05900000
7 5 2e-03 0.0158495040 0.0015704796 0.07000000
8 5 1e-02 0.0353808651 0.0034478772 0.22100000
9 1 1e-04 0.0100000000 0.0002255487 0.05105105
10 1 1e-03 0.0316227766 0.0006625655 0.07500000
11 1 2e-03 0.0447213595 0.0009333676 0.11100000
12 1 1e-02 0.1000000000 0.0019830030 0.42400000
The false positive rate of PMR is well controlled under the dense scenario (sparsity=50), even when PVE of pleiotropy is large. This simulation matches the Eggar model underlying PMR. Holding PVE fixed, sparsity leads to inflated false positives. This inflation can be quite pronounced when the pleiotropy effects are very sparse (sparsity=1 or 5) with high PVE (PVE=0.01). Given that our cTWAS simulations are more similar to the very sparse scenarios, it is not surprising that PMR identifies many false positives in our simulations.
sessionInfo()
R version 3.6.1 (2019-07-05)
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] PMR_1.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 whisker_0.3-2 knitr_1.23
[4] magrittr_2.0.3 workflowr_1.6.2 R6_2.5.0
[7] rlang_1.0.2 fastmap_1.1.0 fansi_0.5.0
[10] stringr_1.4.0 tools_3.6.1 xfun_0.8
[13] utf8_1.2.1 cli_3.3.0 git2r_0.26.1
[16] htmltools_0.5.2 ellipsis_0.3.2 rprojroot_2.0.2
[19] yaml_2.2.0 digest_0.6.20 tibble_3.1.7
[22] lifecycle_1.0.1 crayon_1.4.1 later_0.8.0
[25] vctrs_0.4.1 fs_1.5.2 promises_1.0.1
[28] glue_1.6.2 evaluate_0.14 rmarkdown_1.13
[31] stringi_1.4.3 compiler_3.6.1 pillar_1.7.0
[34] PDSCE_1.2.1 CompQuadForm_1.4.3 httpuv_1.5.1
[37] pkgconfig_2.0.3