For a phenotype of interest, we have collected the marginal statistics
https://drive.google.com/file/d/119Wmw9ockQNssHel3CZ88L2GhWqvW8ZJ/view?usp=sharing
For this question, you may also assume there is no population stratification in this dataset. Both phenotype and genotype were standardized.
Implement the very basic LD score regression algorithm with a programming language of your choice (preferably Python or R) to estimate the heritability of the phenotype.
First, calculate LD score of SNP
Then, we define the SSE loss function between observed value
Therefore, we can calculate the heritability by solving the following objective function is:
Let
Then we can calculate heritability
$$\hat{h}^2 = \frac{\sum_{j=1}^M l_j \left( \tilde{\beta}j^2 - \frac{1}{N} \right)}{\sum{j=1}^M l_j^2 / M}$$