Skip to contents

This function computes pairwise Pearson correlations from a genotype matrix using the exact same formula and floating-point operation order as the original DENTIST C++ binary (calcLDFromBfile_gcta in bfileOperations.cpp). Key differences from R's crossprod-based approach: 1. Accumulates integer-valued sums sequentially (exact intermediate values) 2. Handles per-pair missing data with GCTA correction formula 3. Divides by nKeptSample (trimmed to multiple of 4), not nrow(X)

Usage

compute_LD_gcta_cpp(X, ncpus = 1L)

Arguments

X

Numeric genotype matrix (samples x SNPs), values in 0, 1, 2, NA. Rows should already be trimmed to a multiple of 4.

ncpus

Number of CPU threads for parallel computation.

Value

Symmetric LD correlation matrix with 1.0 on diagonal.