harmonize_mr_data: Harmonize exposure and outcome SNP data

View source: R/mr_transform.R

harmonize_mr_dataR Documentation

Harmonize exposure and outcome SNP data

Description

Takes a data frame that already contains all required MR columns, aligns outcome alleles to the exposure strand (Step 1), then standardizes the sign of beta_exposure (Step 2). Returns both a full working data frame (check_df) and a slim, renamed input data frame (input_df), mirroring the output of format_mr_input().

Usage

harmonize_mr_data(
  df,
  Outcome = NULL,
  Exposure = NULL,
  beta_sign = c("positive", "negative")
)

Arguments

df

Data frame containing required columns: beta_exposure, se_exposure, beta_outcome, se_outcome, Outcome, Exposure. Allele columns may be supplied as NEA_exposure/EA_exposure/NEA_outcome/EA_outcome, or as ALLELE1 (NEA) / ALLELE0 (EA) which are treated as exposure alleles.

Outcome

Optional; character string to set as the Outcome name when the column is absent from df.

Exposure

Optional; character string to set as the Exposure name when the column is absent from df.

beta_sign

Character string controlling the target sign for beta_exposure after harmonization. One of "positive" (default, forces beta_exposure >= 0) or "negative" (forces beta_exposure <= 0). When a row is flipped, beta_outcome is negated as a side effect and all allele columns are swapped consistently.

Value

A named list with two elements:

check_df

Full working data frame retaining all allele columns after harmonization. Useful for quality-checking results.

input_df

Slim data frame ready for MR analysis, with columns: Instrument, beta_exposure, se_exposure, beta_outcome, se_outcome, Outcome, Exposure, ALLELE1, ALLELE0, A1FREQ.

Examples

result1 <- harmonize_mr_data(df = fi_49item)
head(result1$check_df)
head(result1$input_df)

# Force all exposure betas to be negative
result2 <- harmonize_mr_data(df = fi_49item, beta_sign = "negative")
head(result2$input_df)

autoMR documentation built on June 12, 2026, 9:07 a.m.