MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step A.8

Module A · Genotype imputation · step 8 of 10

A.8Is the imputed variant good?

Commands tested on Windows

In short

We read the quality score that the imputation software gives to every imputed variant on chromosome 22. Because the data are simulated, we can compare it with the true quality, measured against the true genotypes, for common and rare variants.

Do this

You should see: 19,832 variants in the comparison with the truth; median R2 0.62, median true r2 0.35.

Command

Module setup, needed before this step

R: module setup

source("R/guided.R")cfg <- guided_init()

R command

Type or paste into the RStudio console.

1module_a <- file.path(cfg$data_dir, "module_a")info <- read_imputation_info(file.path(module_a, "imputed", "chr22.dose.vcf.gz"))print(data.frame(variants = nrow(info), measured_sites = sum(info$TYPED), median_ER2 = round(median(info$ER2[info$TYPED]), 2)))2quality <- compare_with_truth(file.path(module_a, "imputed", "chr22.dose.vcf.gz"),  file.path(module_a, "true_genotypes", "chr22_true_genotypes.vcf.gz"),  panel = file.path(module_a, "reference_panel", "panel_chr22.vcf.gz"))3table_a8 <- imputation_quality_table(quality)print(cbind(table_a8[1:2], round(table_a8[-(1:2)], 2)), row.names = FALSE)stopifnot(nrow(info) == 60224L, sum(info$TYPED) == 277L, nrow(quality) == 19832L)4guided_write(quality, guided_path(cfg, "A.8", "quality_chr22.tsv"))plot_imputation_quality(quality, guided_path(cfg, "A.8", "r2_chr22.png"))
  1. Note 1: Read the quality measures of every variant of the imputed output on chromosome 22.
  2. Note 2: Compare the reported R2 with the true r2, for every variant that varies in the samples.
  3. Note 3: Summarise by frequency class and check the number of variants.
  4. Note 4: Save the table and the figure.

You need

The imputed output of chromosome 22, the true genotypes of chromosome 22 and the reference panel of chromosome 22, all in the module A data.

What we do

Read the quality measures of the imputed output on chromosome 22. Then compare the quality that Minimac4 reports with the true quality, measured against the true genotypes of the simulation.

Why

Each imputed variant comes with a quality score. Minimac4 reports R2 (also written Rsq). IMPUTE reports the INFO score. They measure similar things and run from 0 to 1 (imputation quality (opens in a new tab)).

How Minimac4 computes R2. It compares the variance of the imputed dosages with the variance you would expect if the genotypes were known exactly. Because it is a ratio of two estimates, it can be slightly above 1. What R2 means, in words: how much of the information of a true genotype you actually have. An R2 of 0.8 means that 1,000 people with imputed dosages carry about as much information as 800 people with true genotypes. So a low R2 does not make results wrong. It makes them weak.

Measured sites get a second check. For sites that were on the array, Minimac4 hides each genotype in turn, imputes it and compares it with the measured value. This gives the empirical R2 (ER2). It tells you how well imputation works in your data.

Common filters. Keep variants with an R2 of at least 0.3 (permissive) or 0.8 (strict). The MaCH documentation recommends 0.3: it removes more than 70% of the poorly imputed variants and less than 0.5% of the well imputed ones. Neither threshold is perfect. A strict threshold also throws away true associations; a permissive one keeps more false ones (Stahl et al. 2025 (opens in a new tab)). Choose the threshold before you look at the results, and report it.

The true quality. Because the data are simulated, we know the true genotypes. The true r² is the squared correlation between the dosage and the true number of alternate alleles. We compare it with the reported R2 in groups of variants by their minor allele count (opens in a new tab) (MAC) and frequency. We leave out the array sites and the variants that do not vary in the samples.

The limits of these numbers. The course panel is small and the study is simulated, so the numbers show the direction, not the size you would get with HRC or TOPMed. The panel has 1,521 people, against about 32,000 in HRC and about 97,000 in TOPMed. Only 313 people of the panel are European, and only 106 are southern European. About 60% of the study is southern European. Each study genome is a mosaic of donor segments, so the LD across a junction is not that of a real genome. Almost no variant has a MAC of 1, because each donor haplotype was copied into several study genomes. So read the table for its pattern, not for its values.

Expected result

Show the expected result

60,224 variants in the dosage file, 277 of them measured on the array, with a median ER2 of 0.59. 19,832 variants in the comparison with the truth; median R2 0.62, median true r2 0.35.

ClassVariantsIn the panelMedian R2Median true r²R2 below 0.3R2 at least 0.8Mean R2 minus true r²
MAC 1989%0.220.3588%0%-0.16
MAC 2 to 436881%0.330.0045%4%+0.28
below 0.5%6,24483%0.370.0040%5%+0.22
0.5 to 1%2,02795%0.470.0618%6%+0.28
1 to 5%3,358100%0.650.353%20%+0.25
at least 5%7,826100%0.790.700%47%+0.13
all19,83294%0.620.3514%26%+0.19

How to read it:

  • Common variants are imputed well, and R2 follows the true r² closely.
  • Rare variants are imputed poorly, and R2 overestimates their quality. Below 1%, the median R2 is 0.37 to 0.47, while the median true r² is close to 0. The filter R2 at least 0.3 removes 40% of the variants below 0.5%.
  • About one in six variants below 0.5% is not in the panel at all, so it cannot be imputed.

The figure sA-8_r2_chr22.png shows the same comparison, variant by variant. Points below the orange diagonal are variants whose R2 is too optimistic.

Validation: executable chunks passed on Windows with R 4.5.2 on the module A data (release module-a-2026.1). The table equals the comparison made by the author with an independent Python script.

Four scatter plots of reported R2 against true r2 for the imputed variants of chromosome 22, one for each frequency class: below 0.5%, 0.5 to 1%, 1 to 5% and at least 5%. Each plot has dashed vertical lines at R2 0.3 and 0.8 and an orange diagonal where R2 equals true r2. For variants of at least 5%, the points follow the diagonal closely (median R2 0.79, median true r2 0.70). For variants below 1%, most points lie well below the diagonal, many with a true r2 near zero although R2 is between 0.3 and 0.8.
Reported R2 against true r2 on chromosome 22, by frequency class. Each point is one imputed variant. Points below the orange diagonal are variants whose R2 is too optimistic.

If something goes wrong

If something goes wrong

"The module A data were not found", "Some module A data are missing" or another stop in the first chunk: run the download command of step A.1 in the Console. Do not extract the ZIP file by hand. "samples of the dosage file are not in the truth file": the dosage and truth files come from different releases; use the files of one module A release. The comparison needs about 1 GB of memory and two minutes. Close other programs if R stops with a memory error.

Quick check

A rare variant has an R2 of 0.6. Can you trust it as much as a common variant with the same R2?

Show the answer

No. In the table, R2 is too optimistic for rare variants: below 1%, the median true r² is close to 0 although the median R2 is about 0.4. A rare imputed hit needs extra checks, ideally direct genotyping.

Files created

sA-8_quality_chr22.tsv (one row per variant: class, R2, true r²) and sA-8_r2_chr22.png (the figure).

Another approach (optional)

Another approach (optional)

Hide some array sites and impute them. You can measure imputation quality on your own data, without a truth file. Hide some of the sites you measured, impute them, and compare the dosages with the genotypes you know. This needs Eagle2 and Minimac4 (the box of step A.7).

  1. Choose 5% of the array sites in the regions at random, with a fixed seed. In the course run: 22 of 438 sites.
  2. Write the input VCF without them (PLINK --exclude with the list of their IDs) and run phasing and imputation again.
  3. For each hidden site, compare the dosage with the measured genotype: true r², and the share of best-guess genotypes that match.

Expected result. In the course run all 22 sites were imputed. Median R2 0.70, median true r² 0.46. The best-guess genotypes were right in 89% of cases on average. R2 and true r² correlate well (0.93), but R2 is higher, most of all for sites below 5%. One site at 1.7% had an R2 of 0.44 and a true r² of 0.08.

Reference. Marchini and Howie 2010 (opens in a new tab), section on information measures.