Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

PCA and ancestry-model starter code

This notebook gives the R functions that runs on a small example.

Download the R notebook (.ipynb). Open it in JupyterLab with an R kernel and run the cells in order.

Main functions

prepare_pca() centers each SNP count and divides by the Hardy–Weinberg standard deviation 2p(1−p)\sqrt{2p(1-p)}. fit_ancestry() fits the allele-draw likelihood by an EM algorithm. Read the code before applying it to new data. In particular, check which quantities the functions estimate from the sample.

Plot with title “Ancestry model, K = 2”

Credits

The five-population teaching question follows Hellenthal, Handbook of Statistical Genomics (2019), Figures 8.2–8.3, which adapt the simulation in Lawson et al. (2012). The homework genotype matrix is a new course simulation, not the published matrix. For the allele-draw model, see Pritchard, An Owner’s Guide to the Human Genome, Chapter 3.1.

References
  1. Lawson, D. J., Hellenthal, G., Myers, S., & Falush, D. (2012). Inference of Population Structure using Dense Haplotype Data. PLoS Genetics, 8(1), e1002453. 10.1371/journal.pgen.1002453