Last updated: 2026-04-29

Checks: 6 1

Knit directory: QBS-statsgen/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). 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(20231230) 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 f627c66. 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:    data/e2/
    Ignored:    output/

Untracked files:
    Untracked:  .DS_Store
    Untracked:  analysis/.DS_Store
    Untracked:  analysis/figure/

Unstaged changes:
    Modified:   analysis/e2-finemapping.Rmd
    Modified:   analysis/e2-ldsc.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/e2-finemapping.Rmd) and HTML (docs/e2-finemapping.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 f627c66 Siming 2026-04-27 Update exercise 2 content, add 2a-2c links to index
html f627c66 Siming 2026-04-27 Update exercise 2 content, add 2a-2c links to index
Rmd a29f425 simingz 2024-01-23 e2
html a29f425 simingz 2024-01-23 e2

Before the class

Install R packages susieR and Rfast (the latter speeds up credible set calculations):

install.packages("susieR")
install.packages("Rfast")

Explore the data we will use the analysis

rm(list=ls())
library(susieR)
Warning: package 'susieR' was built under R version 4.3.3
data(N3finemapping)
attach(N3finemapping)
names(N3finemapping)
[1] "X"                 "chrom"             "pos"              
[4] "true_coef"         "residual_variance" "Y"                
[7] "allele_freq"       "V"                

The genotype matrix is X, The phenotype matrix is Y.

We focus on the first trait, let

y = Y[,1]
b = true_coef[,1]
which(b != 0)
[1] 403 653 773

Let’s perform a univariate analysis

sumstats <- univariate_regression(X, y)
z_scores <- sumstats$betahat / sumstats$sebetahat
log10p <- -log10(pchisq(z_scores^2,1,lower.tail=F))
susie_plot(z_scores,y="z",b=b)
Warning! The custom fig.path you set was ignored by workflowr.

Fine mapping using individual level data

fitted <- susie(X, y, L = 10)
HINT: For an X with many columns, please consider installingthe Rfast package for more efficient credible set (CS)calculations.

By default, susie function computes 95% CS each containing one effect variable,

print(fitted$sets)
$cs
$cs$L2
[1] 653

$cs$L1
[1] 773 777

$cs$L3
 [1] 362 365 372 373 374 379 381 383 384 386 387 388 389 391 392 396 397 398 399
[20] 400 401 403 404 405 407 408 415


$purity
   min.abs.corr mean.abs.corr median.abs.corr
L2    1.0000000     1.0000000       1.0000000
L1    0.9815726     0.9815726       0.9815726
L3    0.8686309     0.9640176       0.9720711

$cs_index
[1] 2 1 3

$coverage
[1] 0.9998236 0.9988858 0.9539811

$requested_coverage
[1] 0.95

Plot Posterior Inclusion Probability

susie_plot(fitted, y="PIP", b=b, add_legend=T)
Warning! The custom fig.path you set was ignored by workflowr.

Version Author Date
a29f425 simingz 2024-01-23

Choice of prior effect size:

fitted2 = susie(X, y, L = 10, estimate_prior_variance = FALSE, scaled_prior_variance = 0.2)
HINT: For an X with many columns, please consider installingthe Rfast package for more efficient credible set (CS)calculations.
susie_plot(fitted2, y='PIP', b=b, add_legend=T)
Warning! The custom fig.path you set was ignored by workflowr.

Version Author Date
a29f425 simingz 2024-01-23
fitted2 = susie(X, y, L = 10, estimate_prior_variance = FALSE, scaled_prior_variance = 0.001)
HINT: For an X with many columns, please consider installingthe Rfast package for more efficient credible set (CS)calculations.
susie_plot(fitted2, y='PIP', b=b, add_legend=T)
Warning! The custom fig.path you set was ignored by workflowr.

Version Author Date
a29f425 simingz 2024-01-23

Fine-mapping with summary statistics via susie_rss

z-scores are provided and we can compute R from X.

R <- cor(X)
fitted_rss <- susie_rss(z_scores, R, L = 10, n = nrow(X))
HINT: For large R or large XtX, consider installing the Rfast package for better performance.
plot(fitted$pip, fitted_rss$pip, ylim=c(0,1))
Warning! The custom fig.path you set was ignored by workflowr.

Credit

Credit to Gao Wang: https://statgenetics.github.io/statgen-courses/notebooks/finemapping.html#Fine-mapping-with-summary-statistics-via-susie_rss-6


sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.6.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] susieR_0.14.2

loaded via a namespace (and not attached):
 [1] Matrix_1.6-1.1     gtable_0.3.6       jsonlite_2.0.0     dplyr_1.2.0       
 [5] compiler_4.3.2     crayon_1.5.3       promises_1.5.0     tidyselect_1.2.1  
 [9] Rcpp_1.1.1         stringr_1.6.0      git2r_0.36.2       later_1.4.8       
[13] jquerylib_0.1.4    scales_1.4.0       yaml_2.3.12        fastmap_1.2.0     
[17] lattice_0.21-9     plyr_1.8.9         ggplot2_4.0.2      R6_2.6.1          
[21] generics_0.1.4     mixsqp_0.3-54      workflowr_1.7.1    knitr_1.51        
[25] tibble_3.3.1       rprojroot_2.0.4    RColorBrewer_1.1-3 bslib_0.10.0      
[29] pillar_1.11.1      rlang_1.1.7        reshape_0.8.10     cachem_1.1.0      
[33] stringi_1.8.7      httpuv_1.6.15      xfun_0.52          S7_0.2.1          
[37] fs_1.6.6           sass_0.4.10        otel_0.2.0         cli_3.6.5         
[41] magrittr_2.0.4     digest_0.6.39      grid_4.3.2         irlba_2.3.5.1     
[45] lifecycle_1.0.5    vctrs_0.7.2        evaluate_1.0.5     glue_1.8.0        
[49] farver_2.1.2       whisker_0.4.1      rmarkdown_2.30     matrixStats_1.5.0 
[53] tools_4.3.2        pkgconfig_2.0.3    htmltools_0.5.9