MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 6.6

Module 6 · Association · step 6 of 8

6.6Sparse genotypes and Firth correction

Commands tested on Windows

In short

We choose the variant with the lowest frequency of its less common DNA version among the valid tests on chromosomes 1 to 22 and compare its ordinary model result with a forced Firth result. Firth correction gives usable estimates when very few people carry the allele, but it does not add information.

Do this

You should see: One forced Firth result with a finite value, next to the ordinary estimate from the main scan for the same A1 allele.

Command

Module setup, needed before this step

R: module setup

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

Blue: PLINK option · Orange: value you can change · Green: file name

R command

Type or paste into the RStudio console.

1results <- guided_association(guided_path(cfg, "6.4", "association"))minor <- pmin(results$A1_FREQ, 1 - results$A1_FREQ)candidates <- which(results$CHROM %in% as.character(1:22) & valid_p(results$P) & minor > 0)chosen <- results$ID[candidates[which.min(minor[candidates])]]2guided_list(chosen, guided_path(cfg, "6.6", "variant.txt"))run_plink(cfg, c("--pfile", guided_path(cfg, "5.7"), "--snp", chosen, "--covar", guided_path(cfg, "6.3", "covariates.tsv"),  "--covar-name", "Age,PC1-PC10", "--covar-variance-standardize", "--glm", "firth", "sex", "hide-covar", "--out", guided_path(cfg, "6.6", "firth")))3comparison <- guided_association(guided_path(cfg, "6.6", "firth"))print(results[results$ID == chosen, c("ID", "A1", "OR", "P")])print(comparison[, c("ID", "A1", "OR", "P")])stopifnot(nrow(comparison) == 1L, valid_p(comparison$P))
  1. Note 1: Choose the least frequent variant among valid tests on chromosomes 1 to 22.
  2. Note 2: Save the chosen variant ID and force the Firth model at that variant.
  3. Note 3: Print both estimates and check that the Firth test gives one valid result.

You need

The final cohort, the main results from 6.4 and the covariates from 6.3.

What we do

Compare an ordinary fit with a Firth fit that we force at one low-frequency autosomal variant. The variant is one of the retained variants.

Why

A rare genotype can have very few cases or controls. The ordinary logistic fit uses maximum likelihood (opens in a new tab). It chooses the coefficients that make the observed outcomes most likely under the model. Sometimes one genotype group contains only cases or only controls. This is separation, and the coefficient can then grow without limit. Firth correction (opens in a new tab) reduces the bias of small samples and can give finite estimates. It does not add information. It does not fix confounding, wrong genotype calls or a poor study design. The main scan of this dataset did not need the Firth fallback. We force Firth here so that you can compare the two results at one variant. Variants below the 1% frequency filter do not come back.

What each option does

Each option, with the modifiers under the option they belong to.
Option or modifierWhat it does
--pfile

Reads s5-7_state.pgen, .pvar and .psam, which hold the final study genotypes and sample details.

--snp

Selects the one variant that R chose from the valid tests on chromosomes 1 to 22: the variant with the lowest frequency of its less common DNA version. R saves its ID in s6-6_variant.txt. In a terminal, type that ID instead of VARIANT_ID.

--covar

Reads s6-3_covariates.tsv, matching age and genetic component scores to samples by their IDs.

--covar-name

Selects Age and PC1 to PC10 as extra factors to adjust the disease comparison; each PC describes one pattern of genetic variation.

--covar-variance-standardize

Rescales the numerical adjustment factors to mean zero and variance one, a common scale that helps the model calculation remain stable.

--glm

Fits a logistic model at the selected variant to estimate how each extra copy of the tested DNA version changes the odds of disease. The odds of disease are the chance of having the disease divided by the chance of not having it.

Modifier of --glm: firth

Always uses Firth correction, which gives usable estimates when very few people carry the allele, rather than waiting for the ordinary model calculation to fail.

Modifier of --glm: sex

Adds the recorded sex from s5-7_state.psam as an adjustment factor in the model.

Modifier of --glm: hide-covar

Reports the genetic test without separate rows for the effects of age, sex and genetic component scores.

--out

Starts output file names with s6-6_firth for the forced Firth result.

Every command also uses --threads 2 (PLINK runs at most two tasks at the same time) and --memory 2048 (PLINK uses at most about 2 GB of memory).

PLINK terminal equivalent. Optional: you do not need it for the course.

Blue: PLINK option · Orange: value you can change · Green: file name

Terminal equivalent: plain PLINK 2

Select any option to see what it does. Do not paste terminal commands into the R console.

Command

bin/plink2

No option selected. Each underlined part of the command is an option you can open.

Use bin\plink2.exe on Windows.

Expected result

Show the expected result

One forced Firth result with a finite value, next to the ordinary estimate from the main scan for the same A1 allele. Small differences in the numbers are normal. Forced Firth is not a better scan for the whole genome.

The tested PLINK version is defined in config.R and recorded in software_versions.txt. Validation: executable chunks passed on Windows; main test counts and significance match the expected values.

If something goes wrong

If something goes wrong

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

Quick check

Does Firth correction make an association precise when it rests on very few carriers?

Show the answer

No. It makes the fit more stable, but the uncertainty can stay large.

Files created

The chosen variant ID, the forced Firth report and the log files.

Under the hood & literature

Under the hood & literature

What the tool computes. Ordinary logistic regression chooses the coefficients that maximise the likelihood. Firth regression maximises a penalised likelihood instead: it adds half the log-determinant of the Fisher information (the Jeffreys prior). This removes the leading term of the small-sample bias and keeps the estimates finite. When one genotype group holds only cases or only controls, the ordinary estimate does not exist. The report gives OR (the exponential of the coefficient for the A1 allele), the standard error of the log odds ratio, the Z statistic and P. PLINK 2 reports an asymptotic p-value from the Wald Z statistic, also for Firth fits.

Why these values. The main scan used firth-fallback, PLINK's default, which switches to Firth only when the ordinary fit fails. We force firth once so you can compare. The 1% frequency filter keeps the rarest variants out of the scan.

Pitfalls. Firth shrinks estimates towards no effect and gives no new information. With few carriers the Wald p-value can mislead. Penalised likelihood ratio tests and profile confidence intervals are often preferable to the Wald test. For low-count variants (roughly fewer than 400 minor alleles), simulations favour a Firth likelihood ratio test over the plain Wald, score or likelihood ratio tests in joint analysis. PLINK 2 reports a Wald p-value from the Firth fit instead, so treat borderline results with care. Always look at the carrier counts and doubt genotype calls at rare variants. The spelling --covar-variance-standardize is American; the course text says standardise.

References

  1. Firth D (1993) Bias reduction of maximum likelihood estimates. Biometrika 80:27-38. doi:10.1093/biomet/80.1.27.
  2. Albert A, Anderson JA (1984) On the existence of maximum likelihood estimates in logistic regression models. Biometrika 71:1-10. doi:10.1093/biomet/71.1.1.
  3. Heinze G, Schemper M (2002) A solution to the problem of separation in logistic regression. Stat Med 21:2409-2419. PMID 12210625.
  4. Ma C et al. (2013) Recommended joint and meta-analysis strategies for case-control association testing of single low-count variants. Genet Epidemiol 37:539-550. PMID 23788246.