Skip to content

Fix PRS-CS sigma sampling bug#459

Merged
gaow merged 1 commit intomainfrom
fix-prscs-sigma-sampling
Apr 7, 2026
Merged

Fix PRS-CS sigma sampling bug#459
gaow merged 1 commit intomainfrom
fix-prscs-sigma-sampling

Conversation

@gaow
Copy link
Copy Markdown
Contributor

@gaow gaow commented Apr 7, 2026

Summary

  • Fix incorrect sigma (residual variance) sampling in PRS-CS MCMC (src/prscs_mcmc.h line 262)
  • The bug caused the posterior variance to be off by a factor of err² vs the original PRS-CS (Ge et al., getian107/PRScs)
  • Add signal recovery unit test with realistic binomial genotype data

Bug details

The original PRS-CS samples: sigma = 1/Gamma((n+p)/2, scale=1/err) = InvGamma(a, rate=err) with mean err/(a-1).

The buggy code had: sigma = 1.0 / Gamma((n+p)/2, scale=1) / err which gives InvGamma(a, rate=1) / err with mean 1/(err*(a-1)). These differ by err².

Fix: sigma = err / Gamma((n+p)/2, scale=1) which gives err * InvGamma(a, rate=1) = InvGamma(a, rate=err). ✅

Validation

Cross-method benchmark on simulated data (n=1000, p=50, 4 causal SNPs):

Method cor(est, truth) cor(est, prs_cs) cor(est, sdpr)
PRS-CS (fixed) 0.93 -- 0.99
SDPR 0.96 0.99 --
lassosum (s=0.9) 0.81 0.91 0.87

PRS-CS stability across 5 seeds: mean cor = 0.92, sd = 0.015. Sigma estimates ~0.95 (reasonable for the simulation).

Test plan

  • PRS-CS signal recovery test with realistic genotype data
  • Cross-method agreement (PRS-CS vs SDPR vs lassosum)
  • Full devtools::test(filter="regularized_regression")

🤖 Generated with Claude Code

The sigma (residual variance) sampling had an incorrect parameterization:
  Before: sigma = 1.0 / Gamma((n+p)/2, scale=1) / err = InvGamma(a,1)/err
  After:  sigma = err / Gamma((n+p)/2, scale=1) = err * InvGamma(a,1)

The original PRS-CS (Ge et al., getian107/PRScs) samples sigma as
1/Gamma(a, scale=1/err) = InvGamma(a, rate=err), which has mean
err/(a-1). The buggy version gave mean 1/(err*(a-1)), differing by
err^2. This caused incorrect posterior variance estimation.

Also add a signal recovery test for prs_cs with realistic binomial
genotype data and verify sigma is in a reasonable range.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gaow gaow merged commit 005a01c into main Apr 7, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant