Tutorials › Statistical Genetics › Choosing K in Ancestry Clustering

Ancestry and Population Structure · Tutorial 146 of 989

Choosing K in Ancestry Clustering

Compare predictive performance, penalized likelihood and run-to-run reproducibility to choose a useful K without treating components as literal population counts.

Intermediate 10 min read

What You'll Learn

  • Define K as the number of ancestral components represented in a clustering model
  • Compare candidate K values using held-out genotype log loss
  • Calculate and interpret AIC and BIC for fitted clustering models
  • Assess whether ancestry estimates are reproducible across independent runs
  • Explain why a useful K does not establish a number of discrete populations

Why Choosing K Requires More Than One Number

In model-based ancestry clustering, \(K\) is the number of ancestral components represented by the fitted model. Choosing \(K\) means deciding how many components are useful for describing the genotype data under that model. A larger \(K\) gives the model more flexibility, so its likelihood on the data used to fit it will generally not decrease. That alone is not evidence that the larger value is preferable: added flexibility can fit noise or small, sample-specific features.

Three kinds of evidence are commonly compared: prediction of genotypes that were not used for fitting, likelihood criteria that penalize model complexity, and reproducibility across independent runs. They answer related but different questions. A defensible choice considers how they agree, whether the data and model assumptions make the comparison meaningful, and what scientific purpose the components are meant to serve.

Definition: For a candidate value of \(K\), an ancestry-clustering model represents each individual’s ancestry proportions using \(K\) components and estimates allele frequencies for those components. The selected \(K\) is a modeling choice supported by specified comparison criteria; it is not, by definition, the number of discrete biological populations.

For orientation, let \(g_{il}\) be the genotype count, 0, 1, or 2, for individual \(i\) at locus \(l\). Write \(q_{ik}\) for individual \(i\)’s proportion assigned to component \(k\), and \(f_{kl}\) for the allele frequency at locus \(l\) in component \(k\). The proportions satisfy \(q_{ik}\geq 0\) and \(\sum_{k=1}^{K}q_{ik}=1\). In a simple model, the allele probability for an individual at a locus is \(p_{il}=\sum_{k=1}^{K}q_{ik}f_{kl}\), and genotype probabilities are modeled using that probability under the model’s assumptions. The fitted likelihood summarizes how well the model represents the observed genotypes. Different software can use different likelihoods, estimation procedures, and treatment of genotype data, so comparisons should be made within a consistent analysis setup.

Cross-Validation: Predicting Genotypes Left Out of Fitting

Cross-validation assesses how well a fitted model predicts data not used to estimate it. In ancestry clustering, one common design holds out some genotype observations, fits the model using the remaining observations, and scores the held-out genotypes using their predictive probabilities. The held-out observations must not be used to estimate the parameters used for their own prediction.

A convenient score is the mean negative log predictive probability, sometimes called held-out log loss. Lower values indicate better predictive performance. If \(H\) is the set of held-out genotype observations and \(\hat{P}_{-H}(g_{il})\) is the predictive probability estimated without those observations, the score is:

$$ \text{CV loss}(K) = -\frac{1}{|H|} \sum_{(i,l)\in H} \log \hat{P}_{-H}(g_{il}\mid K) $$

For multiple folds, each observation is held out in one fold, and scores are combined across held-out observations. This score is an estimate of predictive performance on data like those held out, not a direct test of whether the model’s components correspond to real populations. The estimate is most relevant when the held-out data resemble the data on which the model will be used.

Why cross-validation estimates predictive performance: Each held-out genotype contributes a log predictive probability from a fit that did not use that genotype. Averaging these contributions estimates the expected predictive score for observations drawn from the same target setting, provided the folds and observations reflect that setting. If related or linked observations are split in a way that makes training and test data unusually similar, the estimate may be optimistic for a different target setting.

Worked Example: Comparing K Values by Cross-Validation

Suppose a hypothetical analysis uses the same genotype data and preprocessing for each candidate \(K\). Its mean held-out losses, in nats per held-out genotype, are \(0.521\) for \(K=2\), \(0.503\) for \(K=3\), \(0.501\) for \(K=4\), and \(0.512\) for \(K=5\). The estimated standard errors are \(0.006\), \(0.005\), \(0.006\), and \(0.010\), respectively.

The smallest observed loss is at \(K=4\): \(0.501\) nats per genotype. If the goal is to choose the single \(K\) with the minimum cross-validation loss, \(K=4\) is the choice. But the difference between \(K=4\) and \(K=3\) is only \(0.503-0.501=0.002\) nats per genotype.

A common parsimony heuristic is the one-standard-error rule: select the smallest \(K\) whose loss is within one standard error of the minimum. Here the threshold is \(0.501+0.006=0.507\). The loss for \(K=3\), \(0.503\), is below \(0.507\), while \(K=2\), \(0.521\), is above it. Under that heuristic, choose \(K=3\). This is a simpler choice with predictive performance close to the observed minimum; it does not establish that three populations exist.

The design of the folds matters. If the purpose is prediction at new loci, holding out loci is relevant; if the purpose is prediction for new individuals, holding out individuals may be more relevant. Linkage between nearby markers, relatives appearing in different folds, and uneven representation of groups can all affect the score. State the validation design and keep it consistent across candidate values of \(K\).

Likelihood Criteria: Fit Balanced Against Complexity

The maximized likelihood cannot by itself choose \(K\), because a more flexible model can usually achieve at least as high a likelihood on the fitted data. The Akaike information criterion (AIC) and Bayesian information criterion (BIC) penalize the maximized likelihood according to the number of fitted parameters. Smaller values are preferred within the set of models being compared.

Definition: If \(\hat{L}\) is the maximized likelihood and \(d\) is the number of free parameters estimated, then \(\mathrm{AIC}=-2\log\hat{L}+2d\). The BIC is \(\mathrm{BIC}=-2\log\hat{L}+d\log(n)\), where \(n\) is the sample size appropriate to the likelihood under the model’s sampling assumptions.

Both criteria trade fit against complexity, but they use different penalties. AIC adds \(2d\); BIC adds \(d\log(n)\). When \(n\) is sufficiently large, BIC penalizes each additional parameter more heavily. These criteria are not probabilities that a model is true, and neither guarantees that the chosen model has a literal population interpretation.

The parameter count and sample size require care in genetic data. Count only free parameters: for example, proportions constrained to sum to one do not contribute \(K\) independent parameters per individual. Also, genotype observations across linked loci may not act like independent observations. The appropriate \(n\) in BIC depends on the likelihood and its sampling assumptions; using the raw count of genotype cells without justification can give a misleading comparison. Criteria are meaningful only when likelihoods are calculated for comparable data under a consistent model.

Worked Example: AIC and BIC Can Prefer Different K Values

Consider a hypothetical simplified comparison with \(n=1000\) independent likelihood contributions. The candidate models have the following maximized log likelihoods and free parameter counts: \(K=2\), \(\log\hat{L}=-1000\), \(d=20\); \(K=3\), \(\log\hat{L}=-985\), \(d=30\); and \(K=4\), \(\log\hat{L}=-978\), \(d=40\). These are illustrative values, not a universal parameter-count formula for ancestry software.

For \(K=2\), \(\mathrm{AIC}=-2(-1000)+2(20)=2000+40=2040\). For \(K=3\), \(\mathrm{AIC}=-2(-985)+2(30)=1970+60=2030\). For \(K=4\), \(\mathrm{AIC}=-2(-978)+2(40)=1956+80=2036\). AIC is smallest at \(K=3\).

For BIC, \(\log(1000)\approx6.908\). The values are \(K=2:\ 2000+20(6.908)=2138\), \(K=3:\ 1970+30(6.908)=2177\), and \(K=4:\ 1956+40(6.908)=2232\), rounded to the nearest whole number. BIC is smallest at \(K=2\). The disagreement reflects the different complexity penalties, not an arithmetic error. It signals that the preferred \(K\) depends on the criterion and its assumptions.

Run-to-Run Stability

Many ancestry models use iterative or stochastic algorithms, so different initial values or random seeds can lead to different fitted solutions at the same \(K\). Repeating the fit helps distinguish a reproducible pattern from one that appears only under a particular run. Useful comparisons include the maximized likelihood across runs and how similar the estimated ancestry proportions are after corresponding components have been matched.

A practical comparison may summarize the average pairwise correlation of individuals’ ancestry-proportion profiles across runs, or the variation in estimated proportions for individuals of interest. Component labels can be permuted between runs without changing the fitted model, so comparisons must match corresponding components before measuring agreement. This matching is a bookkeeping step; a low raw correlation before matching need not mean that the solutions differ substantively.

Worked Example: Checking Reproducibility Across Runs

Suppose three hypothetical runs at \(K=3\) produce the following estimated proportion for one individual in a component matched across runs: \(0.61\), \(0.59\), and \(0.60\). The mean is \((0.61+0.59+0.60)/3=0.60\). The sample standard deviation is:

$$ s = \sqrt{\frac{(0.61-0.60)^2+(0.59-0.60)^2+(0.60-0.60)^2}{3-1}} = \sqrt{0.0001} = 0.010 $$

The matched component’s estimated proportion is similar across these three runs for this individual. Suppose, in addition, the mean pairwise correlation of the full ancestry-proportion profiles across the runs is \(0.98\). Those summaries suggest high reproducibility for this \(K\) in this hypothetical analysis. They do not show that \(K=3\) is uniquely correct: a different \(K\) may also give stable fits, and stability is not the same as predictive performance or biological validation.

When comparing stability across candidate values, use several runs per \(K\), the same data and settings, and consistent summaries. A stable solution can still reflect a model that is too simple, systematic sampling features, or limitations of the model. Conversely, poor stability can indicate that the data do not strongly distinguish alternative fits at that \(K\), rather than proving that the value should never be used.

What K Does—and Does Not—Mean

A selected \(K\) describes the resolution at which a particular model and comparison procedure represent the data. It need not equal a count of discrete, isolated populations. Human genetic variation may include admixture, shared ancestry, geographic gradients, and other patterns that do not divide neatly into separate groups. A clustering model can approximate such variation using components even when no sharp biological boundaries exist.

For that reason, a component should not automatically be named as a specific population just because its estimated allele frequencies or ancestry proportions distinguish it in a fitted model. Interpretation requires relevant scientific context and careful attention to how the sample was collected and which individuals and markers were included. Choosing \(K\) answers a model-comparison question; it does not by itself settle a taxonomic, historical, or causal question.

A Practical Comparison Strategy

1
Specify candidate values and a consistent analysis.
Fit a considered range of \(K\) values using the same genotype set, preprocessing, model settings, and treatment of missing data.
2
Compare held-out prediction.
Choose a validation design relevant to the intended use and record the cross-validation loss, including its variation across folds.
3
Calculate a likelihood criterion where justified.
Use a consistent likelihood, count free parameters correctly, and state the sample-size assumptions used for BIC.
4
Repeat fits and assess stability.
Run each candidate \(K\) from multiple starts and compare likelihoods and matched ancestry-proportion estimates.
5
Report the basis and limits of the choice.
Describe which evidence supported the selected \(K\), any disagreement among criteria, and why the component count should not be read automatically as a population count.

Common Mistakes

  • Choosing the largest fitted likelihood. The likelihood generally improves as flexibility increases. Compare predictive performance or use an explicitly penalized criterion rather than treating the maximum as decisive.
  • Calling the cross-validation minimum “the true K.” It is the best score among the tested candidates under a particular validation design. It is not proof of a unique number of biological populations.
  • Ignoring assumptions behind BIC. The choice of \(n\) and the likelihood’s independence assumptions matter. Linked genotype observations cannot automatically be counted as independent contributions.
  • Treating stability as proof of correctness. Reproducibility across runs shows that an algorithm repeatedly finds similar fits; it does not establish that the model is adequate or that its components are discrete populations.
  • Comparing component labels without matching them. Component names are arbitrary across runs. Match corresponding components before comparing their estimated proportions.
Key takeaway: Choose \(K\) by considering held-out prediction, complexity-penalized likelihood, and repeat-run stability together. Report what each comparison supports and interpret the selected components as features of a model, not automatically as a count of discrete populations.

Check Your Understanding

Try these questions without looking back.

  1. Why can the maximized likelihood alone not fairly compare models with different values of \(K\)?
  2. A candidate model has a smaller held-out negative log loss than another. What does that indicate, and what does it not establish?
  3. For the same likelihood and parameter count, how do the AIC and BIC complexity penalties differ?
  4. Why can BIC be misleading if linked genotype observations are treated as independent without justification?
  5. Across three runs, ancestry proportions appear different before component matching. Why might this not indicate genuinely different fitted solutions?
  6. Explain why a selected \(K\) need not equal the number of discrete populations in the sampled data.
Clinical Biostats