Last updated: 2021-10-22
Checks: 7 0
Knit directory: Note/
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.
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(20180529)
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 086175e. 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/.Rhistory
Ignored: output/.DS_Store
Untracked files:
Untracked: analysis/Li&Stephens.Rmd
Untracked: data/locus1563.RDS
Untracked: output/MeanNonNullRRMSE.png
Untracked: output/MeanNonNullTPRFPR.png
Untracked: output/SimpleContrastNonNullRRMSE.png
Untracked: output/SimpleContrastTPRFPR.png
Unstaged changes:
Modified: analysis/LD_space.Rmd
Modified: analysis/MASHbaselineCode.Rmd
Modified: analysis/MashMedian.Rmd
Modified: analysis/bibliography.bib
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/susie_memory.Rmd
) and HTML (docs/susie_memory.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 | 086175e | zouyuxin | 2021-10-22 | wflow_publish(“analysis/susie_memory.Rmd”) |
html | 17c8ea7 | zouyuxin | 2021-10-22 | Build site. |
Rmd | 675edb3 | zouyuxin | 2021-10-22 | wflow_publish(“analysis/susie_memory.Rmd”) |
When the number of variants is large, there is a huge memory usage when summarizing the CSs. Here is an illustration.
Suppose there are 12,000 variants, and we simulate under the null. We fit the model using SuSiE-RSS. The memory usage problem is caused by the huge number of variants in the CSs. To reproduce the problem, we fit the model with fixed prior variance. In the case with estimated prior variance, the problem occurs when the estimated prior variance is small and the 95% CS contains a large number of variants.
p = 12000
n = 1000
set.seed(1)
X = matrix(rnorm(n*p), n, p)
y = rnorm(n)
ss = susieR:::univariate_regression(X,y)
z = ss$betahat/ss$sebetahat
R = cor(X)
The LD matrix takes 1.2 GB.
Model profiling for susieR 0.11.52 (the version we’ve used for a long time).
devtools::install_github('stephenslab/susieR@d0965b8da322e098d7e3f376de99d5e9684c3d3a', force=TRUE)
# restart R session
library(profvis)
profvis({
f <- susieR::susie_rss(z, R, estimate_prior_variance = FALSE)
})
I attached a screenshot from the profile.
The is_symmetric_matrix
, is.na
use a lot memory. Moreover, the mean
and median
from get_purity
use a lot memory.
The code related to mean
and median
in get_purity
are
value = abs(Xcorr[pos,pos])
mean(value,na.rm = TRUE)
median(value,na.rm = TRUE)
The value
is a symmetric matrix. We compute the mean and median for the whole matrix, which use those off-diagonal elements twice! It seems like the upper triangular of value
is enough to compute mean and median. So we change the code to the following, which uses Rcpp code from Rfast.
value = abs(Rfast::upper_tri(Xcorr[pos, pos], diag = TRUE))
sum(value,na.rm = TRUE)/sum(!is.na(value)) # mean
Rfast::med(value) # median
devtools::install_github('stephenslab/susieR@445013a0f40073973d390b6b0691f9971bf59131', force=TRUE)
# restart R session
library(profvis)
profvis({
f <- susieR::susie_rss(z, R, estimate_prior_variance = FALSE)
})
The memory usage improves a lot, but it’s still using about 17GB. Getting upper triangular matrix, median
, is_symmetric_matrix
, is.na
, abs
use large memory.
sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/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] workflowr_1.6.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.7 whisker_0.4 knitr_1.33 magrittr_2.0.1
[5] R6_2.5.1 rlang_0.4.12 fansi_0.5.0 stringr_1.4.0
[9] tools_4.1.0 xfun_0.24 utf8_1.2.2 git2r_0.28.0
[13] htmltools_0.5.1.1 ellipsis_0.3.2 rprojroot_2.0.2 yaml_2.2.1
[17] digest_0.6.28 tibble_3.1.5 lifecycle_1.0.1 crayon_1.4.1
[21] later_1.2.0 vctrs_0.3.8 promises_1.2.0.1 fs_1.5.0
[25] glue_1.4.2 evaluate_0.14 rmarkdown_2.9 stringi_1.7.3
[29] compiler_4.1.0 pillar_1.6.4 httpuv_1.6.1 pkgconfig_2.0.3