MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 7.1

Module 7 · Plots and reporting · step 1 of 8

7.1QQ plot

Commands tested on Windows

In short

We draw a QQ plot, which compares observed p-values with those expected by chance, using chromosomes 1 to 22. This helps us see whether most tests behave as expected and whether the results with the smallest p-values stand out.

Do this

You should see: Most points are close to the diagonal line.

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.

1stats <- guided_summary_stats(cfg)2autosomal <- stats$chromosome %in% as.character(1:22)3save_plot(guided_path(cfg, "7.1", "qq.png"), function() plot_qq(stats$p_value[autosomal], "Adjusted simulated GWAS: autosomal QQ plot"))
  1. Note 1: Read the saved association summary table.
  2. Note 2: Select chromosomes 1 to 22 for the plot.
  3. Note 3: Save the plot comparing observed p-values with values expected by chance.

You need

The summary statistics file from step 6.8. If R says that the file is missing, run step 6.8 first.

What we do

Draw a quantile-quantile (QQ) plot. It compares the p-values we observed with the p-values we would expect if no variant were associated with the disease. We use only the autosomal (opens in a new tab) variants, on chromosomes 1 to 22.

The plot reads the summary statistics file (opens in a new tab) that we made at step 6.8. This file is a table with one row for each tested variant. Each row holds the chromosome, the position, the alleles, the odds ratio, the standard error, the p-value and the number of samples. The plots in this module all read this one file, so every figure comes from the same results.

Why

A QQ plot (opens in a new tab) puts the observed p-values in order and pairs each one with the value that we expect by chance. If no variant is associated with the disease, the p-values (opens in a new tab) are spread evenly between 0 and 1. The plot shows -log10 of each p-value. This turns small p-values into large positive numbers, so very small p-values appear high on the plot.

If the tests behave well, the points follow the diagonal line. A few associations with very small p-values lift only the highest points at the right end. A wider departure along the whole line can have several causes: confounding (opens in a new tab), technical problems, a wrong model or many true small effects. The picture alone cannot tell these causes apart. Nearby variants can be correlated through linkage disequilibrium (LD) (opens in a new tab), so the points are not fully independent.

The top left corner of the plot shows a number called lambda. Lambda summarises how far the middle of the p-values departs from what chance predicts. We only read it as a first hint here. We explain it and calculate it in step 7.2.

Illustration in preparation

Alt text: Most adjusted autosomal tests follow the null diagonal, with an upper-tail departure from a few association signals.
PLINK terminal equivalent. Optional: you do not need it for the course.

Not applicable: this step needs no PLINK command. The R chunk is the complete command.

R reads or calculates the displayed values without changing the genotype files.

Expected result

Show the expected result

Most points are close to the diagonal line. The highest points at the right end leave the line by a wide margin. Missing, zero or invalid p-values are not drawn as if they were very small p-values. R saves the picture as a PNG file and prints its path. It does not show the picture in the console. To see it, open the file from the Files pane of RStudio (click the file name, then choose "View File").

The tested PLINK version is set in config.R and recorded in software_versions.txt. Validation: the executable chunks, the comparisons with the expected results and the final plot checks passed on Windows.

If something goes wrong

If something goes wrong

Stop at the first error. Check the input file that R names and the previous step. Keep the command and the messages from the console. Do not use files from a different version of the dataset. See troubleshooting (opens in a new tab).

Quick check

Does a large departure only at the highest points always mean confounding across the whole genome?

Show the answer

No. A few true signals can lift the highest points while most other tests stay close to the line.

Files created

s7-1_qq.png.