# Diagnostic for fine-mapping with summary statistics

#### Yuxin Zou

#### 2025-06-04

This vignette demonstrates the use of the diagnostic plot for assessing consistency of the summary statistics and the reference LD matrix.

The `susie_rss` assumes the LD matrix accurately estimate the correlations among SNPs from the original GWAS genotype data. Typically, the LD matrix comes from some public database of genotypes in a suitable reference population. The inaccurate LD information leads to unreliable fine-mapping result.

The diagnostic for consistency between summary statistics and refenrence LD matrix is based on the RSS model under the null with regularized LD matrix. \[ \hat{z} | R, \lambda \sim N(0, (1-\lambda)R + \lambda I), 0<\lambda<1 \] The parameter \(\lambda\) is estimated by maximum likelihood. A larger \(\lambda\) means a greater inconsistency between summary statistics and the LD matrix. The expected z score is computed for each SNP, \(E(\hat{z}_j | \hat{z}_{-j})\), and plotted against the observed z scores.

    library(susieR)
    library(curl)

## LD information from the original genotype data

We demonstrate the diagnostic plot in a simple case, the LD matrix is estimated from the original genotype data. In this case, we expect the diagnostic plot to confirm that the LD matrix is consistent with the z scores.

We use the same simulated data as in fine mapping vignette.

    data("N3finemapping")
    n = nrow(N3finemapping$X)
    b = N3finemapping$true_coef[,1]
    sumstats <- univariate_regression(N3finemapping$X, N3finemapping$Y[,1])
    z_scores <- sumstats$betahat / sumstats$sebetahat
    Rin = cor(N3finemapping$X)
    attr(Rin, "eigen") = eigen(Rin, symmetric = TRUE)
    susie_plot(z_scores, y = "z", b=b)

The estimated \(\lambda\) is

    lambda = estimate_s_rss(z_scores, Rin, n=n)
    lambda
    # [1] 6.474096e-09

The plot for the observed z scores vs the expected z scores is

    condz_in = kriging_rss(z_scores, Rin, n=n)
    condz_in$plot

Summary of SuSiE Credible Sets:

    fit <- susie_rss(z_scores, Rin, n=n, estimate_residual_variance = TRUE)
    # HINT: For estimate_residual_variance = TRUE, please check that R is the "in-sample" LD matrix; that is, the correlation matrix obtained using the exact same data matrix X that was used for the other summary statistics. Also note, when covariates are included in the univariate regressions that produced the summary statistics, also consider removing these effects from X before computing R.
    susie_plot(fit,y = "PIP", b=b)

## LD information from the reference panel

We use another simulated data where the LD matrix is estimated from a reference panel. In this example data set, there is one association signal in the simulated data (red point), and there is one SNP with mismatched reference and alternative allele between summary statistics and the reference panel (yellow point).

Note: In some versions of PLINK, these mismatches can occur when PLINK automatically flips the alleles to make the minor allele be the effect allele, leading to different allele encodings in the z scores and LD matrix. Adding the flag `--keep-allele-order` will disable this behaviour in PLINK.

    data_file <- tempfile(fileext = ".RData")
    data_url <- paste0("https://raw.githubusercontent.com/stephenslab/susieR/",
                       "master/inst/datafiles/SummaryConsistency1k.RData")
    curl_download(data_url,data_file)
    load(data_file)
    zflip = SummaryConsistency$z
    ld = SummaryConsistency$ldref
    n=10000
    b = numeric(length(zflip))
    b[SummaryConsistency$signal_id] = zflip[SummaryConsistency$signal_id]
    plot(zflip, pch = 16, col = "#767676", main = "Marginal Associations",
         xlab="SNP", ylab = "z scores")
    points(SummaryConsistency$signal_id, zflip[SummaryConsistency$signal_id], col=2, pch=16)
    points(SummaryConsistency$flip_id, zflip[SummaryConsistency$flip_id], col=7, pch=16)

Using the data with misaligned allele, SuSiE-RSS identifies a true positive CS containing the true effect SNP; and a false positive CS that incorrectly contains the mismatched SNP.

    fit = susie_rss(zflip, ld, n=n)
    susie_plot(fit, y='PIP', b=b)
    points(SummaryConsistency$flip_id, fit$pip[SummaryConsistency$flip_id], col=7, pch=16)

The estimated \(\lambda\) is

    lambda = estimate_s_rss(zflip, ld, n=n)
    lambda
    # [1] 0.005005011

In the diagnostic plot, the mismatched SNP shows the largest difference between observed and expected z-scores, and therefore appears furthest away from the diagonal.

    condz = kriging_rss(zflip, ld, n=n)
    condz$plot

After fixing the allele encoding, SuSiE-RSS identifies a single true positive CS containing the true-effect SNP, and the formerly mismatched SNP is (correctly) not included in a CS.

    z = zflip
    z[SummaryConsistency$flip_id] = -z[SummaryConsistency$flip_id]
    fit = susie_rss(z, ld, n=n)
    susie_plot(fit, y='PIP', b=b)

## Session information

Here are some details about the computing environment, including the versions of R, and the R packages, used to generate these results.

    sessionInfo()
    # R version 4.3.3 (2024-02-29)
    # Platform: aarch64-apple-darwin20 (64-bit)
    # Running under: macOS 15.4.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/Chicago
    # tzcode source: internal
    #
    # attached base packages:
    # [1] stats     graphics  grDevices utils     datasets  methods   base
    #
    # other attached packages:
    # [1] curl_5.2.1    Matrix_1.6-5  susieR_0.14.2
    #
    # loaded via a namespace (and not attached):
    #  [1] gtable_0.3.4        jsonlite_1.8.8      highr_0.10
    #  [4] dplyr_1.1.4         compiler_4.3.3      crayon_1.5.2
    #  [7] tidyselect_1.2.1    Rcpp_1.0.12         parallel_4.3.3
    # [10] jquerylib_0.1.4     scales_1.3.0        yaml_2.3.8
    # [13] fastmap_1.1.1       lattice_0.22-5      ggplot2_3.5.0
    # [16] R6_2.5.1            plyr_1.8.9          labeling_0.4.3
    # [19] generics_0.1.3      mixsqp_0.3-54       knitr_1.45
    # [22] tibble_3.2.1        RcppZiggurat_0.1.6  munsell_0.5.0
    # [25] bslib_0.6.1         pillar_1.9.0        rlang_1.1.5
    # [28] utf8_1.2.4          cachem_1.0.8        reshape_0.8.9
    # [31] xfun_0.42           sass_0.4.9          RcppParallel_5.1.10
    # [34] cli_3.6.4           withr_3.0.2         magrittr_2.0.3
    # [37] digest_0.6.34       grid_4.3.3          irlba_2.3.5.1
    # [40] lifecycle_1.0.4     vctrs_0.6.5         Rfast_2.1.0
    # [43] evaluate_1.0.3      glue_1.8.0          farver_2.1.1
    # [46] fansi_1.0.6         colorspace_2.1-0    rmarkdown_2.26
    # [49] matrixStats_1.2.0   tools_4.3.3         pkgconfig_2.0.3
    # [52] htmltools_0.5.8.1