Module 7 · Plots and reporting · step 2 of 8
7.2Genomic inflation factor
Commands tested on Windows
In short
We calculate lambda, a number that compares the middle of the test results with what chance predicts. We check that it is close to 1.016 and save it to help assess the results alongside the QQ plot.
Do this
- Paste in the RStudio ConsoleThe R command in the Command section below
You should see: Lambda is approximately 1.016.
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)2p <- stats$p_value[stats$chromosome %in% as.character(1:22)]3lambda <- lambda_gc(p)print(lambda)stopifnot(abs(lambda - 1.016) < 0.001)4guided_write(data.frame(model = "QC plus ten PCs", lambda = lambda), guided_path(cfg, "7.2", "lambda.tsv"))- Note 1: Read the saved association summary table.
- Note 2: Select p-values for chromosomes 1 to 22.
- Note 3: Calculate and check the overall size of the test results.
- Note 4: Save lambda in a table.
You need
The same autosomal p-values that we used at 7.1. R reads them from the summary statistics file made at step 6.8.
What we do
Calculate lambda for the autosomal variants. Then read it together with the QQ plot.
Why
The genomic inflation factor, lambda (opens in a new tab), is one number that tells if the p-values are too small overall. This problem is called inflation (opens in a new tab). We calculate lambda in three steps. First, we convert each valid p-value into a chi-square statistic (opens in a new tab). Second, we take the median (opens in a new tab) of these statistics, the middle value after sorting. Third, we divide this median by the value expected by chance, which is approximately 0.4549.
A lambda near one means that the middle of the results looks as expected. It does not prove that there is no confounding. Lambda also depends on the sample size, on how many variants have small true effects, on the model and on the set of variants tested. Do not divide every test by lambda without thinking. Do not treat one cut-off as a simple pass or fail.
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
Lambda is approximately 1.016. R calculates it from the valid autosomal tests.
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
Can a lambda near one prove that a particular top variant is causal?
Show the answer
No. Lambda summarises the middle of all the tests. It does not show that one single association is valid or causal.
Files created
s7-2_lambda.tsv.