Last updated: 2023-07-04

Checks: 7 0

Knit directory: komputeExamples/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0.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(20230110) 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 765c95e. 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:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    code/.DS_Store

Unstaged changes:
    Modified:   data/BC.imp.res.v16.RData
    Modified:   data/CC.imp.res.v16.RData
    Modified:   data/OF.imp.res.v16.RData

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/kompute_test_sim_v16.Rmd) and HTML (docs/kompute_test_sim_v16.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 c4571d3 statsleelab 2023-07-04 ggsave added
Rmd 35e42c0 statsleelab 2023-07-04 Figure added
html 9dd6814 statsleelab 2023-06-26 kompute input updated
html f91b920 statsleelab 2023-06-20 text updated
Rmd 289e711 statsleelab 2023-06-20 text updated
html 5dc46e5 statsleelab 2023-06-19 sim_function update
Rmd 7889859 statsleelab 2023-06-19 text
Rmd eddd34d statsleelab 2023-06-19 text
Rmd b733d33 statsleelab 2023-06-19 added

Import the necessary packages

library(MASS)
library(kompute)
library(kableExtra)

Import source functions for the analysis

source("code/svd_impute.R")
source("code/sim_function.R")

Load the phenotypic correlation matrix

Load the phenotypic correlation matrix specific to the Body Composition domain and set initial parameters

pheno.cor <- readRDS("data/BC_pheno_cor.RDS")
n.genes <- 10000 # number of genes
seed <- 05152022 # set seed

Simulations

Matrix Completion

Simulate an association Z-score matrix with 10,000 genes and 9 phenotypes at varying levels of masking and impute the masked z-scores using the Matrix Completion method

mc.res20 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.2, seed=seed)
mc.res40 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.4, seed=seed)
mc.res60 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.6, seed=seed)

KOMPUTE

Perform identical simulations as above, but impute the masked z-scores using the KOMPUTE method. Here, we include all imputed z-scores when computing the correlation coefficients between imputed and origianl z-scores

komp.res20 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.2, method="kompute", seed=seed)

KOMPute running...
# of genes: 10000
# of phenotypes: 9
# of imputed Z-scores: 18000
komp.res40 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.4, method="kompute", seed=seed)

KOMPute running...
# of genes: 10000
# of phenotypes: 9
# of imputed Z-scores: 36000
komp.res60 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.6, method="kompute", seed=seed)

KOMPute running...
# of genes: 10000
# of phenotypes: 9
# of imputed Z-scores: 54000

KOMPUTE with info > 0.8

Perform identical simulations and use the same method (KOMPUTE), however, we only utilize imputed z-scores that have an imputation information value greater than 0.8.

komp.info.res20 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.2, method="kompute", info.cutoff = 0.8, seed=seed)

KOMPute running...
# of genes: 10000
# of phenotypes: 9
# of imputed Z-scores: 18000
komp.info.res40 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.4, method="kompute", info.cutoff = 0.8, seed=seed)

KOMPute running...
# of genes: 10000
# of phenotypes: 9
# of imputed Z-scores: 36000
komp.info.res60 <- simulation(n.genes=n.genes, pheno.cor=pheno.cor, mask.prop=.6, method="kompute", info.cutoff = 0.8, seed=seed)

KOMPute running...
# of genes: 10000
# of phenotypes: 9
# of imputed Z-scores: 54000

Results: Table

Complie a table of correlation coefficients from all the simulations conducted

cor.table <- data.frame(c(mc.res20$cor, komp.res20$cor, komp.info.res20$cor),
                        c(mc.res40$cor, komp.res40$cor, komp.info.res40$cor),
                        c(mc.res60$cor, komp.res60$cor, komp.info.res60$cor))
colnames(cor.table) <- c("20% Removed", "40% Removed", "60% Removed")
rownames(cor.table) <- c("MC", "KPT", "KPT w/ info > 0.8")


cor.table %>%
  kbl(caption = "Pearson correlation coefficients between the original and imputed Z-scores") %>%
  kable_classic(full_width = F, html_font = "Cambria")
Pearson correlation coefficients between the original and imputed Z-scores
20% Removed 40% Removed 60% Removed
MC 0.789 0.656 0.486
KPT 0.879 0.816 0.700
KPT w/ info > 0.8 0.952 0.952 0.953

Results: Figure

library(gridExtra)

p1 <- mc.res20$plot
p2 <- mc.res40$plot
p3 <- mc.res60$plot
p4 <- komp.res20$plot
p5 <- komp.res40$plot
p6 <- komp.res60$plot
p7 <- komp.info.res20$plot
p8 <- komp.info.res40$plot
p9 <- komp.info.res60$plot

combined_plot <- arrangeGrob(p1, p2, p3, p4, p5, p6, p7, p8, p9, ncol = 3)

grid::grid.draw(combined_plot)

ggsave("docs/figure/figures.Rmd/kompute_test_sim_plot_v16.png", combined_plot, height=12, width=13)

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/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] gridExtra_2.3    ggplot2_3.4.1    kableExtra_1.3.4 kompute_0.1.0   
[5] MASS_7.3-58.1   

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0  xfun_0.31         bslib_0.4.0       colorspace_2.1-0 
 [5] vctrs_0.5.2       generics_0.1.3    htmltools_0.5.3   viridisLite_0.4.1
 [9] yaml_2.3.5        utf8_1.2.3        rlang_1.0.6       jquerylib_0.1.4  
[13] later_1.3.0       pillar_1.8.1      withr_2.5.0       DBI_1.1.3        
[17] glue_1.6.2        lifecycle_1.0.3   stringr_1.4.0     munsell_0.5.0    
[21] gtable_0.3.1      workflowr_1.7.0.1 ragg_1.2.2        rvest_1.0.3      
[25] evaluate_0.16     labeling_0.4.2    knitr_1.39        fastmap_1.1.0    
[29] httpuv_1.6.5      fansi_1.0.4       highr_0.9         Rcpp_1.0.10      
[33] promises_1.2.0.1  scales_1.2.1      cachem_1.0.6      webshot_0.5.4    
[37] jsonlite_1.8.0    farver_2.1.1      fs_1.5.2          systemfonts_1.0.4
[41] textshaping_0.3.6 digest_0.6.29     stringi_1.7.8     dplyr_1.0.9      
[45] rprojroot_2.0.3   grid_4.2.1        cli_3.6.0         tools_4.2.1      
[49] magrittr_2.0.3    sass_0.4.2        tibble_3.1.8      whisker_0.4      
[53] pkgconfig_2.0.3   xml2_1.3.3        assertthat_0.2.1  rmarkdown_2.14   
[57] svglite_2.1.1     httr_1.4.3        rstudioapi_0.13   R6_2.5.1         
[61] git2r_0.30.1      compiler_4.2.1