RHE Model
The RHE class implements the Randomized Haseman-Elston regression model for heritability estimation. It inherits from the Base class and provides efficient estimation of additive genetic variance components.
Variance Components
The RHE model estimates:
Additive genetic variance components (σ²g) for each bin
Environmental variance component (σ²e)
Total heritability (h²)
Enrichment scores
Class Inheritance
class RHE(Base):
"""Randomized Haseman-Elston regression model."""
Key Methods
- get_num_estimates()
Returns the number of variance components to estimate:
Returns
num_binfor additive genetic effects
- get_M_last_row()
Specifies the last row of the M matrix:
Returns
self.len_binfor additive effectsself.len_binis provided by the base class, which is the number of SNPs in each bin.
- pre_compute_jackknife_bin(j, all_gen)
Pre-computes statistics for jackknife estimation:
- Parameters:
def pre_compute_jackknife_bin(j, all_gen): for k, X_kj in enumerate(all_gen): # Loop through the partitioned genotype matrix # 1. Process genotype data X_kj = self.standardize_geno(X_kj) # 2. Update M matrix self.M[j][k] = self.M[self.num_jack][k] - X_kj.shape[1] # 3. Compute statistics for b in range(self.num_random_vec): self.XXz[k, j, b, :] = self._compute_XXz(b, X_kj) if self.use_cov: self.UXXz[k, j, b, :] = self._compute_UXXz(self.XXz[k][j][b]) self.XXUz[k, j, b, :] = self._compute_XXUz(b, X_kj) # 4. Compute phenotype-related statistics self.yXXy[k][j] = self._compute_yXXy(X_kj, y=self.pheno)
- b_trace_calculation(k, j, b_idx)
Calculates trace terms for variance estimation:
Returns
num_indvfor standardized genotypes
- run(method)
Runs the complete RHE analysis:
- Parameters:
method (str) – Estimation method (“lstsq” or “QR”)
- Returns:
Dictionary containing: - sigma_ests_total: Estimated variance components - sig_errs: Standard errors of variance components - h2_total: Heritability estimates - h2_errs: Standard errors of heritability - enrichment_total: Enrichment scores - enrichment_errs: Standard errors of enrichment - h2_jackknife_overlap: Jackknife heritability estimates computed based on overlapping setting - h2_errs_overlap: Standard errors of jackknife heritability computed based on overlapping setting - h2_total_overlap: Overlapping heritability estimates computed based on overlapping setting - h2_errs_total_overlap: Standard errors of overlapping heritability computed based on overlapping setting
Usage Example
from pyrhe.models import RHE
# Initialize model
rhe_model = RHE(
geno_file="path/to/genotype",
annot_file="path/to/annotation",
pheno_file="path/to/phenotype",
cov_file="path/to/covariate",
num_bins=10,
num_jack=100,
num_random_vec=10,
num_workers=5,
...
)
# Run analysis
results = rhe_model()
# Access results
# The outputs are automatically logged in the output file.
# In addition, you can also access the results:
print(results)
print(results['sigma_ests_total'])
# The results are stored in a dictionary. The keys are:
# - sigma_ests_total: Estimated variance components
# - sig_errs: Standard errors of variance components
# - h2_total: Heritability estimates
# - h2_errs: Standard errors of heritability
# - enrichment_total: Enrichment scores
# - enrichment_errs: Standard errors of enrichment
# - h2_jackknife_overlap: Jackknife heritability estimates computed based on overlapping setting
# - h2_errs_overlap: Standard errors of jackknife heritability computed based on overlapping setting
# - h2_total_overlap: Overlapping heritability estimates computed based on overlapping setting
# - h2_errs_total_overlap: Standard errors of overlapping heritability computed based on overlapping setting