Details
The haplotype matrix has dimensions n x 2*blocks: each individual contributes two phased copies per block. Column names encode block identity (e.g. hap_1_1 and hap_1_1_1 are the two copies of block 1).
For each block, the most-frequent allele (the baseline, dropped when drop_baseline = TRUE) is removed for identifiability; the remaining alleles become columns of \(W_{\alpha h}\) encoded with the Da (2015) rule. A frequency-weighted projection enforces the sum-to-zero constraint \(E[W_k] = 0\).
W_ah encoding (Da, 2015). For individual \(i\) with phased alleles \((A_i, A_j)\) at haplotype block \(h\), the column corresponding to non-baseline allele \(k\) (with population frequency \(p_k\)) is coded as:
-
Homozygous (\(A_i = A_j = k\)):
-
\(W_{\alpha h}^{(k)} = -2(1 - p_k)\)
-
Heterozygous (\(A_i = k\) or \(A_j = k\)):
-
\(W_{\alpha h}^{(k)} = -(1 - 2p_k)\)
-
Absent (\(A_i \neq k\) and \(A_j \neq k\)):
-
\(W_{\alpha h}^{(k)} = 2p_k\)
Rare alleles receive larger absolute deviations; common alleles receive smaller deviations. The population column-mean is zero by construction, ensuring the additive effects sum to zero across individuals.
Cross-validation / train-test split workflow:
-
Build the matrix on the training set: pass allele_freq_filtered = <freq_table> and reference_structure = NULL.
-
Build the matrix on the test set with the training structure: pass the entire training-set return value as reference_structure and leave allele_freq_filtered = NULL. This guarantees the test matrix has identical columns and the same baseline alleles as the training matrix.